github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/params/config_test.go (about) 1 // This file is part of the go-sberex library. The go-sberex library is 2 // free software: you can redistribute it and/or modify it under the terms 3 // of the GNU Lesser General Public License as published by the Free 4 // Software Foundation, either version 3 of the License, or (at your option) 5 // any later version. 6 // 7 // The go-sberex library is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 10 // General Public License <http://www.gnu.org/licenses/> for more details. 11 12 package params 13 14 import ( 15 "math/big" 16 "reflect" 17 "testing" 18 ) 19 20 func TestCheckCompatible(t *testing.T) { 21 type test struct { 22 stored, new *ChainConfig 23 head uint64 24 wantErr *ConfigCompatError 25 } 26 tests := []test{ 27 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil}, 28 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil}, 29 { 30 stored: &ChainConfig{EIP150Block: big.NewInt(10)}, 31 new: &ChainConfig{EIP150Block: big.NewInt(20)}, 32 head: 9, 33 wantErr: nil, 34 }, 35 { 36 stored: AllEthashProtocolChanges, 37 new: &ChainConfig{HomesteadBlock: nil}, 38 head: 3, 39 wantErr: &ConfigCompatError{ 40 What: "Homestead fork block", 41 StoredConfig: big.NewInt(0), 42 NewConfig: nil, 43 RewindTo: 0, 44 }, 45 }, 46 { 47 stored: AllEthashProtocolChanges, 48 new: &ChainConfig{HomesteadBlock: big.NewInt(1)}, 49 head: 3, 50 wantErr: &ConfigCompatError{ 51 What: "Homestead fork block", 52 StoredConfig: big.NewInt(0), 53 NewConfig: big.NewInt(1), 54 RewindTo: 0, 55 }, 56 }, 57 { 58 stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)}, 59 new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)}, 60 head: 25, 61 wantErr: &ConfigCompatError{ 62 What: "EIP150 fork block", 63 StoredConfig: big.NewInt(10), 64 NewConfig: big.NewInt(20), 65 RewindTo: 9, 66 }, 67 }, 68 } 69 70 for _, test := range tests { 71 err := test.stored.CheckCompatible(test.new, test.head) 72 if !reflect.DeepEqual(err, test.wantErr) { 73 t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr) 74 } 75 } 76 }