EIP-4788: Add parentBeaconBlockRoot field to BlockHeader

This commit is contained in:
jangko 2023-08-18 17:52:55 +07:00
parent 946ffe0a4a
commit 074edff1b4
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 22 additions and 4 deletions

View File

@ -143,6 +143,7 @@ type
withdrawalsRoot*: Option[Hash256] # EIP-4895 withdrawalsRoot*: Option[Hash256] # EIP-4895
blobGasUsed*: Option[uint64] # EIP-4844 blobGasUsed*: Option[uint64] # EIP-4844
excessBlobGas*: Option[uint64] # EIP-4844 excessBlobGas*: Option[uint64] # EIP-4844
parentBeaconBlockRoot*: Option[Hash256] # EIP-4788
BlockBody* = object BlockBody* = object
transactions*: seq[Transaction] transactions*: seq[Transaction]

View File

@ -4,7 +4,9 @@ import
unittest2, unittest2,
nimcrypto/hash, nimcrypto/hash,
serialization/testing/generic_suite, 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 = func `==`*(lhs, rhs: BlockHashOrNumber): bool =
if lhs.isHash != rhs.isHash: if lhs.isHash != rhs.isHash:
@ -15,6 +17,9 @@ func `==`*(lhs, rhs: BlockHashOrNumber): bool =
else: else:
lhs.number == rhs.number lhs.number == rhs.number
const
testHash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"
suite "BlockHashOrNumber": suite "BlockHashOrNumber":
test "construction": test "construction":
expect ValueError: expect ValueError:
@ -53,8 +58,20 @@ suite "BlockHashOrNumber":
"\"1209231231\"" "\"1209231231\""
test "EIP-4399 prevRandao field": test "EIP-4399 prevRandao field":
let hash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"
var blk: BlockHeader var blk: BlockHeader
blk.prevRandao = hash blk.prevRandao = testHash
let res = blk.prevRandao 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