Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically deploy entrypoint, and make it available in the hre #5391

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions hardhat/common-contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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(() =>
Promise.all(
Object.entries(INSTANCES).map(([name, { address, abi, bytecode }]) =>
setCode(address, '0x' + bytecode.replace(/0x/, '')).then(() =>
env.ethers.getContractAt(abi, address).then(instance => (env[name] = instance)),
),
),
),
),
);
17 changes: 8 additions & 9 deletions test/account/utils/draft-ERC4337Utils.test.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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),
);
});
});
Expand Down
31 changes: 0 additions & 31 deletions test/helpers/erc4337-entrypoint.js

This file was deleted.

Loading