tests: update, enable legacy tests, remove vm tests (#23350)

* tests: update, enable legacy tests, remove vm tests

* tests: minor fixes
This commit is contained in:
Martin Holst Swende 2021-08-17 17:30:21 +02:00 committed by GitHub
parent 0a68558e7e
commit fb4007bb22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 11 additions and 301 deletions

View File

@ -1,90 +0,0 @@
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package tests
import (
"encoding/json"
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
)
var _ = (*vmExecMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (v vmExec) MarshalJSON() ([]byte, error) {
type vmExec struct {
Address common.UnprefixedAddress `json:"address" gencodec:"required"`
Caller common.UnprefixedAddress `json:"caller" gencodec:"required"`
Origin common.UnprefixedAddress `json:"origin" gencodec:"required"`
Code hexutil.Bytes `json:"code" gencodec:"required"`
Data hexutil.Bytes `json:"data" gencodec:"required"`
Value *math.HexOrDecimal256 `json:"value" gencodec:"required"`
GasLimit math.HexOrDecimal64 `json:"gas" gencodec:"required"`
GasPrice *math.HexOrDecimal256 `json:"gasPrice" gencodec:"required"`
}
var enc vmExec
enc.Address = common.UnprefixedAddress(v.Address)
enc.Caller = common.UnprefixedAddress(v.Caller)
enc.Origin = common.UnprefixedAddress(v.Origin)
enc.Code = v.Code
enc.Data = v.Data
enc.Value = (*math.HexOrDecimal256)(v.Value)
enc.GasLimit = math.HexOrDecimal64(v.GasLimit)
enc.GasPrice = (*math.HexOrDecimal256)(v.GasPrice)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON.
func (v *vmExec) UnmarshalJSON(input []byte) error {
type vmExec struct {
Address *common.UnprefixedAddress `json:"address" gencodec:"required"`
Caller *common.UnprefixedAddress `json:"caller" gencodec:"required"`
Origin *common.UnprefixedAddress `json:"origin" gencodec:"required"`
Code *hexutil.Bytes `json:"code" gencodec:"required"`
Data *hexutil.Bytes `json:"data" gencodec:"required"`
Value *math.HexOrDecimal256 `json:"value" gencodec:"required"`
GasLimit *math.HexOrDecimal64 `json:"gas" gencodec:"required"`
GasPrice *math.HexOrDecimal256 `json:"gasPrice" gencodec:"required"`
}
var dec vmExec
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Address == nil {
return errors.New("missing required field 'address' for vmExec")
}
v.Address = common.Address(*dec.Address)
if dec.Caller == nil {
return errors.New("missing required field 'caller' for vmExec")
}
v.Caller = common.Address(*dec.Caller)
if dec.Origin == nil {
return errors.New("missing required field 'origin' for vmExec")
}
v.Origin = common.Address(*dec.Origin)
if dec.Code == nil {
return errors.New("missing required field 'code' for vmExec")
}
v.Code = *dec.Code
if dec.Data == nil {
return errors.New("missing required field 'data' for vmExec")
}
v.Data = *dec.Data
if dec.Value == nil {
return errors.New("missing required field 'value' for vmExec")
}
v.Value = (*big.Int)(dec.Value)
if dec.GasLimit == nil {
return errors.New("missing required field 'gas' for vmExec")
}
v.GasLimit = uint64(*dec.GasLimit)
if dec.GasPrice == nil {
return errors.New("missing required field 'gasPrice' for vmExec")
}
v.GasPrice = (*big.Int)(dec.GasPrice)
return nil
}

View File

@ -37,9 +37,8 @@ var (
baseDir = filepath.Join(".", "testdata")
blockTestDir = filepath.Join(baseDir, "BlockchainTests")
stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
//legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
legacyStateTestDir = filepath.Join(baseDir, "LegacyTests", "Constantinople", "GeneralStateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests")
vmTestDir = filepath.Join(baseDir, "VMTests")
rlpTestDir = filepath.Join(baseDir, "RLPTests")
difficultyTestDir = filepath.Join(baseDir, "BasicTests")
)

View File

@ -45,8 +45,7 @@ func TestState(t *testing.T) {
// Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`)
// Un-skip this when https://github.com/ethereum/tests/issues/908 is closed
st.skipLoad(`^stQuadraticComplexityTest/QuadraticComplexitySolidity_CallDataCopy`)
// Broken tests:
// Expected failures:
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Byzantium/0`, "bug in test")
@ -59,9 +58,7 @@ func TestState(t *testing.T) {
// For Istanbul, older tests were moved into LegacyTests
for _, dir := range []string{
stateTestDir,
// legacy state tests are disabled, due to them not being
// regenerated for the no-sender-eoa change.
//legacyStateTestDir,
legacyStateTestDir,
} {
st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
for _, subtest := range test.Subtests() {

View File

@ -358,3 +358,7 @@ func rlpHash(x interface{}) (h common.Hash) {
hw.Sum(h[:0])
return h
}
func vmTestBlockHash(n uint64) common.Hash {
return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
}

@ -1 +1 @@
Subproject commit 5d534e37b80e9310e8c7751f805ca481a451123e
Subproject commit 092a8834dc445e683103689d6f0e75a5d380a190

View File

@ -1,39 +0,0 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
import (
"testing"
"github.com/ethereum/go-ethereum/core/vm"
)
func TestVM(t *testing.T) {
t.Parallel()
vmt := new(testMatcher)
vmt.slow("^vmPerformance")
vmt.fails("^vmSystemOperationsTest.json/createNameRegistrator$", "fails without parallel execution")
vmt.walk(t, vmTestDir, func(t *testing.T, name string, test *VMTest) {
withTrace(t, test.json.Exec.GasLimit, func(vmconfig vm.Config) error {
return vmt.checkFailure(t, test.Run(vmconfig, false))
})
withTrace(t, test.json.Exec.GasLimit, func(vmconfig vm.Config) error {
return vmt.checkFailure(t, test.Run(vmconfig, true))
})
})
}

View File

@ -1,161 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package tests
import (
"bytes"
"encoding/json"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
)
// VMTest checks EVM execution without block or transaction context.
// See https://github.com/ethereum/tests/wiki/VM-Tests for the test format specification.
type VMTest struct {
json vmJSON
}
func (t *VMTest) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &t.json)
}
type vmJSON struct {
Env stEnv `json:"env"`
Exec vmExec `json:"exec"`
Logs common.UnprefixedHash `json:"logs"`
GasRemaining *math.HexOrDecimal64 `json:"gas"`
Out hexutil.Bytes `json:"out"`
Pre core.GenesisAlloc `json:"pre"`
Post core.GenesisAlloc `json:"post"`
PostStateRoot common.Hash `json:"postStateRoot"`
}
//go:generate gencodec -type vmExec -field-override vmExecMarshaling -out gen_vmexec.go
type vmExec struct {
Address common.Address `json:"address" gencodec:"required"`
Caller common.Address `json:"caller" gencodec:"required"`
Origin common.Address `json:"origin" gencodec:"required"`
Code []byte `json:"code" gencodec:"required"`
Data []byte `json:"data" gencodec:"required"`
Value *big.Int `json:"value" gencodec:"required"`
GasLimit uint64 `json:"gas" gencodec:"required"`
GasPrice *big.Int `json:"gasPrice" gencodec:"required"`
}
type vmExecMarshaling struct {
Address common.UnprefixedAddress
Caller common.UnprefixedAddress
Origin common.UnprefixedAddress
Code hexutil.Bytes
Data hexutil.Bytes
Value *math.HexOrDecimal256
GasLimit math.HexOrDecimal64
GasPrice *math.HexOrDecimal256
}
func (t *VMTest) Run(vmconfig vm.Config, snapshotter bool) error {
snaps, statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, snapshotter)
if snapshotter {
preRoot := statedb.IntermediateRoot(false)
defer func() {
if _, err := snaps.Journal(preRoot); err != nil {
panic(err)
}
}()
}
ret, gasRemaining, err := t.exec(statedb, vmconfig)
if t.json.GasRemaining == nil {
if err == nil {
return fmt.Errorf("gas unspecified (indicating an error), but VM returned no error")
}
if gasRemaining > 0 {
return fmt.Errorf("gas unspecified (indicating an error), but VM returned gas remaining > 0")
}
return nil
}
// Test declares gas, expecting outputs to match.
if !bytes.Equal(ret, t.json.Out) {
return fmt.Errorf("return data mismatch: got %x, want %x", ret, t.json.Out)
}
if gasRemaining != uint64(*t.json.GasRemaining) {
return fmt.Errorf("remaining gas %v, want %v", gasRemaining, *t.json.GasRemaining)
}
for addr, account := range t.json.Post {
for k, wantV := range account.Storage {
if haveV := statedb.GetState(addr, k); haveV != wantV {
return fmt.Errorf("wrong storage value at %x:\n got %x\n want %x", k, haveV, wantV)
}
}
}
// if root := statedb.IntermediateRoot(false); root != t.json.PostStateRoot {
// return fmt.Errorf("post state root mismatch, got %x, want %x", root, t.json.PostStateRoot)
// }
if logs := rlpHash(statedb.Logs()); logs != common.Hash(t.json.Logs) {
return fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, t.json.Logs)
}
return nil
}
func (t *VMTest) exec(statedb *state.StateDB, vmconfig vm.Config) ([]byte, uint64, error) {
evm := t.newEVM(statedb, vmconfig)
e := t.json.Exec
return evm.Call(vm.AccountRef(e.Caller), e.Address, e.Data, e.GasLimit, e.Value)
}
func (t *VMTest) newEVM(statedb *state.StateDB, vmconfig vm.Config) *vm.EVM {
initialCall := true
canTransfer := func(db vm.StateDB, address common.Address, amount *big.Int) bool {
if initialCall {
initialCall = false
return true
}
return core.CanTransfer(db, address, amount)
}
transfer := func(db vm.StateDB, sender, recipient common.Address, amount *big.Int) {}
txContext := vm.TxContext{
Origin: t.json.Exec.Origin,
GasPrice: t.json.Exec.GasPrice,
}
context := vm.BlockContext{
CanTransfer: canTransfer,
Transfer: transfer,
GetHash: vmTestBlockHash,
Coinbase: t.json.Env.Coinbase,
BlockNumber: new(big.Int).SetUint64(t.json.Env.Number),
Time: new(big.Int).SetUint64(t.json.Env.Timestamp),
GasLimit: t.json.Env.GasLimit,
Difficulty: t.json.Env.Difficulty,
}
vmconfig.NoRecursion = true
return vm.NewEVM(context, txContext, statedb, params.MainnetChainConfig, vmconfig)
}
func vmTestBlockHash(n uint64) common.Hash {
return common.BytesToHash(crypto.Keccak256([]byte(big.NewInt(int64(n)).String())))
}