forked from babylonlabs-io/babylon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenesis_test.go
52 lines (46 loc) · 1.58 KB
/
genesis_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package checkpointing_test
import (
"testing"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
"github.com/babylonlabs-io/babylon/x/checkpointing"
"github.com/cometbft/cometbft/crypto/ed25519"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
cosmosed "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
simapp "github.com/babylonlabs-io/babylon/app"
"github.com/babylonlabs-io/babylon/x/checkpointing/types"
)
func TestInitGenesis(t *testing.T) {
app := simapp.Setup(t, false)
ctx := app.BaseApp.NewContext(false)
ckptKeeper := app.CheckpointingKeeper
valNum := 10
genKeys := make([]*types.GenesisKey, valNum)
for i := 0; i < valNum; i++ {
valKeys, err := privval.NewValidatorKeys(ed25519.GenPrivKey(), bls12381.GenPrivKey())
require.NoError(t, err)
valPubkey, err := cryptocodec.FromCmtPubKeyInterface(valKeys.ValPubkey)
require.NoError(t, err)
genKey, err := types.NewGenesisKey(
sdk.ValAddress(valKeys.ValPubkey.Address()),
&valKeys.BlsPubkey,
valKeys.PoP,
&cosmosed.PubKey{Key: valPubkey.Bytes()},
)
require.NoError(t, err)
genKeys[i] = genKey
}
genesisState := types.GenesisState{
GenesisKeys: genKeys,
}
checkpointing.InitGenesis(ctx, ckptKeeper, genesisState)
for i := 0; i < valNum; i++ {
addr, err := sdk.ValAddressFromBech32(genKeys[i].ValidatorAddress)
require.NoError(t, err)
blsKey, err := ckptKeeper.GetBlsPubKey(ctx, addr)
require.NoError(t, err)
require.True(t, genKeys[i].BlsKey.Pubkey.Equal(blsKey))
}
}