-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #600 from ava-labs/fix-incompatible-config
Fix config handling with apricot timestamp forks
- Loading branch information
Showing
4 changed files
with
210 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. | ||
// | ||
// This file is a derived work, based on the go-ethereum library whose original | ||
// notices appear below. | ||
// | ||
// It is distributed under a license compatible with the licensing terms of the | ||
// original code from which it is derived. | ||
// | ||
// Much love to the original authors for their work. | ||
// ********** | ||
// 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" | ||
) | ||
|
||
func TestCheckCompatible(t *testing.T) { | ||
type test struct { | ||
stored, new *ChainConfig | ||
headHeight, headTimestamp uint64 | ||
wantErr *ConfigCompatError | ||
} | ||
tests := []test{ | ||
{stored: TestChainConfig, new: TestChainConfig, headHeight: 0, headTimestamp: 0, wantErr: nil}, | ||
{stored: TestChainConfig, new: TestChainConfig, headHeight: 100, headTimestamp: 1000, wantErr: nil}, | ||
{ | ||
stored: &ChainConfig{EIP150Block: big.NewInt(10)}, | ||
new: &ChainConfig{EIP150Block: big.NewInt(20)}, | ||
headHeight: 9, | ||
headTimestamp: 90, | ||
wantErr: nil, | ||
}, | ||
{ | ||
stored: TestChainConfig, | ||
new: &ChainConfig{HomesteadBlock: nil}, | ||
headHeight: 3, | ||
headTimestamp: 30, | ||
wantErr: &ConfigCompatError{ | ||
What: "Homestead fork block", | ||
StoredConfig: big.NewInt(0), | ||
NewConfig: nil, | ||
RewindTo: 0, | ||
}, | ||
}, | ||
{ | ||
stored: TestChainConfig, | ||
new: &ChainConfig{HomesteadBlock: big.NewInt(1)}, | ||
headHeight: 3, | ||
headTimestamp: 30, | ||
wantErr: &ConfigCompatError{ | ||
What: "Homestead fork block", | ||
StoredConfig: big.NewInt(0), | ||
NewConfig: big.NewInt(1), | ||
RewindTo: 0, | ||
}, | ||
}, | ||
{ | ||
stored: &ChainConfig{HomesteadBlock: big.NewInt(30), EIP150Block: big.NewInt(10)}, | ||
new: &ChainConfig{HomesteadBlock: big.NewInt(25), EIP150Block: big.NewInt(20)}, | ||
headHeight: 25, | ||
headTimestamp: 250, | ||
wantErr: &ConfigCompatError{ | ||
What: "EIP150 fork block", | ||
StoredConfig: big.NewInt(10), | ||
NewConfig: big.NewInt(20), | ||
RewindTo: 9, | ||
}, | ||
}, | ||
{ | ||
stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)}, | ||
new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(30)}, | ||
headHeight: 40, | ||
headTimestamp: 400, | ||
wantErr: nil, | ||
}, | ||
{ | ||
stored: &ChainConfig{ConstantinopleBlock: big.NewInt(30)}, | ||
new: &ChainConfig{ConstantinopleBlock: big.NewInt(30), PetersburgBlock: big.NewInt(31)}, | ||
headHeight: 40, | ||
headTimestamp: 400, | ||
wantErr: &ConfigCompatError{ | ||
What: "Petersburg fork block", | ||
StoredConfig: nil, | ||
NewConfig: big.NewInt(31), | ||
RewindTo: 30, | ||
}, | ||
}, | ||
{ | ||
stored: TestChainConfig, | ||
new: TestApricotPhase4Config, | ||
headHeight: 0, | ||
headTimestamp: 0, | ||
wantErr: &ConfigCompatError{ | ||
What: "ApricotPhase5 fork block timestamp", | ||
StoredConfig: big.NewInt(0), | ||
NewConfig: nil, | ||
RewindTo: 0, | ||
}, | ||
}, | ||
{ | ||
stored: TestChainConfig, | ||
new: TestApricotPhase4Config, | ||
headHeight: 10, | ||
headTimestamp: 100, | ||
wantErr: &ConfigCompatError{ | ||
What: "ApricotPhase5 fork block timestamp", | ||
StoredConfig: big.NewInt(0), | ||
NewConfig: nil, | ||
RewindTo: 0, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
err := test.stored.CheckCompatible(test.new, test.headHeight, test.headTimestamp) | ||
if !reflect.DeepEqual(err, test.wantErr) { | ||
t.Errorf("error mismatch:\nstored: %v\nnew: %v\nheadHeight: %v\nerr: %v\nwant: %v", test.stored, test.new, test.headHeight, err, test.wantErr) | ||
} | ||
} | ||
} |