github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/params/config_test.go (about)

     1  package params
     2  
     3  import (
     4  	"math/big"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestCheckCompatible(t *testing.T) {
    10  	type test struct {
    11  		stored, new *ChainConfig
    12  		head        uint64
    13  		wantErr     *ConfigCompatError
    14  	}
    15  	tests := []test{
    16  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil},
    17  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil},
    18  		{
    19  			stored:  &ChainConfig{EIP150Block: big.NewInt(10)},
    20  			new:     &ChainConfig{EIP150Block: big.NewInt(20)},
    21  			head:    9,
    22  			wantErr: nil,
    23  		},
    24  		{
    25  			stored: AllEthashProtocolChanges,
    26  			new:    &ChainConfig{HomesteadBlock: nil},
    27  			head:   3,
    28  			wantErr: &ConfigCompatError{
    29  				What:         "Homestead fork block",
    30  				StoredConfig: big.NewInt(0),
    31  				NewConfig:    nil,
    32  				RewindTo:     0,
    33  			},
    34  		},
    35  		{
    36  			stored: AllEthashProtocolChanges,
    37  			new:    &ChainConfig{HomesteadBlock: big.NewInt(1)},
    38  			head:   3,
    39  			wantErr: &ConfigCompatError{
    40  				What:         "Homestead fork block",
    41  				StoredConfig: big.NewInt(0),
    42  				NewConfig:    big.NewInt(1),
    43  				RewindTo:     0,
    44  			},
    45  		},
    46  		{
    47  			stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
    48  			new:    &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
    49  			head:   25,
    50  			wantErr: &ConfigCompatError{
    51  				What:         "EIP150 fork block",
    52  				StoredConfig: big.NewInt(10),
    53  				NewConfig:    big.NewInt(20),
    54  				RewindTo:     9,
    55  			},
    56  		},
    57  	}
    58  
    59  	for _, test := range tests {
    60  		err := test.stored.CheckCompatible(test.new, test.head)
    61  		if !reflect.DeepEqual(err, test.wantErr) {
    62  			t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
    63  		}
    64  	}
    65  }