mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-24 01:38:33 +00:00
Assembler: Second asmSetupComputation, calls the first
The second `asmSetupComputation looks up state by block number and preceding block number, modifies the first transaction with code for testing, and uses some parts of that transaction to setup an an EVM test. Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
parent
5728491d60
commit
834449d943
@ -207,7 +207,7 @@ proc txCallEvm*(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork:
|
||||
txRefundGas(tx, sender, c)
|
||||
return tx.gasLimit - c.gasMeter.gasRemaining
|
||||
|
||||
proc asmSetupComputation*(tx: Transaction, sender: EthAddress, vmState: BaseVMState, data: seq[byte], forkOverride=none(Fork)): Computation =
|
||||
proc asmSetupComputation(tx: Transaction, sender: EthAddress, vmState: BaseVMState, data: seq[byte], forkOverride=none(Fork)): Computation =
|
||||
doAssert tx.isContractCreation
|
||||
|
||||
let fork =
|
||||
@ -240,3 +240,20 @@ proc asmSetupComputation*(tx: Transaction, sender: EthAddress, vmState: BaseVMSt
|
||||
db.setCode(contractAddress, tx.payload)
|
||||
|
||||
return newComputation(vmState, msg)
|
||||
|
||||
proc asmSetupComputation*(blockNumber: Uint256, chainDB: BaseChainDB, code, data: seq[byte], fork: Fork): Computation =
|
||||
let
|
||||
parentNumber = blockNumber - 1
|
||||
parent = chainDB.getBlockHeader(parentNumber)
|
||||
header = chainDB.getBlockHeader(blockNumber)
|
||||
headerHash = header.blockHash
|
||||
body = chainDB.getBlockBody(headerHash)
|
||||
vmState = newBaseVMState(parent.stateRoot, header, chainDB)
|
||||
|
||||
var
|
||||
tx = body.transactions[0]
|
||||
sender = transaction.getSender(tx)
|
||||
|
||||
tx.payload = code
|
||||
tx.gasLimit = 500000000
|
||||
return asmSetupComputation(tx, sender, vmState, data, some(fork))
|
||||
|
@ -211,25 +211,8 @@ proc initDatabase*(): (Uint256, BaseChainDB) =
|
||||
|
||||
result = (blockNumber, newBaseChainDB(memoryDB, false))
|
||||
|
||||
proc initComputation(blockNumber: Uint256, chainDB: BaseChainDB, code, data: seq[byte], fork: Fork): Computation =
|
||||
let
|
||||
parentNumber = blockNumber - 1
|
||||
parent = chainDB.getBlockHeader(parentNumber)
|
||||
header = chainDB.getBlockHeader(blockNumber)
|
||||
headerHash = header.blockHash
|
||||
body = chainDB.getBlockBody(headerHash)
|
||||
vmState = newBaseVMState(parent.stateRoot, header, chainDB)
|
||||
|
||||
var
|
||||
tx = body.transactions[0]
|
||||
sender = transaction.getSender(tx)
|
||||
|
||||
tx.payload = code
|
||||
tx.gasLimit = 500000000
|
||||
asmSetupComputation(tx, sender, vmState, data, some(fork))
|
||||
|
||||
proc runVM*(blockNumber: Uint256, chainDB: BaseChainDB, boa: Assembler): bool =
|
||||
var computation = initComputation(blockNumber, chainDB, boa.code, boa.data, boa.fork)
|
||||
var computation = asmSetupComputation(blockNumber, chainDB, boa.code, boa.data, boa.fork)
|
||||
|
||||
let gas = computation.gasMeter.gasRemaining
|
||||
execComputation(computation)
|
||||
|
Loading…
x
Reference in New Issue
Block a user