Skip to content

Commit

Permalink
EIP-4788: Add parentBeaconBlockRoot field to BlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Aug 18, 2023
1 parent 946ffe0 commit 074edff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions eth/common/eth_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ type
withdrawalsRoot*: Option[Hash256] # EIP-4895
blobGasUsed*: Option[uint64] # EIP-4844
excessBlobGas*: Option[uint64] # EIP-4844
parentBeaconBlockRoot*: Option[Hash256] # EIP-4788

BlockBody* = object
transactions*: seq[Transaction]
Expand Down
25 changes: 21 additions & 4 deletions tests/common/test_eth_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import
unittest2,
nimcrypto/hash,
serialization/testing/generic_suite,
../../eth/common/[eth_types, eth_types_json_serialization]
../../eth/common/[eth_types, eth_types_json_serialization],
../../eth/common/eth_types_rlp,
../../eth/rlp

func `==`*(lhs, rhs: BlockHashOrNumber): bool =
if lhs.isHash != rhs.isHash:
Expand All @@ -15,6 +17,9 @@ func `==`*(lhs, rhs: BlockHashOrNumber): bool =
else:
lhs.number == rhs.number

const
testHash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"

suite "BlockHashOrNumber":
test "construction":
expect ValueError:
Expand Down Expand Up @@ -53,8 +58,20 @@ suite "BlockHashOrNumber":
"\"1209231231\""

test "EIP-4399 prevRandao field":
let hash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"
var blk: BlockHeader
blk.prevRandao = hash
blk.prevRandao = testHash
let res = blk.prevRandao
check hash == res
check testHash == res

test "EIP-4788 parentBeaconBlockRoot field":
let header = BlockHeader(
fee: some(0.u256),
withdrawalsRoot: some(testHash),
blobGasUsed: some(1'u64),
excessBlobGas: some(2'u64),
parentBeaconBlockRoot: some(testHash),
)
let rlpBytes = rlp.encode(header)
let dh = rlp.decode(rlpBytes, BlockHeader)
check dh.parentBeaconBlockRoot.isSome
check dh.parentBeaconBlockRoot.get == testHash

0 comments on commit 074edff

Please sign in to comment.