mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
tests, core/vm/runtime: formatting
This commit is contained in:
parent
b36baff097
commit
1cc5428c65
8 changed files with 39 additions and 30 deletions
17
core/evm.go
17
core/evm.go
|
|
@ -44,15 +44,14 @@ func NewBlockContext(header *types.Header, chain ChainContext, author *common.Ad
|
||||||
beneficiary = *author
|
beneficiary = *author
|
||||||
}
|
}
|
||||||
return &vm.BlockContext{
|
return &vm.BlockContext{
|
||||||
GetHash: GetHashFn(header, chain),
|
GetHash: GetHashFn(header, chain),
|
||||||
CanTransfer: CanTransfer,
|
CanTransfer: CanTransfer,
|
||||||
Transfer: Transfer,
|
Transfer: Transfer,
|
||||||
Coinbase: beneficiary,
|
Coinbase: beneficiary,
|
||||||
BlockNumber: new(big.Int).Set(header.Number),
|
BlockNumber: new(big.Int).Set(header.Number),
|
||||||
Time: new(big.Int).Set(header.Time),
|
Time: new(big.Int).Set(header.Time),
|
||||||
Difficulty: new(big.Int).Set(header.Difficulty),
|
Difficulty: new(big.Int).Set(header.Difficulty),
|
||||||
GasLimit: header.GasLimit,
|
GasLimit: header.GasLimit,
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,6 @@ func NewStateProcessor(config *params.ChainConfig, bc *BlockChain, engine consen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Process processes the state changes according to the Ethereum rules by running
|
// Process processes the state changes according to the Ethereum rules by running
|
||||||
// the transaction messages using the statedb and applying any rewards to both
|
// the transaction messages using the statedb and applying any rewards to both
|
||||||
// the processor (coinbase) and any included uncles.
|
// the processor (coinbase) and any included uncles.
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ type Context struct {
|
||||||
GasPrice *big.Int // Provides information for GASPRICE
|
GasPrice *big.Int // Provides information for GASPRICE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) GetHash(n uint64) common.Hash{
|
func (c *Context) GetHash(n uint64) common.Hash {
|
||||||
return c.BlockContext.GetHash(n)
|
return c.BlockContext.GetHash(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ type BlockContext struct {
|
||||||
CanTransfer CanTransferFunc
|
CanTransfer CanTransferFunc
|
||||||
// Transfer transfers ether from one account to the other
|
// Transfer transfers ether from one account to the other
|
||||||
Transfer TransferFunc
|
Transfer TransferFunc
|
||||||
GetHash GetHashFunc
|
GetHash GetHashFunc
|
||||||
// Block information
|
// Block information
|
||||||
Coinbase common.Address // Provides information for COINBASE
|
Coinbase common.Address // Provides information for COINBASE
|
||||||
GasLimit uint64 // Provides information for GASLIMIT
|
GasLimit uint64 // Provides information for GASLIMIT
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,17 @@
|
||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Bl
|
||||||
for task := range tasks {
|
for task := range tasks {
|
||||||
signer := types.MakeSigner(api.config, task.block.Number())
|
signer := types.MakeSigner(api.config, task.block.Number())
|
||||||
|
|
||||||
blockCtx := core.NewBlockContext(task.block.Header(), api.eth.blockchain, nil)
|
blockCtx := core.NewBlockContext(task.block.Header(), api.eth.blockchain, nil)
|
||||||
// Trace all the transactions contained within
|
// Trace all the transactions contained within
|
||||||
for i, tx := range task.block.Transactions() {
|
for i, tx := range task.block.Transactions() {
|
||||||
msg, _ := tx.AsMessage(signer)
|
msg, _ := tx.AsMessage(signer)
|
||||||
|
|
@ -477,12 +477,12 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
|
||||||
pend.Add(1)
|
pend.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer pend.Done()
|
defer pend.Done()
|
||||||
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
||||||
|
|
||||||
// Fetch and execute the next transaction trace tasks
|
// Fetch and execute the next transaction trace tasks
|
||||||
for task := range jobs {
|
for task := range jobs {
|
||||||
msg, _ := txs[task.index].AsMessage(signer)
|
msg, _ := txs[task.index].AsMessage(signer)
|
||||||
vmctx := core.NewEVMContext(msg,blockCtx)
|
vmctx := core.NewEVMContext(msg, blockCtx)
|
||||||
|
|
||||||
res, err := api.traceTx(ctx, msg, vmctx, task.statedb, config)
|
res, err := api.traceTx(ctx, msg, vmctx, task.statedb, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -498,11 +498,11 @@ func (api *PrivateDebugAPI) traceBlock(ctx context.Context, block *types.Block,
|
||||||
for i, tx := range txs {
|
for i, tx := range txs {
|
||||||
// Send the trace task over for execution
|
// Send the trace task over for execution
|
||||||
jobs <- &txTraceTask{statedb: statedb.Copy(), index: i}
|
jobs <- &txTraceTask{statedb: statedb.Copy(), index: i}
|
||||||
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
||||||
|
|
||||||
// Generate the next state snapshot fast without tracing
|
// Generate the next state snapshot fast without tracing
|
||||||
msg, _ := tx.AsMessage(signer)
|
msg, _ := tx.AsMessage(signer)
|
||||||
vmctx := core.NewEVMContext(msg,blockCtx)
|
vmctx := core.NewEVMContext(msg, blockCtx)
|
||||||
|
|
||||||
vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{})
|
vmenv := vm.NewEVM(vmctx, statedb, api.config, vm.Config{})
|
||||||
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil {
|
if _, _, _, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.Gas())); err != nil {
|
||||||
|
|
@ -567,7 +567,7 @@ func (api *PrivateDebugAPI) standardTraceBlockToFile(ctx context.Context, block
|
||||||
signer = types.MakeSigner(api.config, block.Number())
|
signer = types.MakeSigner(api.config, block.Number())
|
||||||
dumps []string
|
dumps []string
|
||||||
)
|
)
|
||||||
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
||||||
for i, tx := range block.Transactions() {
|
for i, tx := range block.Transactions() {
|
||||||
// Prepare the trasaction for un-traced execution
|
// Prepare the trasaction for un-traced execution
|
||||||
var (
|
var (
|
||||||
|
|
@ -801,7 +801,7 @@ func (api *PrivateDebugAPI) computeTxEnv(blockHash common.Hash, txIndex int, ree
|
||||||
}
|
}
|
||||||
// Recompute transactions up to the target index.
|
// Recompute transactions up to the target index.
|
||||||
signer := types.MakeSigner(api.config, block.Number())
|
signer := types.MakeSigner(api.config, block.Number())
|
||||||
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
blockCtx := core.NewBlockContext(block.Header(), api.eth.blockchain, nil)
|
||||||
for idx, tx := range block.Transactions() {
|
for idx, tx := range block.Transactions() {
|
||||||
// Assemble the transaction call message and return if the requested offset
|
// Assemble the transaction call message and return if the requested offset
|
||||||
msg, _ := tx.AsMessage(signer)
|
msg, _ := tx.AsMessage(signer)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,13 @@ type dummyStatedb struct {
|
||||||
func (*dummyStatedb) GetRefund() uint64 { return 1337 }
|
func (*dummyStatedb) GetRefund() uint64 { return 1337 }
|
||||||
|
|
||||||
func runTrace(tracer *Tracer) (json.RawMessage, error) {
|
func runTrace(tracer *Tracer) (json.RawMessage, error) {
|
||||||
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
|
env := vm.NewEVM(
|
||||||
|
vm.Context{
|
||||||
|
BlockContext: &vm.BlockContext{
|
||||||
|
BlockNumber: big.NewInt(1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
|
||||||
|
|
||||||
contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000)
|
contract := vm.NewContract(account{}, account{}, big.NewInt(0), 10000)
|
||||||
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0}
|
contract.Code = []byte{byte(vm.PUSH1), 0x1, byte(vm.PUSH1), 0x1, 0x0}
|
||||||
|
|
@ -132,8 +138,13 @@ func TestHaltBetweenSteps(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
env := vm.NewEVM(
|
||||||
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, &dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
|
vm.Context{
|
||||||
|
BlockContext: &vm.BlockContext{
|
||||||
|
BlockNumber: big.NewInt(1),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&dummyStatedb{}, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
|
||||||
contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0)
|
contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0)
|
||||||
|
|
||||||
tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)
|
tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil)
|
||||||
|
|
|
||||||
|
|
@ -133,8 +133,8 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
|
||||||
from.SetBalance(math.MaxBig256)
|
from.SetBalance(math.MaxBig256)
|
||||||
|
|
||||||
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
|
msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
|
||||||
|
blockCtx := core.NewBlockContext(header, bc, nil)
|
||||||
context := core.NewEVMContext(msg, header, bc, nil)
|
context := core.NewEVMContext(msg, blockCtx)
|
||||||
vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
|
vmenv := vm.NewEVM(context, statedb, config, vm.Config{})
|
||||||
|
|
||||||
//vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{})
|
//vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{})
|
||||||
|
|
@ -147,7 +147,8 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai
|
||||||
state := light.NewState(ctx, header, lc.Odr())
|
state := light.NewState(ctx, header, lc.Odr())
|
||||||
state.SetBalance(testBankAddress, math.MaxBig256)
|
state.SetBalance(testBankAddress, math.MaxBig256)
|
||||||
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
|
msg := callmsg{types.NewMessage(testBankAddress, &testContractAddr, 0, new(big.Int), 100000, new(big.Int), data, false)}
|
||||||
context := core.NewEVMContext(msg, header, lc, nil)
|
blockCtx := core.NewBlockContext(header, lc, nil)
|
||||||
|
context := core.NewEVMContext(msg, blockCtx)
|
||||||
vmenv := vm.NewEVM(context, state, config, vm.Config{})
|
vmenv := vm.NewEVM(context, state, config, vm.Config{})
|
||||||
gp := new(core.GasPool).AddGas(math.MaxUint64)
|
gp := new(core.GasPool).AddGas(math.MaxUint64)
|
||||||
ret, _, _, _ := core.ApplyMessage(vmenv, msg, gp)
|
ret, _, _, _ := core.ApplyMessage(vmenv, msg, gp)
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) (*state.StateD
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
blockCtx := core.NewBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
blockCtx := core.NewBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
||||||
context := core.NewEVMContext(msg, blockCtx)
|
context := core.NewEVMContext(msg, blockCtx)
|
||||||
blockCtx.GetHash = vmTestBlockHash
|
blockCtx.GetHash = vmTestBlockHash
|
||||||
evm := vm.NewEVM(context, statedb, config, vmconfig)
|
evm := vm.NewEVM(context, statedb, config, vmconfig)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue