Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion AllTests-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,11 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
+ Accelerated shuffling computation (with epochRefState jump) OK
```
OK: 2/2 Fail: 0/2 Skip: 0/2
## Size bounds
```diff
+ SignedBeaconBlockDeneb OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## Slashing Interchange tests [Preset: mainnet]
```diff
+ Slashing test: duplicate_pubkey_not_slashable.json OK
Expand Down Expand Up @@ -1144,4 +1149,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9

---TOTAL---
OK: 777/782 Fail: 0/782 Skip: 5/782
OK: 778/783 Fail: 0/783 Skip: 5/783
65 changes: 62 additions & 3 deletions tests/test_eth2_ssz_serialization.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Copyright (c) 2018-2025 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
Expand All @@ -9,9 +9,11 @@
{.used.}

import
std/strutils,
unittest2,
../beacon_chain/spec/datatypes/[phase0, altair],
../beacon_chain/spec/eth2_ssz_serialization
../beacon_chain/spec/datatypes/[phase0, altair, bellatrix, deneb],
../beacon_chain/spec/eth2_ssz_serialization,
./consensus_spec/os_ops

static:
doAssert isFixedSize(Slot) == true
Expand Down Expand Up @@ -49,3 +51,60 @@ suite "Specific field types":
testit(phase0.TrustedSignedBeaconBlock)
testit(altair.SignedBeaconBlock)
testit(altair.TrustedSignedBeaconBlock)

suite "Size bounds":
test "SignedBeaconBlockDeneb":
# https://gist.github.com/tbenr/a0ae19fe7496106886ec1f3cc097c208
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
let expected = os_ops.readFile(
sourceDir/"test_files"/"SszLengthBounds_SignedBeaconBlockDeneb.txt")

var
res = ""
loc = @["SignedBeaconBlockDeneb"]
func record(T: typedesc) =
when T is SomeSig|ValidatorPubKey:
res.add loc.join(".") & "[" & $T.blob.len & "]: SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
loc[^1].add "[element]"
byte.record()
elif T is ExecutionAddress|BloomLogs:
res.add loc.join(".") & "[" & $T.data.len & "]: SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
loc[^1].add "[element]"
byte.record()
elif T is KzgCommitment:
res.add loc.join(".") & "[" & $T.bytes.len & "]: SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
loc[^1].add "[element]"
byte.record()
elif T is array|HashArray:
res.add loc.join(".") & "[" & $T.len & "]: SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
loc[^1].add "[element]"
ElemType(T).record()
elif T is List|HashList:
res.add loc.join(".") & "(" & $T.maxLen & "): SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
loc[^1].add "(element)"
ElemType(T).record()
elif T is BitArray:
res.add loc.join(".") & "[" & $T.bits & "]: SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
res.add loc.join(".") & "[element]: SszLengthBounds" &
"{min=0(+1 bits), max=0(+1 bits)}\n"
elif T is BitList:
res.add loc.join(".") & "(" & $T.maxLen & "): SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
res.add loc.join(".") & "(element): SszLengthBounds" &
"{min=0(+1 bits), max=0(+1 bits)}\n"
else:
res.add loc.join(".") & ": SszLengthBounds" &
"{min=" & $T.minSize & ", max=" & $T.maxSize & "}\n"
when T is object and T isnot Eth2Digest|UInt256:
T.enumAllSerializedFields():
loc.add fieldName
record(FieldType)
discard loc.pop()
record deneb.SignedBeaconBlock
check res.splitLines() == expected.splitLines()
Loading