Skip to content

Commit

Permalink
Merge branch 'main' into change-runners-to-matterlabs-ci-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
artmakh authored Oct 9, 2023
2 parents ebdcf41 + da98913 commit c723644
Show file tree
Hide file tree
Showing 12 changed files with 1,045 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/dist/
22 changes: 12 additions & 10 deletions .github/workflows/app-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ on:
required: false

env:
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
ALLURE_SEARCH_REQUEST: '[{"id":"name","type":"string","value":"#${{ github.run_number }}"}]'
ALLURE_BASIC_TAGS: "${{ github.head_ref }}, #${{ github.run_number }}, ${{ github.event.pull_request.title }}"
ALLURE_PROJECT_ID: ${{ vars.ALLURE_PROJECT_ID }}
Expand All @@ -45,15 +44,15 @@ jobs:
matrix:
tags: [
"@artifactsSet1",
# "@artifactsSet2",
# "@artifactsSet3",
# "@artifactsSet4",
# "@redirectionSet1",
# "@redirectionSet2",
# "@redirectionSet3",
# "@copying",
# "@search",
# "@testnetSmokeSuite"
"@artifactsSet2",
"@artifactsSet3",
"@artifactsSet4",
"@redirectionSet1",
"@redirectionSet2",
"@redirectionSet3",
"@copying",
"@search",
"@testnetSmokeSuite"
]

name: '${{ matrix.tags }}'
Expand Down Expand Up @@ -110,11 +109,14 @@ jobs:
env:
ALLURE_LAUNCH_NAME: "#${{ github.run_number }} ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
ALLURE_LAUNCH_TAGS: "${{ env.ALLURE_BASIC_TAGS }}, ${{ env.MATRIX_TAG_WITHOUT_QUOTES }}"
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
run: |
echo "ALLURE_LAUNCH_ID=$(./allurectl launch create --launch-name '${{ env.ALLURE_LAUNCH_NAME }}' --no-header --format ID | tail -n1)" >> $GITHUB_ENV
- name: Upload tests to the Allure proj
if: always() && inputs.publish_to_allure == true
env:
ALLURE_TOKEN: ${{ secrets.ALLURE_TOKEN }}
run: |
./allurectl upload allure-results --launch-id ${{ env.ALLURE_LAUNCH_ID }}
./allurectl launch close ${{ env.ALLURE_LAUNCH_ID }}
Expand Down
7 changes: 7 additions & 0 deletions packages/api/src/api/api.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ describe("ApiController", () => {
});
});

describe("getContractSourceCode", () => {
it("returns null as it is defined only to appear in docs and cannot be called", async () => {
const result = await controller.getContractSourceCode();
expect(result).toBe(null);
});
});

describe("getContractCreation", () => {
it("returns null as it is defined only to appear in docs and cannot be called", async () => {
const result = await controller.getContractCreation();
Expand Down
36 changes: 34 additions & 2 deletions packages/api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Controller, Get, Query, Req, Next, UseFilters } from "@nestjs/common";
import { ApiTags, ApiOkResponse, ApiExcludeEndpoint, ApiQuery, ApiExtraModels } from "@nestjs/swagger";
import { ApiTags, ApiOkResponse, ApiExcludeEndpoint, ApiQuery, ApiExtraModels, ApiOperation } from "@nestjs/swagger";
import { Request, NextFunction } from "express";
import { PagingOptionsWithMaxItemsLimitDto } from "./dtos/common/pagingOptionsWithMaxItemsLimit.dto";
import { ContractAbiResponseDto } from "./dtos/contract/contractAbiResponse.dto";
import { ContractCreationResponseDto, ContractCreationInfoDto } from "./dtos/contract/contractCreationResponse.dto";
import { ContractSourceCodeResponseDto } from "./dtos/contract/contractSourceCodeResponse.dto";
import { TransactionStatusResponseDto, TransactionStatusDto } from "./dtos/transaction/transactionStatusResponse.dto";
import { TransactionReceiptStatusResponseDto } from "./dtos/transaction/transactionReceiptStatusResponse.dto";
import { AccountTransactionDto } from "./dtos/account/accountTransaction.dto";
Expand Down Expand Up @@ -49,6 +50,7 @@ export class ApiController {

@ApiTags("Contract API")
@Get("api?module=contract&action=getabi")
@ApiOperation({ summary: "Fetch the ABI for a given contract address" })
@ApiQuery({
name: "address",
description: "The contract address that has a verified source code",
Expand All @@ -63,8 +65,26 @@ export class ApiController {
return null;
}

@ApiTags("Contract API")
@Get("api?module=contract&action=getsourcecode")
@ApiOperation({ summary: "Fetch the source code for a given contract address" })
@ApiQuery({
name: "address",
description: "The contract address that has a verified source code",
example: "0x8A63F953e19aA4Ce3ED90621EeF61E17A95c6594",
required: true,
})
@ApiOkResponse({
description: "Contract source code",
type: ContractSourceCodeResponseDto,
})
public async getContractSourceCode(): Promise<ContractSourceCodeResponseDto> {
return null;
}

@ApiTags("Contract API")
@Get("api?module=contract&action=getcontractcreation")
@ApiOperation({ summary: "Fetch creation details for a list of contract addresses" })
@ApiQuery({
isArray: true,
explode: false,
Expand All @@ -75,7 +95,7 @@ export class ApiController {
})
@ApiExtraModels(ContractCreationInfoDto)
@ApiOkResponse({
description: "Contract creation info",
description: "Contract creation information",
type: ContractCreationResponseDto,
})
public async getContractCreation(): Promise<ContractCreationResponseDto> {
Expand All @@ -84,6 +104,7 @@ export class ApiController {

@ApiTags("Transaction API")
@Get("api?module=transaction&action=getstatus")
@ApiOperation({ summary: "Fetch the status for a given transaction hash" })
@ApiQuery({
name: "txhash",
description: "The transaction hash to check the execution status",
Expand All @@ -101,6 +122,7 @@ export class ApiController {

@ApiTags("Transaction API")
@Get("api?module=transaction&action=gettxreceiptstatus")
@ApiOperation({ summary: "Fetch the receipt status for a given transaction hash" })
@ApiQuery({
name: "txhash",
description: "The transaction hash to check the execution status",
Expand All @@ -117,6 +139,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=txlist")
@ApiOperation({ summary: "Retrieve transactions for a given address" })
@ApiQuery({
name: "address",
description: "The address to filter transactions by",
Expand Down Expand Up @@ -151,6 +174,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=txlistinternal")
@ApiOperation({ summary: "Retrieve internal transactions for a given address or transaction hash" })
@ApiQuery({
name: "address",
description: "The address to filter internal transactions by",
Expand Down Expand Up @@ -191,6 +215,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=balance")
@ApiOperation({ summary: "Retrieve the balance for a given address" })
@ApiQuery({
name: "address",
description: "The address to get Ether balance for",
Expand All @@ -207,6 +232,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=balancemulti")
@ApiOperation({ summary: "Retrieve the balances for a list of addresses" })
@ApiQuery({
isArray: true,
explode: false,
Expand All @@ -225,6 +251,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokenbalance")
@ApiOperation({ summary: "Retrieve token balance for a specific address" })
@ApiQuery({
name: "address",
description: "The address to get Token balance for",
Expand All @@ -247,6 +274,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokentx")
@ApiOperation({ summary: "Retrieve token transfers for a specific address or token contract" })
@ApiQuery({
name: "address",
description: "The address to get transfers for",
Expand Down Expand Up @@ -287,6 +315,7 @@ export class ApiController {

@ApiTags("Account API")
@Get("api?module=account&action=tokennfttx")
@ApiOperation({ summary: "Retrieve NFT transfers for a specific address" })
@ApiQuery({
name: "address",
description: "The address to get transfers for",
Expand Down Expand Up @@ -327,6 +356,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblocknobytime")
@ApiOperation({ summary: "Retrieve block number closest to a specific timestamp" })
@ApiQuery({
name: "timestamp",
type: "integer",
Expand All @@ -351,6 +381,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblockcountdown")
@ApiOperation({ summary: "Retrieve countdown details for a specific block number" })
@ApiQuery({
name: "blockno",
type: "integer",
Expand All @@ -368,6 +399,7 @@ export class ApiController {

@ApiTags("Block API")
@Get("api?module=block&action=getblockreward")
@ApiOperation({ summary: "Retrieve block reward details for a specific block number" })
@ApiQuery({
name: "blockno",
type: "integer",
Expand Down
102 changes: 102 additions & 0 deletions packages/api/src/api/contract/contract.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { AddressService } from "../../address/address.service";
import { Address } from "../../address/address.entity";
import { ResponseStatus, ResponseMessage } from "../dtos/common/responseBase.dto";
import { ContractController, parseAddressListPipeExceptionFactory } from "./contract.controller";
import { SOURCE_CODE_EMPTY_INFO, mapContractSourceCode } from "../mappers/sourceCodeMapper";

jest.mock("../mappers/sourceCodeMapper", () => ({
...jest.requireActual("../mappers/sourceCodeMapper"),
mapContractSourceCode: jest.fn().mockReturnValue({ mockMappedSourceCode: true }),
}));

describe("ContractController", () => {
let controller: ContractController;
Expand Down Expand Up @@ -142,6 +148,102 @@ describe("ContractController", () => {
});
});

describe("getContractSourceCode", () => {
let pipeMock = jest.fn();

beforeEach(() => {
pipeMock = jest.fn();
jest.spyOn(httpServiceMock, "get").mockReturnValue({
pipe: pipeMock,
} as unknown as rxjs.Observable<AxiosResponse>);
jest.spyOn(rxjs, "catchError").mockImplementation((callback) => callback as any);
});

it("throws error when contract verification info API fails with a server error", async () => {
pipeMock.mockImplementation((callback) => {
callback({
stack: "error stack",
response: {
data: "response data",
status: 500,
},
} as AxiosError);
});

await expect(controller.getContractSourceCode(address)).rejects.toThrowError(
new InternalServerErrorException("Failed to get contract source code")
);
});

it("returns empty source code when response API fails with with no data", async () => {
pipeMock.mockImplementation((callback) => {
return callback({
stack: "error stack",
} as AxiosError);
});

const response = await controller.getContractSourceCode(address);
expect(response).toEqual({
status: ResponseStatus.OK,
message: ResponseMessage.OK,
result: [SOURCE_CODE_EMPTY_INFO],
});
});

it("returns empty source code response when contract verification info is not found", async () => {
pipeMock.mockImplementation((callback) => {
return callback({
stack: "error stack",
response: {
data: "response data",
status: 404,
},
} as AxiosError);
});

const response = await controller.getContractSourceCode(address);
expect(response).toEqual({
status: ResponseStatus.OK,
message: ResponseMessage.OK,
result: [SOURCE_CODE_EMPTY_INFO],
});
});

it("returns mapped source code for verified contract", async () => {
const data = {
artifacts: {
abi: [],
},
request: {
sourceCode: "sourceCode",
constructorArguments: "0x0001",
contractName: "contractName",
optimizationUsed: false,
compilerSolcVersion: "8.10.0",
compilerZksolcVersion: "10.0.0",
},
};

pipeMock.mockReturnValue(
new rxjs.Observable((subscriber) => {
subscriber.next({
data,
});
})
);

const response = await controller.getContractSourceCode(address);
expect(mapContractSourceCode as jest.Mock).toHaveBeenCalledWith(data);
expect(mapContractSourceCode as jest.Mock).toHaveBeenCalledTimes(1);
expect(httpServiceMock.get).toBeCalledWith(`http://verification.api/contract_verification/info/${address}`);
expect(response).toEqual({
message: "OK",
result: [{ mockMappedSourceCode: true }],
status: "1",
});
});
});

describe("getContractCreation", () => {
it("thrown an error when called with more than 5 addresses", async () => {
await expect(
Expand Down
Loading

0 comments on commit c723644

Please sign in to comment.