Skip to content

Commit

Permalink
Update state network tests to use block_header instead of state_root.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhartnett committed Aug 19, 2024
1 parent 193858b commit 6f58abf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
4 changes: 2 additions & 2 deletions fluffy/tests/state_network_tests/state_test_helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const testVectorDir* = "./vendor/portal-spec-tests/tests/mainnet/state/validatio

type
YamlTrieNodeKV* = object
state_root*: string
block_header*: string
content_key*: string
content_value_offer*: string
content_value_retrieval*: string

YamlTrieNodeKVs* = seq[YamlTrieNodeKV]

YamlContractBytecodeKV* = object
state_root*: string
block_header*: string
content_key*: string
content_value_offer*: string
content_value_retrieval*: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import
eth/common,
eth/p2p/discoveryv5/protocol as discv5_protocol,
eth/p2p/discoveryv5/routing_table,
../../common/common_utils,
../../network/wire/[portal_protocol, portal_stream],
../../network/state/
[state_content, state_network, state_gossip, state_endpoints, state_utils],
Expand Down Expand Up @@ -50,7 +49,8 @@ procSuite "State Endpoints":
continue

let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
leafData = testData
contentKeyBytes = leafData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
Expand Down Expand Up @@ -158,7 +158,8 @@ procSuite "State Endpoints":
# seed the account data
let
testData = accountTrieTestCase[0]
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
leafData = testData
contentKeyBytes = leafData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
Expand Down Expand Up @@ -186,7 +187,8 @@ procSuite "State Endpoints":
# seed the storage data
let
testData = contractTrieTestCase[0]
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
leafData = testData
contentKeyBytes = leafData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
Expand Down Expand Up @@ -234,7 +236,8 @@ procSuite "State Endpoints":
testCase = YamlContractBytecodeKVs.loadFromYaml(bytecodeFile).valueOr:
raiseAssert "Cannot read test vector: " & error
testData = testCase[0]
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import
eth/common,
eth/p2p/discoveryv5/protocol as discv5_protocol,
eth/p2p/discoveryv5/routing_table,
../../common/common_utils,
../../network/wire/[portal_protocol, portal_stream],
../../network/state/[state_content, state_network, state_gossip],
../../database/content_db,
Expand Down Expand Up @@ -47,7 +46,8 @@ procSuite "State Gossip - Gossip Offer":

let
parentTestData = testCase[i + 1]
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -120,7 +120,8 @@ procSuite "State Gossip - Gossip Offer":

let
parentTestData = testCase[i + 1]
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -190,7 +191,8 @@ procSuite "State Gossip - Gossip Offer":

for i, testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -104,7 +105,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -173,7 +175,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -243,7 +246,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -292,7 +296,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down Expand Up @@ -342,7 +347,8 @@ procSuite "State Network - Offer Content":

for testData in testCase:
let
stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot
contentKeyBytes = testData.content_key.hexToSeqByte().ContentKeyByteList
contentKey = ContentKey.decode(contentKeyBytes).get()
contentId = toContentId(contentKeyBytes)
Expand Down
24 changes: 16 additions & 8 deletions fluffy/tests/state_network_tests/test_state_validation_vectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

block:
let contentKey = ContentKey
Expand Down Expand Up @@ -185,7 +186,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

let contentKey =
ContentKey.decode(testData.content_key.hexToSeqByte().ContentKeyByteList).get()
Expand All @@ -204,7 +206,8 @@ suite "State Validation - Test Vectors":
for i, testData in testCase:
if i == 2:
continue # second test case only has root node
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

let contentKey =
ContentKey.decode(testData.content_key.hexToSeqByte().ContentKeyByteList).get()
Expand All @@ -221,7 +224,8 @@ suite "State Validation - Test Vectors":
"hash of next node doesn't match the expected" in res.error()

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

let contentKey =
ContentKey.decode(testData.content_key.hexToSeqByte().ContentKeyByteList).get()
Expand All @@ -245,7 +249,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

block:
let contentKey = ContentKey
Expand Down Expand Up @@ -294,7 +299,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

block:
let contentKey = ContentKey
Expand Down Expand Up @@ -387,7 +393,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

let contentKey =
ContentKey.decode(testData.content_key.hexToSeqByte().ContentKeyByteList).get()
Expand Down Expand Up @@ -430,7 +437,8 @@ suite "State Validation - Test Vectors":
raiseAssert "Cannot read test vector: " & error

for i, testData in testCase:
var stateRoot = KeccakHash.fromBytes(testData.state_root.hexToSeqByte())
let stateRoot =
rlp.decode(testData.block_header.hexToSeqByte(), BlockHeader).stateRoot

block:
let contentKey = ContentKey
Expand Down

0 comments on commit 6f58abf

Please sign in to comment.