github.com/theQRL/go-zond@v0.1.1/params/config_test.go (about) 1 // Copyright 2017 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 params 18 19 import ( 20 "math/big" 21 "reflect" 22 "testing" 23 "time" 24 25 "github.com/theQRL/go-zond/common/math" 26 ) 27 28 func TestCheckCompatible(t *testing.T) { 29 type test struct { 30 stored, new *ChainConfig 31 headBlock uint64 32 headTimestamp uint64 33 wantErr *ConfigCompatError 34 } 35 tests := []test{ 36 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, headBlock: 0, headTimestamp: 0, wantErr: nil}, 37 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, headBlock: 0, headTimestamp: uint64(time.Now().Unix()), wantErr: nil}, 38 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, headBlock: 100, wantErr: nil}, 39 { 40 stored: &ChainConfig{EIP150Block: big.NewInt(10)}, 41 new: &ChainConfig{EIP150Block: big.NewInt(20)}, 42 headBlock: 9, 43 wantErr: nil, 44 }, 45 { 46 stored: AllEthashProtocolChanges, 47 new: &ChainConfig{HomesteadBlock: nil}, 48 headBlock: 3, 49 wantErr: &ConfigCompatError{ 50 What: "Homestead fork block", 51 StoredBlock: big.NewInt(0), 52 NewBlock: nil, 53 RewindToBlock: 0, 54 }, 55 }, 56 { 57 stored: AllEthashProtocolChanges, 58 new: &ChainConfig{HomesteadBlock: big.NewInt(1)}, 59 headBlock: 3, 60 wantErr: &ConfigCompatError{ 61 What: "Homestead fork block", 62 StoredBlock: big.NewInt(0), 63 NewBlock: big.NewInt(1), 64 RewindToBlock: 0, 65 }, 66 }, 67 { 68 stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)}, 69 new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)}, 70 headBlock: 25, 71 wantErr: &ConfigCompatError{ 72 What: "EIP150 fork block", 73 StoredBlock: big.NewInt(10), 74 NewBlock: big.NewInt(20), 75 RewindToBlock: 9, 76 }, 77 }, 78 { 79 stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)}, 80 new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)}, 81 headBlock: 40, 82 wantErr: nil, 83 }, 84 { 85 stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)}, 86 new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)}, 87 headBlock: 40, 88 wantErr: &ConfigCompatError{ 89 What: "Petersburg fork block", 90 StoredBlock: nil, 91 NewBlock: big.NewInt(31), 92 RewindToBlock: 30, 93 }, 94 }, 95 { 96 stored: &ChainConfig{ShanghaiTime: newUint64(10)}, 97 new: &ChainConfig{ShanghaiTime: newUint64(20)}, 98 headTimestamp: 9, 99 wantErr: nil, 100 }, 101 { 102 stored: &ChainConfig{ShanghaiTime: newUint64(10)}, 103 new: &ChainConfig{ShanghaiTime: newUint64(20)}, 104 headTimestamp: 25, 105 wantErr: &ConfigCompatError{ 106 What: "Shanghai fork timestamp", 107 StoredTime: newUint64(10), 108 NewTime: newUint64(20), 109 RewindToTime: 9, 110 }, 111 }, 112 } 113 114 for _, test := range tests { 115 err := test.stored.CheckCompatible(test.new, test.headBlock, test.headTimestamp) 116 if !reflect.DeepEqual(err, test.wantErr) { 117 t.Errorf("error mismatch:\nstored: %v\nnew: %v\nheadBlock: %v\nheadTimestamp: %v\nerr: %v\nwant: %v", test.stored, test.new, test.headBlock, test.headTimestamp, err, test.wantErr) 118 } 119 } 120 } 121 122 func TestConfigRules(t *testing.T) { 123 c := &ChainConfig{ 124 LondonBlock: new(big.Int), 125 ShanghaiTime: newUint64(500), 126 } 127 var stamp uint64 128 if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai { 129 t.Errorf("expected %v to not be shanghai", stamp) 130 } 131 stamp = 500 132 if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai { 133 t.Errorf("expected %v to be shanghai", stamp) 134 } 135 stamp = math.MaxInt64 136 if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai { 137 t.Errorf("expected %v to be shanghai", stamp) 138 } 139 }