Skip to content

Commit

Permalink
fix: test replay blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Jan 25, 2025
1 parent febf580 commit 486da90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 58 deletions.
56 changes: 1 addition & 55 deletions test/e2e/initialization/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
sdkmath "cosmossdk.io/math"

minttypes "github.com/babylonlabs-io/babylon/x/mint/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -23,12 +21,10 @@ import (
staketypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/cosmos/gogoproto/proto"

"github.com/babylonlabs-io/babylon/privval"
bbn "github.com/babylonlabs-io/babylon/types"
btccheckpointtypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
blctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
btclighttypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
finalitytypes "github.com/babylonlabs-io/babylon/x/finality/types"

"github.com/babylonlabs-io/babylon/test/e2e/util"
Expand Down Expand Up @@ -248,11 +244,6 @@ func initGenesis(
return err
}

err = updateModuleGenesis(appGenState, checkpointingtypes.ModuleName, checkpointingtypes.DefaultGenesis(), updateCheckpointingGenesis(chain))
if err != nil {
return err
}

err = updateModuleGenesis(appGenState, blctypes.ModuleName, blctypes.DefaultGenesis(), updateBtcLightClientGenesis(btcHeaders))
if err != nil {
return err
Expand Down Expand Up @@ -375,7 +366,7 @@ func updateGenUtilGenesis(c *internalChain) func(*genutiltypes.GenesisState) {
if c.chainMeta.Id != ChainAID {
stakeAmountCoin = StakeAmountCoinB
}
createValmsg, err := node.buildCreateValidatorMsg(stakeAmountCoin)
createValmsg, err := node.buildCreateValidatorMsg(stakeAmountCoin, node.consensusKey)
if err != nil {
panic("genutil genesis setup failed: " + err.Error())
}
Expand All @@ -394,48 +385,3 @@ func updateGenUtilGenesis(c *internalChain) func(*genutiltypes.GenesisState) {
genUtilGenState.GenTxs = genTxs
}
}

func updateCheckpointingGenesis(c *internalChain) func(*checkpointingtypes.GenesisState) {
return func(checkpointingGenState *checkpointingtypes.GenesisState) {
var genKeys []*checkpointingtypes.GenesisKey

for _, node := range c.nodes {
if !node.isValidator {
continue
}

proofOfPossession, err := privval.BuildPoP(node.consensusKey.PrivKey, node.consensusKey.BlsPrivKey)

if err != nil {
panic("It should be possible to build proof of possession from validator private keys")
}

valPubKey, err := cryptocodec.FromCmtPubKeyInterface(node.consensusKey.PubKey)

if err != nil {
panic("It should be possible to retrieve validator public key")
}

da, err := sdk.AccAddressFromBech32(node.consensusKey.DelegatorAddress)

if err != nil {
panic("It should be possible to get validator address from delegator address")
}

va := sdk.ValAddress(da)

genKey := &checkpointingtypes.GenesisKey{
ValidatorAddress: va.String(),
BlsKey: &checkpointingtypes.BlsKey{
Pubkey: &node.consensusKey.BlsPubKey,
Pop: proofOfPossession,
},
ValPubkey: valPubKey.(*ed25519.PubKey),
}

genKeys = append(genKeys, genKey)
}

checkpointingGenState.GenesisKeys = genKeys
}
}
16 changes: 13 additions & 3 deletions test/e2e/initialization/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"cosmossdk.io/math"
checkpointingtypes "github.com/babylonlabs-io/babylon/x/checkpointing/types"
cmtconfig "github.com/cometbft/cometbft/config"
cmted25519 "github.com/cometbft/cometbft/crypto/ed25519"
cmtos "github.com/cometbft/cometbft/libs/os"
Expand Down Expand Up @@ -79,7 +80,7 @@ func (n *internalNode) configDir() string {
return fmt.Sprintf("%s/%s", n.chain.chainMeta.configDir(), n.moniker)
}

func (n *internalNode) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error) {
func (n *internalNode) buildCreateValidatorMsg(amount sdk.Coin, consensusKey privval.WrappedFilePVKey) (sdk.Msg, error) {
description := stakingtypes.NewDescription(n.moniker, "", "", "", "")
commissionRates := stakingtypes.CommissionRates{
Rate: math.LegacyMustNewDecFromStr("0.1"),
Expand All @@ -96,19 +97,28 @@ func (n *internalNode) buildCreateValidatorMsg(amount sdk.Coin) (sdk.Msg, error)
}

addr, err := n.keyInfo.GetAddress()

if err != nil {
return nil, err
}

return stakingtypes.NewMsgCreateValidator(
stkMsgCreateVal, err := stakingtypes.NewMsgCreateValidator(
sdk.ValAddress(addr).String(),
valPubKey,
amount,
description,
commissionRates,
minSelfDelegation,
)
if err != nil {
return nil, err
}

proofOfPossession, err := privval.BuildPoP(consensusKey.PrivKey, consensusKey.BlsPrivKey)
if err != nil {
return nil, err
}

return checkpointingtypes.NewMsgWrappedCreateValidator(stkMsgCreateVal, &consensusKey.BlsPubKey, proofOfPossession)
}

func (n *internalNode) createConfig() error {
Expand Down

0 comments on commit 486da90

Please sign in to comment.