Fixtures: Prepare fixtureSetupComputation to support fixtureCallEvm
In the `text_vm_json` ("fixtures") test code, there is another variant of `rpcSetupComputation` and `txSetupComputation` with slightly different paremeters. The similarity is obvious. It is a special setup for testing, though, as it requires slightly different parameters. Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
parent
39ce2390ae
commit
9e99bb6cd9
|
@ -282,3 +282,23 @@ proc asmCallEvm*(blockNumber: Uint256, chainDB: BaseChainDB, code, data: seq[byt
|
||||||
result.memory = c.memory
|
result.memory = c.memory
|
||||||
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): Computation =
|
||||||
|
vmState.setupTxContext(
|
||||||
|
origin = origin, # Differs from `rpcSetupComputation`
|
||||||
|
gasPrice = call.gasPrice,
|
||||||
|
# fork is not set.
|
||||||
|
)
|
||||||
|
|
||||||
|
var msg = Message(
|
||||||
|
kind: if call.contractCreation: evmcCreate else: evmcCall,
|
||||||
|
depth: 0,
|
||||||
|
gas: call.gas, # Differs from `rpcSetupComputation`
|
||||||
|
sender: call.source,
|
||||||
|
contractAddress: call.to, # Differs from `rpcSetupComputation`
|
||||||
|
codeAddress: call.to,
|
||||||
|
value: call.value,
|
||||||
|
data: call.data
|
||||||
|
)
|
||||||
|
|
||||||
|
return newComputation(vmState, msg)
|
||||||
|
|
|
@ -10,7 +10,8 @@ import
|
||||||
stew/byteutils, eth/[rlp, common], eth/trie/db,
|
stew/byteutils, eth/[rlp, common], eth/trie/db,
|
||||||
./test_helpers, ./test_allowed_to_fail, ../nimbus/vm_internals,
|
./test_helpers, ./test_allowed_to_fail, ../nimbus/vm_internals,
|
||||||
../nimbus/[constants, vm_state, vm_types, utils],
|
../nimbus/[constants, vm_state, vm_types, utils],
|
||||||
../nimbus/db/[db_chain]
|
../nimbus/db/[db_chain],
|
||||||
|
../nimbus/transaction/call_evm
|
||||||
|
|
||||||
func bytesToHex(x: openarray[byte]): string {.inline.} =
|
func bytesToHex(x: openarray[byte]): string {.inline.} =
|
||||||
## TODO: use seq[byte] for raw data and delete this proc
|
## TODO: use seq[byte] for raw data and delete this proc
|
||||||
|
@ -44,24 +45,21 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||||
vmState.mutateStateDB:
|
vmState.mutateStateDB:
|
||||||
setupStateDB(fixture{"pre"}, db)
|
setupStateDB(fixture{"pre"}, db)
|
||||||
|
|
||||||
vmState.setupTxContext(
|
var call: RpcCallData
|
||||||
origin = fexec{"origin"}.getStr.parseAddress,
|
|
||||||
gasPrice = fexec{"gasPrice"}.getHexadecimalInt
|
|
||||||
)
|
|
||||||
|
|
||||||
let toAddress = fexec{"address"}.getStr.parseAddress
|
let toAddress = fexec{"address"}.getStr.parseAddress
|
||||||
let message = Message(
|
let origin = fexec{"origin"}.getStr.parseAddress
|
||||||
kind: if toAddress == ZERO_ADDRESS: evmcCreate else: evmcCall, # assume ZERO_ADDRESS is a contract creation
|
|
||||||
depth: 0,
|
|
||||||
gas: fexec{"gas"}.getHexadecimalInt,
|
|
||||||
sender: fexec{"caller"}.getStr.parseAddress,
|
|
||||||
contractAddress: toAddress,
|
|
||||||
codeAddress: toAddress,
|
|
||||||
value: cast[uint64](fexec{"value"}.getHexadecimalInt).u256, # Cast workaround for negative value
|
|
||||||
data: fexec{"data"}.getStr.hexToSeqByte
|
|
||||||
)
|
|
||||||
|
|
||||||
var computation = newComputation(vmState, message)
|
call.source = fexec{"caller"}.getStr.parseAddress
|
||||||
|
call.to = toAddress
|
||||||
|
call.gas = fexec{"gas"}.getHexadecimalInt
|
||||||
|
call.gasPrice = fexec{"gasPrice"}.getHexadecimalInt
|
||||||
|
# Cast workaround for negative value
|
||||||
|
call.value = cast[uint64](fexec{"value"}.getHexadecimalInt).u256
|
||||||
|
call.data = fexec{"data"}.getStr.hexToSeqByte
|
||||||
|
# assume ZERO_ADDRESS is a contract creation
|
||||||
|
call.contractCreation = (toAddress == ZERO_ADDRESS)
|
||||||
|
|
||||||
|
var computation = fixtureSetupComputation(vmState, call, origin)
|
||||||
computation.executeOpcodes()
|
computation.executeOpcodes()
|
||||||
|
|
||||||
if not fixture{"post"}.isNil:
|
if not fixture{"post"}.isNil:
|
||||||
|
|
Loading…
Reference in New Issue