Skip to content

Commit

Permalink
debug and fix vm api 6110, 7002 request spec test
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed May 4, 2024
1 parent a48299f commit ff01018
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/vm/test/api/EIPs/eip-6110.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Block } from '@ethereumjs/block'
import { Chain, Common, Hardfork } from '@ethereumjs/common'
import { RLP } from '@ethereumjs/rlp'
import { TransactionFactory } from '@ethereumjs/tx'
import { Account, Address, bytesToHex, hexToBytes, randomBytes } from '@ethereumjs/util'
import { keccak256 } from 'ethereum-cryptography/keccak.js'
import { assert, describe, it } from 'vitest'

import { setupVM } from '../utils.js'

import type { DepositRequest } from '../../../../util/src/requests.js'
import type { PrefixedHexString } from '@ethereumjs/util'

const depositContractByteCode = hexToBytes(
Expand Down Expand Up @@ -59,7 +59,8 @@ describe('EIP-6110 runBlock tests', () => {
)
const res = await vm.runBlock({ block, generate: true, skipBlockValidation: true })
assert.equal(res.requests?.length, 1)
assert.equal(bytesToHex((RLP.decode(res.requests![0].bytes) as Uint8Array[])[0]), pubkey)
const reqPubkey = (res.requests![0] as DepositRequest).pubkey
assert.equal(bytesToHex(reqPubkey), pubkey)
})
})

Expand Down Expand Up @@ -92,6 +93,7 @@ describe('EIP-7685 buildBlock tests', () => {
await blockBuilder.addTransaction(depositTx)
const res = await blockBuilder.build()
assert.equal(res.requests?.length, 1)
assert.equal(bytesToHex((RLP.decode(res.requests![0].bytes) as Uint8Array[])[0]), pubkey)
const reqPubkey = (res.requests![0] as DepositRequest).pubkey
assert.equal(bytesToHex(reqPubkey), pubkey)
})
})
7 changes: 5 additions & 2 deletions packages/vm/test/api/EIPs/eip-7002.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { bytesToBigInt } from '../../../../util/src/bytes.js'
import { setupVM } from '../utils.js'

const pkey = hexToBytes(`0x${'20'.repeat(32)}`)
Expand Down Expand Up @@ -117,7 +118,7 @@ describe('EIP-7002 tests', () => {
// Ensure the request is generated
assert.ok(generatedBlock!.requests!.length === 1)

const requestDecoded = RLP.decode(generatedBlock!.requests![0].bytes)
const requestDecoded = RLP.decode(generatedBlock!.requests![0].serialize().slice(1))

const sourceAddressRequest = requestDecoded[0] as Uint8Array
const validatorPubkeyRequest = requestDecoded[1] as Uint8Array
Expand All @@ -126,7 +127,9 @@ describe('EIP-7002 tests', () => {
// Ensure the requests are correct
assert.ok(equalsBytes(sourceAddressRequest, tx.getSenderAddress().bytes))
assert.ok(equalsBytes(validatorPubkey, validatorPubkeyRequest))
assert.ok(equalsBytes(amountBytes, amountRequest))
// the direct byte comparision fails because leadign zeros have been stripped
// off the amountBytes because it was serialized in request from bigint
assert.ok(bytesToBigInt(amountBytes), bytesToBigInt(amountRequest))

await vm.runBlock({ block: generatedBlock!, skipHeaderValidation: true, root })

Expand Down

0 comments on commit ff01018

Please sign in to comment.