erigon-pulse/tests/state_test.go

135 lines
4.3 KiB
Go
Raw Normal View History

// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
2015-07-07 00:54:22 +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.
//
// 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
// 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
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
2015-07-07 00:54:22 +00:00
2015-06-10 16:04:56 +00:00
package tests
2015-06-10 16:34:38 +00:00
import (
"bufio"
"bytes"
"context"
"fmt"
"reflect"
2021-05-20 16:46:12 +00:00
"runtime"
2015-06-10 16:34:38 +00:00
"testing"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/ethdb"
2015-06-10 16:34:38 +00:00
)
func TestState(t *testing.T) {
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
}
t.Parallel()
st := new(testMatcher)
// Long tests:
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(`^stSystemOperationsTest/CallRecursiveBomb`)
st.slow(`^stTransactionTest/Opcodes_TransactionInit`)
// Very time consuming
st.skipLoad(`^stTimeConsuming/`)
// Uses 1GB RAM per tested fork
st.skipLoad(`^stStaticCall/static_Call1MB`)
// Broken tests:
st.skipLoad(`^stCreate2/create2collisionStorage.json`)
st.skipLoad(`^stExtCodeHash/dynamicAccountOverwriteEmpty.json`)
st.skipLoad(`^stSStoreTest/InitCollision.json`)
// Expected failures:
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Byzantium/0`, "bug in test")
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Byzantium/3`, "bug in test")
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Constantinople/0`, "bug in test")
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/Constantinople/3`, "bug in test")
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/ConstantinopleFix/0`, "bug in test")
//st.fails(`^stRevertTest/RevertPrecompiledTouch(_storage)?\.json/ConstantinopleFix/3`, "bug in test")
// For Istanbul, older tests were moved into LegacyTests
for _, dir := range []string{
stateTestDir,
legacyStateTestDir,
} {
st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
db := ethdb.NewTestKV(t)
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, test.gasLimit(subtest), func(vmconfig vm.Config) error {
2019-12-03 13:02:09 +00:00
config, ok := Forks[subtest.Fork]
if !ok {
return UnsupportedForkError{subtest.Fork}
}
Aleut support (Eip1559) (#1704) * Where I am at * Refactoring of transaction types * More refactoring * Use Homested signer in rpc daemon * Unified signer * Continue unified signer * A bit more * Fixes and down the rabbit hole... * More tx pool fixes * More refactoring fixes * More fixes' * more fixes * More fixes * More compile fixes * More RLP hand-writing * Finish RLP encoding/decoding of transactions * Fixes to header encoding, start on protocol packets * Transaction decoding * Use DecodeTransaction function * Decoding BlockBodyPacket * Encode and decode for pool txs * Start fixing tests * Introduce SigningHash * Fixes to SignHash * RLP encoding fixes * Fixes for encoding/decoding * More test fixes * Fix more tests * More test fixes * More test fixes * Fix core tests * More fixes for signer * Fix for tx * Fixes to string encoding/size * Fix eip2930 test * Fix rest of ./tests * More fixes * Fix compilation * More test fixes * More test fixes * Test fixes * More fixes * Reuse EncodingSize in EncodeRLP for accessList * Rearrange things in dynamic fee tx * Add MarshalBinary * More fixes * Make V,R,S non-pointers * More NPE fixes * More fixes * Receipt fixes * Fix core/types * Fix ./eth * More compile fixes for tests * More test fixes * More test fixes * Try to see lint errors better * Try to see lint errors better * Fix lint * Debugging eip1559 test * Fix TestEIP1559Transition test * Fix NewBlockPacket encoding/decoding * Fix calculation of TxHash * Fix perf problem with senders * Update aleut config values * Try adding static peers * Add staticpeers to defaul flags * Change aleut networkID * Fix test Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro.local> Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
2021-04-22 17:11:37 +00:00
ctx := config.WithEIPsFlags(context.Background(), 1)
2021-03-31 15:30:09 +00:00
tx, err := db.BeginRw(context.Background())
2021-03-31 15:30:09 +00:00
if err != nil {
t.Fatal(err)
}
defer tx.Rollback()
_, err = test.Run(ctx, tx, subtest, vmconfig)
tx.Rollback()
2019-12-03 13:02:09 +00:00
return st.checkFailure(t, err)
})
})
}
})
}
2016-10-31 10:32:05 +00:00
}
// Transactions with gasLimit above this value will not get a VM trace on failure.
2021-04-02 05:14:43 +00:00
const traceErrorLimit = 4000000000
2016-10-31 10:32:05 +00:00
func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
// Use config from command line arguments.
config := vm.Config{}
err := test(config)
if err == nil {
return
2016-10-31 10:32:05 +00:00
}
// Test failed, re-run with tracing enabled.
t.Error(err)
if gasLimit > traceErrorLimit {
t.Log("gas limit too high for EVM trace")
return
2016-10-31 10:32:05 +00:00
}
buf := new(bytes.Buffer)
w := bufio.NewWriter(buf)
tracer := vm.NewJSONLogger(&vm.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)
2016-10-31 10:32:05 +00:00
}
w.Flush()
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
}
//t.Logf("EVM output: 0x%x", tracer.Output())
//t.Logf("EVM error: %v", tracer.Error())
2016-10-31 10:32:05 +00:00
}