github.com/luckypickle/go-ethereum-vet@v1.14.2/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  )
    24  
    25  func TestCheckCompatible(t *testing.T) {
    26  	type test struct {
    27  		stored, new *ChainConfig
    28  		head        uint64
    29  		wantErr     *ConfigCompatError
    30  	}
    31  	tests := []test{
    32  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil},
    33  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil},
    34  		{
    35  			stored:  &ChainConfig{EIP150Block: big.NewInt(10)},
    36  			new:     &ChainConfig{EIP150Block: big.NewInt(20)},
    37  			head:    9,
    38  			wantErr: nil,
    39  		},
    40  		{
    41  			stored: AllEthashProtocolChanges,
    42  			new:    &ChainConfig{HomesteadBlock: nil},
    43  			head:   3,
    44  			wantErr: &ConfigCompatError{
    45  				What:         "Homestead fork block",
    46  				StoredConfig: big.NewInt(0),
    47  				NewConfig:    nil,
    48  				RewindTo:     0,
    49  			},
    50  		},
    51  		{
    52  			stored: AllEthashProtocolChanges,
    53  			new:    &ChainConfig{HomesteadBlock: big.NewInt(1)},
    54  			head:   3,
    55  			wantErr: &ConfigCompatError{
    56  				What:         "Homestead fork block",
    57  				StoredConfig: big.NewInt(0),
    58  				NewConfig:    big.NewInt(1),
    59  				RewindTo:     0,
    60  			},
    61  		},
    62  		{
    63  			stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
    64  			new:    &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
    65  			head:   25,
    66  			wantErr: &ConfigCompatError{
    67  				What:         "EIP150 fork block",
    68  				StoredConfig: big.NewInt(10),
    69  				NewConfig:    big.NewInt(20),
    70  				RewindTo:     9,
    71  			},
    72  		},
    73  	}
    74  
    75  	for _, test := range tests {
    76  		err := test.stored.CheckCompatible(test.new, test.head)
    77  		if !reflect.DeepEqual(err, test.wantErr) {
    78  			t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
    79  		}
    80  	}
    81  }