Skip to content

Commit

Permalink
fix: api tests coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyl-ivanchuk committed Oct 2, 2023
1 parent a284d6c commit 1dc69d0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
43 changes: 37 additions & 6 deletions packages/api/src/api/contract/contract.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,37 @@ describe("ContractController", () => {
);
});

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: [
{
ABI: "Contract source code not verified",
CompilerVersion: "",
ConstructorArguments: "",
ContractName: "",
EVMVersion: "Default",
Implementation: "",
Library: "",
LicenseType: "Unknown",
OptimizationUsed: "",
Proxy: "0",
Runs: "",
SourceCode: "",
SwarmSource: "",
},
],
});
});

it("returns empty source code response when contract verification info API fails with response status 404", async () => {
pipeMock.mockImplementation((callback) => {
return callback({
Expand Down Expand Up @@ -218,7 +249,7 @@ describe("ContractController", () => {
sourceCode: "sourceCode",
constructorArguments: "0x0001",
contractName: "contractName",
optimizationUsed: true,
optimizationUsed: false,
compilerSolcVersion: "8.10.0",
compilerZksolcVersion: "10.0.0",
},
Expand All @@ -241,7 +272,7 @@ describe("ContractController", () => {
Implementation: "",
Library: "",
LicenseType: "",
OptimizationUsed: "1",
OptimizationUsed: "0",
Proxy: "0",
Runs: "",
SourceCode: "sourceCode",
Expand Down Expand Up @@ -280,7 +311,7 @@ describe("ContractController", () => {
},
},
},
constructorArguments: "0x0001",
constructorArguments: "0001",
contractName: "contractName",
optimizationUsed: true,
compilerSolcVersion: "8.10.0",
Expand Down Expand Up @@ -332,7 +363,7 @@ describe("ContractController", () => {
sourceCode: "sourceCode",
constructorArguments: "0x0001",
contractName: "contractName",
optimizationUsed: true,
optimizationUsed: false,
compilerVyperVersion: "9.10.0",
compilerZkvyperVersion: "11.0.0",
},
Expand All @@ -355,7 +386,7 @@ describe("ContractController", () => {
Implementation: "",
Library: "",
LicenseType: "",
OptimizationUsed: "1",
OptimizationUsed: "0",
Proxy: "0",
Runs: "",
SourceCode: "sourceCode",
Expand Down Expand Up @@ -394,7 +425,7 @@ describe("ContractController", () => {
},
},
},
constructorArguments: "0x0001",
constructorArguments: "0001",
contractName: "contractName",
optimizationUsed: true,
compilerVyperVersion: "9.10.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/api/contract/contract.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class ContractController {
? data.request.sourceCode
: `{${JSON.stringify(data.request.sourceCode)}}`,
// remove leading 0x as Etherscan does
ConstructorArguments: data.request.constructorArguments?.startsWith("0x")
ConstructorArguments: data.request.constructorArguments.startsWith("0x")
? data.request.constructorArguments.substring(2)
: data.request.constructorArguments,
ContractName: data.request.contractName,
Expand Down

0 comments on commit 1dc69d0

Please sign in to comment.