2018-02-14 12:49:11 +00:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2022-05-04 03:35:59 +00:00
|
|
|
//go:build integration
|
|
|
|
|
2015-06-10 16:04:56 +00:00
|
|
|
package tests
|
|
|
|
|
2015-06-10 16:34:38 +00:00
|
|
|
import (
|
2019-01-24 10:36:30 +00:00
|
|
|
"bufio"
|
2017-07-11 11:49:14 +00:00
|
|
|
"bytes"
|
2019-05-27 13:51:49 +00:00
|
|
|
"context"
|
2017-07-11 11:49:14 +00:00
|
|
|
"fmt"
|
|
|
|
"reflect"
|
2021-05-20 16:46:12 +00:00
|
|
|
"runtime"
|
2015-06-10 16:34:38 +00:00
|
|
|
"testing"
|
2016-10-20 11:36:29 +00:00
|
|
|
|
2023-06-14 03:01:00 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/common/datadir"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon/core/state/temporal"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core/vm"
|
2022-12-28 10:58:37 +00:00
|
|
|
"github.com/ledgerwatch/erigon/eth/tracers/logger"
|
2015-06-10 16:34:38 +00:00
|
|
|
)
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
func TestState(t *testing.T) {
|
2021-11-18 14:07:55 +00:00
|
|
|
defer log.Root().SetHandler(log.Root().GetHandler())
|
|
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlError, log.StderrHandler))
|
2021-05-20 16:46:12 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
t.Skip("fix me on win please") // it's too slow on win, need generally improve speed of this tests
|
|
|
|
}
|
2022-11-10 23:47:35 +00:00
|
|
|
//t.Parallel()
|
2017-07-11 11:49:14 +00:00
|
|
|
|
|
|
|
st := new(testMatcher)
|
2019-10-02 08:33:51 +00:00
|
|
|
|
|
|
|
// Very time consuming
|
|
|
|
st.skipLoad(`^stTimeConsuming/`)
|
2021-12-06 08:00:54 +00:00
|
|
|
st.skipLoad(`.*vmPerformance/loop.*`)
|
2020-05-05 09:27:09 +00:00
|
|
|
|
2021-12-06 08:00:54 +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)
|
|
|
|
t.Run(key, func(t *testing.T) {
|
2023-06-26 06:55:36 +00:00
|
|
|
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
|
2022-01-11 08:16:13 +00:00
|
|
|
withTrace(t, func(vmconfig vm.Config) error {
|
2021-12-06 08:00:54 +00:00
|
|
|
tx, err := db.BeginRw(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
2022-11-22 15:07:31 +00:00
|
|
|
_, err = test.Run(tx, subtest, vmconfig)
|
2021-12-06 08:00:54 +00:00
|
|
|
tx.Rollback()
|
2022-05-30 13:45:28 +00:00
|
|
|
if err != nil && len(test.json.Post[subtest.Fork][subtest.Index].ExpectException) > 0 {
|
|
|
|
// Ignore expected errors
|
|
|
|
return nil
|
|
|
|
}
|
2021-12-06 08:00:54 +00:00
|
|
|
return st.checkFailure(t, err)
|
2019-10-02 08:33:51 +00:00
|
|
|
})
|
2021-12-06 08:00:54 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2016-10-31 10:32:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 08:16:13 +00:00
|
|
|
func withTrace(t *testing.T, test func(vm.Config) error) {
|
2019-09-11 12:41:22 +00:00
|
|
|
// Use config from command line arguments.
|
2021-03-26 02:08:01 +00:00
|
|
|
config := vm.Config{}
|
2019-09-11 12:41:22 +00:00
|
|
|
err := test(config)
|
2017-07-11 11:49:14 +00:00
|
|
|
if err == nil {
|
|
|
|
return
|
2016-10-31 10:32:05 +00:00
|
|
|
}
|
2019-09-11 12:41:22 +00:00
|
|
|
|
|
|
|
// Test failed, re-run with tracing enabled.
|
2017-07-11 11:49:14 +00:00
|
|
|
t.Error(err)
|
2019-01-24 10:36:30 +00:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
w := bufio.NewWriter(buf)
|
2022-12-28 10:58:37 +00:00
|
|
|
tracer := logger.NewJSONLogger(&logger.LogConfig{DisableMemory: true}, w)
|
2019-09-11 12:41:22 +00:00
|
|
|
config.Debug, config.Tracer = true, tracer
|
|
|
|
err2 := test(config)
|
2017-07-11 11:49:14 +00:00
|
|
|
if !reflect.DeepEqual(err, err2) {
|
|
|
|
t.Errorf("different error for second run: %v", err2)
|
2016-10-31 10:32:05 +00:00
|
|
|
}
|
2019-01-24 10:36:30 +00:00
|
|
|
w.Flush()
|
2017-07-11 11:49:14 +00:00
|
|
|
if buf.Len() == 0 {
|
|
|
|
t.Log("no EVM operation logs generated")
|
|
|
|
} else {
|
|
|
|
t.Log("EVM operation log:\n" + buf.String())
|
2016-10-31 10:32:05 +00:00
|
|
|
}
|
2019-01-24 10:36:30 +00:00
|
|
|
//t.Logf("EVM output: 0x%x", tracer.Output())
|
|
|
|
//t.Logf("EVM error: %v", tracer.Error())
|
2016-10-31 10:32:05 +00:00
|
|
|
}
|