Skip to content

Commit

Permalink
vm: bump 7702 test coverage with one passing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Jul 1, 2024
1 parent aeccb99 commit f079602
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions packages/vm/test/api/EIPs/eip-7702.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EOACodeEIP7702Transaction } from '@ethereumjs/tx'
import {
Account,
Address,
BIGINT_1,
//BIGINT_1,
bigIntToBytes,
concatBytes,
Expand Down Expand Up @@ -68,8 +69,7 @@ describe('EIP 7702: set code to EOA accounts', () => {
maxFeePerGas: 1000,
authorizationList: authList,
to: defaultAuthAddr,
// value: BIGINT_1 // Note, by enabling this line, the account will not get deleted
// Therefore, this test will pass
value: BIGINT_1,
},
{ common }
).sign(defaultSenderPkey)
Expand All @@ -83,17 +83,47 @@ describe('EIP 7702: set code to EOA accounts', () => {
acc.balance = BigInt(1_000_000_000)
await vm.stateManager.putAccount(defaultSenderAddr, acc)

console.log(defaultAuthAddr.toString())
await vm.runTx({ tx })

const slot = hexToBytes('0x' + '00'.repeat(31) + '01')
const value = await vm.stateManager.getContractStorage(defaultAuthAddr, slot)
assert.ok(equalsBytes(unpadBytes(slot), value))
})

it('EIP-161 test case', async () => {
const vm = await VM.create({ common })
const authList = [
getAuthorizationListItem({
address: codeAddr,
}),
]
const tx = EOACodeEIP7702Transaction.fromTxData(
{
gasLimit: 100000,
maxFeePerGas: 1000,
authorizationList: authList,
to: defaultAuthAddr,
// value: BIGINT_1 // Note, by enabling this line, the account will not get deleted
// Therefore, this test will pass
},
{ common }
).sign(defaultSenderPkey)

// Store value 1 in storage slot 1
// PUSH1 PUSH1 SSTORE STOP
const code = hexToBytes('0x600160015500')
await vm.stateManager.putContractCode(codeAddr, code)

vm.evm.events?.on('step', (e) => {
console.log(e.address.toString(), e.opcode.name, e.stack)
})
const acc = (await vm.stateManager.getAccount(defaultSenderAddr)) ?? new Account()
acc.balance = BigInt(1_000_000_000)
await vm.stateManager.putAccount(defaultSenderAddr, acc)

await vm.runTx({ tx })

// Note: due to EIP-161, defaultAuthAddr is now deleted

const slot = hexToBytes('0x' + '00'.repeat(31) + '01')
// This will therefore throw (account does not exist)
const value = await vm.stateManager.getContractStorage(defaultAuthAddr, slot)

Check failure on line 127 in packages/vm/test/api/EIPs/eip-7702.spec.ts

View workflow job for this annotation

GitHub Actions / vm-api

test/api/EIPs/eip-7702.spec.ts > EIP 7702: set code to EOA accounts > EIP-161 test case

Error: getContractStorage() called on non-existing account ❯ DefaultStateManager.getContractStorage ../statemanager/src/stateManager.ts:490:13 ❯ test/api/EIPs/eip-7702.spec.ts:127:19
assert.ok(equalsBytes(unpadBytes(slot), value))
})
Expand Down

0 comments on commit f079602

Please sign in to comment.