github.com/core-coin/go-core/v2@v2.1.9/params/config_test.go (about)

     1  // Copyright 2017 by the Authors
     2  // This file is part of the go-core library.
     3  //
     4  // The go-core 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-core 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-core 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: MainnetChainConfig, new: MainnetChainConfig, head: 0, wantErr: nil},
    33  		{stored: MainnetChainConfig, new: MainnetChainConfig, head: 100, wantErr: nil},
    34  		{
    35  			stored:  &ChainConfig{},
    36  			new:     &ChainConfig{},
    37  			head:    9,
    38  			wantErr: nil,
    39  		},
    40  		{
    41  			stored: &ChainConfig{EWASMBlock: big.NewInt(10)},
    42  			new:    &ChainConfig{EWASMBlock: big.NewInt(20)},
    43  			head:   25,
    44  			wantErr: &ConfigCompatError{
    45  				What:         "ewasm fork block",
    46  				StoredConfig: big.NewInt(10),
    47  				NewConfig:    big.NewInt(20),
    48  				RewindTo:     9,
    49  			},
    50  		},
    51  	}
    52  
    53  	for _, test := range tests {
    54  		err := test.stored.CheckCompatible(test.new, test.head)
    55  		if !reflect.DeepEqual(err, test.wantErr) {
    56  			t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
    57  		}
    58  	}
    59  }