github.com/MetalBlockchain/subnet-evm@v0.4.9/params/config_test.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc.
     2  //
     3  // This file is a derived work, based on the go-ethereum library whose original
     4  // notices appear below.
     5  //
     6  // It is distributed under a license compatible with the licensing terms of the
     7  // original code from which it is derived.
     8  //
     9  // Much love to the original authors for their work.
    10  // **********
    11  // Copyright 2017 The go-ethereum Authors
    12  // This file is part of the go-ethereum library.
    13  //
    14  // The go-ethereum library is free software: you can redistribute it and/or modify
    15  // it under the terms of the GNU Lesser General Public License as published by
    16  // the Free Software Foundation, either version 3 of the License, or
    17  // (at your option) any later version.
    18  //
    19  // The go-ethereum library is distributed in the hope that it will be useful,
    20  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    21  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    22  // GNU Lesser General Public License for more details.
    23  //
    24  // You should have received a copy of the GNU Lesser General Public License
    25  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    26  
    27  package params
    28  
    29  import (
    30  	"math/big"
    31  	"reflect"
    32  	"testing"
    33  )
    34  
    35  func TestCheckCompatible(t *testing.T) {
    36  	type test struct {
    37  		stored, new                 *ChainConfig
    38  		blockHeight, blockTimestamp uint64
    39  		wantErr                     *ConfigCompatError
    40  	}
    41  	tests := []test{
    42  		{stored: TestChainConfig, new: TestChainConfig, blockHeight: 0, blockTimestamp: 0, wantErr: nil},
    43  		{stored: TestChainConfig, new: TestChainConfig, blockHeight: 100, blockTimestamp: 1000, wantErr: nil},
    44  		{
    45  			stored:         &ChainConfig{EIP150Block: big.NewInt(10)},
    46  			new:            &ChainConfig{EIP150Block: big.NewInt(20)},
    47  			blockHeight:    9,
    48  			blockTimestamp: 90,
    49  			wantErr:        nil,
    50  		},
    51  		{
    52  			stored:         TestChainConfig,
    53  			new:            &ChainConfig{HomesteadBlock: nil},
    54  			blockHeight:    3,
    55  			blockTimestamp: 30,
    56  			wantErr: &ConfigCompatError{
    57  				What:         "Homestead fork block",
    58  				StoredConfig: big.NewInt(0),
    59  				NewConfig:    nil,
    60  				RewindTo:     0,
    61  			},
    62  		},
    63  		{
    64  			stored:         TestChainConfig,
    65  			new:            &ChainConfig{HomesteadBlock: big.NewInt(1)},
    66  			blockHeight:    3,
    67  			blockTimestamp: 30,
    68  			wantErr: &ConfigCompatError{
    69  				What:         "Homestead fork block",
    70  				StoredConfig: big.NewInt(0),
    71  				NewConfig:    big.NewInt(1),
    72  				RewindTo:     0,
    73  			},
    74  		},
    75  		{
    76  			stored:         &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
    77  			new:            &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
    78  			blockHeight:    25,
    79  			blockTimestamp: 250,
    80  			wantErr: &ConfigCompatError{
    81  				What:         "EIP150 fork block",
    82  				StoredConfig: big.NewInt(10),
    83  				NewConfig:    big.NewInt(20),
    84  				RewindTo:     9,
    85  			},
    86  		},
    87  		{
    88  			stored:         &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
    89  			new:            &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)},
    90  			blockHeight:    40,
    91  			blockTimestamp: 400,
    92  			wantErr:        nil,
    93  		},
    94  		{
    95  			stored:         &ChainConfig{ConstantinopleBlock: big.NewInt(30)},
    96  			new:            &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)},
    97  			blockHeight:    40,
    98  			blockTimestamp: 400,
    99  			wantErr: &ConfigCompatError{
   100  				What:         "Petersburg fork block",
   101  				StoredConfig: nil,
   102  				NewConfig:    big.NewInt(31),
   103  				RewindTo:     30,
   104  			},
   105  		},
   106  		{
   107  			stored:         TestChainConfig,
   108  			new:            TestPreSubnetEVMConfig,
   109  			blockHeight:    0,
   110  			blockTimestamp: 0,
   111  			wantErr: &ConfigCompatError{
   112  				What:         "SubnetEVM fork block timestamp",
   113  				StoredConfig: big.NewInt(0),
   114  				NewConfig:    nil,
   115  				RewindTo:     0,
   116  			},
   117  		},
   118  		{
   119  			stored:         TestChainConfig,
   120  			new:            TestPreSubnetEVMConfig,
   121  			blockHeight:    10,
   122  			blockTimestamp: 100,
   123  			wantErr: &ConfigCompatError{
   124  				What:         "SubnetEVM fork block timestamp",
   125  				StoredConfig: big.NewInt(0),
   126  				NewConfig:    nil,
   127  				RewindTo:     0,
   128  			},
   129  		},
   130  	}
   131  
   132  	for _, test := range tests {
   133  		err := test.stored.CheckCompatible(test.new, test.blockHeight, test.blockTimestamp)
   134  		if !reflect.DeepEqual(err, test.wantErr) {
   135  			t.Errorf("error mismatch:\nstored: %v\nnew: %v\nblockHeight: %v\nerr: %v\nwant: %v", test.stored, test.new, test.blockHeight, err, test.wantErr)
   136  		}
   137  	}
   138  }