From f5b8931fad23e88b1ffbbb2f17850ae81bc9a921 Mon Sep 17 00:00:00 2001 From: Dustin Brody Date: Fri, 22 Nov 2019 16:47:08 +0100 Subject: [PATCH] switch assert(...) to doAssert(...) and minor cleanup --- README.md | 3 -- beacon_chain/block_pool.nim | 2 +- beacon_chain/deposit_contract.nim | 2 +- beacon_chain/spec/crypto.nim | 2 +- tests/helpers/debug_state.nim | 2 +- tests/helpers/digest_helpers.nim | 2 +- .../test_fixture_ssz_consensus_objects.nim | 4 +-- .../test_fixture_ssz_generic_types.nim | 12 ++++---- tests/test_ssz.nim | 29 ++++++++++--------- 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index b24c779e2..0137a907d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/beacon_chain/block_pool.nim b/beacon_chain/block_pool.nim index cd640037b..f2d3c4cf8 100644 --- a/beacon_chain/block_pool.nim +++ b/beacon_chain/block_pool.nim @@ -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: diff --git a/beacon_chain/deposit_contract.nim b/beacon_chain/deposit_contract.nim index 22ecae958..97fa9c118 100644 --- a/beacon_chain/deposit_contract.nim +++ b/beacon_chain/deposit_contract.nim @@ -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 diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index 922b08a9a..198527fcb 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -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 = diff --git a/tests/helpers/debug_state.nim b/tests/helpers/debug_state.nim index 320e4153a..7f15e7d13 100644 --- a/tests/helpers/debug_state.nim +++ b/tests/helpers/debug_state.nim @@ -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 diff --git a/tests/helpers/digest_helpers.nim b/tests/helpers/digest_helpers.nim index 5d65a67fb..24242d8c5 100644 --- a/tests/helpers/digest_helpers.nim +++ b/tests/helpers/digest_helpers.nim @@ -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] diff --git a/tests/official/test_fixture_ssz_consensus_objects.nim b/tests/official/test_fixture_ssz_consensus_objects.nim index 252ccc628..a8cb2e0cd 100644 --- a/tests/official/test_fixture_ssz_consensus_objects.nim +++ b/tests/official/test_fixture_ssz_consensus_objects.nim @@ -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 diff --git a/tests/official/test_fixture_ssz_generic_types.nim b/tests/official/test_fixture_ssz_generic_types.nim index f3e889e8e..d0957d9b2 100644 --- a/tests/official/test_fixture_ssz_generic_types.nim +++ b/tests/official/test_fixture_ssz_generic_types.nim @@ -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 diff --git a/tests/test_ssz.nim b/tests/test_ssz.nim index 0090583c8..820e24a9c 100644 --- a/tests/test_ssz.nim +++ b/tests/test_ssz.nim @@ -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