Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions chain/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@ func (s spec) validate() error {

// EVM Inflation values can be zero or non-zero, no validation needed.

// Enforce ordering of the forks. Like most chains, BeaconKit does not support arbitrary ordering of forks.
// Fork times here are in chronological order
orderedForkTimes := []uint64{
s.Data.GenesisTime,
s.Data.Deneb1ForkTime,
s.Data.ElectraForkTime,
}
for i := 1; i < len(orderedForkTimes); i++ {
prev, cur := orderedForkTimes[i-1], orderedForkTimes[i]
// must not go backwards
if prev > cur {
return fmt.Errorf(
"fork ordering violation: timestamp at index %d (%d) > index %d (%d)",
i-1, prev, i, cur,
)
}
}

// TODO: Add more validation rules here.
return nil
}
Expand Down
83 changes: 83 additions & 0 deletions chain/spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (C) 2025, Berachain Foundation. All rights reserved.
// Use of this software is governed by the Business Source License included
// in the LICENSE file of this repository and at www.mariadb.com/bsl11.
//
// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY
// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER
// VERSIONS OF THE LICENSED WORK.
//
// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF
// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF
// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE).
//
// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
// TITLE.

package chain_test

import (
"testing"

"github.com/berachain/beacon-kit/chain"
"github.com/stretchr/testify/require"
)

func baseSpecData() *chain.SpecData {
return &chain.SpecData{
// satisfy the pre-checks in validate()
MaxWithdrawalsPerPayload: 2,
ValidatorSetCap: 100,
ValidatorRegistryLimit: 100,
}
}

func TestValidate_ForkOrder_Success(t *testing.T) {
t.Parallel()
data := baseSpecData()
data.GenesisTime = 10
data.Deneb1ForkTime = 20
data.ElectraForkTime = 30

_, err := chain.NewSpec(data)
require.NoError(t, err)
}

func TestValidate_ForkOrder_GenesisAfterDeneb(t *testing.T) {
t.Parallel()
data := baseSpecData()
data.GenesisTime = 50
data.Deneb1ForkTime = 20
data.ElectraForkTime = 60

_, err := chain.NewSpec(data)
require.Error(t, err)
require.Contains(t, err.Error(), "timestamp at index 0 (50) > index 1 (20)")
}

func TestValidate_ForkOrder_DenebAfterElectra(t *testing.T) {
t.Parallel()
data := baseSpecData()
data.GenesisTime = 10
data.Deneb1ForkTime = 80
data.ElectraForkTime = 40

_, err := chain.NewSpec(data)
require.Error(t, err)
require.Contains(t, err.Error(), "timestamp at index 1 (80) > index 2 (40)")
}

func TestValidate_ForkOrder_AllForksAtGenesis(t *testing.T) {
t.Parallel()
data := baseSpecData()
data.GenesisTime = 0
data.Deneb1ForkTime = 0
data.ElectraForkTime = 0

_, err := chain.NewSpec(data)
require.NoError(t, err)
}
Loading