Skip to content
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

Fix a typo. Eliminate an unnecessary verification error #53

Merged
merged 13 commits into from
Oct 31, 2023
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@solarity/hardhat-migrate",
"version": "2.0.0-alpha.9",
"version": "2.0.0-alpha.10",
"description": "Automatic deployment and verification of smart contracts",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/migrator/Migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class Migrator {
}

public async migrate() {
await Reporter.reportMigrationBegin(this._migrationFiles);
Reporter.reportMigrationBegin(this._migrationFiles);

for (const element of this._migrationFiles) {
Reporter.reportMigrationFileBegin(element);
Expand All @@ -55,7 +55,7 @@ export class Migrator {
}
}

await Reporter.summary();
Reporter.summary();
}

private _getMigrationFiles() {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/reporters/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class Reporter {
console.log("\nStarting verification of all deployed contracts\n");
}

public static reportNothingToVerify() {
console.log(`\nNothing to verify. Selected network is ${this._network.name}\n`);
}

public static reportSuccessfulVerification(contractAddress: string, contractName: string) {
const output = `\nContract ${contractName} (${contractAddress}) verified successfully.\n`;

Expand Down
44 changes: 24 additions & 20 deletions src/verifier/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,31 @@ export class Verifier {
}

@catchError
public async verify(verifierArgs: VerifierArgs): Promise<void> {
const { contractAddress, contractName, constructorArguments, chainId } = verifierArgs;
public async verifyBatch(verifierBatchArgs: VerifierArgs[]) {
const currentChainId = Number(await getChainId());

if (chainId && Number(await getChainId()) != chainId) {
// TODO: Add actions for this case.
const toVerify = verifierBatchArgs.filter((args) => args.chainId && currentChainId == args.chainId);

if (!toVerify || toVerify.length === 0) {
Reporter.reportNothingToVerify();
return;
}

Reporter.reportVerificationBatchBegin();

const parallel = this._config.parallel;

for (let i = 0; i < toVerify.length; i += parallel) {
const batch = toVerify.slice(i, i + parallel);

await Promise.all(batch.map((args) => this._verify(args)));
}
}

@catchError
private async _verify(verifierArgs: VerifierArgs): Promise<void> {
const { contractAddress, contractName, constructorArguments } = verifierArgs;

const instance = await this._getEtherscanInstance(this._hre);

for (let attempts = 0; attempts < this._config.attempts; attempts++) {
Expand All @@ -50,19 +67,6 @@ export class Verifier {
}
}

@catchError
public async verifyBatch(verifierButchArgs: VerifierArgs[]) {
Reporter.reportVerificationBatchBegin();

const parallel = this._config.parallel;

for (let i = 0; i < verifierButchArgs.length; i += parallel) {
const batch = verifierButchArgs.slice(i, i + parallel);

await Promise.all(batch.map((args) => this.verify(args)));
}
}

@catchError
private async _tryVerify(
instance: Etherscan,
Expand All @@ -72,13 +76,13 @@ export class Verifier {
) {
await this._tryRunVerificationTask(contractAddress, contractName, constructorArguments);

const status = await instance.getVerificationStatus(contractAddress);
const isVerified = await instance.isVerified(contractAddress);

if (status.isSuccess()) {
if (isVerified) {
Reporter.reportSuccessfulVerification(contractAddress, contractName);
return;
} else {
Reporter.reportVerificationError(contractAddress, contractName, status.message);
Reporter.reportVerificationError(contractAddress, contractName, "Verification failed");
}
}

Expand Down