assert() -> doAssert()

This commit is contained in:
Ștefan Talpalaru 2019-03-13 22:36:54 +01:00
parent 404a75cbe7
commit a67edd693a
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
13 changed files with 33 additions and 33 deletions

View File

@ -27,7 +27,7 @@ proc put*(db: CaptureDB, key, value: openArray[byte]) =
proc contains*(db: CaptureDB, key: openArray[byte]): bool = proc contains*(db: CaptureDB, key: openArray[byte]): bool =
result = db.srcDb.contains(key) result = db.srcDb.contains(key)
assert(db.dstDb.contains(key) == result) doAssert(db.dstDb.contains(key) == result)
proc del*(db: CaptureDB, key: openArray[byte]) = proc del*(db: CaptureDB, key: openArray[byte]) =
db.dstDb.del(key) db.dstDb.del(key)

View File

@ -33,7 +33,7 @@ proc transactionHashToBlockKey*(h: Hash256): DbKey {.inline.} =
proc blockNumberToHashKey*(u: BlockNumber): DbKey {.inline.} = proc blockNumberToHashKey*(u: BlockNumber): DbKey {.inline.} =
result.data[0] = byte ord(blockNumberToHash) result.data[0] = byte ord(blockNumberToHash)
assert sizeof(u) <= 32 doAssert sizeof(u) <= 32
copyMem(addr result.data[1], unsafeAddr u, sizeof(u)) copyMem(addr result.data[1], unsafeAddr u, sizeof(u))
result.dataEndPos = uint8 sizeof(u) result.dataEndPos = uint8 sizeof(u)
@ -42,7 +42,7 @@ proc canonicalHeadHashKey*(): DbKey {.inline.} =
result.dataEndPos = 1 result.dataEndPos = 1
proc slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} = proc slotHashToSlotKey*(h: openArray[byte]): DbKey {.inline.} =
assert(h.len == 32) doAssert(h.len == 32)
result.data[0] = byte ord(slotHashToSlot) result.data[0] = byte ord(slotHashToSlot)
result.data[1 .. 32] = h result.data[1 .. 32] = h
result.dataEndPos = uint8 32 result.dataEndPos = uint8 32

View File

@ -102,7 +102,7 @@ proc toBlock*(g: Genesis, db: BaseChainDB = nil): BlockHeader =
proc commit*(g: Genesis, db: BaseChainDB) = proc commit*(g: Genesis, db: BaseChainDB) =
let b = g.toBlock(db) 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) discard db.persistHeaderToDb(b)
proc initializeEmptyDb*(db: BaseChainDB) = proc initializeEmptyDb*(db: BaseChainDB) =

View File

@ -64,7 +64,7 @@ proc start(): NimbusObject =
if canonicalHeadHashKey().toOpenArray notin trieDB: if canonicalHeadHashKey().toOpenArray notin trieDB:
initializeEmptyDb(chainDb) initializeEmptyDb(chainDb)
assert(canonicalHeadHashKey().toOpenArray in trieDB) doAssert(canonicalHeadHashKey().toOpenArray in trieDB)
nimbus.ethNode = newEthereumNode(keypair, address, conf.net.networkId, nimbus.ethNode = newEthereumNode(keypair, address, conf.net.networkId,
nil, nimbusClientId) nil, nimbusClientId)

View File

@ -493,7 +493,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
let contractAddress = generateAddress(sender, tx.accountNonce) let contractAddress = generateAddress(sender, tx.accountNonce)
result.contractAddress = some(contractAddress) result.contractAddress = some(contractAddress)
else: else:
assert(false) doAssert(false)
else: else:
result.contractAddress = none(EthAddress) result.contractAddress = none(EthAddress)

View File

@ -80,8 +80,8 @@ proc traceTransaction*(db: BaseChainDB, header: BlockHeader,
var stateDb = vmState.accountDb var stateDb = vmState.accountDb
if header.txRoot == BLANK_ROOT_HASH: return newJNull() if header.txRoot == BLANK_ROOT_HASH: return newJNull()
assert(body.transactions.calcTxRoot == header.txRoot) doAssert(body.transactions.calcTxRoot == header.txRoot)
assert(body.transactions.len != 0) doAssert(body.transactions.len != 0)
var var
gasUsed: GasInt gasUsed: GasInt
@ -199,8 +199,8 @@ proc traceBlock*(db: BaseChainDB, header: BlockHeader, body: BlockBody, tracerFl
vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, tracerFlags + {EnableTracing}) vmState = newBaseVMState(parent.stateRoot, header, captureChainDB, tracerFlags + {EnableTracing})
if header.txRoot == BLANK_ROOT_HASH: return newJNull() if header.txRoot == BLANK_ROOT_HASH: return newJNull()
assert(body.transactions.calcTxRoot == header.txRoot) doAssert(body.transactions.calcTxRoot == header.txRoot)
assert(body.transactions.len != 0) doAssert(body.transactions.len != 0)
var gasUsed = GasInt(0) var gasUsed = GasInt(0)

View File

@ -101,7 +101,7 @@ macro genSwap*(): untyped =
computation.stack.swap(`pos`) computation.stack.swap(`pos`)
proc logImpl(c: var BaseComputation, opcode: Op, topicCount: int) = 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 (memStartPosition, size) = c.stack.popInt(2)
let (memPos, len) = (memStartPosition.cleanMemRef, size.cleanMemRef) let (memPos, len) = (memStartPosition.cleanMemRef, size.cleanMemRef)

View File

@ -40,7 +40,7 @@ proc rememberStorageKey(tracer: var TransactionTracer, compDepth: int, key: Uint
tracer.storageKeys[compDepth].incl key tracer.storageKeys[compDepth].incl key
iterator storage(tracer: TransactionTracer, compDepth: int): Uint256 = 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]: for key in tracer.storageKeys[compDepth]:
yield key yield key

View File

@ -97,7 +97,7 @@ when false:
if `readOnly`: if `readOnly`:
# This acts as a secondary check that no mutation took place for # This acts as a secondary check that no mutation took place for
# read_only databases. # read_only databases.
assert `db`.rootHash == `vmState`.blockHeader.stateRoot doAssert `db`.rootHash == `vmState`.blockHeader.stateRoot
elif `vmState`.blockHeader.stateRoot != `db`.rootHash: elif `vmState`.blockHeader.stateRoot != `db`.rootHash:
`vmState`.blockHeader.stateRoot = `db`.rootHash `vmState`.blockHeader.stateRoot = `db`.rootHash
@ -160,7 +160,7 @@ proc dispose*(s: var Snapshot) {.inline.} =
s.transaction.dispose() s.transaction.dispose()
proc getTracingResult*(vmState: BaseVMState): JsonNode = proc getTracingResult*(vmState: BaseVMState): JsonNode =
assert(vmState.tracingEnabled) doAssert(vmState.tracingEnabled)
vmState.tracer.trace vmState.tracer.trace
proc addLogs*(vmState: BaseVMState, logs: seq[Log]) = proc addLogs*(vmState: BaseVMState, logs: seq[Log]) =

View File

@ -35,27 +35,27 @@ type
proc fromJson(n: JsonNode, name: string, x: var SomeData) = proc fromJson(n: JsonNode, name: string, x: var SomeData) =
hexToByteArray(n[name].getStr(), x) 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) = proc fromJson(n: JsonNode, name: string, x: var Hash256) =
hexToByteArray(n[name].getStr(), x.data) 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) = proc fromJson(n: JsonNode, name: string, x: var Blob) =
x = hexToSeqByte(n[name].getStr()) 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) = proc fromJson(n: JsonNode, name: string, x: var UInt256) =
x = UInt256.fromHex(n[name].getStr()) 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) = proc fromJson(n: JsonNode, name: string, x: var SomeInteger) =
x = hexToInt(n[name].getStr(), type(x)) 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) = proc fromJson(n: JsonNode, name: string, x: var EthTime) =
x = initTime(hexToInt(n[name].getStr(), int64), 0) 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 = proc parseBlockHeader*(n: JsonNode): BlockHeader =
n.fromJson "parentHash", result.parentHash n.fromJson "parentHash", result.parentHash
@ -90,8 +90,8 @@ proc parseTransaction*(n: JsonNode): Transaction =
n.fromJson "s", result.S n.fromJson "s", result.S
var sender = result.getSender() var sender = result.getSender()
assert sender.prefixHex == n["from"].getStr() doAssert sender.prefixHex == n["from"].getStr()
assert n["hash"].getStr() == result.rlpHash().prefixHex doAssert n["hash"].getStr() == result.rlpHash().prefixHex
proc parseLog(n: JsonNode): Log = proc parseLog(n: JsonNode): Log =
n.fromJson "address", result.address n.fromJson "address", result.address

View File

@ -16,10 +16,10 @@ const
template persistToDb(db: ChainDB, body: untyped) = template persistToDb(db: ChainDB, body: untyped) =
when manualCommit: when manualCommit:
if not db.txBegin(): assert(false) if not db.txBegin(): doAssert(false)
body body
when manualCommit: when manualCommit:
if not db.txCommit(): assert(false) if not db.txCommit(): doAssert(false)
proc main() = proc main() =
# 97 block with uncles # 97 block with uncles
@ -47,7 +47,7 @@ proc main() =
if canonicalHeadHashKey().toOpenArray notin trieDB: if canonicalHeadHashKey().toOpenArray notin trieDB:
persistToDb(db): persistToDb(db):
initializeEmptyDb(chainDB) initializeEmptyDb(chainDB)
assert(canonicalHeadHashKey().toOpenArray in trieDB) doAssert(canonicalHeadHashKey().toOpenArray in trieDB)
var head = chainDB.getCanonicalHead() var head = chainDB.getCanonicalHead()
var blockNumber = head.blockNumber + 1 var blockNumber = head.blockNumber + 1

View File

@ -60,7 +60,7 @@ proc validateStorage(val: NimNode): Storage =
val.expectKind(nnkCall) val.expectKind(nnkCall)
val[0].expectKind(nnkStrLit) val[0].expectKind(nnkStrLit)
val[1].expectKind(nnkStmtList) val[1].expectKind(nnkStmtList)
assert(val[1].len == 1) doAssert(val[1].len == 1)
val[1][0].expectKind(nnkStrLit) val[1][0].expectKind(nnkStrLit)
result = (validateVMWord(val[0]), validateVMWord(val[1][0])) result = (validateVMWord(val[0]), validateVMWord(val[1][0]))
@ -181,7 +181,7 @@ const
blockFile = "tests" / "fixtures" / "PersistBlockTests" / "block47205.json" blockFile = "tests" / "fixtures" / "PersistBlockTests" / "block47205.json"
proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress, data: seq[byte], forkOverride=none(Fork)) : BaseComputation = proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress, data: seq[byte], forkOverride=none(Fork)) : BaseComputation =
assert tx.isContractCreation doAssert tx.isContractCreation
let fork = let fork =
if forkOverride.isSome: if forkOverride.isSome:

View File

@ -30,9 +30,9 @@ macro all(element: untyped, handler: untyped): untyped =
# @pytest.mark.parametrize("value", (0, 10)) # @pytest.mark.parametrize("value", (0, 10))
# def test_start_gas_on_instantiation(value): # def test_start_gas_on_instantiation(value):
# meter = GasMeter(value) # meter = GasMeter(value)
# assert meter.start_gas == value # doAssert meter.start_gas == value
# assert meter.gas_remaining == value # doAssert meter.gas_remaining == value
# assert meter.gas_refunded == 0 # doAssert meter.gas_refunded == 0
# @pytest.mark.parametrize("value", (-1, 2**256, 'a')) # @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)) # @pytest.mark.parametrize("amount", (0, 1, 10))
# def test_consume_gas(gas_meter, amount): # def test_consume_gas(gas_meter, amount):
# gas_meter.consume_gas(amount, "reason") # 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)) # @pytest.mark.parametrize("amount", (0, 1, 99))
# def test_return_gas(gas_meter, amount): # def test_return_gas(gas_meter, amount):
# gas_meter.return_gas(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)) # @pytest.mark.parametrize("amount", (0, 1, 99))
# def test_refund_gas(gas_meter, amount): # def test_refund_gas(gas_meter, amount):
# gas_meter.refund_gas(amount) # gas_meter.refund_gas(amount)
# assert gas_meter.gas_refunded == amount # doAssert gas_meter.gas_refunded == amount
suite "gasMeter": suite "gasMeter":