github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/params/config_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:42</date> 10 //</624450107621773312> 11 12 13 package params 14 15 import ( 16 "math/big" 17 "reflect" 18 "testing" 19 ) 20 21 func TestCheckCompatible(t *testing.T) { 22 type test struct { 23 stored, new *ChainConfig 24 head uint64 25 wantErr *ConfigCompatError 26 } 27 tests := []test{ 28 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil}, 29 {stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil}, 30 { 31 stored: &ChainConfig{EIP150Block: big.NewInt(10)}, 32 new: &ChainConfig{EIP150Block: big.NewInt(20)}, 33 head: 9, 34 wantErr: nil, 35 }, 36 { 37 stored: AllEthashProtocolChanges, 38 new: &ChainConfig{HomesteadBlock: nil}, 39 head: 3, 40 wantErr: &ConfigCompatError{ 41 What: "Homestead fork block", 42 StoredConfig: big.NewInt(0), 43 NewConfig: nil, 44 RewindTo: 0, 45 }, 46 }, 47 { 48 stored: AllEthashProtocolChanges, 49 new: &ChainConfig{HomesteadBlock: big.NewInt(1)}, 50 head: 3, 51 wantErr: &ConfigCompatError{ 52 What: "Homestead fork block", 53 StoredConfig: big.NewInt(0), 54 NewConfig: big.NewInt(1), 55 RewindTo: 0, 56 }, 57 }, 58 { 59 stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)}, 60 new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)}, 61 head: 25, 62 wantErr: &ConfigCompatError{ 63 What: "EIP150 fork block", 64 StoredConfig: big.NewInt(10), 65 NewConfig: big.NewInt(20), 66 RewindTo: 9, 67 }, 68 }, 69 } 70 71 for _, test := range tests { 72 err := test.stored.CheckCompatible(test.new, test.head) 73 if !reflect.DeepEqual(err, test.wantErr) { 74 t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr) 75 } 76 } 77 } 78