Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
wnjoon committed Jan 13, 2025
1 parent 8037568 commit aeeb4cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
14 changes: 14 additions & 0 deletions test/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"github.com/babylonlabs-io/babylon/test/e2e/configurer/config"
"github.com/babylonlabs-io/babylon/test/e2e/containers"
"github.com/babylonlabs-io/babylon/test/e2e/initialization"
"github.com/babylonlabs-io/babylon/testutil/signer"
cmtCfg "github.com/cometbft/cometbft/config"
cmtos "github.com/cometbft/cometbft/libs/os"
)

type UpgradeSettings struct {
Expand Down Expand Up @@ -257,6 +260,9 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe
uc.containerManager.CurrentTag = "latest"

for _, node := range chainConfig.NodeConfigs {
if err := saveIfNotExists(node); err != nil {
return err
}
if err := node.Run(); err != nil {
return err
}
Expand All @@ -268,6 +274,14 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe
return nil
}

func saveIfNotExists(cfg *chain.NodeConfig) error {
nodeDir := cfg.Node.ConfigDir
if !cmtos.FileExists(filepath.Join(nodeDir, cmtCfg.DefaultConfig().PrivValidatorKeyFile())) {
return signer.GeneratePrivSigner(nodeDir)
}
return nil
}

// ParseGovPropFromFile loads the proposal from the UpgradeSignetLaunchFilePath
func (uc *UpgradeConfigurer) ParseGovPropFromFile() (*upgradetypes.MsgSoftwareUpgrade, error) {
pwd, err := os.Getwd()
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/initialization/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package initialization

import (
"fmt"

"github.com/babylonlabs-io/babylon/privval"
)

type ChainMeta struct {
Expand All @@ -19,6 +21,7 @@ type Node struct {
PrivateKey []byte `json:"privateKey"`
PeerId string `json:"peerId"`
IsValidator bool `json:"isValidator"`
ConsensusKey privval.WrappedFilePVKey
}

type Chain struct {
Expand Down
18 changes: 12 additions & 6 deletions test/e2e/initialization/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
babylonApp "github.com/babylonlabs-io/babylon/app"
appparams "github.com/babylonlabs-io/babylon/app/params"
"github.com/babylonlabs-io/babylon/cmd/babylond/cmd"
"github.com/babylonlabs-io/babylon/crypto/bls12381"
"github.com/babylonlabs-io/babylon/privval"
"github.com/babylonlabs-io/babylon/test/e2e/util"
cmtprivval "github.com/cometbft/cometbft/privval"
Expand Down Expand Up @@ -180,20 +181,24 @@ func (n *internalNode) createConsensusKey() error {

// create new key for consensus
// file pv
var privKey ed25519.PrivKey
var cmtPrivKey ed25519.PrivKey
var blsPrivKey bls12381.PrivateKey
if n.mnemonic == "" {
privKey = ed25519.GenPrivKey()
cmtPrivKey = ed25519.GenPrivKey()
blsPrivKey = bls12381.GenPrivKey()
} else {
privKey = ed25519.GenPrivKeyFromSecret([]byte(n.mnemonic))
cmtPrivKey = ed25519.GenPrivKeyFromSecret([]byte(n.mnemonic))
blsPrivKey = bls12381.GenPrivKeyFromSecret([]byte(n.mnemonic))
}
filePV := cmtprivval.NewFilePV(privKey, pvKeyFile, pvStateFile)

filePV := cmtprivval.NewFilePV(cmtPrivKey, pvKeyFile, pvStateFile)
filePV.Key.Save()
filePV.LastSignState.Save()

// bls pv
blsPV := privval.GenBlsPV(blsKeyFile, blsPasswordFile, "password", accAddress.String())
blsPV := privval.NewBlsPV(blsPrivKey, blsKeyFile, blsPasswordFile, accAddress.String())
blsPV.Key.Save("password", accAddress.String())

// n.consensusKey = filePV.Key
n.consensusKey = privval.WrappedFilePVKey{
CometPVKey: filePV.Key,
BlsPVKey: blsPV.Key,
Expand Down Expand Up @@ -267,6 +272,7 @@ func (n *internalNode) export() *Node {
PrivateKey: n.privateKey.Bytes(),
PeerId: n.peerId,
IsValidator: n.isValidator,
ConsensusKey: n.consensusKey,
}
}

Expand Down

0 comments on commit aeeb4cb

Please sign in to comment.