@@ -19,7 +19,6 @@ package forkid
1919import (
2020 "bytes"
2121 "math"
22- "math/big"
2322 "testing"
2423
2524 "github.com/ledgerwatch/erigon-lib/chain"
@@ -32,6 +31,8 @@ import (
3231
3332// TestCreation tests that different genesis and fork rule combinations result in
3433// the correct fork ID.
34+ // Forks before Shanghai are triggered by the block number,
35+ // while Shanghai and later forks are triggered by the block time.
3536func TestCreation (t * testing.T ) {
3637 type testcase struct {
3738 head uint64
@@ -48,32 +49,34 @@ func TestCreation(t *testing.T) {
4849 params .MainnetChainConfig ,
4950 params .MainnetGenesisHash ,
5051 []testcase {
51- {0 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Unsynced
52- {1149999 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Last Frontier block
53- {1150000 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // First Homestead block
54- {1919999 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // Last Homestead block
55- {1920000 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // First DAO block
56- {2462999 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // Last DAO block
57- {2463000 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // First Tangerine block
58- {2674999 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // Last Tangerine block
59- {2675000 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // First Spurious block
60- {4369999 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // Last Spurious block
61- {4370000 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // First Byzantium block
62- {7279999 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // Last Byzantium block
63- {7280000 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // First and last Constantinople, first Petersburg block
64- {9068999 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // Last Petersburg block
65- {9069000 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // First Istanbul block
66- {9199999 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // Last Istanbul block
67- {9200000 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // First Muir Glacier block
68- {12243999 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // Last Muir Glacier block
69- {12244000 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // First Berlin block
70- {12964999 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // Last Berlin block
71- {12965000 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // First London block
72- {13772999 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // Last London block
73- {13773000 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // First Arrow Glacier block
74- {15049999 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // Last Arrow Glacier block
75- {15050000 , 0 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 0 }}, // First Gray Glacier block
76- {20000000 , 0 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 0 }}, // Future Gray Glacier block
52+ {0 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Unsynced
53+ {1149999 , 1457981342 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Last Frontier block
54+ {1150000 , 1457981393 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // First Homestead block
55+ {1919999 , 1469020838 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // Last Homestead block
56+ {1920000 , 1469020840 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // First DAO block
57+ {2462999 , 1476796747 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // Last DAO block
58+ {2463000 , 1476796771 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // First Tangerine block
59+ {2674999 , 1479831337 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // Last Tangerine block
60+ {2675000 , 1479831344 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // First Spurious block
61+ {4369999 , 1508131303 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // Last Spurious block
62+ {4370000 , 1508131331 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // First Byzantium block
63+ {7279999 , 1551383501 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // Last Byzantium block
64+ {7280000 , 1551383524 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // First and last Constantinople, first Petersburg block
65+ {9068999 , 1575764708 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // Last Petersburg block
66+ {9069000 , 1575764709 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // First Istanbul block
67+ {9199999 , 1577953806 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // Last Istanbul block
68+ {9200000 , 1577953849 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // First Muir Glacier block
69+ {12243999 , 1618481214 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // Last Muir Glacier block
70+ {12244000 , 1618481223 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // First Berlin block
71+ {12964999 , 1628166812 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // Last Berlin block
72+ {12965000 , 1628166822 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // First London block
73+ {13772999 , 1639079715 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // Last London block
74+ {13773000 , 1639079723 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // First Arrow Glacier block
75+ {15049999 , 1656586434 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // Last Arrow Glacier block
76+ {15050000 , 1656586444 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 1681338455 }}, // First Gray Glacier block
77+ {17037484 , 1681338443 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 1681338455 }}, // Last pre-Shanghai block (approx)
78+ {17037485 , 1681338455 , ID {Hash : checksumToBytes (0xdce96c2d ), Next : 0 }}, // First Shanghai block (approx)
79+ {19000000 , 1700000000 , ID {Hash : checksumToBytes (0xdce96c2d ), Next : 0 }}, // Future Shanghai block (mock)
7780 },
7881 },
7982 // Rinkeby test cases
@@ -112,8 +115,9 @@ func TestCreation(t *testing.T) {
112115 {4460644 , 1616045391 , ID {Hash : checksumToBytes (0x757a1c47 ), Next : 5062605 }}, // First Berlin block
113116 {5062604 , 1625109564 , ID {Hash : checksumToBytes (0x757a1c47 ), Next : 5062605 }}, // Last Berlin block
114117 {5062605 , 1625109579 , ID {Hash : checksumToBytes (0xB8C6299D ), Next : 1678832736 }}, // First London block
115- {8671878 , 1678832724 , ID {Hash : checksumToBytes (0xB8C6299D ), Next : 1678832736 }}, // Last pre-Shanghai block (approx height)
116- {8671879 , 1678832736 , ID {Hash : checksumToBytes (0xf9843abf ), Next : 0 }}, // First Shanghai block (approx height)
118+ {8656122 , 1678832724 , ID {Hash : checksumToBytes (0xB8C6299D ), Next : 1678832736 }}, // Last pre-Shanghai block
119+ {8656123 , 1678832784 , ID {Hash : checksumToBytes (0xf9843abf ), Next : 0 }}, // First Shanghai block
120+ {9900000 , 1700000000 , ID {Hash : checksumToBytes (0xf9843abf ), Next : 0 }}, // Future Shanghai block (mock)
117121 },
118122 },
119123 // Sepolia test cases
@@ -126,6 +130,7 @@ func TestCreation(t *testing.T) {
126130 {1735371 , 1661130108 , ID {Hash : checksumToBytes (0xb96cbd13 ), Next : 1677557088 }}, // First MergeNetsplit block
127131 {2990907 , 1677557076 , ID {Hash : checksumToBytes (0xb96cbd13 ), Next : 1677557088 }}, // Last pre-Shanghai block
128132 {2990908 , 1677557088 , ID {Hash : checksumToBytes (0xf7f9bc08 ), Next : 0 }}, // First Shanghai block
133+ {5000000 , 1700000000 , ID {Hash : checksumToBytes (0xf7f9bc08 ), Next : 0 }}, // Future Shanghai block (mock)
129134 },
130135 },
131136 // Gnosis test cases
@@ -167,104 +172,6 @@ func TestCreation(t *testing.T) {
167172 }
168173}
169174
170- // TestCreationWithTimestamps tests that different genesis and fork rule combinations result in
171- // the correct fork ID even for time based forks.
172- func TestCreationWithTimestamps (t * testing.T ) {
173- mergeConfig := * params .MainnetChainConfig
174- mergeConfig .MergeNetsplitBlock = big .NewInt (18000000 )
175-
176- withdrawalConfig := * params .MainnetChainConfig
177- withdrawalConfig .MergeNetsplitBlock = big .NewInt (18000000 )
178- withdrawalConfig .ShanghaiTime = big .NewInt (1668000000 )
179- type testcase struct {
180- head uint64
181- time uint64
182- want ID
183- }
184- tests := []struct {
185- config * chain.Config
186- genesis libcommon.Hash
187- cases []testcase
188- }{
189- // Mainnet test cases
190- {
191- params .MainnetChainConfig ,
192- params .MainnetGenesisHash ,
193- []testcase {
194- {0 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Unsynced
195- {1149999 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Last Frontier block
196- {1150000 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // First Homestead block
197- {1919999 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // Last Homestead block
198- {1920000 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // First DAO block
199- {2462999 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // Last DAO block
200- {2463000 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // First Tangerine block
201- {2674999 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // Last Tangerine block
202- {2675000 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // First Spurious block
203- {4369999 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // Last Spurious block
204- {4370000 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // First Byzantium block
205- {7279999 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // Last Byzantium block
206- {7280000 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // First and last Constantinople, first Petersburg block
207- {9068999 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // Last Petersburg block
208- {9069000 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // First Istanbul and first Muir Glacier block
209- {9199999 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // Last Istanbul and first Muir Glacier block
210- {9200000 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // First Muir Glacier block
211- {12243999 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // Last Muir Glacier block
212- {12244000 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // First Berlin block
213- {12964999 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // Last Berlin block
214- {12965000 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // First London block
215- {13772999 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // Last London block
216- {13773000 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // First Arrow Glacier block
217- {15049999 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // Last Arrow Glacier block
218- {15050000 , 0 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 0 }}, // First Gray Glacier block
219- {20000000 , 0 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 0 }}, // Future Gray Glacier block
220- },
221- },
222- // Withdrawal test cases
223- {
224- & withdrawalConfig ,
225- params .MainnetGenesisHash ,
226- []testcase {
227- {0 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Unsynced
228- {1149999 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Last Frontier block
229- {1150000 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // First Homestead block
230- {1919999 , 0 , ID {Hash : checksumToBytes (0x97c2c34c ), Next : 1920000 }}, // Last Homestead block
231- {1920000 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // First DAO block
232- {2462999 , 0 , ID {Hash : checksumToBytes (0x91d1f948 ), Next : 2463000 }}, // Last DAO block
233- {2463000 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // First Tangerine block
234- {2674999 , 0 , ID {Hash : checksumToBytes (0x7a64da13 ), Next : 2675000 }}, // Last Tangerine block
235- {2675000 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // First Spurious block
236- {4369999 , 0 , ID {Hash : checksumToBytes (0x3edd5b10 ), Next : 4370000 }}, // Last Spurious block
237- {4370000 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // First Byzantium block
238- {7279999 , 0 , ID {Hash : checksumToBytes (0xa00bc324 ), Next : 7280000 }}, // Last Byzantium block
239- {7280000 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // First and last Constantinople, first Petersburg block
240- {9068999 , 0 , ID {Hash : checksumToBytes (0x668db0af ), Next : 9069000 }}, // Last Petersburg block
241- {9069000 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // First Istanbul and first Muir Glacier block
242- {9199999 , 0 , ID {Hash : checksumToBytes (0x879d6e30 ), Next : 9200000 }}, // Last Istanbul and first Muir Glacier block
243- {9200000 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // First Muir Glacier block
244- {12243999 , 0 , ID {Hash : checksumToBytes (0xe029e991 ), Next : 12244000 }}, // Last Muir Glacier block
245- {12244000 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // First Berlin block
246- {12964999 , 0 , ID {Hash : checksumToBytes (0x0eb440f6 ), Next : 12965000 }}, // Last Berlin block
247- {12965000 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // First London block
248- {13772999 , 0 , ID {Hash : checksumToBytes (0xb715077d ), Next : 13773000 }}, // Last London block
249- {13773000 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // First Arrow Glacier block
250- {15049999 , 0 , ID {Hash : checksumToBytes (0x20c327fc ), Next : 15050000 }}, // Last Arrow Glacier block
251- {15050000 , 0 , ID {Hash : checksumToBytes (0xf0afd0e3 ), Next : 18000000 }}, // First Gray Glacier block
252- {18000000 , 0 , ID {Hash : checksumToBytes (0x4fb8a872 ), Next : 1668000000 }}, // First Merge Start block
253- {20000000 , 0 , ID {Hash : checksumToBytes (0x4fb8a872 ), Next : 1668000000 }}, // Last Merge Start block
254- {20000000 , 1668000000 , ID {Hash : checksumToBytes (0xc1fdf181 ), Next : 0 }}, // First Merge Start block
255- {20000000 , 2668000000 , ID {Hash : checksumToBytes (0xc1fdf181 ), Next : 0 }}, // Future Merge Start block
256- },
257- },
258- }
259- for i , tt := range tests {
260- for j , ttt := range tt .cases {
261- if have := NewID (tt .config , tt .genesis , ttt .head , ttt .time ); have != ttt .want {
262- t .Errorf ("test %d, case %d: fork ID mismatch: have %x, want %x" , i , j , have , ttt .want )
263- }
264- }
265- }
266- }
267-
268175// TestValidation tests that a local peer correctly validates and accepts a remote
269176// fork ID.
270177func TestValidation (t * testing.T ) {
0 commit comments