diff --git a/CHANGELOG.md b/CHANGELOG.md index 303d4c5..e0dc31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 2.1.6 + +* Fixed a bug when the default signer was used instead of the actual signer + ## Version 2.1.5 * Fixed behaviour of connect method in Ethers Adapter. diff --git a/package-lock.json b/package-lock.json index 2cbca33..d1f6065 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.1.5", + "version": "2.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@solarity/hardhat-migrate", - "version": "2.1.5", + "version": "2.1.6", "license": "MIT", "workspaces": [ "test/fixture-projects/*" diff --git a/package.json b/package.json index 391d20a..0380950 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solarity/hardhat-migrate", - "version": "2.1.5", + "version": "2.1.6", "description": "Automatic deployment and verification of smart contracts", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", diff --git a/src/deployer/adapters/AbstractEthersAdapter.ts b/src/deployer/adapters/AbstractEthersAdapter.ts index fa6e4b0..768ead1 100644 --- a/src/deployer/adapters/AbstractEthersAdapter.ts +++ b/src/deployer/adapters/AbstractEthersAdapter.ts @@ -70,7 +70,7 @@ export abstract class AbstractEthersAdapter extends Adapter { const oldMethod: BaseContractMethod = (contract as any)[methodName]; - const newMethod = this._wrapOldMethod(contractName, methodName, methodFragments, oldMethod); + const newMethod = this._wrapOldMethod(contractName, methodName, methodFragments, oldMethod, contract.runner!); defineProperties(newMethod, { name: oldMethod.name, @@ -134,9 +134,12 @@ export abstract class AbstractEthersAdapter extends Adapter { methodName: string, methodFragments: FunctionFragment, oldMethod: BaseContractMethod, + runner: ContractRunner, ): (...args: any[]) => Promise { return async (...args: any[]): Promise => { const tx = await oldMethod.populateTransaction(...args); + tx.from = (runner as any).address; + await fillParameters(tx); const methodString = getMethodString(contractName, methodName, methodFragments, args); @@ -199,7 +202,6 @@ export abstract class AbstractEthersAdapter extends Adapter { } as unknown as ContractTransactionResponse; } - // TODO: run normal migrations in tests. private _getKeyFieldsFromTransaction(tx: ContractTransaction): KeyTransactionFields { return { name: this._getTransactionName(tx), diff --git a/src/deployer/adapters/TruffleAdapter.ts b/src/deployer/adapters/TruffleAdapter.ts index d52e7df..cdcae0b 100644 --- a/src/deployer/adapters/TruffleAdapter.ts +++ b/src/deployer/adapters/TruffleAdapter.ts @@ -129,7 +129,12 @@ export class TruffleAdapter extends Adapter { let contractMethod = ethersBaseContract.getFunction(methodName); // Build transaction. Under the hood, ethers handle overrides. + // In Truffle to specify different signer the particular `{ from: 0x... }` override should be used. const tx = await contractMethod.populateTransaction(...args); + + // In case if the `from` field is not specified, it should be filled with the default signer. + tx.from = tx.from ?? (await getSignerHelper()).address; + await fillParameters(tx); const keyFields = this._getKeyFieldsFromTransaction(tx, contractMethod, args); diff --git a/src/tools/reporters/Reporter.ts b/src/tools/reporters/Reporter.ts index d280f50..be26522 100644 --- a/src/tools/reporters/Reporter.ts +++ b/src/tools/reporters/Reporter.ts @@ -258,7 +258,7 @@ class BaseReporter { } public reportWarnings() { - if (this._warningsToPrint.size === 0) { + if (this.getWarningsCount() === 0) { return; } @@ -276,6 +276,10 @@ class BaseReporter { console.log(""); } + public getWarningsCount(): number { + return this._warningsToPrint.size; + } + private _printContractCollision(output: string, oldData: ContractFieldsToSave, dataToSave: ContractFieldsToSave) { output += `\n> Contract: ${oldData.contractKeyData?.name || dataToSave.contractKeyData?.name}`; output += `\n> Previous Collision Details: `; diff --git a/src/utils/migration.ts b/src/utils/migration.ts index 0d46a0a..31bf742 100644 --- a/src/utils/migration.ts +++ b/src/utils/migration.ts @@ -17,16 +17,10 @@ import { deepCopy, toJSON } from "./common"; import { MigrateError } from "../errors"; import { UNKNOWN_CONTRACT_NAME } from "../constants"; -import { networkManager } from "../tools/network/NetworkManager"; - import { Bytecode } from "../types/deployer"; import { KeyDeploymentFields, KeyTransactionFields } from "../types/tools"; export async function fillParameters(parameters: Overrides): Promise { - if (parameters.from === undefined) { - parameters.from = await (await networkManager!.provider.getSigner()).getAddress(); - } - if (parameters.chainId === undefined) { parameters.chainId = await getChainId(); } diff --git a/test/integration/deployer/base-contract-interaction.ts b/test/integration/deployer/base-contract-interaction.ts index d6b1421..27f5963 100644 --- a/test/integration/deployer/base-contract-interaction.ts +++ b/test/integration/deployer/base-contract-interaction.ts @@ -13,6 +13,7 @@ import { import { Deployer } from "../../../src/deployer/Deployer"; import { Migrator } from "../../../src/migrator/Migrator"; +import { Reporter } from "../../../src/tools/reporters/Reporter"; import { ethersProvider } from "../../../src/tools/network/EthersProvider"; import { TransactionStorage } from "../../../src/tools/storage/MigrateStorage"; @@ -82,10 +83,11 @@ describe("deployer", () => { expect(receipt!.from).to.equal(signer1.address); - tx = await contract.connect(signer2).pay({ value: 110n }); + tx = await contract.connect(signer2).pay({ value: 100n }); receipt = await tx.wait(); expect(receipt!.from).to.equal(signer2.address); + expect(Reporter?.getWarningsCount()).to.be.equal(0); }); }); });