mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-24 09:48:24 +00:00
Adjust ForkDigest dynamically in Portal beacon content tests (#2778)
Also iterates over multiple dirs now to run tests for each fork.
This commit is contained in:
parent
738cb277cf
commit
85d8ed7be1
@ -8,6 +8,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/os,
|
||||
unittest2,
|
||||
stew/byteutils,
|
||||
stew/io2,
|
||||
@ -42,9 +43,10 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
genesis_validators_root = getStateField(genesisState[], genesis_validators_root)
|
||||
forkDigests = newClone ForkDigests.init(metadata.cfg, genesis_validators_root)
|
||||
|
||||
for path in walkDirRec(testVectorDir, yieldFilter = {pcDir}):
|
||||
test "LightClientBootstrap":
|
||||
const file = testVectorDir & "bootstrap.yaml"
|
||||
let
|
||||
file = path / "bootstrap.yaml"
|
||||
c = YamlPortalContent.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Invalid test vector file: " & error
|
||||
|
||||
@ -67,15 +69,22 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
let blockRoot = hash_tree_root(forkyObject.header.beacon)
|
||||
check blockRoot == key.lightClientBootstrapKey.blockHash
|
||||
|
||||
# re-encode content and content key
|
||||
let encoded = encodeForkedLightClientObject(bootstrap, forkDigests.capella)
|
||||
# Getting the forkDigest here is not great, ideally we can use `atConsensusFork`
|
||||
# but it turns out that the `LightClientDataFork` is not the same as the
|
||||
# `ConsensusFork`.
|
||||
let forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.header.beacon.slot), metadata.cfg
|
||||
)
|
||||
|
||||
check encoded == contentValueEncoded
|
||||
# re-encode content and content key
|
||||
let encoded = encodeForkedLightClientObject(bootstrap, forkDigest)
|
||||
|
||||
check encoded.toHex() == contentValueEncoded.toHex()
|
||||
check encode(key).asSeq() == contentKeyEncoded
|
||||
|
||||
test "LightClientUpdates":
|
||||
const file = testVectorDir & "updates.yaml"
|
||||
let
|
||||
file = path / "updates.yaml"
|
||||
c = YamlPortalContent.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Invalid test vector file: " & error
|
||||
|
||||
@ -84,7 +93,8 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
|
||||
# Decode content and content key
|
||||
contentKey = decodeSsz(contentKeyEncoded, ContentKey)
|
||||
contentValue = decodeLightClientUpdatesByRange(forkDigests[], contentValueEncoded)
|
||||
contentValue =
|
||||
decodeLightClientUpdatesByRange(forkDigests[], contentValueEncoded)
|
||||
check:
|
||||
contentKey.isOk()
|
||||
contentValue.isOk()
|
||||
@ -101,15 +111,21 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
(SLOTS_PER_EPOCH * EPOCHS_PER_SYNC_COMMITTEE_PERIOD) ==
|
||||
key.lightClientUpdateKey.startPeriod + uint64(i)
|
||||
|
||||
# re-encode content and content key
|
||||
let encoded = encodeLightClientUpdatesForked(forkDigests.capella, updates.asSeq())
|
||||
let forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[],
|
||||
epoch(forkyObject.attested_header.beacon.slot),
|
||||
metadata.cfg,
|
||||
)
|
||||
|
||||
check encoded == contentValueEncoded
|
||||
# re-encode content and content key
|
||||
let encoded = encodeLightClientUpdatesForked(forkDigest, updates.asSeq())
|
||||
|
||||
check encoded.toHex() == contentValueEncoded.toHex()
|
||||
check encode(key).asSeq() == contentKeyEncoded
|
||||
|
||||
test "LightClientFinalityUpdate":
|
||||
const file = testVectorDir & "finality_update.yaml"
|
||||
let
|
||||
file = path / "finality_update.yaml"
|
||||
c = YamlPortalContent.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Invalid test vector file: " & error
|
||||
|
||||
@ -132,15 +148,19 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
check forkyObject.finalized_header.beacon.slot ==
|
||||
key.lightClientFinalityUpdateKey.finalizedSlot
|
||||
|
||||
# re-encode content and content key
|
||||
let encoded = encodeForkedLightClientObject(update, forkDigests.capella)
|
||||
let forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), metadata.cfg
|
||||
)
|
||||
|
||||
check encoded == contentValueEncoded
|
||||
# re-encode content and content key
|
||||
let encoded = encodeForkedLightClientObject(update, forkDigest)
|
||||
|
||||
check encoded.toHex() == contentValueEncoded.toHex()
|
||||
check encode(key).asSeq() == contentKeyEncoded
|
||||
|
||||
test "LightClientOptimisticUpdate":
|
||||
const file = testVectorDir & "optimistic_update.yaml"
|
||||
let
|
||||
file = path / "optimistic_update.yaml"
|
||||
c = YamlPortalContent.loadFromYaml(file).valueOr:
|
||||
raiseAssert "Invalid test vector file: " & error
|
||||
|
||||
@ -163,10 +183,13 @@ suite "Beacon Content Keys and Values - Test Vectors":
|
||||
check forkyObject.signature_slot ==
|
||||
key.lightClientOptimisticUpdateKey.optimisticSlot
|
||||
|
||||
let forkDigest = forkDigestAtEpoch(
|
||||
forkDigests[], epoch(forkyObject.attested_header.beacon.slot), metadata.cfg
|
||||
)
|
||||
# re-encode content and content key
|
||||
let encoded = encodeForkedLightClientObject(update, forkDigests.capella)
|
||||
let encoded = encodeForkedLightClientObject(update, forkDigest)
|
||||
|
||||
check encoded == contentValueEncoded
|
||||
check encoded.toHex() == contentValueEncoded.toHex()
|
||||
check encode(key).asSeq() == contentKeyEncoded
|
||||
|
||||
suite "Beacon Content Keys and Values":
|
||||
|
Loading…
x
Reference in New Issue
Block a user