github.com/pfcoder/quorum@v2.0.3-0.20180501191142-d4a1b0958135+incompatible/tests/state_test.go (about)

     1  // Copyright 2017 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package tests
    18  
    19  import (
    20  	"bytes"
    21  	"fmt"
    22  	"reflect"
    23  	"testing"
    24  
    25  	"github.com/ethereum/go-ethereum/core/vm"
    26  )
    27  
    28  func TestState(t *testing.T) {
    29  	t.Parallel()
    30  
    31  	st := new(testMatcher)
    32  	// Long tests:
    33  	st.skipShortMode(`^stQuadraticComplexityTest/`)
    34  	// Broken tests:
    35  	st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits
    36  	st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet
    37  	// Expected failures:
    38  	st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
    39  	st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`, "bug in test")
    40  	st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test")
    41  	st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium`, "bug in test")
    42  	st.fails(`^stRandom/randomStatetest645\.json/EIP150/.*`, "known bug #15119")
    43  	st.fails(`^stRandom/randomStatetest645\.json/Frontier/.*`, "known bug #15119")
    44  	st.fails(`^stRandom/randomStatetest645\.json/Homestead/.*`, "known bug #15119")
    45  	st.fails(`^stRandom/randomStatetest644\.json/EIP150/.*`, "known bug #15119")
    46  	st.fails(`^stRandom/randomStatetest644\.json/Frontier/.*`, "known bug #15119")
    47  	st.fails(`^stRandom/randomStatetest644\.json/Homestead/.*`, "known bug #15119")
    48  	st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/2`, "known bug ")
    49  	st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/EIP158/3`, "known bug ")
    50  	st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/2`, "known bug ")
    51  	st.fails(`^stCreateTest/TransactionCollisionToEmpty\.json/Byzantium/3`, "known bug ")
    52  
    53  	// Skip invalid receipt root hash / invalid nonce quorum failures
    54  	st.skipLoad(`(StoreClearsAndInternlCallStoreClearsOOG|TransactionSendingToZero|SuicidesAndInternlCallSuicidesOOG|SuicidesAndInternlCallSuicidesSuccess|SuicidesAndInternlCallSuicidesBonusGasAtCallFailed|SuicidesAndInternlCallSuicidesBonusGasAtCall|StoreClearsAndInternlCallStoreClearsSuccess|InternlCallStoreClearsSucces|InternlCallStoreClearsOOG|failed_tx_xcf416c53|CallContractToCreateContractOOG)\.json`) // EIP-86 is not supported yet
    55  
    56  	st.walk(t, stateTestDir, func(t *testing.T, name string, test *StateTest) {
    57  		for _, subtest := range test.Subtests() {
    58  			subtest := subtest
    59  			key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
    60  			name := name + "/" + key
    61  			t.Run(key, func(t *testing.T) {
    62  				if subtest.Fork == "Constantinople" {
    63  					t.Skip("constantinople not supported yet")
    64  				}
    65  				withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
    66  					_, err := test.Run(subtest, vmconfig)
    67  					return st.checkFailure(t, name, err)
    68  				})
    69  			})
    70  		}
    71  	})
    72  }
    73  
    74  // Transactions with gasLimit above this value will not get a VM trace on failure.
    75  //const traceErrorLimit = 400000
    76  const traceErrorLimit = 0
    77  
    78  func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
    79  	err := test(vm.Config{})
    80  	if err == nil {
    81  		return
    82  	}
    83  	t.Error(err)
    84  	if gasLimit > traceErrorLimit {
    85  		t.Log("gas limit too high for EVM trace")
    86  		return
    87  	}
    88  	tracer := vm.NewStructLogger(nil)
    89  	err2 := test(vm.Config{Debug: true, Tracer: tracer})
    90  	if !reflect.DeepEqual(err, err2) {
    91  		t.Errorf("different error for second run: %v", err2)
    92  	}
    93  	buf := new(bytes.Buffer)
    94  	vm.WriteTrace(buf, tracer.StructLogs())
    95  	if buf.Len() == 0 {
    96  		t.Log("no EVM operation logs generated")
    97  	} else {
    98  		t.Log("EVM operation log:\n" + buf.String())
    99  	}
   100  }