2017-07-11 04:49:14 -07:00
// Copyright 2017 The go-ethereum Authors
2015-07-22 09:48:40 -07:00
// This file is part of the go-ethereum library.
2015-07-06 17:54:22 -07:00
//
2015-07-23 09:35:11 -07:00
// The go-ethereum library is free software: you can redistribute it and/or modify
2015-07-06 17:54:22 -07: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 09:48:40 -07:00
// The go-ethereum library is distributed in the hope that it will be useful,
2015-07-06 17:54:22 -07:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2015-07-22 09:48:40 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2015-07-06 17:54:22 -07: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 09:48:40 -07:00
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
2015-07-06 17:54:22 -07:00
2015-06-10 09:04:56 -07:00
package tests
2015-06-10 09:34:38 -07:00
import (
2017-07-11 04:49:14 -07:00
"bytes"
"fmt"
"reflect"
2015-06-10 09:34:38 -07:00
"testing"
2016-10-20 04:36:29 -07:00
2017-07-11 04:49:14 -07:00
"github.com/ethereum/go-ethereum/core/vm"
2015-06-10 09:34:38 -07:00
)
2017-07-11 04:49:14 -07:00
func TestState ( t * testing . T ) {
t . Parallel ( )
st := new ( testMatcher )
// Long tests:
st . skipShortMode ( ` ^stQuadraticComplexityTest/ ` )
// Broken tests:
st . skipLoad ( ` ^stTransactionTest/OverflowGasRequire\.json ` ) // gasLimit > 256 bits
st . skipLoad ( ` ^stTransactionTest/zeroSigTransa[^/]*\.json ` ) // EIP-86 is not supported yet
// Expected failures:
2017-08-10 02:38:17 -07:00
st . fails ( ` ^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead|EIP150) ` ,
2017-07-11 04:49:14 -07:00
"code size limit implementation is not conditional on fork" )
st . fails ( ` ^stRevertTest/RevertDepthCreateAddressCollision\.json/EIP15[08]/[67] ` , "bug in test" )
st . fails ( ` ^stRevertTest/RevertPrecompiledTouch\.json/EIP158 ` , "bug in test" )
st . fails ( ` ^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158 ` , "bug in test" )
2017-08-16 07:12:46 -07:00
st . fails ( ` ^stRevertTest/RevertDepthCreateAddressCollision\.json/Byzantium/[67] ` , "bug in test" )
st . fails ( ` ^stRevertTest/RevertPrecompiledTouch\.json/Byzantium ` , "bug in test" )
st . fails ( ` ^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium ` , "bug in test" )
2017-07-11 04:49:14 -07:00
2017-06-28 11:28:24 -07:00
// Skip invalid receipt root hash / invalid nonce quorum failures
st . skipLoad ( ` (StoreClearsAndInternlCallStoreClearsOOG|TransactionSendingToZero|SuicidesAndInternlCallSuicidesOOG|SuicidesAndInternlCallSuicidesSuccess|SuicidesAndInternlCallSuicidesBonusGasAtCallFailed|SuicidesAndInternlCallSuicidesBonusGasAtCall|StoreClearsAndInternlCallStoreClearsSuccess|InternlCallStoreClearsSucces|InternlCallStoreClearsOOG|failed_tx_xcf416c53|CallContractToCreateContractOOG)\.json ` ) // EIP-86 is not supported yet
2017-07-11 04:49:14 -07: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 ) {
2017-08-22 04:03:14 -07:00
if subtest . Fork == "Constantinople" {
t . Skip ( "constantinople not supported yet" )
2017-07-11 04:49:14 -07:00
}
withTrace ( t , test . gasLimit ( subtest ) , func ( vmconfig vm . Config ) error {
return st . checkFailure ( t , name , test . Run ( subtest , vmconfig ) )
} )
} )
2015-06-10 13:10:33 -07:00
}
2017-07-11 04:49:14 -07:00
} )
2016-10-31 03:32:05 -07:00
}
2017-07-11 04:49:14 -07:00
// Transactions with gasLimit above this value will not get a VM trace on failure.
const traceErrorLimit = 400000
2016-10-31 03:32:05 -07:00
2017-07-11 04:49:14 -07:00
func withTrace ( t * testing . T , gasLimit uint64 , test func ( vm . Config ) error ) {
err := test ( vm . Config { } )
if err == nil {
return
2016-10-31 03:32:05 -07:00
}
2017-07-11 04:49:14 -07:00
t . Error ( err )
if gasLimit > traceErrorLimit {
t . Log ( "gas limit too high for EVM trace" )
return
2016-10-31 03:32:05 -07:00
}
2017-07-11 04:49:14 -07:00
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 )
2016-10-31 03:32:05 -07:00
}
2017-07-11 04:49:14 -07:00
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 ( ) )
2016-10-31 03:32:05 -07:00
}
}