mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-10 14:26:26 +00:00
switch assert(...) to doAssert(...) and minor cleanup
This commit is contained in:
parent
e46e9b12a2
commit
f5b8931fad
@ -19,9 +19,6 @@ Nimbus is currently going through interoperability testing with several other be
|
|||||||
* [multinet](https://github.com/status-im/nim-beacon-chain/tree/master/multinet) - a set of scripts to build and run several Eth2 clients locally
|
* [multinet](https://github.com/status-im/nim-beacon-chain/tree/master/multinet) - a set of scripts to build and run several Eth2 clients locally
|
||||||
* [ncli](https://github.com/status-im/nim-beacon-chain/tree/master/multinet) - command line tools for working with SSZ files and state transitions
|
* [ncli](https://github.com/status-im/nim-beacon-chain/tree/master/multinet) - command line tools for working with SSZ files and state transitions
|
||||||
|
|
||||||
⚠️ Important: To save bandwith `export GIT_LFS_SKIP_SMUDGE=1` before cloning the repo.
|
|
||||||
This prevents LFS during unusual clones (i.e. when you add `--recurse-submodules` without being instructed to do so).
|
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
* [status-im/nimbus](https://github.com/status-im/nimbus/): main Nimbus repository - start here to learn more about the Nimbus eco-system
|
* [status-im/nimbus](https://github.com/status-im/nimbus/): main Nimbus repository - start here to learn more about the Nimbus eco-system
|
||||||
|
@ -33,7 +33,7 @@ func init*(T: type BlockRef, root: Eth2Digest, blck: BeaconBlock): BlockRef =
|
|||||||
|
|
||||||
func findAncestorBySlot*(blck: BlockRef, slot: Slot): BlockSlot =
|
func findAncestorBySlot*(blck: BlockRef, slot: Slot): BlockSlot =
|
||||||
## Find the first ancestor that has a slot number less than or equal to `slot`
|
## Find the first ancestor that has a slot number less than or equal to `slot`
|
||||||
assert(not blck.isNil)
|
doAssert(not blck.isNil)
|
||||||
var ret = blck
|
var ret = blck
|
||||||
|
|
||||||
while ret.parent != nil and ret.slot > slot:
|
while ret.parent != nil and ret.slot > slot:
|
||||||
|
@ -70,7 +70,7 @@ proc main() {.async.} =
|
|||||||
web3.privateKey = initPrivateKey(cfg.privateKey)
|
web3.privateKey = initPrivateKey(cfg.privateKey)
|
||||||
else:
|
else:
|
||||||
let accounts = await web3.provider.eth_accounts()
|
let accounts = await web3.provider.eth_accounts()
|
||||||
assert(accounts.len > 0)
|
doAssert(accounts.len > 0)
|
||||||
web3.defaultAccount = accounts[0]
|
web3.defaultAccount = accounts[0]
|
||||||
|
|
||||||
case cfg.cmd
|
case cfg.cmd
|
||||||
|
@ -215,7 +215,7 @@ func fromBytes*[T](R: type BlsValue[T], bytes: openarray[byte]): R =
|
|||||||
if not success:
|
if not success:
|
||||||
# TODO: chronicles trace
|
# TODO: chronicles trace
|
||||||
result = R(kind: OpaqueBlob)
|
result = R(kind: OpaqueBlob)
|
||||||
assert result.blob.len == bytes.len
|
doAssert result.blob.len == bytes.len
|
||||||
result.blob[result.blob.low .. result.blob.high] = bytes
|
result.blob[result.blob.low .. result.blob.high] = bytes
|
||||||
|
|
||||||
func fromHex*[T](R: type BlsValue[T], hexStr: string): R =
|
func fromHex*[T](R: type BlsValue[T], hexStr: string): R =
|
||||||
|
@ -107,7 +107,7 @@ proc inspectType(tImpl, xSubField, ySubField: NimNode, stmts: var NimNode) =
|
|||||||
"\" of type \"" & tImpl.repr
|
"\" of type \"" & tImpl.repr
|
||||||
|
|
||||||
macro reportDiff*(x, y: typed{`var`|`let`|`const`}): untyped =
|
macro reportDiff*(x, y: typed{`var`|`let`|`const`}): untyped =
|
||||||
assert sameType(x, y)
|
doAssert sameType(x, y)
|
||||||
result = newStmtList()
|
result = newStmtList()
|
||||||
|
|
||||||
let typeImpl = x.getTypeImpl
|
let typeImpl = x.getTypeImpl
|
||||||
|
@ -9,6 +9,6 @@ import
|
|||||||
../../beacon_chain/spec/digest
|
../../beacon_chain/spec/digest
|
||||||
|
|
||||||
proc `*`*(a: static array[1, byte], n: static int): static Eth2Digest =
|
proc `*`*(a: static array[1, byte], n: static int): static Eth2Digest =
|
||||||
assert n == 32
|
doAssert n == 32
|
||||||
for mbyte in result.data.mitems:
|
for mbyte in result.data.mitems:
|
||||||
mbyte = a[0]
|
mbyte = a[0]
|
||||||
|
@ -102,7 +102,7 @@ proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
|
|||||||
proc runSSZtests() =
|
proc runSSZtests() =
|
||||||
doAssert existsDir(SSZDir), "You need to run the \"download_test_vectors.sh\" script to retrieve the official test vectors."
|
doAssert existsDir(SSZDir), "You need to run the \"download_test_vectors.sh\" script to retrieve the official test vectors."
|
||||||
for pathKind, sszType in walkDir(SSZDir, relative = true):
|
for pathKind, sszType in walkDir(SSZDir, relative = true):
|
||||||
assert pathKind == pcDir
|
doAssert pathKind == pcDir
|
||||||
if sszType in Unsupported:
|
if sszType in Unsupported:
|
||||||
test &" Skipping {sszType:20} consensus object ✗✗✗":
|
test &" Skipping {sszType:20} consensus object ✗✗✗":
|
||||||
discard
|
discard
|
||||||
@ -117,7 +117,7 @@ proc runSSZtests() =
|
|||||||
test &" Testing {sszType:20} consensus object ✓✓✓":
|
test &" Testing {sszType:20} consensus object ✓✓✓":
|
||||||
let path = SSZDir/sszType
|
let path = SSZDir/sszType
|
||||||
for pathKind, sszTestKind in walkDir(path, relative = true):
|
for pathKind, sszTestKind in walkDir(path, relative = true):
|
||||||
assert pathKind == pcDir
|
doAssert pathKind == pcDir
|
||||||
let path = SSZDir/sszType/sszTestKind
|
let path = SSZDir/sszType/sszTestKind
|
||||||
for pathKind, sszTestCase in walkDir(path, relative = true):
|
for pathKind, sszTestCase in walkDir(path, relative = true):
|
||||||
let path = SSZDir/sszType/sszTestKind/sszTestCase
|
let path = SSZDir/sszType/sszTestKind/sszTestCase
|
||||||
|
@ -133,7 +133,7 @@ proc checkVector(sszSubType, dir: string, expectedHash: SSZHashTreeRoot) =
|
|||||||
var typeIdent: string
|
var typeIdent: string
|
||||||
var size: int
|
var size: int
|
||||||
let wasMatched = scanf(sszSubType, "vec_$+_$i", typeIdent, size)
|
let wasMatched = scanf(sszSubType, "vec_$+_$i", typeIdent, size)
|
||||||
assert wasMatched
|
doAssert wasMatched
|
||||||
testVector(typeIdent, size)
|
testVector(typeIdent, size)
|
||||||
|
|
||||||
type BitContainer[N: static int] = BitList[N] or BitArray[N]
|
type BitContainer[N: static int] = BitList[N] or BitArray[N]
|
||||||
@ -147,7 +147,7 @@ proc testBitContainer(T: typedesc[BitContainer], dir: string, expectedHash: SSZH
|
|||||||
proc checkBitVector(sszSubType, dir: string, expectedHash: SSZHashTreeRoot) =
|
proc checkBitVector(sszSubType, dir: string, expectedHash: SSZHashTreeRoot) =
|
||||||
var size: int
|
var size: int
|
||||||
let wasMatched = scanf(sszSubType, "bitvec_$i", size)
|
let wasMatched = scanf(sszSubType, "bitvec_$i", size)
|
||||||
assert wasMatched
|
doAssert wasMatched
|
||||||
case size
|
case size
|
||||||
of 1: testBitContainer(BitArray[1], dir, expectedHash)
|
of 1: testBitContainer(BitArray[1], dir, expectedHash)
|
||||||
of 2: testBitContainer(BitArray[2], dir, expectedHash)
|
of 2: testBitContainer(BitArray[2], dir, expectedHash)
|
||||||
@ -199,7 +199,7 @@ proc sszCheck(sszType, sszSubType: string) =
|
|||||||
of "uints":
|
of "uints":
|
||||||
var bitsize: int
|
var bitsize: int
|
||||||
let wasMatched = scanf(sszSubType, "uint_$i", bitsize)
|
let wasMatched = scanf(sszSubType, "uint_$i", bitsize)
|
||||||
assert wasMatched
|
doAssert wasMatched
|
||||||
case bitsize
|
case bitsize
|
||||||
of 8: checkBasic(uint8, dir, expectedHash)
|
of 8: checkBasic(uint8, dir, expectedHash)
|
||||||
of 16: checkBasic(uint16, dir, expectedHash)
|
of 16: checkBasic(uint16, dir, expectedHash)
|
||||||
@ -219,7 +219,7 @@ proc sszCheck(sszType, sszSubType: string) =
|
|||||||
of "containers":
|
of "containers":
|
||||||
var name: string
|
var name: string
|
||||||
let wasMatched = scanf(sszSubtype, "$+_", name)
|
let wasMatched = scanf(sszSubtype, "$+_", name)
|
||||||
assert wasMatched
|
doAssert wasMatched
|
||||||
case name
|
case name
|
||||||
of "SingleFieldTestStruct": checkBasic(SingleFieldTestStruct, dir, expectedHash)
|
of "SingleFieldTestStruct": checkBasic(SingleFieldTestStruct, dir, expectedHash)
|
||||||
of "SmallTestStruct": checkBasic(SmallTestStruct, dir, expectedHash)
|
of "SmallTestStruct": checkBasic(SmallTestStruct, dir, expectedHash)
|
||||||
@ -249,7 +249,7 @@ proc sszCheck(sszType, sszSubType: string) =
|
|||||||
proc runSSZtests() =
|
proc runSSZtests() =
|
||||||
doAssert existsDir(SSZDir), "You need to run the \"download_test_vectors.sh\" script to retrieve the official test vectors."
|
doAssert existsDir(SSZDir), "You need to run the \"download_test_vectors.sh\" script to retrieve the official test vectors."
|
||||||
for pathKind, sszType in walkDir(SSZDir, relative = true):
|
for pathKind, sszType in walkDir(SSZDir, relative = true):
|
||||||
assert pathKind == pcDir
|
doAssert pathKind == pcDir
|
||||||
if sszType == "bitlist":
|
if sszType == "bitlist":
|
||||||
test &"**Skipping** {sszType} inputs - valid - skipped altogether":
|
test &"**Skipping** {sszType} inputs - valid - skipped altogether":
|
||||||
# TODO: serialization of "type BitList[maxLen] = distinct BitSeq is not supported"
|
# TODO: serialization of "type BitList[maxLen] = distinct BitSeq is not supported"
|
||||||
@ -269,7 +269,7 @@ proc runSSZtests() =
|
|||||||
test &"Testing {sszType:12} inputs - valid" & skipped:
|
test &"Testing {sszType:12} inputs - valid" & skipped:
|
||||||
let path = SSZDir/sszType/"valid"
|
let path = SSZDir/sszType/"valid"
|
||||||
for pathKind, sszSubType in walkDir(path, relative = true):
|
for pathKind, sszSubType in walkDir(path, relative = true):
|
||||||
assert pathKind == pcDir
|
doAssert pathKind == pcDir
|
||||||
sszCheck(sszType, sszSubType)
|
sszCheck(sszType, sszSubType)
|
||||||
|
|
||||||
# TODO: nim-serialization forces us to use exceptions as control flow
|
# TODO: nim-serialization forces us to use exceptions as control flow
|
||||||
|
@ -24,24 +24,24 @@ type
|
|||||||
# data: array[256, bool]
|
# data: array[256, bool]
|
||||||
|
|
||||||
template reject(stmt) =
|
template reject(stmt) =
|
||||||
assert(not compiles(stmt))
|
doAssert(not compiles(stmt))
|
||||||
|
|
||||||
static:
|
static:
|
||||||
assert isFixedSize(bool) == true
|
doAssert isFixedSize(bool) == true
|
||||||
|
|
||||||
assert fixedPortionSize(array[10, bool]) == 10
|
doAssert fixedPortionSize(array[10, bool]) == 10
|
||||||
assert fixedPortionSize(array[SomeEnum, uint64]) == 24
|
doAssert fixedPortionSize(array[SomeEnum, uint64]) == 24
|
||||||
assert fixedPortionSize(array[3..5, string]) == 12
|
doAssert fixedPortionSize(array[3..5, string]) == 12
|
||||||
|
|
||||||
assert fixedPortionSize(string) == 4
|
doAssert fixedPortionSize(string) == 4
|
||||||
assert fixedPortionSize(seq[bool]) == 4
|
doAssert fixedPortionSize(seq[bool]) == 4
|
||||||
assert fixedPortionSize(seq[string]) == 4
|
doAssert fixedPortionSize(seq[string]) == 4
|
||||||
|
|
||||||
assert isFixedSize(array[20, bool]) == true
|
doAssert isFixedSize(array[20, bool]) == true
|
||||||
assert isFixedSize(Simple) == true
|
doAssert isFixedSize(Simple) == true
|
||||||
assert isFixedSize(string) == false
|
doAssert isFixedSize(string) == false
|
||||||
assert isFixedSize(seq[bool]) == false
|
doAssert isFixedSize(seq[bool]) == false
|
||||||
assert isFixedSize(seq[string]) == false
|
doAssert isFixedSize(seq[string]) == false
|
||||||
|
|
||||||
reject fixedPortionSize(int)
|
reject fixedPortionSize(int)
|
||||||
|
|
||||||
@ -55,7 +55,8 @@ type
|
|||||||
f5: ValidatorIndex
|
f5: ValidatorIndex
|
||||||
|
|
||||||
static:
|
static:
|
||||||
assert fixedPortionSize(ObjWithFields) == 1 + 4 + sizeof(EthAddress) + (256 div 8) + 4 + 8
|
doAssert fixedPortionSize(ObjWithFields) ==
|
||||||
|
1 + 4 + sizeof(EthAddress) + (256 div 8) + 4 + 8
|
||||||
|
|
||||||
executeRoundTripTests SSZ
|
executeRoundTripTests SSZ
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user