Skip to content

Commit

Permalink
Fix a typo. Eliminate an unnecessary verification error (#53)
Browse files Browse the repository at this point in the history
* Fixed buf with VerificationFailedToSave

* Fixed typo

* Updated versions

* Added ability to recover contract verification data

* Added Provider init in migrateVerify

* Restore reporter

* Fixed typos. And used isVerified for status.

* Updated versions.

* Checked for undefined (verifierBatchArgs)

* Fixed typo in case if nothing to verify.

* Made verify private

* Made verify method in Verifier private.
  • Loading branch information
KyrylR authored Oct 31, 2023
1 parent 228b693 commit e958f58
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
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

0 comments on commit e958f58

Please sign in to comment.