switch assert(...) to doAssert(...) and minor cleanup

This commit is contained in:
Dustin Brody 2019-11-22 16:47:08 +01:00
parent e46e9b12a2
commit f5b8931fad
9 changed files with 28 additions and 30 deletions

View File

@ -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
* [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
* [status-im/nimbus](https://github.com/status-im/nimbus/): main Nimbus repository - start here to learn more about the Nimbus eco-system

View File

@ -33,7 +33,7 @@ func init*(T: type BlockRef, root: Eth2Digest, blck: BeaconBlock): BlockRef =
func findAncestorBySlot*(blck: BlockRef, slot: Slot): BlockSlot =
## 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
while ret.parent != nil and ret.slot > slot:

View File

@ -70,7 +70,7 @@ proc main() {.async.} =
web3.privateKey = initPrivateKey(cfg.privateKey)
else:
let accounts = await web3.provider.eth_accounts()
assert(accounts.len > 0)
doAssert(accounts.len > 0)
web3.defaultAccount = accounts[0]
case cfg.cmd

View File

@ -215,7 +215,7 @@ func fromBytes*[T](R: type BlsValue[T], bytes: openarray[byte]): R =
if not success:
# TODO: chronicles trace
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
func fromHex*[T](R: type BlsValue[T], hexStr: string): R =

View File

@ -107,7 +107,7 @@ proc inspectType(tImpl, xSubField, ySubField: NimNode, stmts: var NimNode) =
"\" of type \"" & tImpl.repr
macro reportDiff*(x, y: typed{`var`|`let`|`const`}): untyped =
assert sameType(x, y)
doAssert sameType(x, y)
result = newStmtList()
let typeImpl = x.getTypeImpl

View File

@ -9,6 +9,6 @@ import
../../beacon_chain/spec/digest
proc `*`*(a: static array[1, byte], n: static int): static Eth2Digest =
assert n == 32
doAssert n == 32
for mbyte in result.data.mitems:
mbyte = a[0]

View File

@ -102,7 +102,7 @@ proc loadExpectedHashTreeRoot(dir: string): SSZHashTreeRoot =
proc runSSZtests() =
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):
assert pathKind == pcDir
doAssert pathKind == pcDir
if sszType in Unsupported:
test &" Skipping {sszType:20} consensus object ✗✗✗":
discard
@ -117,7 +117,7 @@ proc runSSZtests() =
test &" Testing {sszType:20} consensus object ✓✓✓":
let path = SSZDir/sszType
for pathKind, sszTestKind in walkDir(path, relative = true):
assert pathKind == pcDir
doAssert pathKind == pcDir
let path = SSZDir/sszType/sszTestKind
for pathKind, sszTestCase in walkDir(path, relative = true):
let path = SSZDir/sszType/sszTestKind/sszTestCase

View File

@ -133,7 +133,7 @@ proc checkVector(sszSubType, dir: string, expectedHash: SSZHashTreeRoot) =
var typeIdent: string
var size: int
let wasMatched = scanf(sszSubType, "vec_$+_$i", typeIdent, size)
assert wasMatched
doAssert wasMatched
testVector(typeIdent, size)
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) =
var size: int
let wasMatched = scanf(sszSubType, "bitvec_$i", size)
assert wasMatched
doAssert wasMatched
case size
of 1: testBitContainer(BitArray[1], dir, expectedHash)
of 2: testBitContainer(BitArray[2], dir, expectedHash)
@ -199,7 +199,7 @@ proc sszCheck(sszType, sszSubType: string) =
of "uints":
var bitsize: int
let wasMatched = scanf(sszSubType, "uint_$i", bitsize)
assert wasMatched
doAssert wasMatched
case bitsize
of 8: checkBasic(uint8, dir, expectedHash)
of 16: checkBasic(uint16, dir, expectedHash)
@ -219,7 +219,7 @@ proc sszCheck(sszType, sszSubType: string) =
of "containers":
var name: string
let wasMatched = scanf(sszSubtype, "$+_", name)
assert wasMatched
doAssert wasMatched
case name
of "SingleFieldTestStruct": checkBasic(SingleFieldTestStruct, dir, expectedHash)
of "SmallTestStruct": checkBasic(SmallTestStruct, dir, expectedHash)
@ -249,7 +249,7 @@ proc sszCheck(sszType, sszSubType: string) =
proc runSSZtests() =
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):
assert pathKind == pcDir
doAssert pathKind == pcDir
if sszType == "bitlist":
test &"**Skipping** {sszType} inputs - valid - skipped altogether":
# TODO: serialization of "type BitList[maxLen] = distinct BitSeq is not supported"
@ -269,7 +269,7 @@ proc runSSZtests() =
test &"Testing {sszType:12} inputs - valid" & skipped:
let path = SSZDir/sszType/"valid"
for pathKind, sszSubType in walkDir(path, relative = true):
assert pathKind == pcDir
doAssert pathKind == pcDir
sszCheck(sszType, sszSubType)
# TODO: nim-serialization forces us to use exceptions as control flow

View File

@ -24,24 +24,24 @@ type
# data: array[256, bool]
template reject(stmt) =
assert(not compiles(stmt))
doAssert(not compiles(stmt))
static:
assert isFixedSize(bool) == true
doAssert isFixedSize(bool) == true
assert fixedPortionSize(array[10, bool]) == 10
assert fixedPortionSize(array[SomeEnum, uint64]) == 24
assert fixedPortionSize(array[3..5, string]) == 12
doAssert fixedPortionSize(array[10, bool]) == 10
doAssert fixedPortionSize(array[SomeEnum, uint64]) == 24
doAssert fixedPortionSize(array[3..5, string]) == 12
assert fixedPortionSize(string) == 4
assert fixedPortionSize(seq[bool]) == 4
assert fixedPortionSize(seq[string]) == 4
doAssert fixedPortionSize(string) == 4
doAssert fixedPortionSize(seq[bool]) == 4
doAssert fixedPortionSize(seq[string]) == 4
assert isFixedSize(array[20, bool]) == true
assert isFixedSize(Simple) == true
assert isFixedSize(string) == false
assert isFixedSize(seq[bool]) == false
assert isFixedSize(seq[string]) == false
doAssert isFixedSize(array[20, bool]) == true
doAssert isFixedSize(Simple) == true
doAssert isFixedSize(string) == false
doAssert isFixedSize(seq[bool]) == false
doAssert isFixedSize(seq[string]) == false
reject fixedPortionSize(int)
@ -55,7 +55,8 @@ type
f5: ValidatorIndex
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