Fixtures: Change JSON fixture tests to go through unified EVM runner

Simplify how JSON fixtures tests are run to use `runComputation`.
Drop other code.

These use the `noTransfer` option, which is similar enough to calling
`c.executeOpcodes()` instead of `c.execComputation()`.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-17 17:27:20 +01:00 committed by zah
parent 5fb3c51e5e
commit 9211a15c0a
1 changed files with 23 additions and 29 deletions

View File

@ -229,21 +229,6 @@ proc asmCallEvm*(blockNumber: Uint256, chainDB: BaseChainDB, code, data: seq[byt
result.vmState = c.vmState result.vmState = c.vmState
result.contractAddress = c.msg.contractAddress result.contractAddress = c.msg.contractAddress
proc fixtureSetupComputation(vmState: BaseVMState, call: RpcCallData,
origin: EthAddress, forkOverride = none(Fork)): Computation =
return setupComputation(CallParams(
vmState: vmState,
forkOverride: forkOverride,
origin: some(origin),
gasPrice: call.gasPrice,
gasLimit: call.gas, # Differs from `rpcSetupComputation`
sender: call.source,
to: call.to,
isCreate: call.contractCreation,
value: call.value,
input: call.data
))
type type
FixtureResult* = object FixtureResult* = object
isError*: bool isError*: bool
@ -255,20 +240,29 @@ type
proc fixtureCallEvm*(vmState: BaseVMState, call: RpcCallData, proc fixtureCallEvm*(vmState: BaseVMState, call: RpcCallData,
origin: EthAddress, forkOverride = none(Fork)): FixtureResult = origin: EthAddress, forkOverride = none(Fork)): FixtureResult =
var c = fixtureSetupComputation(vmState, call, origin, forkOverride) let callResult = runComputation(CallParams(
let gas = c.gasMeter.gasRemaining vmState: vmState,
forkOverride: forkOverride,
# Next line differs from all the other EVM calls. With `execComputation`, origin: some(origin), # Differs from `rpcSetupComputation`.
# most "vm json tests" fail with either `balanceDiff` or `nonceDiff` errors. gasPrice: call.gasPrice,
c.executeOpcodes() gasLimit: call.gas, # Differs from `rpcSetupComputation`.
doAssert c.continuation.isNil sender: call.source,
doAssert c.child.isNil to: call.to,
isCreate: call.contractCreation,
value: call.value,
input: call.data,
noIntrinsic: true, # Don't charge intrinsic gas.
noAccessList: true, # Don't initialise EIP-2929 access list.
noGasCharge: true, # Don't charge sender account for gas.
noRefund: true, # Don't apply gas refund/burn rule.
noTransfer: true, # Don't update balances, nonces, code.
))
# Some of these are extra returned state, for testing, that a normal EVMC API # Some of these are extra returned state, for testing, that a normal EVMC API
# computation doesn't return. We'll have to obtain them outside EVMC. # computation doesn't return. We'll have to obtain them outside EVMC.
result.isError = c.isError result.isError = callResult.isError
result.error = c.error result.error = callResult.error
result.gasUsed = gas - c.gasMeter.gasRemaining result.gasUsed = callResult.gasUsed
result.output = c.output result.output = callResult.output
result.vmState = c.vmState result.vmState = vmState
shallowCopy(result.logEntries, c.logEntries) shallowCopy(result.logEntries, callResult.logEntries)