Skip to content

Commit d4ed5f9

Browse files
authored
Automatically deploy entrypoint, and make it available in the hre (#5391)
1 parent 4826654 commit d4ed5f9

File tree

3 files changed

+39
-40
lines changed

3 files changed

+39
-40
lines changed

hardhat/common-contracts.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const { task } = require('hardhat/config');
2+
const { TASK_TEST_SETUP_TEST_ENVIRONMENT } = require('hardhat/builtin-tasks/task-names');
3+
const { setCode } = require('@nomicfoundation/hardhat-network-helpers');
4+
5+
const fs = require('fs');
6+
const path = require('path');
7+
8+
const INSTANCES = {
9+
entrypoint: {
10+
address: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
11+
abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../test/bin/EntryPoint070.abi'), 'utf-8')),
12+
bytecode: fs.readFileSync(path.resolve(__dirname, '../test/bin/EntryPoint070.bytecode'), 'hex'),
13+
},
14+
senderCreator: {
15+
address: '0xEFC2c1444eBCC4Db75e7613d20C6a62fF67A167C',
16+
abi: JSON.parse(fs.readFileSync(path.resolve(__dirname, '../test/bin/SenderCreator070.abi'), 'utf-8')),
17+
bytecode: fs.readFileSync(path.resolve(__dirname, '../test/bin/SenderCreator070.bytecode'), 'hex'),
18+
},
19+
};
20+
21+
task(TASK_TEST_SETUP_TEST_ENVIRONMENT).setAction((_, env, runSuper) =>
22+
runSuper().then(() =>
23+
Promise.all(
24+
Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) =>
25+
setCode(address, '0x' + bytecode.replace(/0x/, '')).then(() =>
26+
env.ethers.getContractAt(abi, address).then(instance => (env[name] = instance)),
27+
),
28+
),
29+
),
30+
),
31+
);

test/account/utils/draft-ERC4337Utils.test.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
const { ethers } = require('hardhat');
1+
const { ethers, entrypoint } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

55
const { packValidationData, UserOperation } = require('../../helpers/erc4337');
6-
const { deployEntrypoint } = require('../../helpers/erc4337-entrypoint');
76
const { MAX_UINT48 } = require('../../helpers/constants');
87
const ADDRESS_ONE = '0x0000000000000000000000000000000000000001';
98

109
const fixture = async () => {
11-
const { entrypoint } = await deployEntrypoint();
1210
const [authorizer, sender, factory, paymaster] = await ethers.getSigners();
1311
const utils = await ethers.deployContract('$ERC4337Utils');
1412
const SIG_VALIDATION_SUCCESS = await utils.$SIG_VALIDATION_SUCCESS();
1513
const SIG_VALIDATION_FAILED = await utils.$SIG_VALIDATION_FAILED();
16-
return { utils, authorizer, sender, entrypoint, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED };
14+
15+
return { utils, authorizer, sender, factory, paymaster, SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED };
1716
};
1817

1918
describe('ERC4337Utils', function () {
@@ -173,14 +172,14 @@ describe('ERC4337Utils', function () {
173172
const otherChainId = 0xdeadbeef;
174173

175174
// check that helper matches entrypoint logic
176-
expect(this.entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(this.entrypoint, chainId));
175+
expect(entrypoint.getUserOpHash(userOp.packed)).to.eventually.equal(userOp.hash(entrypoint, chainId));
177176

178177
// check library against helper
179-
expect(this.utils.$hash(userOp.packed, this.entrypoint, chainId)).to.eventually.equal(
180-
userOp.hash(this.entrypoint, chainId),
178+
expect(this.utils.$hash(userOp.packed, entrypoint, chainId)).to.eventually.equal(
179+
userOp.hash(entrypoint, chainId),
181180
);
182-
expect(this.utils.$hash(userOp.packed, this.entrypoint, otherChainId)).to.eventually.equal(
183-
userOp.hash(this.entrypoint, otherChainId),
181+
expect(this.utils.$hash(userOp.packed, entrypoint, otherChainId)).to.eventually.equal(
182+
userOp.hash(entrypoint, otherChainId),
184183
);
185184
});
186185
});

test/helpers/erc4337-entrypoint.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)