From 80068844f39fea340023690dda7cb46d9b771981 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 19 Dec 2024 10:11:50 +0100 Subject: [PATCH 1/4] Automatically deploy entrypoint, and make it available in the hre --- hardhat/erc4337-entrypoint.js | 33 +++++++++++++++++++ test/account/utils/draft-ERC4337Utils.test.js | 17 +++++----- test/helpers/erc4337-entrypoint.js | 31 ----------------- 3 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 hardhat/erc4337-entrypoint.js delete mode 100644 test/helpers/erc4337-entrypoint.js diff --git a/hardhat/erc4337-entrypoint.js b/hardhat/erc4337-entrypoint.js new file mode 100644 index 00000000000..848dffdd4ee --- /dev/null +++ b/hardhat/erc4337-entrypoint.js @@ -0,0 +1,33 @@ +const { task } = require('hardhat/config'); +const { TASK_TEST_SETUP_TEST_ENVIRONMENT } = require('hardhat/builtin-tasks/task-names'); +const { setCode } = require('@nomicfoundation/hardhat-network-helpers'); + +const fs = require('fs'); +const path = require('path'); + +const INSTANCES = { + entrypoint: { + address: '0x0000000071727De22E5E9d8BAf0edAc6f37da032', + abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../test/bin/EntryPoint070.abi'), 'utf-8')), + bytecode: fs.readFileSync(path.resolve(__dirname, '../test/bin/EntryPoint070.bytecode'), 'hex'), + }, + senderCreator: { + address: '0xEFC2c1444eBCC4Db75e7613d20C6a62fF67A167C', + abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../test/bin/SenderCreator070.abi'), 'utf-8')), + bytecode: fs.readFileSync(path.resolve(__dirname, '../test/bin/SenderCreator070.bytecode'), 'hex'), + }, +}; + +task(TASK_TEST_SETUP_TEST_ENVIRONMENT).setAction((_, env, runSuper) => + runSuper().then(result => + Promise.all( + Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) => + setCode(address, '0x' + bytecode.replace(/0x/, '')) + .then(() => env.ethers.getContractAt(abi, address)) + .then(instance => ({ [name]: instance })), + ), + ) + .then(namedInstances => Object.assign(env, ...namedInstances)) + .then(() => result), + ), +); diff --git a/test/account/utils/draft-ERC4337Utils.test.js b/test/account/utils/draft-ERC4337Utils.test.js index 7c292910dfb..baddbf4db71 100644 --- a/test/account/utils/draft-ERC4337Utils.test.js +++ b/test/account/utils/draft-ERC4337Utils.test.js @@ -1,19 +1,18 @@ -const { ethers } = require('hardhat'); +const { ethers, entrypoint } = require('hardhat'); const { expect } = require('chai'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { packValidationData, UserOperation } = require('../../helpers/erc4337'); -const { deployEntrypoint } = require('../../helpers/erc4337-entrypoint'); const { MAX_UINT48 } = require('../../helpers/constants'); const ADDRESS_ONE = '0x0000000000000000000000000000000000000001'; const fixture = async () => { - const { entrypoint } = await deployEntrypoint(); const [authorizer, sender, factory, paymaster] = await ethers.getSigners(); const utils = await ethers.deployContract('$ERC4337Utils'); const SIG_VALIDATION_SUCCESS = await utils.$SIG_VALIDATION_SUCCESS(); const SIG_VALIDATION_FAILED = await utils.$SIG_VALIDATION_FAILED(); - return { utils, authorizer, sender, entrypoint, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED }; + + return { utils, authorizer, sender, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED }; }; describe('ERC4337Utils', function () { @@ -173,14 +172,14 @@ describe('ERC4337Utils', function () { const otherChainId = 0xdeadbeef; // check that helper matches entrypoint logic - expect(this.entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(this.entrypoint, chainId)); + expect(entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(entrypoint, chainId)); // check library against helper - expect(this.utils.$hash(userOp.packed, this.entrypoint, chainId)).to.eventually.equal( - userOp.hash(this.entrypoint, chainId), + expect(this.utils.$hash(userOp.packed, entrypoint, chainId)).to.eventually.equal( + userOp.hash(entrypoint, chainId), ); - expect(this.utils.$hash(userOp.packed, this.entrypoint, otherChainId)).to.eventually.equal( - userOp.hash(this.entrypoint, otherChainId), + expect(this.utils.$hash(userOp.packed, entrypoint, otherChainId)).to.eventually.equal( + userOp.hash(entrypoint, otherChainId), ); }); }); diff --git a/test/helpers/erc4337-entrypoint.js b/test/helpers/erc4337-entrypoint.js deleted file mode 100644 index aba49f4c458..00000000000 --- a/test/helpers/erc4337-entrypoint.js +++ /dev/null @@ -1,31 +0,0 @@ -const { ethers } = require('hardhat'); -const { setCode } = require('@nomicfoundation/hardhat-network-helpers'); -const fs = require('fs'); -const path = require('path'); - -const INSTANCES = { - entrypoint: { - address: '0x0000000071727De22E5E9d8BAf0edAc6f37da032', - abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../bin/EntryPoint070.abi'), 'utf-8')), - bytecode: fs.readFileSync(path.resolve(__dirname, '../bin/EntryPoint070.bytecode'), 'hex'), - }, - sendercreator: { - address: '0xEFC2c1444eBCC4Db75e7613d20C6a62fF67A167C', - abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../bin/SenderCreator070.abi'), 'utf-8')), - bytecode: fs.readFileSync(path.resolve(__dirname, '../bin/SenderCreator070.bytecode'), 'hex'), - }, -}; - -function deployEntrypoint() { - return Promise.all( - Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) => - setCode(address, '0x' + bytecode.replace(/0x/, '')) - .then(() => ethers.getContractAt(abi, address)) - .then(instance => ({ [name]: instance })), - ), - ).then(namedInstances => Object.assign(...namedInstances)); -} - -module.exports = { - deployEntrypoint, -}; From 07844bf8216b7dc1e5c41e67d428ddddbb9f30f9 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 19 Dec 2024 10:24:05 +0100 Subject: [PATCH 2/4] rename --- hardhat/{erc4337-entrypoint.js => common-contracts.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename hardhat/{erc4337-entrypoint.js => common-contracts.js} (100%) diff --git a/hardhat/erc4337-entrypoint.js b/hardhat/common-contracts.js similarity index 100% rename from hardhat/erc4337-entrypoint.js rename to hardhat/common-contracts.js From d7dd3c5a2d1e04f16a81abf2ad6d54dbf0a8c6d0 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 19 Dec 2024 10:34:37 +0100 Subject: [PATCH 3/4] TASK_TEST_SETUP_TEST_ENVIRONMENT has no return --- hardhat/common-contracts.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardhat/common-contracts.js b/hardhat/common-contracts.js index 848dffdd4ee..0df05fe836e 100644 --- a/hardhat/common-contracts.js +++ b/hardhat/common-contracts.js @@ -19,7 +19,7 @@ const INSTANCES = { }; task(TASK_TEST_SETUP_TEST_ENVIRONMENT).setAction((_, env, runSuper) => - runSuper().then(result => + runSuper().then(() => Promise.all( Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) => setCode(address, '0x' + bytecode.replace(/0x/, '')) @@ -28,6 +28,6 @@ task(TASK_TEST_SETUP_TEST_ENVIRONMENT).setAction((_, env, runSuper) => ), ) .then(namedInstances => Object.assign(env, ...namedInstances)) - .then(() => result), + .then(() => {}), ), ); From 7215bd1b1bee8184633b4594ca5fd7dd71f4fd86 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 19 Dec 2024 16:29:21 +0100 Subject: [PATCH 4/4] simplify --- hardhat/common-contracts.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hardhat/common-contracts.js b/hardhat/common-contracts.js index 0df05fe836e..d9a3bd25295 100644 --- a/hardhat/common-contracts.js +++ b/hardhat/common-contracts.js @@ -22,12 +22,10 @@ task(TASK_TEST_SETUP_TEST_ENVIRONMENT).setAction((_, env, runSuper) => runSuper().then(() => Promise.all( Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) => - setCode(address, '0x' + bytecode.replace(/0x/, '')) - .then(() => env.ethers.getContractAt(abi, address)) - .then(instance => ({ [name]: instance })), + setCode(address, '0x' + bytecode.replace(/0x/, '')).then(() => + env.ethers.getContractAt(abi, address).then(instance => (env[name] = instance)), + ), ), - ) - .then(namedInstances => Object.assign(env, ...namedInstances)) - .then(() => {}), + ), ), );