diff --git a/package.json b/package.json index 726ace9..63ad2f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.0.0-alpha.13", + "version": "2.0.0-alpha.14", "description": "Automatic deployment and verification of smart contracts", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/deployer/Deployer.ts b/src/deployer/Deployer.ts index 2148797..e8efdbc 100644 --- a/src/deployer/Deployer.ts +++ b/src/deployer/Deployer.ts @@ -13,8 +13,8 @@ import { EthersContractAdapter } from "./adapters/EthersContractAdapter"; import { EthersFactoryAdapter } from "./adapters/EthersFactoryAdapter"; import { OverridesAndLibs } from "../types/deployer"; -import { KeyTransactionFields, MigrationMetadata } from "../types/tools"; import { Instance, TypedArgs } from "../types/adapter"; +import { KeyTransactionFields, MigrationMetadata } from "../types/tools"; import { isContractFactory, isEthersContract, isBytecodeFactory, isTruffleFactory } from "../types/type-checks"; import { Stats } from "../tools/Stats"; @@ -94,7 +94,7 @@ export class Deployer { const [receipt] = await Promise.all([ txResponse.wait(this._hre.config.migrate.wait), - Reporter.reportTransaction(txResponse, methodString), + Reporter.reportTransactionResponse(txResponse, methodString), ]); const saveMetadata: MigrationMetadata = { diff --git a/src/deployer/MinimalContract.ts b/src/deployer/MinimalContract.ts index c076057..140da0c 100644 --- a/src/deployer/MinimalContract.ts +++ b/src/deployer/MinimalContract.ts @@ -10,7 +10,7 @@ import { MigrateError } from "../errors"; import { MigrationMetadata } from "../types/tools"; import { MigrateConfig } from "../types/migrations"; -import { ContractDeployTransactionWithContractName, OverridesAndLibs } from "../types/deployer"; +import { ContractDeployTxWithName, OverridesAndLibs } from "../types/deployer"; import { Stats } from "../tools/Stats"; import { Reporter } from "../tools/reporters/Reporter"; @@ -69,10 +69,7 @@ export class MinimalContract { } } - private async _createDeployTransaction( - args: any[], - txOverrides: Overrides, - ): Promise { + private async _createDeployTransaction(args: any[], txOverrides: Overrides): Promise { const factory = new ethers.ContractFactory(this._interface, this._bytecode); return { @@ -83,19 +80,7 @@ export class MinimalContract { }; } - private async _recoverContractAddress(tx: ContractDeployTransactionWithContractName, args: any[]): Promise { - try { - const contractAddress = await TransactionProcessor.tryRestoreContractAddressByName(tx.contractName); - - Reporter.notifyContractRecovery(tx.contractName, contractAddress); - - await this._saveContractForVerification(contractAddress, tx, args); - - return contractAddress; - } catch { - /* empty */ - } - + private async _recoverContractAddress(tx: ContractDeployTxWithName, args: any[]): Promise { try { const contractAddress = await TransactionProcessor.tryRestoreContractAddressByKeyFields(tx); @@ -113,15 +98,12 @@ export class MinimalContract { return this._processContractDeploymentTransaction(tx, args); } - private async _processContractDeploymentTransaction( - tx: ContractDeployTransactionWithContractName, - args: any[], - ): Promise { + private async _processContractDeploymentTransaction(tx: ContractDeployTxWithName, args: any[]): Promise { const signer: Signer = await getSignerHelper(tx.from); const txResponse = await signer.sendTransaction(tx); - await Reporter.reportTransaction(txResponse, tx.contractName); + await Reporter.reportTransactionResponse(txResponse, tx.contractName); const contractAddress = (await txResponse.wait(0))!.contractAddress; @@ -141,11 +123,7 @@ export class MinimalContract { return contractAddress; } - private async _saveContractForVerification( - contractAddress: string, - tx: ContractDeployTransactionWithContractName, - args: any[], - ) { + private async _saveContractForVerification(contractAddress: string, tx: ContractDeployTxWithName, args: any[]) { if (VerificationProcessor.isVerificationDataSaved(contractAddress)) { return; } diff --git a/src/deployer/adapters/AbstractEthersAdapter.ts b/src/deployer/adapters/AbstractEthersAdapter.ts index e3c4ccb..c294eb1 100644 --- a/src/deployer/adapters/AbstractEthersAdapter.ts +++ b/src/deployer/adapters/AbstractEthersAdapter.ts @@ -170,7 +170,7 @@ export abstract class AbstractEthersAdapter extends Adapter { TransactionProcessor.saveTransaction(tx, (await txResponse.wait())!, saveMetadata); - await Reporter.reportTransaction(txResponse, methodString); + await Reporter.reportTransactionResponse(txResponse, methodString); return txResponse; } diff --git a/src/index.ts b/src/index.ts index 5324aee..b1506c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,8 +23,8 @@ import { Provider } from "./tools/Provider"; import { Verifier } from "./verifier/Verifier"; export { Deployer } from "./deployer/Deployer"; -export { Reporter } from "./tools/reporters/Reporter"; export { DefaultStorage } from "./tools/storage/MigrateStorage"; +export { PublicReporter as Reporter } from "./tools/reporters/PublicReporter"; extendConfig(migrateConfigExtender); diff --git a/src/tools/reporters/PublicReporter.ts b/src/tools/reporters/PublicReporter.ts new file mode 100644 index 0000000..a45ab1b --- /dev/null +++ b/src/tools/reporters/PublicReporter.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +import { Reporter } from "./Reporter"; + +import { Provider } from "../Provider"; + +import { MigrateError } from "../../errors"; + +export class PublicReporter { + public static async reportTransactionByHash(txHash: string, instanceName: string) { + const tx = await Provider.provider.getTransaction(txHash); + + if (!tx) { + throw new MigrateError("Transaction not found."); + } + + await Reporter.reportTransactionResponse(tx, instanceName); + } + + public static reportContracts(...contracts: [string, string][]): void { + const table: { Contract: string; Address: string }[] = contracts.map(([contract, address]) => ({ + Contract: contract, + Address: address, + })); + console.log(); + console.table(table); + console.log(); + } +} diff --git a/src/tools/reporters/Reporter.ts b/src/tools/reporters/Reporter.ts index fbaf9ad..0981732 100644 --- a/src/tools/reporters/Reporter.ts +++ b/src/tools/reporters/Reporter.ts @@ -2,29 +2,29 @@ import ora from "ora"; import axios from "axios"; -import { Network, TransactionReceipt, TransactionResponse, formatEther, formatUnits } from "ethers"; +import { Network, TransactionResponse, formatEther, formatUnits, TransactionReceipt } from "ethers"; import { Provider } from "../Provider"; -import { MigrateError } from "../../errors"; - import { catchError, underline } from "../../utils"; +import { MigrateError } from "../../errors"; + import { MigrateConfig } from "../../types/migrations"; import { ChainRecord, predefinedChains } from "../../types/verifier"; import { ContractFieldsToSave, MigrationMetadata, TransactionFieldsToSave } from "../../types/tools"; @catchError export class Reporter { - private static _config: MigrateConfig; - private static _network: Network; - private static _nativeSymbol: string; - private static _explorerUrl: string; + protected static _config: MigrateConfig; + protected static _network: Network; + protected static _nativeSymbol: string; + protected static _explorerUrl: string; - private static totalCost: bigint = 0n; - private static totalTransactions: number = 0; + protected static totalCost: bigint = 0n; + protected static totalTransactions: number = 0; - private static _warningsToPrint: string[] = []; + protected static _warningsToPrint: string[] = []; public static async init(config: MigrateConfig) { this._config = config; @@ -47,59 +47,34 @@ export class Reporter { console.log(`\n${underline(`Running ${file}...`)}`); } - public static summary() { - const output = - `> ${"Total transactions:".padEnd(20)} ${this.totalTransactions}\n` + - `> ${"Final cost:".padEnd(20)} ${this.castAmount(this.totalCost, this._nativeSymbol)}\n`; - - console.log(`\n${output}`); - - this.reportWarnings(); - } - - public static async reportTransactionByHash(txHash: string, instanceName: string) { - const tx = await Provider.provider.getTransaction(txHash); - - if (!tx) { - throw new MigrateError("Transaction not found."); - } - - await this.reportTransaction(tx, instanceName); - } - - public static async reportTransaction(tx: TransactionResponse, instanceName: string) { - const timeStart = Date.now(); - const blockStart = await Provider.provider.getBlockNumber(); - + public static async reportTransactionResponse(tx: TransactionResponse, instanceName: string) { console.log("\n" + underline(this._parseTransactionTitle(tx, instanceName))); console.log(`> explorer: ${this._getExplorerLink(tx.hash)}`); - const formatPendingTimeTask = async () => this._formatPendingTime(tx, timeStart, blockStart); - - const spinner = ora(await formatPendingTimeTask()).start(); - - // TODO: make 1000 configurable - const spinnerInterval = setInterval(async () => (spinner.text = await formatPendingTimeTask()), 1000); - - let receipt: TransactionReceipt; - try { - // We will wait for both contract deployment and common transactions - receipt = (await tx.wait(this._config.wait))!; - } catch (e: any) { - throw new MigrateError(`Transaction failed: ${e.message}`); - } finally { - clearInterval(spinnerInterval); - - spinner.stop(); + let receipt; + if (tx.isMined()) { + receipt = (await tx.wait())!; + } else { + receipt = await this._showTransactionMining(tx); } - await this._printTransaction(receipt); + await this._printTransactionReceipt(receipt); this.totalCost += receipt.fee + tx.value ?? 0n; this.totalTransactions++; } + public static summary() { + const output = + `> ${"Total transactions:".padEnd(20)} ${this.totalTransactions}\n` + + `> ${"Final cost:".padEnd(20)} ${this._castAmount(this.totalCost, this._nativeSymbol)}\n`; + + console.log(`\n${output}`); + + this.reportWarnings(); + } + public static notifyDeploymentInsteadOfRecovery(contractName: string): void { const output = `\nCan't recover contract address for ${contractName}. Deploying instead...`; @@ -162,19 +137,15 @@ export class Reporter { console.log(output); } - public static notifyContractCollision(oldData: ContractFieldsToSave, dataToSave: ContractFieldsToSave) { - let output = `\nContract collision detected!`; - output += `\n> Contract: ${oldData.contractName || dataToSave.contractName}`; - output += `\n> Previous Collision Details: `; - output += `\n\t- Migration Number: ${oldData.metadata.migrationNumber}`; - output += `\n\t- Contract Address: ${oldData.contractAddress}`; - output += `\n> New Collision Details: `; - output += `\n\t- Migration Number: ${dataToSave.metadata.migrationNumber}`; - output += `\n\t- Contract Address: ${dataToSave.contractAddress}`; - - console.log(output); + public static notifyContractCollisionByName(oldData: ContractFieldsToSave, dataToSave: ContractFieldsToSave) { + const output = `\nContract collision by Contract Name detected!`; + this._printContractCollision(output, oldData, dataToSave); + } - this._warningsToPrint.push(output); + public static notifyContractCollisionByKeyFields(oldData: ContractFieldsToSave, dataToSave: ContractFieldsToSave) { + let output = `\nContract collision by key fields detected!`; + output += `\nKey fields are bytecode, from, chainId, value and contract name`; + this._printContractCollision(output, oldData, dataToSave); } public static notifyTransactionCollision(oldData: TransactionFieldsToSave, dataToSave: TransactionFieldsToSave) { @@ -210,16 +181,6 @@ export class Reporter { this._warningsToPrint.push(output); } - public static reportContracts(...contracts: [string, string][]): void { - const table: { Contract: string; Address: string }[] = contracts.map(([contract, address]) => ({ - Contract: contract, - Address: address, - })); - console.log(); - console.table(table); - console.log(); - } - public static reportWarnings() { if (this._warningsToPrint.length === 0) { return; @@ -239,7 +200,7 @@ export class Reporter { console.log(""); } - private static _parseTransactionTitle(tx: TransactionResponse, instanceName: string): string { + protected static _parseTransactionTitle(tx: TransactionResponse, instanceName: string): string { if (tx.to === null) { if (instanceName.split(":").length == 1) { return `Deploying ${instanceName}`; @@ -251,7 +212,7 @@ export class Reporter { return `Transaction: ${instanceName}`; } - private static async _formatPendingTime( + protected static async _formatPendingTime( tx: TransactionResponse, startTime: number, blockStart: number, @@ -261,39 +222,11 @@ export class Reporter { }; Seconds: ${((Date.now() - startTime) / 1000).toFixed(0)}`; } - private static _getExplorerLink(txHash: string): string { + protected static _getExplorerLink(txHash: string): string { return this._explorerUrl + txHash; } - private static async _printTransaction(tx: TransactionReceipt) { - let output = ""; - - if (tx.contractAddress) { - output += `> contractAddress: ${tx.contractAddress}\n`; - } - - const nativeSymbol = this._nativeSymbol; - - output += `> blockNumber: ${tx.blockNumber}\n`; - - output += `> blockTimestamp: ${(await tx.getBlock()).timestamp}\n`; - - output += `> account: ${tx.from}\n`; - - output += `> value: ${this.castAmount((await tx.getTransaction()).value, nativeSymbol)}\n`; - - output += `> balance: ${this.castAmount(await tx.provider.getBalance(tx.from), nativeSymbol)}\n`; - - output += `> gasUsed: ${tx.gasUsed}\n`; - - output += `> gasPrice: ${this.castAmount(tx.gasPrice, nativeSymbol)}\n`; - - output += `> fee: ${this.castAmount(tx.fee, nativeSymbol)}\n`; - - console.log(output); - } - - public static castAmount(value: bigint, nativeSymbol: string): string { + protected static _castAmount(value: bigint, nativeSymbol: string): string { if (value > 0n && value < 10n ** 12n) { return this._toGWei(value) + " GWei"; } @@ -301,11 +234,11 @@ export class Reporter { return formatEther(value) + ` ${nativeSymbol}`; } - private static _toGWei(value: bigint): string { + protected static _toGWei(value: bigint): string { return formatUnits(value, "gwei"); } - private static _reportMigrationFiles(files: string[]) { + protected static _reportMigrationFiles(files: string[]) { console.log("\nMigration files:"); files.forEach((file) => { @@ -315,13 +248,85 @@ export class Reporter { console.log(""); } - private static _reportChainInfo() { + protected static _reportChainInfo() { console.log(`> ${"Network:".padEnd(20)} ${this._network.name}`); console.log(`> ${"Network id:".padEnd(20)} ${this._network.chainId}`); } - private static async _getNetwork(): Promise { + protected static async _showTransactionMining(tx: TransactionResponse) { + const timeStart = Date.now(); + const blockStart = await Provider.provider.getBlockNumber(); + + const formatPendingTimeTask = async () => this._formatPendingTime(tx, timeStart, blockStart); + + const spinner = ora(await formatPendingTimeTask()).start(); + + // TODO: make 1000 configurable + const spinnerInterval = setInterval(async () => (spinner.text = await formatPendingTimeTask()), 1000); + + let receipt: TransactionReceipt; + try { + // We will wait for both contract deployment and common transactions + receipt = (await tx.wait(this._config.wait))!; + } catch (e: any) { + throw new MigrateError(`Transaction failed: ${e.message}`); + } finally { + clearInterval(spinnerInterval); + + spinner.stop(); + } + + return receipt; + } + + protected static async _printTransactionReceipt(receipt: TransactionReceipt) { + let output = ""; + + if (receipt.contractAddress) { + output += `> contractAddress: ${receipt.contractAddress}\n`; + } + + const nativeSymbol = this._nativeSymbol; + + output += `> blockNumber: ${receipt.blockNumber}\n`; + + output += `> blockTimestamp: ${(await receipt.getBlock()).timestamp}\n`; + + output += `> account: ${receipt.from}\n`; + + output += `> value: ${this._castAmount((await receipt.getTransaction()).value, nativeSymbol)}\n`; + + output += `> balance: ${this._castAmount(await receipt.provider.getBalance(receipt.from), nativeSymbol)}\n`; + + output += `> gasUsed: ${receipt.gasUsed}\n`; + + output += `> gasPrice: ${this._castAmount(receipt.gasPrice, nativeSymbol)}\n`; + + output += `> fee: ${this._castAmount(receipt.fee, nativeSymbol)}\n`; + + console.log(output); + } + + protected static _printContractCollision( + output: string, + oldData: ContractFieldsToSave, + dataToSave: ContractFieldsToSave, + ) { + output += `\n> Contract: ${oldData.contractKeyData?.name || dataToSave.contractKeyData?.name}`; + output += `\n> Previous Collision Details: `; + output += `\n\t- Migration Number: ${oldData.metadata.migrationNumber}`; + output += `\n\t- Contract Address: ${oldData.contractAddress}`; + output += `\n> New Collision Details: `; + output += `\n\t- Migration Number: ${dataToSave.metadata.migrationNumber}`; + output += `\n\t- Contract Address: ${dataToSave.contractAddress}`; + + console.log(output); + + this._warningsToPrint.push(output); + } + + protected static async _getNetwork(): Promise { try { return Provider.provider.getNetwork(); } catch { @@ -329,7 +334,7 @@ export class Reporter { } } - private static async _getExplorerUrl(): Promise { + protected static async _getExplorerUrl(): Promise { const chainId = Number(this._network.chainId); if (predefinedChains[chainId]) { @@ -343,7 +348,7 @@ export class Reporter { return chain.explorers[0].url; } - private static async _getNativeSymbol(): Promise { + protected static async _getNativeSymbol(): Promise { const chainId = Number(this._network.chainId); if (predefinedChains[chainId]) { @@ -355,7 +360,7 @@ export class Reporter { return chain.nativeCurrency.symbol; } - private static async _getChainMetadataById(chainId: number): Promise { + protected static async _getChainMetadataById(chainId: number): Promise { try { const chains = await this._tryGetAllRecords(); @@ -373,7 +378,7 @@ export class Reporter { } } - private static async _tryGetAllRecords(): Promise { + protected static async _tryGetAllRecords(): Promise { const url = "https://chainid.network/chains.json"; const response = await axios.get(url); diff --git a/src/tools/reporters/TruffleReporter.ts b/src/tools/reporters/TruffleReporter.ts index 3ed4cf0..514b690 100644 --- a/src/tools/reporters/TruffleReporter.ts +++ b/src/tools/reporters/TruffleReporter.ts @@ -1,5 +1,5 @@ /* eslint-disable no-console */ -import { Reporter } from "./Reporter"; +import { PublicReporter } from "./PublicReporter"; import { TruffleTransactionResponse } from "../../types/deployer"; @@ -7,7 +7,7 @@ export class TruffleReporter { public static async reportTransaction(tx: TruffleTransactionResponse | string, instanceName: string) { const hash = typeof tx === "string" ? tx : tx.receipt.transactionHash; - await Reporter.reportTransactionByHash(hash, instanceName); + await PublicReporter.reportTransactionByHash(hash, instanceName); } public static notifyTransactionSending(methodString: string) { diff --git a/src/tools/storage/TransactionProcessor.ts b/src/tools/storage/TransactionProcessor.ts index 92bf8fd..db42a23 100644 --- a/src/tools/storage/TransactionProcessor.ts +++ b/src/tools/storage/TransactionProcessor.ts @@ -1,5 +1,7 @@ import { ContractDeployTransaction, isAddress, TransactionReceiptParams } from "ethers"; +import { isFullyQualifiedName } from "hardhat/utils/contract-names"; + import { TransactionStorage } from "./MigrateStorage"; import { Reporter } from "../reporters/Reporter"; @@ -18,8 +20,8 @@ import { KeyTransactionFields, MigrationMetadata, TransactionFieldsToSave, - UNKNOWN_CONTRACT_NAME, } from "../../types/tools"; +import { ContractDeployTxWithName } from "../../types/deployer"; import { validateKeyDeploymentFields, validateKeyTxFields } from "../../types/type-checks"; @catchError @@ -34,26 +36,19 @@ export class TransactionProcessor { ) { const dataToSave: ContractFieldsToSave = { contractKeyData: { + name: contractName, data: args.data, from: args.from!, chainId: args.chainId!, value: args.value!, }, contractAddress, - contractName, metadata, }; - if (contractName === UNKNOWN_CONTRACT_NAME) { - this._saveContract(args, dataToSave); - - return; - } - - if (TransactionStorage.has(contractName)) { - this._processCollision(contractName, dataToSave); - } + const keyByArgs = createKeyDeploymentFieldsHash(dataToSave.contractKeyData!); + this._saveContract(keyByArgs, dataToSave); this._saveContractByName(contractName, dataToSave); } @@ -83,9 +78,10 @@ export class TransactionProcessor { @catchError @validateKeyDeploymentFields - public static async tryRestoreContractAddressByKeyFields(key: ContractDeployTransaction): Promise { + public static async tryRestoreContractAddressByKeyFields(key: ContractDeployTxWithName): Promise { const restoredData = this._tryGetDataFromStorage( createKeyDeploymentFieldsHash({ + name: key.contractName, data: key.data, from: key.from!, chainId: key.chainId!, @@ -152,18 +148,19 @@ export class TransactionProcessor { TransactionStorage.set(dataKey, dataToSave, true); } - private static _saveContract(args: ContractDeployTransaction, dataToSave: ContractFieldsToSave) { - const keyByArgs = createKeyDeploymentFieldsHash({ - data: args.data, - from: args.from!, - chainId: args.chainId!, - value: args.value!, - }); + private static _saveContract(keyByArgs: string, dataToSave: ContractFieldsToSave) { + if (TransactionStorage.has(keyByArgs)) { + this._processCollision(keyByArgs, dataToSave); + } TransactionStorage.set(keyByArgs, dataToSave, true); } private static _saveContractByName(contractName: string, dataToSave: ContractFieldsToSave) { + if (TransactionStorage.has(contractName)) { + this._processCollision(contractName, dataToSave); + } + TransactionStorage.set(contractName, dataToSave, true); } @@ -174,8 +171,14 @@ export class TransactionProcessor { metadata: MigrationMetadata; } = TransactionStorage.get(dataKey); + if (oldData.contractAddress && isFullyQualifiedName(dataKey)) { + Reporter.notifyContractCollisionByName(oldData as ContractFieldsToSave, dataToSave as ContractFieldsToSave); + + return; + } + if (oldData.contractAddress) { - Reporter.notifyContractCollision(oldData as ContractFieldsToSave, dataToSave as ContractFieldsToSave); + Reporter.notifyContractCollisionByKeyFields(oldData as ContractFieldsToSave, dataToSave as ContractFieldsToSave); return; } diff --git a/src/types/deployer.ts b/src/types/deployer.ts index c6c68bb..382e065 100644 --- a/src/types/deployer.ts +++ b/src/types/deployer.ts @@ -10,7 +10,7 @@ export type OverridesAndName = Overrides & { name?: string }; export type OverridesAndLibs = OverridesAndName & { libraries?: Libraries }; -export type ContractDeployTransactionWithContractName = ContractDeployTransaction & { contractName: string }; +export type ContractDeployTxWithName = ContractDeployTransaction & { contractName: string }; export interface Link { sourceName: string; diff --git a/src/types/tools.ts b/src/types/tools.ts index cee6a59..232d2ce 100644 --- a/src/types/tools.ts +++ b/src/types/tools.ts @@ -1,6 +1,7 @@ import { TransactionReceiptParams } from "ethers"; export interface KeyDeploymentFields { + name: string; data: string; from: string; chainId: bigint; @@ -23,7 +24,6 @@ export interface TransactionFieldsToSave { export interface ContractFieldsToSave { contractKeyData?: KeyDeploymentFields; - contractName?: string; contractAddress: string; metadata: MigrationMetadata; } diff --git a/src/utils.ts b/src/utils.ts index d129240..d272b72 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -84,6 +84,7 @@ export function bytecodeHash(bytecode: any): string { export function createKeyDeploymentFieldsHash(keyTxFields: KeyDeploymentFields): string { const obj: KeyDeploymentFields = { + name: keyTxFields.name, data: keyTxFields.data, from: keyTxFields.from, chainId: keyTxFields.chainId, @@ -206,6 +207,7 @@ export function suppressLogs(target: any, propertyKey: string, descriptor: Prope descriptor.value = function (...args: any[]) { const log = console.log; + console.log(); console.log = () => {}; const result = originalMethod.apply(this, args); diff --git a/src/verifier/Verifier.ts b/src/verifier/Verifier.ts index 346c510..0482945 100644 --- a/src/verifier/Verifier.ts +++ b/src/verifier/Verifier.ts @@ -63,7 +63,7 @@ export class Verifier { this._handleVerificationError(contractAddress, contractName, e); } - await new Promise((resolve) => setTimeout(resolve, 1000)); + await new Promise((resolve) => setTimeout(resolve, 2500)); } } diff --git a/test/integration/transaction-storage.ts b/test/integration/transaction-storage.ts index d2209b0..941f503 100644 --- a/test/integration/transaction-storage.ts +++ b/test/integration/transaction-storage.ts @@ -4,6 +4,12 @@ import { ContractFactory, ZeroAddress } from "ethers"; import { useEnvironment } from "../helpers"; import { Deployer } from "../../src/deployer/Deployer"; + +import { UNKNOWN_CONTRACT_NAME } from "../../src/types/tools"; +import { ContractDeployTxWithName } from "../../src/types/deployer"; + +import { Provider } from "../../src/tools/Provider"; +import { Reporter } from "../../src/tools/reporters/Reporter"; import { ArtifactProcessor } from "../../src/tools/storage/ArtifactProcessor"; import { TransactionStorage } from "../../src/tools/storage/MigrateStorage"; import { TransactionProcessor } from "../../src/tools/storage/TransactionProcessor"; @@ -12,9 +18,6 @@ import { ContractWithConstructorArguments__factory, ContractWithPayableConstructor__factory, } from "../fixture-projects/hardhat-project-repeats-typechain-ethers/typechain-types"; -import { Reporter } from "../../src/tools/reporters/Reporter"; -import { Provider } from "../../src/tools/Provider"; -import { UNKNOWN_CONTRACT_NAME } from "../../src/types/tools"; describe("TransactionStorage", async () => { useEnvironment("repeats-typechain-ethers"); @@ -53,7 +56,15 @@ describe("TransactionStorage", async () => { value: 0, }); - assert.equal(await TransactionProcessor.tryRestoreContractAddressByKeyFields(tx), await contract.getAddress()); + const keyFields: ContractDeployTxWithName = { + ...tx, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + assert.equal( + await TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields), + await contract.getAddress(), + ); }); it("should save deployment transaction by name", async function () { @@ -85,7 +96,15 @@ describe("TransactionStorage", async () => { chainId: await deployer.getChainId(), }); - assert.equal(await TransactionProcessor.tryRestoreContractAddressByKeyFields(tx), await contract.getAddress()); + const keyFields: ContractDeployTxWithName = { + ...tx, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + assert.equal( + await TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields), + await contract.getAddress(), + ); }); it("should differ contracts with chainId", async function () { @@ -102,7 +121,12 @@ describe("TransactionStorage", async () => { value: 0, }); - await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(data)).to.be.rejectedWith( + const keyFields: ContractDeployTxWithName = { + ...data, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields)).to.be.rejectedWith( "tryRestoreContractAddressByKeyFields(): Requested data not found in storage", ); }); @@ -121,7 +145,12 @@ describe("TransactionStorage", async () => { value: 0, }); - await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(tx)).to.be.rejectedWith( + const keyFields: ContractDeployTxWithName = { + ...tx, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields)).to.be.rejectedWith( "tryRestoreContractAddressByKeyFields(): Requested data not found in storage", ); }); @@ -143,7 +172,15 @@ describe("TransactionStorage", async () => { value: 0, }); - assert.equal(await TransactionProcessor.tryRestoreContractAddressByKeyFields(data), await contract.getAddress()); + const keyFields: ContractDeployTxWithName = { + ...data, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + assert.equal( + await TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields), + await contract.getAddress(), + ); }); it("should differ contracts with args", async function () { @@ -160,7 +197,12 @@ describe("TransactionStorage", async () => { value: 0, }); - await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(data)).to.be.rejectedWith( + const keyFields: ContractDeployTxWithName = { + ...data, + contractName: UNKNOWN_CONTRACT_NAME, + }; + + await expect(TransactionProcessor.tryRestoreContractAddressByKeyFields(keyFields)).to.be.rejectedWith( "tryRestoreContractAddressByKeyFields(): Requested data not found in storage", ); });