mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
// 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/>.
|
|
|
|
//go:build integration
|
|
|
|
package tests
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"reflect"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/erigon-lib/common/datadir"
|
|
"github.com/ledgerwatch/erigon/core/state/temporal"
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
"github.com/ledgerwatch/erigon/core/vm"
|
|
"github.com/ledgerwatch/erigon/eth/tracers/logger"
|
|
)
|
|
|
|
func TestState(t *testing.T) {
|
|
defer log.Root().SetHandler(log.Root().GetHandler())
|
|
log.Root().SetHandler(log.LvlFilterHandler(log.LvlError, log.StderrHandler))
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("fix me on win please") // it's too slow on win and stops on macos, need generally improve speed of this tests
|
|
}
|
|
//t.Parallel()
|
|
|
|
st := new(testMatcher)
|
|
|
|
// Very time consuming
|
|
st.skipLoad(`^stTimeConsuming/`)
|
|
st.skipLoad(`.*vmPerformance/loop.*`)
|
|
|
|
_, db, _ := temporal.NewTestDB(t, datadir.New(t.TempDir()), nil)
|
|
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) {
|
|
withTrace(t, func(vmconfig vm.Config) error {
|
|
tx, err := db.BeginRw(context.Background())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer tx.Rollback()
|
|
_, err = test.Run(tx, subtest, vmconfig)
|
|
tx.Rollback()
|
|
if err != nil && len(test.json.Post[subtest.Fork][subtest.Index].ExpectException) > 0 {
|
|
// Ignore expected errors
|
|
return nil
|
|
}
|
|
return st.checkFailure(t, err)
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func withTrace(t *testing.T, test func(vm.Config) error) {
|
|
// Use config from command line arguments.
|
|
config := vm.Config{}
|
|
err := test(config)
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
// Test failed, re-run with tracing enabled.
|
|
t.Error(err)
|
|
buf := new(bytes.Buffer)
|
|
w := bufio.NewWriter(buf)
|
|
tracer := logger.NewJSONLogger(&logger.LogConfig{DisableMemory: true}, w)
|
|
config.Debug, config.Tracer = true, tracer
|
|
err2 := test(config)
|
|
if !reflect.DeepEqual(err, err2) {
|
|
t.Errorf("different error for second run: %v", err2)
|
|
}
|
|
w.Flush()
|
|
if buf.Len() == 0 {
|
|
t.Log("no EVM operation logs generated")
|
|
} else {
|
|
t.Log("EVM operation log:\n" + buf.String())
|
|
}
|
|
//t.Logf("EVM output: 0x%x", tracer.Output())
|
|
//t.Logf("EVM error: %v", tracer.Error())
|
|
}
|