github.com/ethereumproject/go-ethereum@v5.5.2+incompatible/core/defaults_test.go (about) 1 package core 2 3 import ( 4 "math/big" 5 "testing" 6 ) 7 8 // Implement chain config defaults tests, ensure all existing 9 // features are correctly in place (as to not break backwards compatibility). 10 // New chain configurations should be accompanied by relevant associated tests. 11 // Tests are designed to ensure that compiled JSON default configs 12 // are up-to-date and accurate. 13 14 func TestDefaultChainConfigurationVariablesExist(t *testing.T) { 15 16 if DefaultConfigMainnet.Identity != "mainnet" { 17 t.Errorf("got: %v, want: %v", DefaultConfigMainnet.Identity, "mainnet") 18 } 19 if DefaultConfigMorden.Identity != "morden" { 20 t.Errorf("got: %v, want: %v", DefaultConfigMorden.Identity, "mainnet") 21 } 22 23 if DefaultConfigMainnet.Name != "Ethereum Classic Mainnet" { 24 t.Errorf("got: %v, want: %v", DefaultConfigMainnet.Name, "Ethereum Classic Mainnet") 25 } 26 if DefaultConfigMorden.Name != "Morden Testnet" { 27 t.Errorf("got: %v, want: %v", DefaultConfigMorden.Name, "Morden Testnet") 28 } 29 30 if DefaultConfigMainnet.ChainConfig.GetChainID().Cmp(big.NewInt(61)) != 0 { 31 t.Errorf("got: %v, want: %v", DefaultConfigMainnet.ChainConfig.GetChainID(), big.NewInt(61)) 32 } 33 if DefaultConfigMorden.ChainConfig.GetChainID().Cmp(big.NewInt(62)) != 0 { 34 t.Errorf("got: %v, want: %v", DefaultConfigMorden.ChainConfig.GetChainID(), big.NewInt(62)) 35 } 36 37 // Test forks existence and block numbers 38 // Homestead 39 if fork := DefaultConfigMainnet.ChainConfig.ForkByName("Homestead"); fork.Block.Cmp(big.NewInt(1150000)) != 0 { 40 t.Errorf("Unexpected fork: %v", fork) 41 } 42 if fork := DefaultConfigMorden.ChainConfig.ForkByName("Homestead"); fork.Block.Cmp(big.NewInt(494000)) != 0 { 43 t.Errorf("Unexpected fork: %v", fork) 44 } 45 // The DAO Hard Fork 46 if fork := DefaultConfigMainnet.ChainConfig.ForkByName("The DAO Hard Fork"); fork.Block.Cmp(big.NewInt(1920000)) != 0 { 47 t.Errorf("Unexpected fork: %v", fork) 48 } 49 if fork := DefaultConfigMorden.ChainConfig.ForkByName("The DAO Hard Fork"); fork.Block.Cmp(big.NewInt(1885000)) != 0 { 50 t.Errorf("Unexpected fork: %v", fork) 51 } 52 // GasReprice 53 if fork := DefaultConfigMainnet.ChainConfig.ForkByName("GasReprice"); fork.Block.Cmp(big.NewInt(2500000)) != 0 { 54 t.Errorf("Unexpected fork: %v", fork) 55 } 56 if fork := DefaultConfigMorden.ChainConfig.ForkByName("GasReprice"); fork.Block.Cmp(big.NewInt(1783000)) != 0 { 57 t.Errorf("Unexpected fork: %v", fork) 58 } 59 // Diehard 60 if fork := DefaultConfigMainnet.ChainConfig.ForkByName("Diehard"); fork.Block.Cmp(big.NewInt(3000000)) != 0 { 61 t.Errorf("Unexpected fork: %v", fork) 62 } 63 if fork := DefaultConfigMorden.ChainConfig.ForkByName("Diehard"); fork.Block.Cmp(big.NewInt(1915000)) != 0 { 64 t.Errorf("Unexpected fork: %v", fork) 65 } 66 // Gotham 67 if fork := DefaultConfigMainnet.ChainConfig.ForkByName("Gotham"); fork.Block.Cmp(big.NewInt(5000000)) != 0 { 68 t.Errorf("Unexpected fork: %v", fork) 69 } 70 if fork := DefaultConfigMorden.ChainConfig.ForkByName("Gotham"); fork.Block.Cmp(big.NewInt(2000000)) != 0 { 71 t.Errorf("Unexpected fork: %v", fork) 72 } 73 74 checks := []struct { 75 Config *SufficientChainConfig 76 Block *big.Int 77 Name string 78 Features []*ForkFeature 79 }{ 80 { 81 Config: DefaultConfigMorden, 82 Block: big.NewInt(494000), 83 Name: "Homestead", 84 Features: []*ForkFeature{ 85 { 86 ID: "difficulty", 87 Options: ChainFeatureConfigOptions{ 88 "type": "homestead", 89 }, 90 }, 91 { 92 ID: "gastable", 93 Options: ChainFeatureConfigOptions{ 94 "type": "homestead", 95 }, 96 }, 97 }, 98 }, 99 { 100 Config: DefaultConfigMainnet, 101 Block: big.NewInt(1150000), 102 Name: "Homestead", 103 Features: []*ForkFeature{ 104 { 105 ID: "difficulty", 106 Options: ChainFeatureConfigOptions{ 107 "type": "homestead", 108 }, 109 }, 110 { 111 ID: "gastable", 112 Options: ChainFeatureConfigOptions{ 113 "type": "homestead", 114 }, 115 }, 116 }, 117 }, 118 { 119 Config: DefaultConfigMorden, 120 Block: big.NewInt(1885000), 121 Name: "The DAO Hard Fork", 122 }, 123 { 124 Config: DefaultConfigMainnet, 125 Block: big.NewInt(1920000), 126 Name: "The DAO Hard Fork", 127 }, 128 { 129 Config: DefaultConfigMorden, 130 Block: big.NewInt(1783000), 131 Name: "GasReprice", 132 Features: []*ForkFeature{ 133 { 134 ID: "gastable", 135 Options: ChainFeatureConfigOptions{ 136 "type": "eip150", 137 }, 138 }, 139 }, 140 }, 141 { 142 Config: DefaultConfigMainnet, 143 Block: big.NewInt(2500000), 144 Name: "GasReprice", 145 Features: []*ForkFeature{ 146 { 147 ID: "gastable", 148 Options: ChainFeatureConfigOptions{ 149 "type": "eip150", 150 }, 151 }, 152 }, 153 }, 154 { 155 Config: DefaultConfigMorden, 156 Block: big.NewInt(1915000), 157 Name: "Diehard", 158 Features: []*ForkFeature{ 159 { 160 ID: "gastable", 161 Options: ChainFeatureConfigOptions{ 162 "type": "eip160", 163 }, 164 }, 165 { 166 ID: "eip155", 167 Options: ChainFeatureConfigOptions{ 168 "chainID": big.NewInt(62), 169 }, 170 }, 171 { 172 ID: "difficulty", 173 Options: ChainFeatureConfigOptions{ 174 "length": big.NewInt(2000000), 175 "type": "ecip1010", 176 }, 177 }, 178 }, 179 }, 180 { 181 Config: DefaultConfigMainnet, 182 Block: big.NewInt(3000000), 183 Name: "Diehard", 184 Features: []*ForkFeature{ 185 { 186 ID: "gastable", 187 Options: ChainFeatureConfigOptions{ 188 "type": "eip160", 189 }, 190 }, 191 { 192 ID: "eip155", 193 Options: ChainFeatureConfigOptions{ 194 "chainID": big.NewInt(61), 195 }, 196 }, 197 { 198 ID: "difficulty", 199 Options: ChainFeatureConfigOptions{ 200 "length": big.NewInt(2000000), 201 "type": "ecip1010", 202 }, 203 }, 204 }, 205 }, 206 { 207 Config: DefaultConfigMorden, 208 Block: big.NewInt(2000000), 209 Name: "Gotham", 210 Features: []*ForkFeature{ 211 { 212 ID: "reward", 213 Options: ChainFeatureConfigOptions{ 214 "era": big.NewInt(2000000), 215 "type": "ecip1017", 216 }, 217 }, 218 }, 219 }, 220 { 221 Config: DefaultConfigMainnet, 222 Block: big.NewInt(5000000), 223 Name: "Gotham", 224 Features: []*ForkFeature{ 225 { 226 ID: "reward", 227 Options: ChainFeatureConfigOptions{ 228 "era": big.NewInt(5000000), 229 "type": "ecip1017", 230 }, 231 }, 232 }, 233 }, 234 } 235 for _, check := range checks { 236 // Ensure fork exists at correct block 237 if fork := check.Config.ChainConfig.ForkByName(check.Name); fork.Block.Cmp(check.Block) != 0 { 238 t.Errorf("got: %v, want: %v", fork.Block, check.Block) 239 } 240 for _, feat := range check.Features { 241 ff, f, ok := check.Config.ChainConfig.GetFeature(check.Block, feat.ID) 242 if !ok { 243 t.Errorf("unfound fork feat: %s", feat.ID) 244 } 245 for k, v := range ff.Options { 246 switch v.(type) { 247 case *big.Int: 248 if big.NewInt(feat.Options[k].(int64)).Cmp(big.NewInt(v.(int64))) != 0 { 249 t.Errorf("mismatch for feature options: got: %v/%v, want: %v/%v", k, feat.Options[k], k, v) 250 } 251 case string: 252 if feat.Options[k] != v { 253 t.Errorf("mismatch for feature options: got: %v/%v, want: %v/%v", k, feat.Options[k], k, v) 254 } 255 } 256 257 } 258 if f.Block.Cmp(check.Block) != 0 { 259 t.Errorf("feature fork block wrong: got: %v, want: %v", f.Block, check.Block) 260 } 261 } 262 } 263 264 // Number of bootstrap nodes 265 if l := len(DefaultConfigMainnet.ParsedBootstrap); l != 10 { 266 t.Errorf("got: %v, want: %v", l, 10) 267 } 268 if l := len(DefaultConfigMorden.ParsedBootstrap); l != 15 { 269 t.Errorf("got: %v, want: %v", l, 7) 270 } 271 272 // Config validity checks. 273 if s, ok := DefaultConfigMainnet.IsValid(); !ok { 274 t.Errorf("Unexpected invalid default chain config: %s", s) 275 } 276 if s, ok := DefaultConfigMorden.IsValid(); !ok { 277 t.Errorf("Unexpected invalid default chain config: %s", s) 278 } 279 280 }