@@ -18,10 +18,14 @@ package forkid
18
18
19
19
import (
20
20
"bytes"
21
+ "hash/crc32"
21
22
"math"
23
+ "math/big"
22
24
"testing"
23
25
24
26
"github.com/ethereum/go-ethereum/common"
27
+ "github.com/ethereum/go-ethereum/core"
28
+ "github.com/ethereum/go-ethereum/core/types"
25
29
"github.com/ethereum/go-ethereum/params"
26
30
"github.com/ethereum/go-ethereum/rlp"
27
31
)
@@ -36,13 +40,13 @@ func TestCreation(t *testing.T) {
36
40
}
37
41
tests := []struct {
38
42
config * params.ChainConfig
39
- genesis common. Hash
43
+ genesis * types. Block
40
44
cases []testcase
41
45
}{
42
46
// Mainnet test cases
43
47
{
44
48
params .MainnetChainConfig ,
45
- params . MainnetGenesisHash ,
49
+ core . DefaultGenesisBlock (). ToBlock () ,
46
50
[]testcase {
47
51
{0 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Unsynced
48
52
{1149999 , 0 , ID {Hash : checksumToBytes (0xfc64ec04 ), Next : 1150000 }}, // Last Frontier block
@@ -77,7 +81,7 @@ func TestCreation(t *testing.T) {
77
81
// Goerli test cases
78
82
{
79
83
params .GoerliChainConfig ,
80
- params . GoerliGenesisHash ,
84
+ core . DefaultGoerliGenesisBlock (). ToBlock () ,
81
85
[]testcase {
82
86
{0 , 0 , ID {Hash : checksumToBytes (0xa3f5ab08 ), Next : 1561651 }}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople and first Petersburg block
83
87
{1561650 , 0 , ID {Hash : checksumToBytes (0xa3f5ab08 ), Next : 1561651 }}, // Last Petersburg block
@@ -94,7 +98,7 @@ func TestCreation(t *testing.T) {
94
98
// Sepolia test cases
95
99
{
96
100
params .SepoliaChainConfig ,
97
- params . SepoliaGenesisHash ,
101
+ core . DefaultSepoliaGenesisBlock (). ToBlock () ,
98
102
[]testcase {
99
103
{0 , 0 , ID {Hash : checksumToBytes (0xfe3366e7 ), Next : 1735371 }}, // Unsynced, last Frontier, Homestead, Tangerine, Spurious, Byzantium, Constantinople, Petersburg, Istanbul, Berlin and first London block
100
104
{1735370 , 0 , ID {Hash : checksumToBytes (0xfe3366e7 ), Next : 1735371 }}, // Last London block
@@ -382,3 +386,55 @@ func TestEncoding(t *testing.T) {
382
386
}
383
387
}
384
388
}
389
+
390
+ // Tests that time-based forks which are active at genesis are not included in
391
+ // forkid hash.
392
+ func TestTimeBasedForkInGenesis (t * testing.T ) {
393
+ var (
394
+ time = uint64 (1690475657 )
395
+ genesis = types .NewBlockWithHeader (& types.Header {Time : time })
396
+ forkidHash = checksumToBytes (crc32 .ChecksumIEEE (genesis .Hash ().Bytes ()))
397
+ config = func (shanghai , cancun uint64 ) * params.ChainConfig {
398
+ return & params.ChainConfig {
399
+ ChainID : big .NewInt (1337 ),
400
+ HomesteadBlock : big .NewInt (0 ),
401
+ DAOForkBlock : nil ,
402
+ DAOForkSupport : true ,
403
+ EIP150Block : big .NewInt (0 ),
404
+ EIP155Block : big .NewInt (0 ),
405
+ EIP158Block : big .NewInt (0 ),
406
+ ByzantiumBlock : big .NewInt (0 ),
407
+ ConstantinopleBlock : big .NewInt (0 ),
408
+ PetersburgBlock : big .NewInt (0 ),
409
+ IstanbulBlock : big .NewInt (0 ),
410
+ MuirGlacierBlock : big .NewInt (0 ),
411
+ BerlinBlock : big .NewInt (0 ),
412
+ LondonBlock : big .NewInt (0 ),
413
+ TerminalTotalDifficulty : big .NewInt (0 ),
414
+ TerminalTotalDifficultyPassed : true ,
415
+ MergeNetsplitBlock : big .NewInt (0 ),
416
+ ShanghaiTime : & shanghai ,
417
+ CancunTime : & cancun ,
418
+ Ethash : new (params.EthashConfig ),
419
+ }
420
+ }
421
+ )
422
+ tests := []struct {
423
+ config * params.ChainConfig
424
+ want ID
425
+ }{
426
+ // Shanghai active before genesis, skip
427
+ {config (time - 1 , time + 1 ), ID {Hash : forkidHash , Next : time + 1 }},
428
+
429
+ // Shanghai active at genesis, skip
430
+ {config (time , time + 1 ), ID {Hash : forkidHash , Next : time + 1 }},
431
+
432
+ // Shanghai not active, skip
433
+ {config (time + 1 , time + 2 ), ID {Hash : forkidHash , Next : time + 1 }},
434
+ }
435
+ for _ , tt := range tests {
436
+ if have := NewID (tt .config , genesis , 0 , time ); have != tt .want {
437
+ t .Fatalf ("incorrect forkid hash: have %x, want %x" , have , tt .want )
438
+ }
439
+ }
440
+ }
0 commit comments