Skip to content

Commit 85d54f9

Browse files
authored
test: fix genesis validator set helper (#1309)
## Overview This PR removes a `TODO` in the test helper `getGenesisValidatorSetWithSigner`. This helper should only ever called with `n=1`. The validator set and key are structs, so they can't be `consts`. Closes: #860 ## Checklist - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [x] Linked issues closed with keywords <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated the genesis validator generation process to support multiple validators. - **Tests** - Adjusted test functions to accommodate the updated genesis validator generation process. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent e3d1f82 commit 85d54f9

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

node/full_client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestTx(t *testing.T) {
482482
mockApp := &mocks.Application{}
483483
mockApp.On(InitChain, mock.Anything).Return(abci.ResponseInitChain{})
484484
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
485-
genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
485+
genesisValidators, signingKey := getGenesisValidatorSetWithSigner()
486486
node, err := newFullNode(context.Background(), config.NodeConfig{
487487
DALayer: "mock",
488488
Aggregator: true,
@@ -1115,7 +1115,7 @@ func TestFutureGenesisTime(t *testing.T) {
11151115
mockApp.On(DeliverTx, mock.Anything).Return(abci.ResponseDeliverTx{})
11161116
mockApp.On(CheckTx, mock.Anything).Return(abci.ResponseCheckTx{})
11171117
key, _, _ := crypto.GenerateEd25519Key(crand.Reader)
1118-
genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
1118+
genesisValidators, signingKey := getGenesisValidatorSetWithSigner()
11191119
genesisTime := time.Now().Local().Add(time.Second * time.Duration(1))
11201120
ctx, cancel := context.WithCancel(context.Background())
11211121
defer cancel()

node/full_node_integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestAggregatorMode(t *testing.T) {
4545
app.On(Commit, mock.Anything).Return(abci.ResponseCommit{})
4646

4747
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
48-
genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
48+
genesisValidators, signingKey := getGenesisValidatorSetWithSigner()
4949
blockManagerConfig := config.BlockManagerConfig{
5050
BlockTime: 1 * time.Second,
5151
NamespaceID: types.NamespaceID{1, 2, 3, 4, 5, 6, 7, 8},
@@ -141,7 +141,7 @@ func TestLazyAggregator(t *testing.T) {
141141
app.On(Commit, mock.Anything).Return(abci.ResponseCommit{})
142142

143143
key, _, _ := crypto.GenerateEd25519Key(rand.Reader)
144-
genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
144+
genesisValidators, signingKey := getGenesisValidatorSetWithSigner()
145145
blockManagerConfig := config.BlockManagerConfig{
146146
// After the genesis header is published, the syncer is started
147147
// which takes little longer (due to initialization) and the syncer
@@ -548,7 +548,7 @@ func createNode(ctx context.Context, n int, aggregator bool, isLight bool, keys
548548
ctx = context.Background()
549549
}
550550

551-
genesisValidators, signingKey := getGenesisValidatorSetWithSigner(1)
551+
genesisValidators, signingKey := getGenesisValidatorSetWithSigner()
552552
genesis := &cmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}
553553
// TODO: need to investigate why this needs to be done for light nodes
554554
genesis.InitialHeight = 1

node/test_helpers.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ func waitForAtLeastNBlocks(node Node, n int, source Source) error {
117117
})
118118
}
119119

120-
// TODO: use n and return n validators
121-
func getGenesisValidatorSetWithSigner(n int) ([]cmtypes.GenesisValidator, crypto.PrivKey) {
120+
func getGenesisValidatorSetWithSigner() ([]cmtypes.GenesisValidator, crypto.PrivKey) {
122121
nodeKey := &p2p.NodeKey{
123122
PrivKey: genesisValidatorKey,
124123
}
125124
signingKey, _ := GetNodeKey(nodeKey)
126125
pubKey := genesisValidatorKey.PubKey()
127126

128-
genesisValidators := []cmtypes.GenesisValidator{
129-
{Address: pubKey.Address(), PubKey: pubKey, Power: int64(100), Name: "gen #1"},
130-
}
127+
genesisValidators := []cmtypes.GenesisValidator{{
128+
Address: pubKey.Address(),
129+
PubKey: pubKey,
130+
Power: int64(100),
131+
Name: "gen #1",
132+
}}
131133
return genesisValidators, signingKey
132134
}

0 commit comments

Comments
 (0)