fixes 32 bit problem in test_helpers.nim and transaction_tracer.nim

This commit is contained in:
andri lim 2019-08-17 21:48:45 +07:00 committed by zah
parent 742f53f5e9
commit e675182506
2 changed files with 12 additions and 12 deletions

View File

@ -104,7 +104,7 @@ proc traceOpCodeEnded*(tracer: var TransactionTracer, c: BaseComputation, op: Op
storage[key.dumpHex] = %(value.dumpHex) storage[key.dumpHex] = %(value.dumpHex)
j["storage"] = storage j["storage"] = storage
let gasRemaining = j["gas"].getInt() let gasRemaining = j["gas"].getBiggestInt()
j["gasCost"] = %(gasRemaining - c.gasMeter.gasRemaining) j["gasCost"] = %(gasRemaining - c.gasMeter.gasRemaining)
if op in {Return, Revert}: if op in {Return, Revert}:
@ -123,7 +123,7 @@ proc traceError*(tracer: var TransactionTracer, c: BaseComputation) =
# even though the gasCost is incorrect, # even though the gasCost is incorrect,
# we have something to display, # we have something to display,
# it is an error anyway # it is an error anyway
let gasRemaining = j["gas"].getInt() let gasRemaining = j["gas"].getBiggestInt()
j["gasCost"] = %(gasRemaining - c.gasMeter.gasRemaining) j["gasCost"] = %(gasRemaining - c.gasMeter.gasRemaining)
tracer.trace["failed"] = %true tracer.trace["failed"] = %true

View File

@ -277,13 +277,19 @@ func safeHexToSeqByte*(hexStr: string): seq[byte] =
else: else:
hexStr.hexToSeqByte hexStr.hexToSeqByte
func getHexadecimalInt*(j: JsonNode): int64 =
# parseutils.parseHex works with int which will overflow in 32 bit
var data: StUInt[64]
data = fromHex(StUInt[64], j.getStr)
result = cast[int64](data)
proc setupStateDB*(wantedState: JsonNode, stateDB: var AccountStateDB) = proc setupStateDB*(wantedState: JsonNode, stateDB: var AccountStateDB) =
for ac, accountData in wantedState: for ac, accountData in wantedState:
let account = ethAddressFromHex(ac) let account = ethAddressFromHex(ac)
for slot, value in accountData{"storage"}: for slot, value in accountData{"storage"}:
stateDB.setStorage(account, fromHex(UInt256, slot), fromHex(UInt256, value.getStr)) stateDB.setStorage(account, fromHex(UInt256, slot), fromHex(UInt256, value.getStr))
let nonce = accountData{"nonce"}.getStr.parseHexInt.AccountNonce let nonce = accountData{"nonce"}.getHexadecimalInt.AccountNonce
let code = accountData{"code"}.getStr.safeHexToSeqByte.toRange let code = accountData{"code"}.getStr.safeHexToSeqByte.toRange
let balance = UInt256.fromHex accountData{"balance"}.getStr let balance = UInt256.fromHex accountData{"balance"}.getStr
@ -316,16 +322,10 @@ proc verifyStateDB*(wantedState: JsonNode, stateDB: ReadOnlyStateDB) =
doAssert wantedBalance == actualBalance, &"{wantedBalance.toHex} != {actualBalance.toHex}" doAssert wantedBalance == actualBalance, &"{wantedBalance.toHex} != {actualBalance.toHex}"
doAssert wantedNonce == actualNonce, &"{wantedNonce.toHex} != {actualNonce.toHex}" doAssert wantedNonce == actualNonce, &"{wantedNonce.toHex} != {actualNonce.toHex}"
func getHexadecimalInt*(j: JsonNode): int64 =
# parseutils.parseHex works with int which will overflow in 32 bit
var data: StUInt[64]
data = fromHex(StUInt[64], j.getStr)
result = cast[int64](data)
proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int): Transaction = proc getFixtureTransaction*(j: JsonNode, dataIndex, gasIndex, valueIndex: int): Transaction =
result.accountNonce = j["nonce"].getStr.parseHexInt.AccountNonce result.accountNonce = j["nonce"].getHexadecimalInt.AccountNonce
result.gasPrice = j["gasPrice"].getStr.parseHexInt result.gasPrice = j["gasPrice"].getHexadecimalInt
result.gasLimit = j["gasLimit"][gasIndex].getStr.parseHexInt result.gasLimit = j["gasLimit"][gasIndex].getHexadecimalInt
# TODO: there are a couple fixtures which appear to distinguish between # TODO: there are a couple fixtures which appear to distinguish between
# empty and 0 transaction.to; check/verify whether correct conditions. # empty and 0 transaction.to; check/verify whether correct conditions.