mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 12:54:13 +00:00
assert() -> doAssert()
This commit is contained in:
parent
404a75cbe7
commit
a67edd693a
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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) =
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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]) =
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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":
|
||||
|
Loading…
x
Reference in New Issue
Block a user