2018-03-07 21:29:21 +00:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2018-01-29 19:44:18 +00:00
|
|
|
// 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"
|
2019-01-14 10:31:28 +00:00
|
|
|
"flag"
|
2018-01-29 19:44:18 +00:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-01-14 10:31:28 +00:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2018-01-29 19:44:18 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestState(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
st := new(testMatcher)
|
|
|
|
// Long tests:
|
2018-11-21 15:30:00 +00:00
|
|
|
st.slow(`^stAttackTest/ContractCreationSpam`)
|
|
|
|
st.slow(`^stBadOpcode/badOpcodes`)
|
|
|
|
st.slow(`^stPreCompiledContracts/modexp`)
|
|
|
|
st.slow(`^stQuadraticComplexityTest/`)
|
|
|
|
st.slow(`^stStaticCall/static_Call50000`)
|
|
|
|
st.slow(`^stStaticCall/static_Return50000`)
|
|
|
|
st.slow(`^stStaticCall/static_Call1MB`)
|
|
|
|
st.slow(`^stSystemOperationsTest/CallRecursiveBomb`)
|
|
|
|
st.slow(`^stTransactionTest/Opcodes_TransactionInit`)
|
2018-01-29 19:44:18 +00:00
|
|
|
// Broken tests:
|
|
|
|
st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits
|
|
|
|
st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet
|
|
|
|
// Expected failures:
|
|
|
|
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
|
|
|
|
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test")
|
2018-11-21 15:30:00 +00:00
|
|
|
st.fails(`^stRevertTest/RevertPrecompiledTouch.json/Constantinople`, "bug in test")
|
2018-03-07 21:29:21 +00:00
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) {
|
|
|
|
for _, subtest := range test.Subtests() {
|
|
|
|
subtest := subtest
|
|
|
|
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
|
|
|
|
name := name + "/" + key
|
|
|
|
t.Run(key, func(t *testing.T) {
|
|
|
|
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
|
|
|
|
_, err := test.Run(subtest, vmconfig)
|
|
|
|
return st.checkFailure(t, name, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transactions with gasLimit above this value will not get a VM trace on failure.
|
2018-03-07 21:29:21 +00:00
|
|
|
const traceErrorLimit = 400000
|
2018-01-29 19:44:18 +00:00
|
|
|
|
2019-01-14 10:31:28 +00:00
|
|
|
// The VM config for state tests that accepts --vm.* command line arguments.
|
|
|
|
var testVMConfig = func() vm.Config {
|
|
|
|
vmconfig := vm.Config{}
|
|
|
|
flag.StringVar(&vmconfig.EVMInterpreter, utils.EVMInterpreterFlag.Name, utils.EVMInterpreterFlag.Value, utils.EVMInterpreterFlag.Usage)
|
|
|
|
flag.StringVar(&vmconfig.EWASMInterpreter, utils.EWASMInterpreterFlag.Name, utils.EWASMInterpreterFlag.Value, utils.EWASMInterpreterFlag.Usage)
|
|
|
|
flag.Parse()
|
|
|
|
return vmconfig
|
|
|
|
}()
|
|
|
|
|
2018-01-29 19:44:18 +00:00
|
|
|
func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
|
2019-01-14 10:31:28 +00:00
|
|
|
err := test(testVMConfig)
|
2018-01-29 19:44:18 +00:00
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t.Error(err)
|
|
|
|
if gasLimit > traceErrorLimit {
|
|
|
|
t.Log("gas limit too high for EVM trace")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tracer := vm.NewStructLogger(nil)
|
|
|
|
err2 := test(vm.Config{Debug: true, Tracer: tracer})
|
|
|
|
if !reflect.DeepEqual(err, err2) {
|
|
|
|
t.Errorf("different error for second run: %v", err2)
|
|
|
|
}
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
vm.WriteTrace(buf, tracer.StructLogs())
|
|
|
|
if buf.Len() == 0 {
|
|
|
|
t.Log("no EVM operation logs generated")
|
|
|
|
} else {
|
|
|
|
t.Log("EVM operation log:\n" + buf.String())
|
|
|
|
}
|
2018-03-07 21:29:21 +00:00
|
|
|
t.Logf("EVM output: 0x%x", tracer.Output())
|
|
|
|
t.Logf("EVM error: %v", tracer.Error())
|
2018-01-29 19:44:18 +00:00
|
|
|
}
|