EIP-4399 preparation

From EIP-4399 spec:

Renaming

The mixHash field SHOULD further be renamed to random.

...
This commit is contained in:
jangko 2022-02-01 13:41:50 +07:00
parent eb6fd2a7b6
commit cf95b688e6
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 19 additions and 0 deletions

View File

@ -74,6 +74,9 @@ task test_db, "Run db tests":
task test_utp, "Run utp tests": task test_utp, "Run utp tests":
runTest("tests/utp/all_utp_tests") runTest("tests/utp/all_utp_tests")
task test_common, "Run common tests":
runTest("tests/common/test_eth_types")
task test, "Run all tests": task test, "Run all tests":
for filename in [ for filename in [
"test_bloom", "test_bloom",
@ -87,6 +90,7 @@ task test, "Run all tests":
test_trie_task() test_trie_task()
test_db_task() test_db_task()
test_utp_task() test_utp_task()
test_common_task()
task test_discv5_full, "Run discovery v5 and its dependencies tests": task test_discv5_full, "Run discovery v5 and its dependencies tests":
test_keys_task() test_keys_task()

View File

@ -244,6 +244,14 @@ func baseFee*(h: BlockHeader | BlockHeaderRef): UInt256 =
template `baseFee=`*(h: BlockHeader | BlockHeaderRef, data: UInt256) = template `baseFee=`*(h: BlockHeader | BlockHeaderRef, data: UInt256) =
h.fee = some(data) h.fee = some(data)
# starting from EIP-4399, `mixHash`/`mixDigest` field will be alled `random`
# https://github.com/ethereum/EIPs/blob/bd156daf2afa38aa95bc2137d3121ff536e50645/EIPS/eip-4399.md
template random*(h: BlockHeader | BlockHeaderRef): Hash256 =
h.mixDigest
template `random=`*(h: BlockHeader | BlockHeaderRef, hash: Hash256) =
h.mixDigest = hash
func toBlockNonce*(n: uint64): BlockNonce = func toBlockNonce*(n: uint64): BlockNonce =
n.toBytesBE() n.toBytesBE()

View File

@ -49,3 +49,10 @@ suite "BlockHashOrNumber":
Json.roundtripTest BlockHashOrNumber(isHash: false, number: 1209231231), Json.roundtripTest BlockHashOrNumber(isHash: false, number: 1209231231),
"\"1209231231\"" "\"1209231231\""
test "EIP-4399 random field":
let hash = Hash256.fromHex "0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588"
var blk: BlockHeader
blk.random = hash
let res = blk.random
check hash == res