github.com/ethereum/go-ethereum@v1.16.1/tests/block_test.go (about)

     1  // Copyright 2015 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  	"math/rand"
    21  	"testing"
    22  
    23  	"github.com/ethereum/go-ethereum/common"
    24  	"github.com/ethereum/go-ethereum/core/rawdb"
    25  )
    26  
    27  func TestBlockchain(t *testing.T) {
    28  	bt := new(testMatcher)
    29  
    30  	// We are running most of GeneralStatetests to tests witness support, even
    31  	// though they are ran as state tests too. Still, the performance tests are
    32  	// less about state andmore about EVM number crunching, so skip those.
    33  	bt.skipLoad(`^GeneralStateTests/VMTests/vmPerformance`)
    34  
    35  	// Skip random failures due to selfish mining test
    36  	bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`)
    37  
    38  	// Slow tests
    39  	bt.slow(`.*bcExploitTest/DelegateCallSpam.json`)
    40  	bt.slow(`.*bcExploitTest/ShanghaiLove.json`)
    41  	bt.slow(`.*bcExploitTest/SuicideIssue.json`)
    42  	bt.slow(`.*/bcForkStressTest/`)
    43  	bt.slow(`.*/bcGasPricerTest/RPC_API_Test.json`)
    44  	bt.slow(`.*/bcWalletTest/`)
    45  
    46  	// Very slow test
    47  	bt.skipLoad(`.*/stTimeConsuming/.*`)
    48  	// test takes a lot for time and goes easily OOM because of sha3 calculation on a huge range,
    49  	// using 4.6 TGas
    50  	bt.skipLoad(`.*randomStatetest94.json.*`)
    51  
    52  	// After the merge we would accept side chains as canonical even if they have lower td
    53  	bt.skipLoad(`.*bcMultiChainTest/ChainAtoChainB_difficultyB.json`)
    54  	bt.skipLoad(`.*bcMultiChainTest/CallContractFromNotBestBlock.json`)
    55  	bt.skipLoad(`.*bcTotalDifficultyTest/uncleBlockAtBlock3afterBlock4.json`)
    56  	bt.skipLoad(`.*bcTotalDifficultyTest/lotsOfBranchesOverrideAtTheMiddle.json`)
    57  	bt.skipLoad(`.*bcTotalDifficultyTest/sideChainWithMoreTransactions.json`)
    58  	bt.skipLoad(`.*bcForkStressTest/ForkStressTest.json`)
    59  	bt.skipLoad(`.*bcMultiChainTest/lotsOfLeafs.json`)
    60  	bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain.json`)
    61  	bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json`)
    62  
    63  	// With chain history removal, TDs become unavailable, this transition tests based on TTD are unrunnable
    64  	bt.skipLoad(`.*bcArrowGlacierToParis/powToPosBlockRejection.json`)
    65  
    66  	// This directory contains no test.
    67  	bt.skipLoad(`.*\.meta/.*`)
    68  
    69  	bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) {
    70  		execBlockTest(t, bt, test)
    71  	})
    72  	// There is also a LegacyTests folder, containing blockchain tests generated
    73  	// prior to Istanbul. However, they are all derived from GeneralStateTests,
    74  	// which run natively, so there's no reason to run them here.
    75  }
    76  
    77  // TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests.
    78  func TestExecutionSpecBlocktests(t *testing.T) {
    79  	if !common.FileExist(executionSpecBlockchainTestDir) {
    80  		t.Skipf("directory %s does not exist", executionSpecBlockchainTestDir)
    81  	}
    82  	bt := new(testMatcher)
    83  
    84  	bt.skipLoad(".*prague/eip7251_consolidations/contract_deployment/system_contract_deployment.json")
    85  	bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/contract_deployment/system_contract_deployment.json")
    86  
    87  	bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) {
    88  		execBlockTest(t, bt, test)
    89  	})
    90  }
    91  
    92  func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) {
    93  	// Define all the different flag combinations we should run the tests with,
    94  	// picking only one for short tests.
    95  	//
    96  	// Note, witness building and self-testing is always enabled as it's a very
    97  	// good test to ensure that we don't break it.
    98  	var (
    99  		snapshotConf = []bool{false, true}
   100  		dbschemeConf = []string{rawdb.HashScheme, rawdb.PathScheme}
   101  	)
   102  	if testing.Short() {
   103  		snapshotConf = []bool{snapshotConf[rand.Int()%2]}
   104  		dbschemeConf = []string{dbschemeConf[rand.Int()%2]}
   105  	}
   106  	for _, snapshot := range snapshotConf {
   107  		for _, dbscheme := range dbschemeConf {
   108  			if err := bt.checkFailure(t, test.Run(snapshot, dbscheme, true, nil, nil)); err != nil {
   109  				t.Errorf("test with config {snapshotter:%v, scheme:%v} failed: %v", snapshot, dbscheme, err)
   110  				return
   111  			}
   112  		}
   113  	}
   114  }