gitlab.com/aquachain/aquachain@v1.17.16-rc3.0.20221018032414-e3ddf1e1c055/params/config_test.go (about)

     1  // Copyright 2018 The aquachain Authors
     2  // This file is part of the aquachain library.
     3  //
     4  // The aquachain 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 aquachain 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 aquachain 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: AllAquahashProtocolChanges, new: AllAquahashProtocolChanges, head: 0, wantErr: nil},
    33  		{stored: AllAquahashProtocolChanges, new: AllAquahashProtocolChanges, head: 100, wantErr: nil},
    34  		{
    35  			stored: &ChainConfig{HF: ForkMap{1: big.NewInt(10)}},
    36  			new:    &ChainConfig{HF: ForkMap{1: big.NewInt(20)}},
    37  			head:   11,
    38  			wantErr: &ConfigCompatError{
    39  				What:         "Aquachain HF1 block",
    40  				StoredConfig: big.NewInt(10),
    41  				NewConfig:    big.NewInt(20),
    42  				RewindTo:     9,
    43  			},
    44  		},
    45  		{
    46  			stored:  &ChainConfig{EIP150Block: big.NewInt(10)},
    47  			new:     &ChainConfig{EIP150Block: big.NewInt(20)},
    48  			head:    9,
    49  			wantErr: nil,
    50  		},
    51  		{
    52  			stored: AllAquahashProtocolChanges,
    53  			new:    &ChainConfig{HomesteadBlock: nil},
    54  			head:   3,
    55  			wantErr: &ConfigCompatError{
    56  				What:         "Homestead fork block",
    57  				StoredConfig: big.NewInt(0),
    58  				NewConfig:    nil,
    59  				RewindTo:     0,
    60  			},
    61  		},
    62  		{
    63  			stored: AllAquahashProtocolChanges,
    64  			new:    &ChainConfig{HomesteadBlock: big.NewInt(1)},
    65  			head:   3,
    66  			wantErr: &ConfigCompatError{
    67  				What:         "Homestead fork block",
    68  				StoredConfig: big.NewInt(0),
    69  				NewConfig:    big.NewInt(1),
    70  				RewindTo:     0,
    71  			},
    72  		},
    73  		{
    74  			stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
    75  			new:    &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
    76  			head:   25,
    77  			wantErr: &ConfigCompatError{
    78  				What:         "EIP150 fork block",
    79  				StoredConfig: big.NewInt(10),
    80  				NewConfig:    big.NewInt(20),
    81  				RewindTo:     9,
    82  			},
    83  		},
    84  	}
    85  
    86  	for i, test := range tests {
    87  		err := test.stored.CheckCompatible(test.new, test.head)
    88  		if !reflect.DeepEqual(err, test.wantErr) {
    89  			t.Errorf("test #%v error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", i, test.stored, test.new, test.head, err, test.wantErr)
    90  		}
    91  	}
    92  }