github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/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/big" 21 mrand "math/rand" 22 "os" 23 "path/filepath" 24 "testing" 25 26 "github.com/ethereumproject/go-ethereum/logger/glog" 27 ) 28 29 func init() { 30 glog.SetD(0) 31 glog.SetV(0) 32 } 33 34 func TestBcValidBlockTests(t *testing.T) { 35 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcValidBlockTest.json"), BlockSkipTests) 36 if err != nil { 37 t.Fatal(err) 38 } 39 } 40 41 func TestBcUncleHeaderValidityTests(t *testing.T) { 42 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), BlockSkipTests) 43 if err != nil { 44 t.Fatal(err) 45 } 46 } 47 48 func TestBcUncleTests(t *testing.T) { 49 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcUncleTest.json"), BlockSkipTests) 50 if err != nil { 51 t.Fatal(err) 52 } 53 } 54 55 func TestBcForkUncleTests(t *testing.T) { 56 // This test case depends on code that is non-deterministic by purpose - it's a protection against 57 // selfish miners. By seeding random number generator here, just before test, with constant seed, 58 // we ensure that correct path is selected - randomised chain reorganization action is not executed. 59 // This enable to deterministically test non-deterministic code. 60 mrand.Seed(123) 61 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcForkUncle.json"), BlockSkipTests) 62 if err != nil { 63 t.Fatal(err) 64 } 65 } 66 67 func TestBcInvalidHeaderTests(t *testing.T) { 68 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), BlockSkipTests) 69 if err != nil { 70 t.Fatal(err) 71 } 72 } 73 74 func TestBcInvalidRLPTests(t *testing.T) { 75 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), BlockSkipTests) 76 if err != nil { 77 t.Fatal(err) 78 } 79 } 80 81 func TestBcRPCAPITests(t *testing.T) { 82 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcRPC_API_Test.json"), BlockSkipTests) 83 if err != nil { 84 t.Fatal(err) 85 } 86 } 87 88 func TestBcForkBlockTests(t *testing.T) { 89 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcForkBlockTest.json"), BlockSkipTests) 90 if err != nil { 91 t.Fatal(err) 92 } 93 } 94 95 func TestBcForkStress(t *testing.T) { 96 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcForkStressTest.json"), BlockSkipTests) 97 if err != nil { 98 t.Fatal(err) 99 } 100 } 101 102 func TestBcTotalDifficulty(t *testing.T) { 103 // skip because these will fail due to selfish mining fix 104 t.Skip() 105 106 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), BlockSkipTests) 107 if err != nil { 108 t.Fatal(err) 109 } 110 } 111 112 func TestBcWallet(t *testing.T) { 113 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcWalletTest.json"), BlockSkipTests) 114 if err != nil { 115 t.Fatal(err) 116 } 117 } 118 119 func TestBcGasPricer(t *testing.T) { 120 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcGasPricerTest.json"), BlockSkipTests) 121 if err != nil { 122 t.Fatal(err) 123 } 124 } 125 126 // TODO: iterate over files once we got more than a few 127 func TestBcRandom(t *testing.T) { 128 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "RandomTests/bl201507071825GO.json"), BlockSkipTests) 129 if err != nil { 130 t.Fatal(err) 131 } 132 } 133 134 func TestBcMultiChain(t *testing.T) { 135 // skip due to selfish mining 136 t.Skip() 137 138 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcMultiChainTest.json"), BlockSkipTests) 139 if err != nil { 140 t.Fatal(err) 141 } 142 } 143 144 func TestBcState(t *testing.T) { 145 err := RunBlockTest(big.NewInt(1000000), big.NewInt(100000), filepath.Join(blockTestDir, "bcStateTest.json"), BlockSkipTests) 146 if err != nil { 147 t.Fatal(err) 148 } 149 } 150 151 // Homestead tests 152 func TestHomesteadBcValidBlockTests(t *testing.T) { 153 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcValidBlockTest.json"), BlockSkipTests) 154 if err != nil { 155 t.Fatal(err) 156 } 157 } 158 159 func TestHomesteadBcUncleHeaderValidityTests(t *testing.T) { 160 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcUncleHeaderValiditiy.json"), BlockSkipTests) 161 if err != nil { 162 t.Fatal(err) 163 } 164 } 165 166 func TestHomesteadBcUncleTests(t *testing.T) { 167 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcUncleTest.json"), BlockSkipTests) 168 if err != nil { 169 t.Fatal(err) 170 } 171 } 172 173 func TestHomesteadBcInvalidHeaderTests(t *testing.T) { 174 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcInvalidHeaderTest.json"), BlockSkipTests) 175 if err != nil { 176 t.Fatal(err) 177 } 178 } 179 180 func TestHomesteadBcRPCAPITests(t *testing.T) { 181 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcRPC_API_Test.json"), BlockSkipTests) 182 if err != nil { 183 t.Fatal(err) 184 } 185 } 186 187 func TestHomesteadBcForkStress(t *testing.T) { 188 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcForkStressTest.json"), BlockSkipTests) 189 if err != nil { 190 t.Fatal(err) 191 } 192 } 193 194 func TestHomesteadBcTotalDifficulty(t *testing.T) { 195 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcTotalDifficultyTest.json"), BlockSkipTests) 196 if err != nil { 197 t.Fatal(err) 198 } 199 } 200 201 func TestHomesteadBcWallet(t *testing.T) { 202 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcWalletTest.json"), BlockSkipTests) 203 if err != nil { 204 t.Fatal(err) 205 } 206 } 207 208 func TestHomesteadBcGasPricer(t *testing.T) { 209 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcGasPricerTest.json"), BlockSkipTests) 210 if err != nil { 211 t.Fatal(err) 212 } 213 } 214 215 func TestHomesteadBcMultiChain(t *testing.T) { 216 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcMultiChainTest.json"), BlockSkipTests) 217 if err != nil { 218 t.Fatal(err) 219 } 220 } 221 222 func TestHomesteadBcState(t *testing.T) { 223 err := RunBlockTest(big.NewInt(0), big.NewInt(100000), filepath.Join(blockTestDir, "Homestead", "bcStateTest.json"), BlockSkipTests) 224 if err != nil { 225 t.Fatal(err) 226 } 227 } 228 229 func TestEIP150Bc(t *testing.T) { 230 if _, err := os.Stat(filepath.Join(blockTestDir, "TestNetwork", "bcEIP150Test.json")); os.IsNotExist(err) { 231 t.Skip("skipping test, need bcEIP150Test.json file") 232 } 233 err := RunBlockTest(big.NewInt(0), big.NewInt(10), filepath.Join(blockTestDir, "TestNetwork", "bcEIP150Test.json"), BlockSkipTests) 234 if err != nil { 235 t.Fatal(err) 236 } 237 }