mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core,vm,tests: fix failures and formatting
This commit is contained in:
parent
1363909843
commit
5e52a98d90
11 changed files with 76 additions and 50 deletions
|
|
@ -282,7 +282,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
|
||||||
// Execute the call.
|
// Execute the call.
|
||||||
msg := callmsg{call}
|
msg := callmsg{call}
|
||||||
|
|
||||||
evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain, nil)
|
evmContext := core.NewEVMContext(msg, block.Header(), b.blockchain)
|
||||||
// Ignore error, we're past header validation
|
// Ignore error, we're past header validation
|
||||||
beneficiary, _ := b.blockchain.Engine().Author(block.Header())
|
beneficiary, _ := b.blockchain.Engine().Author(block.Header())
|
||||||
blockContext := core.NewBlockContext(block.Header(), beneficiary, b.config)
|
blockContext := core.NewBlockContext(block.Header(), beneficiary, b.config)
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,12 @@
|
||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"bytes"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ type twoOperandTest struct {
|
||||||
|
|
||||||
func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
|
func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error)) {
|
||||||
var (
|
var (
|
||||||
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
|
blockContext = &BlockContext{Coinbase: common.Address{}, BlockNumber: big.NewInt(1337), Intpool: NewIntpool()}
|
||||||
|
env = NewEVM(&Context{}, nil, params.TestChainConfig, &Config{}, blockContext)
|
||||||
stack = newstack()
|
stack = newstack()
|
||||||
pc = uint64(0)
|
pc = uint64(0)
|
||||||
)
|
)
|
||||||
|
|
@ -50,13 +51,13 @@ func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64
|
||||||
// Check pool usage
|
// Check pool usage
|
||||||
// 1.pool is not allowed to contain anything on the stack
|
// 1.pool is not allowed to contain anything on the stack
|
||||||
// 2.pool is not allowed to contain the same pointers twice
|
// 2.pool is not allowed to contain the same pointers twice
|
||||||
if env.interpreter.intPool.pool.len() > 0 {
|
if env.BlockContext.Intpool.pool.len() > 0 {
|
||||||
|
|
||||||
poolvals := make(map[*big.Int]struct{})
|
poolvals := make(map[*big.Int]struct{})
|
||||||
poolvals[actual] = struct{}{}
|
poolvals[actual] = struct{}{}
|
||||||
|
|
||||||
for env.interpreter.intPool.pool.len() > 0 {
|
for env.BlockContext.Intpool.pool.len() > 0 {
|
||||||
key := env.interpreter.intPool.get()
|
key := env.BlockContext.Intpool.get()
|
||||||
if _, exist := poolvals[key]; exist {
|
if _, exist := poolvals[key]; exist {
|
||||||
t.Errorf("Testcase %d, pool contains double-entry", i)
|
t.Errorf("Testcase %d, pool contains double-entry", i)
|
||||||
}
|
}
|
||||||
|
|
@ -68,7 +69,8 @@ func testTwoOperandOp(t *testing.T, tests []twoOperandTest, opFn func(pc *uint64
|
||||||
|
|
||||||
func TestByteOp(t *testing.T) {
|
func TestByteOp(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
|
blockContext = &BlockContext{Coinbase: common.Address{}, BlockNumber: big.NewInt(1337), Intpool: NewIntpool()}
|
||||||
|
env = NewEVM(&Context{}, nil, params.TestChainConfig, &Config{}, blockContext)
|
||||||
stack = newstack()
|
stack = newstack()
|
||||||
)
|
)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
|
@ -198,7 +200,8 @@ func TestSLT(t *testing.T) {
|
||||||
|
|
||||||
func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
|
func opBenchmark(bench *testing.B, op func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error), args ...string) {
|
||||||
var (
|
var (
|
||||||
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
|
blockContext = &BlockContext{Coinbase: common.Address{}, BlockNumber: big.NewInt(1337), Intpool: NewIntpool()}
|
||||||
|
env = NewEVM(&Context{}, nil, params.TestChainConfig, &Config{}, blockContext)
|
||||||
stack = newstack()
|
stack = newstack()
|
||||||
)
|
)
|
||||||
// convert args
|
// convert args
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,10 @@ type dummyStateDB struct {
|
||||||
|
|
||||||
func TestStoreCapture(t *testing.T) {
|
func TestStoreCapture(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
env = NewEVM(Context{}, nil, params.TestChainConfig, Config{})
|
blkCtx = &BlockContext{
|
||||||
|
Intpool: NewIntpool(),
|
||||||
|
}
|
||||||
|
env = NewEVM(&Context{}, nil, params.TestChainConfig, &Config{}, blkCtx)
|
||||||
logger = NewStructLogger(nil)
|
logger = NewStructLogger(nil)
|
||||||
mem = NewMemory()
|
mem = NewMemory()
|
||||||
stack = newstack()
|
stack = newstack()
|
||||||
|
|
|
||||||
|
|
@ -19,23 +19,24 @@ package runtime
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEnv(cfg *Config) *vm.EVM {
|
func NewEnv(cfg *Config) *vm.EVM {
|
||||||
context := vm.Context{
|
context := &vm.Context{
|
||||||
CanTransfer: core.CanTransfer,
|
CanTransfer: core.CanTransfer,
|
||||||
Transfer: core.Transfer,
|
Transfer: core.Transfer,
|
||||||
GetHash: func(uint64) common.Hash { return common.Hash{} },
|
GetHash: func(uint64) common.Hash { return common.Hash{} },
|
||||||
|
|
||||||
Origin: cfg.Origin,
|
Origin: cfg.Origin,
|
||||||
Coinbase: cfg.Coinbase,
|
GasPrice: cfg.GasPrice,
|
||||||
BlockNumber: cfg.BlockNumber,
|
}
|
||||||
|
header := &types.Header{
|
||||||
|
Number: cfg.BlockNumber,
|
||||||
Time: cfg.Time,
|
Time: cfg.Time,
|
||||||
Difficulty: cfg.Difficulty,
|
Difficulty: cfg.Difficulty,
|
||||||
GasLimit: cfg.GasLimit,
|
GasLimit: cfg.GasLimit,
|
||||||
GasPrice: cfg.GasPrice,
|
|
||||||
}
|
}
|
||||||
|
blockContext := core.NewBlockContext(header, cfg.Coinbase, cfg.ChainConfig)
|
||||||
return vm.NewEVM(context, cfg.State, cfg.ChainConfig, cfg.EVMConfig)
|
return vm.NewEVM(context, cfg.State, cfg.ChainConfig, &cfg.EVMConfig, blockContext)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,17 @@
|
||||||
package eth
|
package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
||||||
"bytes"
|
|
||||||
"context"
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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"
|
||||||
|
|
@ -37,9 +39,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"io/ioutil"
|
|
||||||
"runtime"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"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"
|
||||||
)
|
)
|
||||||
|
|
@ -43,8 +45,19 @@ func (account) ReturnGas(*big.Int) {}
|
||||||
func (account) SetCode(common.Hash, []byte) {}
|
func (account) SetCode(common.Hash, []byte) {}
|
||||||
func (account) ForEachStorage(cb func(key, value common.Hash) bool) {}
|
func (account) ForEachStorage(cb func(key, value common.Hash) bool) {}
|
||||||
|
|
||||||
|
func getEvm(tracer *Tracer) *vm.EVM {
|
||||||
|
header := &types.Header{
|
||||||
|
Number: new(big.Int).SetUint64(1),
|
||||||
|
Time: new(big.Int).SetUint64(0),
|
||||||
|
Coinbase: common.Address{},
|
||||||
|
Difficulty: big.NewInt(1000000),
|
||||||
|
}
|
||||||
|
blockContext := core.NewBlockContext(header, header.Coinbase, params.MainnetChainConfig)
|
||||||
|
return vm.NewEVM(&vm.Context{}, nil, params.TestChainConfig, &vm.Config{Debug: true, Tracer: tracer}, blockContext)
|
||||||
|
|
||||||
|
}
|
||||||
func runTrace(tracer *Tracer) (json.RawMessage, error) {
|
func runTrace(tracer *Tracer) (json.RawMessage, error) {
|
||||||
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer})
|
env := getEvm(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}
|
||||||
|
|
@ -125,8 +138,7 @@ func TestHaltBetweenSteps(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
env := getEvm(tracer)
|
||||||
env := vm.NewEVM(vm.Context{BlockNumber: big.NewInt(1)}, nil, 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)
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"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/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/tests"
|
"github.com/ethereum/go-ethereum/tests"
|
||||||
)
|
)
|
||||||
|
|
@ -152,13 +153,16 @@ func TestCallTracer(t *testing.T) {
|
||||||
CanTransfer: core.CanTransfer,
|
CanTransfer: core.CanTransfer,
|
||||||
Transfer: core.Transfer,
|
Transfer: core.Transfer,
|
||||||
Origin: origin,
|
Origin: origin,
|
||||||
Coinbase: test.Context.Miner,
|
|
||||||
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
|
||||||
Time: new(big.Int).SetUint64(uint64(test.Context.Time)),
|
|
||||||
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
||||||
GasLimit: uint64(test.Context.GasLimit),
|
|
||||||
GasPrice: tx.GasPrice(),
|
GasPrice: tx.GasPrice(),
|
||||||
}
|
}
|
||||||
|
header := &types.Header{
|
||||||
|
Coinbase: test.Context.Miner,
|
||||||
|
Number: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
||||||
|
Time: new(big.Int).SetUint64(uint64(test.Context.Time)),
|
||||||
|
GasLimit: uint64(test.Context.GasLimit),
|
||||||
|
Difficulty: (*big.Int)(test.Context.Difficulty),
|
||||||
|
}
|
||||||
|
blockContext := core.NewBlockContext(header, header.Coinbase, params.MainnetChainConfig)
|
||||||
statedb := tests.MakePreState(ethdb.NewMemDatabase(), test.Genesis.Alloc)
|
statedb := tests.MakePreState(ethdb.NewMemDatabase(), test.Genesis.Alloc)
|
||||||
|
|
||||||
// Create the tracer, the EVM environment and run it
|
// Create the tracer, the EVM environment and run it
|
||||||
|
|
@ -166,7 +170,7 @@ func TestCallTracer(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create call tracer: %v", err)
|
t.Fatalf("failed to create call tracer: %v", err)
|
||||||
}
|
}
|
||||||
evm := vm.NewEVM(context, statedb, test.Genesis.Config, vm.Config{Debug: true, Tracer: tracer})
|
evm := vm.NewEVM(&context, statedb, test.Genesis.Config, &vm.Config{Debug: true, Tracer: tracer}, blockContext)
|
||||||
|
|
||||||
msg, err := tx.AsMessage(signer)
|
msg, err := tx.AsMessage(signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"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/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
|
@ -135,15 +136,18 @@ func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM {
|
||||||
Transfer: transfer,
|
Transfer: transfer,
|
||||||
GetHash: vmTestBlockHash,
|
GetHash: vmTestBlockHash,
|
||||||
Origin: t.json.Exec.Origin,
|
Origin: t.json.Exec.Origin,
|
||||||
|
GasPrice: t.json.Exec.GasPrice,
|
||||||
|
}
|
||||||
|
header := &types.Header{
|
||||||
Coinbase: t.json.Env.Coinbase,
|
Coinbase: t.json.Env.Coinbase,
|
||||||
BlockNumber: new(big.Int).SetUint64(t.json.Env.Number),
|
Number: new(big.Int).SetUint64(t.json.Env.Number),
|
||||||
Time: new(big.Int).SetUint64(t.json.Env.Timestamp),
|
Time: new(big.Int).SetUint64(t.json.Env.Timestamp),
|
||||||
GasLimit: t.json.Env.GasLimit,
|
GasLimit: t.json.Env.GasLimit,
|
||||||
Difficulty: t.json.Env.Difficulty,
|
Difficulty: t.json.Env.Difficulty,
|
||||||
GasPrice: t.json.Exec.GasPrice,
|
|
||||||
}
|
}
|
||||||
|
blockContext := core.NewBlockContext(header, header.Coinbase, params.MainnetChainConfig)
|
||||||
vmconfig.NoRecursion = true
|
vmconfig.NoRecursion = true
|
||||||
return vm.NewEVM(context, statedb, params.MainnetChainConfig, vmconfig)
|
return vm.NewEVM(&context, statedb, params.MainnetChainConfig, &vmconfig, blockContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func vmTestBlockHash(n uint64) common.Hash {
|
func vmTestBlockHash(n uint64) common.Hash {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue