Skip to content

Commit

Permalink
use latest hardhat, with support for eth_call state-override
Browse files Browse the repository at this point in the history
  • Loading branch information
drortirosh committed Aug 28, 2023
1 parent e2f4703 commit 28e0fe7
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 155 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
"@typechain/ethers-v5": "^10.1.0",
"@types/chai": "^4.2.21",
"@types/node": "^16.4.12",
Expand All @@ -48,7 +48,7 @@
"eslint-plugin-standard": "^5.0.0",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.2",
"hardhat": "^2.6.6",
"hardhat": "^2.17.2",
"solhint": "^3.3.7",
"ts-generator": "^0.1.1",
"ts-mocha": "^10.0.0",
Expand Down
22 changes: 2 additions & 20 deletions test/UserOp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,22 +218,6 @@ export async function fillAndSign (op: Partial<UserOperation>, signer: Wallet |
}

// temporary helper method: hardhat currently doesn't support "stateOverride"
async function provider_eth_call (tx: TransactionRequest, blockTag: BlockTag, stateOverride: any): Promise<string> {
try {
return await ethers.provider.send('eth_call', [tx, blockTag, stateOverride])
} catch (e) {
// minimal "stateOverride" support: assuming a single [entryPointAddress]: { code: deployedBytedCode } entry
const entryPointAddress = Object.keys(stateOverride)[0]
const deployedByteCode = stateOverride[entryPointAddress].code
await ethers.provider.send('hardhat_setCode', [entryPointAddress, deployedByteCode])
try {
return await ethers.provider.send('eth_call', [tx, blockTag])
} finally {
await ethers.provider.send('hardhat_setCode', [entryPointAddress, EntryPointJson.deployedBytecode])
}
}
}

/**
* This function relies on a "state override" functionality of the 'eth_call' RPC method
* in order to provide the details of a simulated validation call to the bundler
Expand All @@ -258,8 +242,7 @@ export async function simulateValidation (
}
}
try {
// const simulationResult = await ethers.provider.send('eth_call', [tx, 'latest', stateOverride])
const simulationResult = await provider_eth_call(tx, 'latest', stateOverride)
const simulationResult = await ethers.provider.send('eth_call', [tx, 'latest', stateOverride])
const res = entryPointSimulations.decodeFunctionResult('simulateValidation', simulationResult)
// note: here collapsing the returned "tuple of one" into a single value - will break for returning actual tuples
return res[0]
Expand Down Expand Up @@ -294,8 +277,7 @@ export async function simulateHandleOp (
}
}
try {
// const simulationResult = await ethers.provider.send('eth_call', [tx, 'latest', stateOverride])
const simulationResult = await provider_eth_call(tx, 'latest', stateOverride)
const simulationResult = await ethers.provider.send('eth_call', [tx, 'latest', stateOverride])
const res = entryPointSimulations.decodeFunctionResult('simulateHandleOp', simulationResult)
// note: here collapsing the returned "tuple of one" into a single value - will break for returning actual tuples
return res[0]
Expand Down
2 changes: 1 addition & 1 deletion test/entrypointsimulations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('EntryPointSimulations', function () {
// await checkStateDiffSupported()
})

describe.only('Simulation Contract Sannity checks', () => {
describe('Simulation Contract Sannity checks', () => {
const addr = createAddress()

function costInRange (simCost: BigNumber, epCost: BigNumber, message: string): void {
Expand Down
Loading

0 comments on commit 28e0fe7

Please sign in to comment.