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