-
Notifications
You must be signed in to change notification settings - Fork 140
fix: verification endpoint alignment with etherscan #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4484934
e3f982f
1264ed3
3ca1ce0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,6 @@ import { | |
| ContractVerificationStatusResponse, | ||
| } from "../types"; | ||
| import { VerifyContractResponseDto } from "../dtos/contract/verifyContractResponse.dto"; | ||
|
|
||
| const entityName = "contract"; | ||
|
|
||
| export const parseAddressListPipeExceptionFactory = () => new BadRequestException("Missing contract addresses"); | ||
|
|
@@ -136,6 +135,14 @@ export class ContractController { | |
| ContractVerificationCodeFormatEnum.solidityJsonInput, | ||
| ].includes(request.codeformat); | ||
|
|
||
| request.zksolcVersion = request.zksolcVersion || request.zkCompilerVersion; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-var-requires | ||
| const semver = require("semver"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not import it?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Import doesn't work because the semver package only functions with CommonJS modules. I found a workaround using require to properly use the object.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you try to add types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried with |
||
| if (semver.gte(request.zksolcVersion, "1.3.23")) { | ||
| request.compilerversion = `zkVM-${request.compilerversion}-1.0.1`; | ||
| } | ||
|
|
||
| if (isSolidityContract && request.sourceCode instanceof Object) { | ||
| const libraries: { [key: string]: Record<string, string> } = {}; | ||
| for (let i = 1; i <= 10; i++) { | ||
|
|
@@ -166,21 +173,37 @@ export class ContractController { | |
| } | ||
| } | ||
|
|
||
| let formatedStringSourceCode = undefined; | ||
| if (isSolidityContract && typeof request.sourceCode === "string") { | ||
| try { | ||
| formatedStringSourceCode = JSON.parse(request.sourceCode); | ||
| if (formatedStringSourceCode.settings.optimizer?.enabled) { | ||
| request.optimizationUsed = "1"; | ||
| } | ||
| } catch (e) { | ||
| formatedStringSourceCode = request.sourceCode; | ||
| } | ||
| } | ||
|
|
||
| const { data } = await firstValueFrom<{ data: number }>( | ||
| this.httpService | ||
| .post(`${this.contractVerificationApiUrl}/contract_verification`, { | ||
| codeFormat: request.codeformat, | ||
| contractAddress, | ||
| contractName: request.contractname, | ||
| optimizationUsed: request.optimizationUsed === "1", | ||
| sourceCode: request.sourceCode, | ||
| constructorArguments: request.constructorArguements, | ||
| sourceCode: typeof request.sourceCode === "string" ? formatedStringSourceCode : request.sourceCode, | ||
| constructorArguments: request.constructorArguements | ||
| ? request.constructorArguements.slice(0, 2) !== "0x" | ||
| ? `0x${request.constructorArguements}` | ||
| : request.constructorArguements | ||
| : "0x", | ||
| ...(isSolidityContract && { | ||
| compilerZksolcVersion: request.zkCompilerVersion, | ||
| compilerZksolcVersion: request.zksolcVersion, | ||
| compilerSolcVersion: request.compilerversion, | ||
| }), | ||
| ...(!isSolidityContract && { | ||
| compilerZkvyperVersion: request.zkCompilerVersion, | ||
| compilerZkvyperVersion: request.zksolcVersion, | ||
| compilerVyperVersion: request.compilerversion, | ||
| }), | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { validate } from "class-validator"; | ||
| import { FormatAndValidateCompilerVersion } from "./formatAndValidateCompilerVersion"; | ||
|
|
||
| class TestDto { | ||
| constructor(version: string) { | ||
| this.version = version; | ||
| } | ||
|
|
||
| @FormatAndValidateCompilerVersion() | ||
| public version: string; | ||
| } | ||
|
|
||
| describe("FormatAndValidateCompilerVersion", () => { | ||
| it("when version is null returns a validation error", async () => { | ||
| const errors = await validate(new TestDto(null)); | ||
| expect(errors.length).toBe(1); | ||
| expect(errors[0].property).toBe("version"); | ||
| }); | ||
|
|
||
| it("when version is an empty string returns a validation error", async () => { | ||
| const errors = await validate(new TestDto("")); | ||
| expect(errors.length).toBe(1); | ||
| expect(errors[0].property).toBe("version"); | ||
| }); | ||
|
|
||
| it("when version is a valid", async () => { | ||
| const errors = await validate(new TestDto("2.3.7")); | ||
| expect(errors.length).toBe(0); | ||
| }); | ||
|
|
||
| it("when version is valid with commit", async () => { | ||
| const errors = await validate(new TestDto("2.5.7-commit.32")); | ||
| expect(errors.length).toBe(0); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { registerDecorator, ValidationOptions } from "class-validator"; | ||
| export function FormatAndValidateCompilerVersion(validationOptions?: ValidationOptions) { | ||
| return function (object: any, propertyName: string) { | ||
| registerDecorator({ | ||
| name: "formatAndValidateCompilerVersion", | ||
| target: object.constructor, | ||
| propertyName: propertyName, | ||
| options: validationOptions, | ||
| validator: { | ||
| validate(value: any) { | ||
| return value && typeof value === "string"; | ||
| }, | ||
| }, | ||
| }); | ||
| // Custom setter to format the value | ||
| Object.defineProperty(object, propertyName, { | ||
| set(value: string) { | ||
| const regex = /^(0\.\d+\.\d+(\.\d+)?|zkVM-\d+\.\d+\.\d+(\.\d+)?-\d+\.\d+\.\d+(\.\d+)?)$/; | ||
| if (value && !regex.test(value)) { | ||
| let [major, minor, patch] = value.split("."); | ||
| major = major.slice(1); | ||
| patch = patch.replace(/\+.*$/, ""); | ||
| minor = minor; | ||
| const formattedValue = `${major}.${minor}.${patch}`; | ||
| Object.defineProperty(object, `_${propertyName}`, { | ||
| value: formattedValue, | ||
| writable: true, | ||
| configurable: true, | ||
| }); | ||
| } else { | ||
| Object.defineProperty(object, `_${propertyName}`, { | ||
| value: value, | ||
| writable: true, | ||
| configurable: true, | ||
| }); | ||
| } | ||
| }, | ||
| get() { | ||
| return this[`_${propertyName}`]; | ||
| }, | ||
| }); | ||
| }; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.