From a67edd693a915e50b880a8ca20fa72abfd72ae35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Wed, 13 Mar 2019 22:36:54 +0100 Subject: [PATCH] assert() -> doAssert() --- nimbus/db/capturedb.nim | 2 +- nimbus/db/storage_types.nim | 4 ++-- nimbus/genesis.nim | 2 +- nimbus/nimbus.nim | 2 +- nimbus/rpc/p2p.nim | 2 +- nimbus/tracer.nim | 8 ++++---- .../interpreter/utils/macros_procs_opcodes.nim | 2 +- nimbus/vm/transaction_tracer.nim | 2 +- nimbus/vm_state.nim | 4 ++-- premix/parser.nim | 16 ++++++++-------- premix/persist.nim | 6 +++--- tests/macro_assembler.nim | 4 ++-- tests/test_gas_meter.nim | 12 ++++++------ 13 files changed, 33 insertions(+), 33 deletions(-) diff --git a/nimbus/db/capturedb.nim b/nimbus/db/capturedb.nim index 37d22165d..f8c7d4f23 100644 --- a/nimbus/db/capturedb.nim +++ b/nimbus/db/capturedb.nim @@ -27,7 +27,7 @@ proc put*(db: CaptureDB, key, value: openArray[byte]) = proc contains*(db: CaptureDB, key: openArray[byte]): bool = result = db.srcDb.contains(key) - assert(db.dstDb.contains(key) == result) + doAssert(db.dstDb.contains(key) == result) proc del*(db: CaptureDB, key: openArray[byte]) = db.dstDb.del(key) diff --git a/nimbus/db/storage_types.nim b/nimbus/db/storage_types.nim index b7a8bb171..0c7340bcb 100644 --- a/nimbus/db/storage_types.nim +++ b/nimbus/db/storage_types.nim @@ -33,7 +33,7 @@ proc transactionHashToBlockKey*(h: Hash256): DbKey {.inline.} = proc blockNumberToHashKey*(u: BlockNumber): DbKey {.inline.} = result.data[0] = byte ord(blockNumberToHash) - assert sizeof(u) <= 32 + doAssert sizeof(u) <= 32 copyMem(addr result.data[1], unsafeAddr u, sizeof(u)) result.dataEndPos = uint8 sizeof(u) @@ -42,7 +42,7 @@ proc canonicalHeadHashKey*(): DbKey {.inline.} = result.dataEndPos = 1 proc slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} = - assert(h.len == 32) + doAssert(h.len == 32) result.data[0] = byte ord(slotHashToSlot) result.data[1 .. 32] = h result.dataEndPos = uint8 32 diff --git a/nimbus/genesis.nim b/nimbus/genesis.nim index 623a82328..48d258d89 100644 --- a/nimbus/genesis.nim +++ b/nimbus/genesis.nim @@ -102,7 +102,7 @@ proc toBlock*(g: Genesis, db: BaseChainDB = nil): BlockHeader = proc commit*(g: Genesis, db: BaseChainDB) = let b = g.toBlock(db) - assert(b.blockNumber == 0, "can't commit genesis block with number > 0") + doAssert(b.blockNumber == 0, "can't commit genesis block with number > 0") discard db.persistHeaderToDb(b) proc initializeEmptyDb*(db: BaseChainDB) = diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index 2b8e42057..4cec91658 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -64,7 +64,7 @@ proc start(): NimbusObject = if canonicalHeadHashKey().toOpenArray notin trieDB: initializeEmptyDb(chainDb) - assert(canonicalHeadHashKey().toOpenArray in trieDB) + doAssert(canonicalHeadHashKey().toOpenArray in trieDB) nimbus.ethNode = newEthereumNode(keypair, address, conf.net.networkId, nil, nimbusClientId) diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 024fada9c..90f43e05e 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -493,7 +493,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) = let contractAddress = generateAddress(sender, tx.accountNonce) result.contractAddress = some(contractAddress) else: - assert(false) + doAssert(false) else: result.contractAddress = none(EthAddress) diff --git a/nimbus/tracer.nim b/nimbus/tracer.nim index f940540e9..c22ba166d 100644 --- a/nimbus/tracer.nim +++ b/nimbus/tracer.nim @@ -80,8 +80,8 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader, var stateDb = vmState.accountDb if header.txRoot == BLANK_ROOT_HASH: return newJNull() - assert(body.transactions.calcTxRoot == header.txRoot) - assert(body.transactions.len != 0) + doAssert(body.transactions.calcTxRoot == header.txRoot) + doAssert(body.transactions.len != 0) var gasUsed: GasInt @@ -199,8 +199,8 @@ proc traceBlock*(db: BaseChainDB, header: BlockHeader, body: BlockBody, tracerFl vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, tracerFlags + {EnableTracing}) if header.txRoot == BLANK_ROOT_HASH: return newJNull() - assert(body.transactions.calcTxRoot == header.txRoot) - assert(body.transactions.len != 0) + doAssert(body.transactions.calcTxRoot == header.txRoot) + doAssert(body.transactions.len != 0) var gasUsed = GasInt(0) diff --git a/nimbus/vm/interpreter/utils/macros_procs_opcodes.nim b/nimbus/vm/interpreter/utils/macros_procs_opcodes.nim index a76e60c49..df25831a0 100644 --- a/nimbus/vm/interpreter/utils/macros_procs_opcodes.nim +++ b/nimbus/vm/interpreter/utils/macros_procs_opcodes.nim @@ -101,7 +101,7 @@ macro genSwap*(): untyped = computation.stack.swap(`pos`) proc logImpl(c: var BaseComputation, opcode: Op, topicCount: int) = - assert(topicCount in 0 .. 4) + doAssert(topicCount in 0 .. 4) let (memStartPosition, size) = c.stack.popInt(2) let (memPos, len) = (memStartPosition.cleanMemRef, size.cleanMemRef) diff --git a/nimbus/vm/transaction_tracer.nim b/nimbus/vm/transaction_tracer.nim index c25e470e8..f826eda36 100644 --- a/nimbus/vm/transaction_tracer.nim +++ b/nimbus/vm/transaction_tracer.nim @@ -40,7 +40,7 @@ proc rememberStorageKey(tracer: var TransactionTracer, compDepth: int, key: Uint tracer.storageKeys[compDepth].incl key iterator storage(tracer: TransactionTracer, compDepth: int): Uint256 = - assert compDepth >= 0 and compDepth < tracer.storageKeys.len + doAssert compDepth >= 0 and compDepth < tracer.storageKeys.len for key in tracer.storageKeys[compDepth]: yield key diff --git a/nimbus/vm_state.nim b/nimbus/vm_state.nim index d0b564de5..d1fcd9167 100644 --- a/nimbus/vm_state.nim +++ b/nimbus/vm_state.nim @@ -97,7 +97,7 @@ when false: if `readOnly`: # This acts as a secondary check that no mutation took place for # read_only databases. - assert `db`.rootHash == `vmState`.blockHeader.stateRoot + doAssert `db`.rootHash == `vmState`.blockHeader.stateRoot elif `vmState`.blockHeader.stateRoot != `db`.rootHash: `vmState`.blockHeader.stateRoot = `db`.rootHash @@ -160,7 +160,7 @@ proc dispose*(s: var Snapshot) {.inline.} = s.transaction.dispose() proc getTracingResult*(vmState: BaseVMState): JsonNode = - assert(vmState.tracingEnabled) + doAssert(vmState.tracingEnabled) vmState.tracer.trace proc addLogs*(vmState: BaseVMState, logs: seq[Log]) = diff --git a/premix/parser.nim b/premix/parser.nim index 94e8f668b..e0cb712f7 100644 --- a/premix/parser.nim +++ b/premix/parser.nim @@ -35,27 +35,27 @@ type proc fromJson(n: JsonNode, name: string, x: var SomeData) = hexToByteArray(n[name].getStr(), x) - assert(x.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.prefixHex == toLowerAscii(n[name].getStr())) proc fromJson(n: JsonNode, name: string, x: var Hash256) = hexToByteArray(n[name].getStr(), x.data) - assert(x.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.prefixHex == toLowerAscii(n[name].getStr())) proc fromJson(n: JsonNode, name: string, x: var Blob) = x = hexToSeqByte(n[name].getStr()) - assert(x.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.prefixHex == toLowerAscii(n[name].getStr())) proc fromJson(n: JsonNode, name: string, x: var UInt256) = x = UInt256.fromHex(n[name].getStr()) - assert(x.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.prefixHex == toLowerAscii(n[name].getStr())) proc fromJson(n: JsonNode, name: string, x: var SomeInteger) = x = hexToInt(n[name].getStr(), type(x)) - assert(x.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.prefixHex == toLowerAscii(n[name].getStr())) proc fromJson(n: JsonNode, name: string, x: var EthTime) = x = initTime(hexToInt(n[name].getStr(), int64), 0) - assert(x.toUnix.prefixHex == toLowerAscii(n[name].getStr())) + doAssert(x.toUnix.prefixHex == toLowerAscii(n[name].getStr())) proc parseBlockHeader*(n: JsonNode): BlockHeader = n.fromJson "parentHash", result.parentHash @@ -90,8 +90,8 @@ proc parseTransaction*(n: JsonNode): Transaction = n.fromJson "s", result.S var sender = result.getSender() - assert sender.prefixHex == n["from"].getStr() - assert n["hash"].getStr() == result.rlpHash().prefixHex + doAssert sender.prefixHex == n["from"].getStr() + doAssert n["hash"].getStr() == result.rlpHash().prefixHex proc parseLog(n: JsonNode): Log = n.fromJson "address", result.address diff --git a/premix/persist.nim b/premix/persist.nim index f07d95077..db6658356 100644 --- a/premix/persist.nim +++ b/premix/persist.nim @@ -16,10 +16,10 @@ const template persistToDb(db: ChainDB, body: untyped) = when manualCommit: - if not db.txBegin(): assert(false) + if not db.txBegin(): doAssert(false) body when manualCommit: - if not db.txCommit(): assert(false) + if not db.txCommit(): doAssert(false) proc main() = # 97 block with uncles @@ -47,7 +47,7 @@ proc main() = if canonicalHeadHashKey().toOpenArray notin trieDB: persistToDb(db): initializeEmptyDb(chainDB) - assert(canonicalHeadHashKey().toOpenArray in trieDB) + doAssert(canonicalHeadHashKey().toOpenArray in trieDB) var head = chainDB.getCanonicalHead() var blockNumber = head.blockNumber + 1 diff --git a/tests/macro_assembler.nim b/tests/macro_assembler.nim index 9073bee81..be11cc29e 100644 --- a/tests/macro_assembler.nim +++ b/tests/macro_assembler.nim @@ -60,7 +60,7 @@ proc validateStorage(val: NimNode): Storage = val.expectKind(nnkCall) val[0].expectKind(nnkStrLit) val[1].expectKind(nnkStmtList) - assert(val[1].len == 1) + doAssert(val[1].len == 1) val[1][0].expectKind(nnkStrLit) result = (validateVMWord(val[0]), validateVMWord(val[1][0])) @@ -181,7 +181,7 @@ const blockFile = "tests" / "fixtures" / "PersistBlockTests" / "block47205.json" proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress, data: seq[byte], forkOverride=none(Fork)) : BaseComputation = - assert tx.isContractCreation + doAssert tx.isContractCreation let fork = if forkOverride.isSome: diff --git a/tests/test_gas_meter.nim b/tests/test_gas_meter.nim index f6eabca1e..c0cd8c8d5 100644 --- a/tests/test_gas_meter.nim +++ b/tests/test_gas_meter.nim @@ -30,9 +30,9 @@ macro all(element: untyped, handler: untyped): untyped = # @pytest.mark.parametrize("value", (0, 10)) # def test_start_gas_on_instantiation(value): # meter = GasMeter(value) -# assert meter.start_gas == value -# assert meter.gas_remaining == value -# assert meter.gas_refunded == 0 +# doAssert meter.start_gas == value +# doAssert meter.gas_remaining == value +# doAssert meter.gas_refunded == 0 # @pytest.mark.parametrize("value", (-1, 2**256, 'a')) @@ -44,18 +44,18 @@ macro all(element: untyped, handler: untyped): untyped = # @pytest.mark.parametrize("amount", (0, 1, 10)) # def test_consume_gas(gas_meter, amount): # gas_meter.consume_gas(amount, "reason") -# assert gas_meter.gas_remaining == gas_meter.start_gas - amount +# doAssert gas_meter.gas_remaining == gas_meter.start_gas - amount # @pytest.mark.parametrize("amount", (0, 1, 99)) # def test_return_gas(gas_meter, amount): # gas_meter.return_gas(amount) -# assert gas_meter.gas_remaining == (gas_meter.start_gas + amount) +# doAssert gas_meter.gas_remaining == (gas_meter.start_gas + amount) # @pytest.mark.parametrize("amount", (0, 1, 99)) # def test_refund_gas(gas_meter, amount): # gas_meter.refund_gas(amount) -# assert gas_meter.gas_refunded == amount +# doAssert gas_meter.gas_refunded == amount suite "gasMeter":