2017-03-02 13:03:33 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package params
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2023-01-13 18:12:18 +00:00
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/chain"
|
2017-03-02 13:03:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCheckCompatible(t *testing.T) {
|
|
|
|
type test struct {
|
2023-01-13 18:12:18 +00:00
|
|
|
stored, new *chain.Config
|
2017-03-02 13:03:33 +00:00
|
|
|
head uint64
|
2023-01-13 18:12:18 +00:00
|
|
|
wantErr *chain.ConfigCompatError
|
2017-03-02 13:03:33 +00:00
|
|
|
}
|
|
|
|
tests := []test{
|
2022-11-21 16:21:59 +00:00
|
|
|
{stored: AllProtocolChanges, new: AllProtocolChanges, head: 0, wantErr: nil},
|
|
|
|
{stored: AllProtocolChanges, new: AllProtocolChanges, head: 100, wantErr: nil},
|
2017-03-02 13:03:33 +00:00
|
|
|
{
|
2023-01-13 18:12:18 +00:00
|
|
|
stored: &chain.Config{TangerineWhistleBlock: big.NewInt(10)},
|
|
|
|
new: &chain.Config{TangerineWhistleBlock: big.NewInt(20)},
|
2017-03-02 13:03:33 +00:00
|
|
|
head: 9,
|
|
|
|
wantErr: nil,
|
|
|
|
},
|
|
|
|
{
|
2022-11-21 16:21:59 +00:00
|
|
|
stored: AllProtocolChanges,
|
2023-01-13 18:12:18 +00:00
|
|
|
new: &chain.Config{HomesteadBlock: nil},
|
2017-03-02 13:03:33 +00:00
|
|
|
head: 3,
|
2023-01-13 18:12:18 +00:00
|
|
|
wantErr: &chain.ConfigCompatError{
|
2017-03-02 13:03:33 +00:00
|
|
|
What: "Homestead fork block",
|
|
|
|
StoredConfig: big.NewInt(0),
|
|
|
|
NewConfig: nil,
|
|
|
|
RewindTo: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-11-21 16:21:59 +00:00
|
|
|
stored: AllProtocolChanges,
|
2023-01-13 18:12:18 +00:00
|
|
|
new: &chain.Config{HomesteadBlock: big.NewInt(1)},
|
2017-03-02 13:03:33 +00:00
|
|
|
head: 3,
|
2023-01-13 18:12:18 +00:00
|
|
|
wantErr: &chain.ConfigCompatError{
|
2017-03-02 13:03:33 +00:00
|
|
|
What: "Homestead fork block",
|
|
|
|
StoredConfig: big.NewInt(0),
|
|
|
|
NewConfig: big.NewInt(1),
|
|
|
|
RewindTo: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2023-01-13 18:12:18 +00:00
|
|
|
stored: &chain.Config{HomesteadBlock: big.NewInt(30), TangerineWhistleBlock: big.NewInt(10)},
|
|
|
|
new: &chain.Config{HomesteadBlock: big.NewInt(25), TangerineWhistleBlock: big.NewInt(20)},
|
2017-03-02 13:03:33 +00:00
|
|
|
head: 25,
|
2023-01-13 18:12:18 +00:00
|
|
|
wantErr: &chain.ConfigCompatError{
|
2022-05-26 10:08:59 +00:00
|
|
|
What: "Tangerine Whistle fork block",
|
2017-03-02 13:03:33 +00:00
|
|
|
StoredConfig: big.NewInt(10),
|
|
|
|
NewConfig: big.NewInt(20),
|
|
|
|
RewindTo: 9,
|
|
|
|
},
|
|
|
|
},
|
2020-09-16 06:39:35 +00:00
|
|
|
{
|
2023-01-13 18:12:18 +00:00
|
|
|
stored: &chain.Config{ConstantinopleBlock: big.NewInt(30)},
|
|
|
|
new: &chain.Config{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)},
|
2020-09-16 06:39:35 +00:00
|
|
|
head: 40,
|
|
|
|
wantErr: nil,
|
|
|
|
},
|
|
|
|
{
|
2023-01-13 18:12:18 +00:00
|
|
|
stored: &chain.Config{ConstantinopleBlock: big.NewInt(30)},
|
|
|
|
new: &chain.Config{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)},
|
2020-09-16 06:39:35 +00:00
|
|
|
head: 40,
|
2023-01-13 18:12:18 +00:00
|
|
|
wantErr: &chain.ConfigCompatError{
|
2020-09-16 06:39:35 +00:00
|
|
|
What: "Petersburg fork block",
|
|
|
|
StoredConfig: nil,
|
|
|
|
NewConfig: big.NewInt(31),
|
|
|
|
RewindTo: 30,
|
|
|
|
},
|
|
|
|
},
|
2017-03-02 13:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
err := test.stored.CheckCompatible(test.new, test.head)
|
|
|
|
if !reflect.DeepEqual(err, test.wantErr) {
|
|
|
|
t.Errorf("error mismatch:\nstored: %v\nnew: %v\nhead: %v\nerr: %v\nwant: %v", test.stored, test.new, test.head, err, test.wantErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|