From b236e940977ac40e7fe5929cc9d8087e8b1cc1b2 Mon Sep 17 00:00:00 2001 From: Vicky Date: Tue, 17 Mar 2026 02:44:37 +0800 Subject: [PATCH] params: add regression test for fork helper completeness --- params/config_test.go | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/params/config_test.go b/params/config_test.go index f658c336dc..e34c4c13d4 100644 --- a/params/config_test.go +++ b/params/config_test.go @@ -23,6 +23,7 @@ import ( "testing" "time" + "github.com/ethereum/go-ethereum/params/forks" "github.com/stretchr/testify/require" ) @@ -155,3 +156,46 @@ func TestTimestampCompatError(t *testing.T) { require.Equal(t, newTimestampCompatError(errWhat, newUint64(0), newUint64(1681338455)).Error(), "mismatching Shanghai fork timestamp in database (have timestamp 0, want timestamp 1681338455, rewindto timestamp 0)") } + +// TestForkHelperCompleteness ensures that Timestamp() and BlobConfig() cover +// every fork that LatestFork() can return. This catches the common mistake of +// adding a new fork to LatestFork but forgetting to update the helper methods. +func TestForkHelperCompleteness(t *testing.T) { + ts := newUint64(1) + cfg := &ChainConfig{ + LondonBlock: big.NewInt(0), + ShanghaiTime: ts, + CancunTime: ts, + PragueTime: ts, + OsakaTime: ts, + BPO1Time: ts, + BPO2Time: ts, + BPO3Time: ts, + BPO4Time: ts, + BPO5Time: ts, + AmsterdamTime: ts, + BlobScheduleConfig: &BlobScheduleConfig{ + Cancun: DefaultCancunBlobConfig, + Prague: DefaultPragueBlobConfig, + Osaka: DefaultPragueBlobConfig, + BPO1: DefaultPragueBlobConfig, + BPO2: DefaultPragueBlobConfig, + BPO3: DefaultPragueBlobConfig, + BPO4: DefaultPragueBlobConfig, + BPO5: DefaultPragueBlobConfig, + Amsterdam: DefaultPragueBlobConfig, + }, + } + // Timestamp() must return non-nil for every time-based fork (Shanghai onward). + for f := forks.Shanghai; f <= forks.Amsterdam; f++ { + if cfg.Timestamp(f) == nil { + t.Errorf("Timestamp(%s) returned nil — add a case to Timestamp()", f) + } + } + // BlobConfig() must return non-nil for every blob-capable fork (Cancun onward). + for f := forks.Cancun; f <= forks.Amsterdam; f++ { + if cfg.BlobConfig(f) == nil { + t.Errorf("BlobConfig(%s) returned nil — add a case to BlobConfig()", f) + } + } +}