|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +// |
| 3 | +// Copyright (C) 2025, Berachain Foundation. All rights reserved. |
| 4 | +// Use of this software is governed by the Business Source License included |
| 5 | +// in the LICENSE file of this repository and at www.mariadb.com/bsl11. |
| 6 | +// |
| 7 | +// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY |
| 8 | +// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER |
| 9 | +// VERSIONS OF THE LICENSED WORK. |
| 10 | +// |
| 11 | +// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF |
| 12 | +// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF |
| 13 | +// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). |
| 14 | +// |
| 15 | +// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON |
| 16 | +// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, |
| 17 | +// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF |
| 18 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND |
| 19 | +// TITLE. |
| 20 | +// |
| 21 | + |
| 22 | +package cometbft_test |
| 23 | + |
| 24 | +import ( |
| 25 | + "testing" |
| 26 | + |
| 27 | + "github.com/berachain/beacon-kit/chain" |
| 28 | + "github.com/berachain/beacon-kit/config/spec" |
| 29 | + cometbft "github.com/berachain/beacon-kit/consensus/cometbft/service" |
| 30 | + "github.com/berachain/beacon-kit/primitives/crypto" |
| 31 | + cmttypes "github.com/cometbft/cometbft/types" |
| 32 | + "github.com/stretchr/testify/require" |
| 33 | +) |
| 34 | + |
| 35 | +func TestSBTEnableHeightAlignedWithChainSpecs(t *testing.T) { |
| 36 | + t.Parallel() |
| 37 | + |
| 38 | + tests := []struct { |
| 39 | + name string |
| 40 | + getChainSpecs func(t *testing.T) chain.Spec |
| 41 | + }{ |
| 42 | + { |
| 43 | + name: "mainnet", |
| 44 | + getChainSpecs: func(t *testing.T) chain.Spec { |
| 45 | + t.Helper() |
| 46 | + cs, err := spec.MainnetChainSpec() |
| 47 | + require.NoError(t, err) |
| 48 | + return cs |
| 49 | + }, |
| 50 | + }, |
| 51 | + { |
| 52 | + name: "testnet", |
| 53 | + getChainSpecs: func(t *testing.T) chain.Spec { |
| 54 | + t.Helper() |
| 55 | + cs, err := spec.TestnetChainSpec() |
| 56 | + require.NoError(t, err) |
| 57 | + return cs |
| 58 | + }, |
| 59 | + }, |
| 60 | + { |
| 61 | + name: "devnet", |
| 62 | + getChainSpecs: func(t *testing.T) chain.Spec { |
| 63 | + t.Helper() |
| 64 | + cs, err := spec.DevnetChainSpec() |
| 65 | + require.NoError(t, err) |
| 66 | + return cs |
| 67 | + }, |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + for _, tt := range tests { |
| 72 | + t.Run(tt.name, func(t *testing.T) { |
| 73 | + t.Parallel() |
| 74 | + |
| 75 | + cs := tt.getChainSpecs(t) |
| 76 | + |
| 77 | + var cp *cmttypes.ConsensusParams |
| 78 | + require.NotPanics(t, func() { |
| 79 | + cp = cometbft.DefaultConsensusParams(crypto.CometBLSType, cs) |
| 80 | + }) |
| 81 | + |
| 82 | + // Make sure that the Enable Height in consensus parameters matches with |
| 83 | + // chain spec one. This is relevant to make sure that consensus parameters |
| 84 | + // are well set when chain spec is modified and genesis is regenerated. |
| 85 | + require.Equal(t, cp.Feature.SBTEnableHeight, cs.SbtConsensusEnableHeight()) |
| 86 | + }) |
| 87 | + } |
| 88 | +} |
0 commit comments