github.com/SmartMeshFoundation/Spectrum@v0.0.0-20220621030607-452a266fee1e/params/config_test.go (about)

     1  // Copyright 2017 The Spectrum Authors
     2  // This file is part of the Spectrum library.
     3  //
     4  // The Spectrum 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 Spectrum 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 Spectrum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package params
    18  
    19  import (
    20  	"github.com/SmartMeshFoundation/Spectrum/common"
    21  	"math/big"
    22  	"reflect"
    23  	"testing"
    24  )
    25  
    26  func TestCheckCompatible(t *testing.T) {
    27  	type test struct {
    28  		stored, new *ChainConfig
    29  		head        uint64
    30  		wantErr     *ConfigCompatError
    31  	}
    32  	tests := []test{
    33  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 0, wantErr: nil},
    34  		{stored: AllEthashProtocolChanges, new: AllEthashProtocolChanges, head: 100, wantErr: nil},
    35  		{
    36  			stored:  &ChainConfig{EIP150Block: big.NewInt(10)},
    37  			new:     &ChainConfig{EIP150Block: big.NewInt(20)},
    38  			head:    9,
    39  			wantErr: nil,
    40  		},
    41  		{
    42  			stored: AllEthashProtocolChanges,
    43  			new:    &ChainConfig{HomesteadBlock: nil},
    44  			head:   3,
    45  			wantErr: &ConfigCompatError{
    46  				What:         "Homestead fork block",
    47  				StoredConfig: big.NewInt(0),
    48  				NewConfig:    nil,
    49  				RewindTo:     0,
    50  			},
    51  		},
    52  		{
    53  			stored: AllEthashProtocolChanges,
    54  			new:    &ChainConfig{HomesteadBlock: big.NewInt(1)},
    55  			head:   3,
    56  			wantErr: &ConfigCompatError{
    57  				What:         "Homestead fork block",
    58  				StoredConfig: big.NewInt(0),
    59  				NewConfig:    big.NewInt(1),
    60  				RewindTo:     0,
    61  			},
    62  		},
    63  		{
    64  			stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)},
    65  			new:    &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)},
    66  			head:   25,
    67  			wantErr: &ConfigCompatError{
    68  				What:         "EIP150 fork block",
    69  				StoredConfig: big.NewInt(10),
    70  				NewConfig:    big.NewInt(20),
    71  				RewindTo:     9,
    72  			},
    73  		},
    74  	}
    75  
    76  	for _, test := range tests {
    77  		err := test.stored.CheckCompatible(test.new, test.head)
    78  		if !reflect.DeepEqual(err, test.wantErr) {
    79  			t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
    80  		}
    81  	}
    82  }
    83  
    84  func TestHash(t *testing.T) {
    85  	h := common.Hash{}
    86  	t.Log(h == common.Hash{})
    87  
    88  }