From 0c258428cad2b3a59958d088ce8a407b8ac6c763 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 17:08:55 -0300 Subject: [PATCH 01/10] chore: try to clean up all and only then return the error --- test/e2e/containers/containers.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index 09782d7f1..c1daa3597 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -321,17 +321,17 @@ func (m *Manager) RemoveNodeResource(containerName string) error { } // ClearResources removes all outstanding Docker resources created by the Manager. -func (m *Manager) ClearResources() error { +func (m *Manager) ClearResources() (e error) { for _, resource := range m.resources { if err := m.pool.Purge(resource); err != nil { - return err + e = err } } if err := m.pool.RemoveNetwork(m.network); err != nil { - return err + e = err } - return nil + return e } func noRestart(config *docker.HostConfig) { From 61278f067e3aaaa10d1c723050ccdbe7e9309471 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 17:13:53 -0300 Subject: [PATCH 02/10] chore: add errgroup to clear resources and new mount path to set proposasl --- test/e2e/configurer/base.go | 17 ++++++++++------- test/e2e/containers/containers.go | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/e2e/configurer/base.go b/test/e2e/configurer/base.go index 6744fff94..d7d474be1 100644 --- a/test/e2e/configurer/base.go +++ b/test/e2e/configurer/base.go @@ -19,6 +19,7 @@ import ( "github.com/babylonchain/babylon/types" types2 "github.com/babylonchain/babylon/x/btccheckpoint/types" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) // baseConfigurer is the base implementation for the @@ -39,16 +40,18 @@ const defaultSyncUntilHeight = 3 func (bc *baseConfigurer) ClearResources() error { bc.t.Log("tearing down e2e integration test suite...") - if err := bc.containerManager.ClearResources(); err != nil { - return err - } + g := new(errgroup.Group) + g.Go(func() error { + return bc.containerManager.ClearResources() + }) for _, chainConfig := range bc.chainConfigs { - if err := os.RemoveAll(chainConfig.DataDir); err != nil { - return err - } + chainConfig := chainConfig + g.Go(func() error { + return os.RemoveAll(chainConfig.DataDir) + }) } - return nil + return g.Wait() } func (bc *baseConfigurer) GetChainConfig(chainIndex int) *chain.Config { diff --git a/test/e2e/containers/containers.go b/test/e2e/containers/containers.go index c1daa3597..737af78ea 100644 --- a/test/e2e/containers/containers.go +++ b/test/e2e/containers/containers.go @@ -13,6 +13,7 @@ import ( "github.com/ory/dockertest/v3" "github.com/ory/dockertest/v3/docker" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) const ( @@ -264,6 +265,7 @@ func (m *Manager) RunNodeResource(chainId string, containerName, valCondifDir st Mounts: []string{ fmt.Sprintf("%s/:%s", valCondifDir, BabylonHomePath), fmt.Sprintf("%s/bytecode:/bytecode", pwd), + fmt.Sprintf("%s/upgrades:/upgrades", pwd), }, } @@ -322,16 +324,19 @@ func (m *Manager) RemoveNodeResource(containerName string) error { // ClearResources removes all outstanding Docker resources created by the Manager. func (m *Manager) ClearResources() (e error) { + g := new(errgroup.Group) for _, resource := range m.resources { - if err := m.pool.Purge(resource); err != nil { - e = err - } + resource := resource + g.Go(func() error { + return m.pool.Purge(resource) + }) } - if err := m.pool.RemoveNetwork(m.network); err != nil { - e = err - } - return e + g.Go(func() error { + return m.pool.RemoveNetwork(m.network) + }) + + return g.Wait() } func noRestart(config *docker.HostConfig) { From b1f9a76f711af35a8c2ccda05a02a68d2329ad73 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 17:15:10 -0300 Subject: [PATCH 03/10] chore: add upgrade e2e from current branch --- app/app.go | 7 +- app/upgrades/vanilla/upgrades.go | 1 - test/e2e/configurer/factory.go | 17 +++++ test/e2e/e2e_test.go | 5 ++ ...oftware_upgrade_current_branch_e2e_test.go | 70 +++++++++++++++++++ test/e2e/upgrades/vanilla.json | 14 ++++ 6 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 test/e2e/software_upgrade_current_branch_e2e_test.go create mode 100644 test/e2e/upgrades/vanilla.json diff --git a/app/app.go b/app/app.go index 67b0b7800..cd05f8084 100644 --- a/app/app.go +++ b/app/app.go @@ -94,6 +94,7 @@ import ( "github.com/spf13/cast" "github.com/babylonchain/babylon/app/upgrades" + "github.com/babylonchain/babylon/app/upgrades/vanilla" bbn "github.com/babylonchain/babylon/types" appkeepers "github.com/babylonchain/babylon/app/keepers" @@ -158,8 +159,10 @@ var ( } // software upgrades and forks - Upgrades = []upgrades.Upgrade{} - Forks = []upgrades.Fork{} + Upgrades = []upgrades.Upgrade{ + vanilla.Upgrade, + } + Forks = []upgrades.Fork{} ) func init() { diff --git a/app/upgrades/vanilla/upgrades.go b/app/upgrades/vanilla/upgrades.go index 1cc0c9060..156e5de72 100644 --- a/app/upgrades/vanilla/upgrades.go +++ b/app/upgrades/vanilla/upgrades.go @@ -32,7 +32,6 @@ func CreateUpgradeHandler( keepers *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx := sdk.UnwrapSDKContext(context) propVanilla(ctx, &keepers.AccountKeeper, &keepers.BTCStakingKeeper) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index bcac549e5..0182a40dc 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -195,3 +195,20 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, containerManager, ), nil } + +// NewSoftwareUpgradeTest returns a new Configurer for Software Upgrade testing +func NewSoftwareUpgradeTest(t *testing.T, isDebugLogEnabled bool) (Configurer, error) { + containerManager, err := containers.NewManager(isDebugLogEnabled, false) + if err != nil { + return nil, err + } + + return NewCurrentBranchConfigurer(t, + []*chain.Config{ + // we only need 1 chain for testing upgrade + chain.New(t, containerManager, initialization.ChainAID, validatorConfigsChainA, nil), + }, + baseSetup, // base set up + containerManager, + ), nil +} diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 4c877c6c8..d27b66acf 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -35,3 +35,8 @@ func TestBTCTimestampingPhase2RlyTestSuite(t *testing.T) { func TestBTCStakingTestSuite(t *testing.T) { suite.Run(t, new(BTCStakingTestSuite)) } + +// TestSoftwareUpgradeTestSuite tests software upgrade protocol end-to-end +func TestSoftwareUpgradeTestSuite(t *testing.T) { + suite.Run(t, new(SoftwareUpgradeCurrentBranchTestSuite)) +} diff --git a/test/e2e/software_upgrade_current_branch_e2e_test.go b/test/e2e/software_upgrade_current_branch_e2e_test.go new file mode 100644 index 000000000..bb319a841 --- /dev/null +++ b/test/e2e/software_upgrade_current_branch_e2e_test.go @@ -0,0 +1,70 @@ +package e2e + +import ( + "github.com/stretchr/testify/suite" + + "github.com/babylonchain/babylon/test/e2e/configurer" +) + +var ( +// r = rand.New(rand.NewSource(time.Now().Unix())) +// net = &chaincfg.SimNetParams +// // finality provider +// fpBTCSK, _, _ = datagen.GenRandomBTCKeyPair(r) +// cacheFP *bstypes.FinalityProvider +// // BTC delegation +// delBTCSK, delBTCPK, _ = datagen.GenRandomBTCKeyPair(r) +// // covenant +// covenantSKs, _, covenantQuorum = bstypes.DefaultCovenantCommittee() + +// stakingValue = int64(2 * 10e8) +) + +const ( + // Mount path in container is fmt.Sprintf("%s/upgrades:/upgrades", pwd) + vanillaUpgradeFilePath = "/upgrades/vanilla.json" +) + +type SoftwareUpgradeCurrentBranchTestSuite struct { + suite.Suite + + configurer configurer.Configurer +} + +func (s *SoftwareUpgradeCurrentBranchTestSuite) SetupSuite() { + s.T().Log("setting up e2e integration test suite...") + var err error + + // The e2e test flow is as follows: + // + // 1. Configure 1 chain with some validator nodes + // 2. Execute various e2e tests + s.configurer, err = configurer.NewSoftwareUpgradeTest(s.T(), true) + s.NoError(err) + err = s.configurer.ConfigureChains() + s.NoError(err) + err = s.configurer.RunSetup() + s.NoError(err) +} + +func (s *SoftwareUpgradeCurrentBranchTestSuite) TearDownSuite() { + err := s.configurer.ClearResources() + s.Require().NoError(err) +} + +// Test1UpgradeVanilla is an end-to-end test for +// running a software upgrade proposal +func (s *SoftwareUpgradeCurrentBranchTestSuite) Test1UpgradeVanilla() { + // chain is already start the chain with software upgrade available + chainA := s.configurer.GetChainConfig(0) + chainA.WaitUntilHeight(1) + + nonValidatorNode, err := chainA.GetNodeAtIndex(2) + s.NoError(err) + + propID := nonValidatorNode.TxGovPropSubmitProposal(vanillaUpgradeFilePath, nonValidatorNode.WalletName) + s.Equal(1, propID) + // run software upgrade gov prop + // waits for block to reach + // verifies if vanilla update was done +} diff --git a/test/e2e/upgrades/vanilla.json b/test/e2e/upgrades/vanilla.json new file mode 100644 index 000000000..2b7f9ad39 --- /dev/null +++ b/test/e2e/upgrades/vanilla.json @@ -0,0 +1,14 @@ +{ + "title": "any title", + "summary": "any summary", + "messages": [ + { + "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", + "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", + "plan": { "name": "vanilla", "info": "Msg info", "height": 14 } + } + ], + "deposit": "500000000ubbn", + "initial_deposit": "500000000ubbn", + "initialDeposit": "500000000ubbn" +} From 67bda21666f673e44191c8bb2c4d39127a667343 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 17:15:40 -0300 Subject: [PATCH 04/10] feat: add query proposals to container CLI --- test/e2e/configurer/chain/queries.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index c0bb049f8..969ef69bb 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -19,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/require" "github.com/babylonchain/babylon/test/e2e/util" @@ -406,6 +407,31 @@ func (n *NodeConfig) QueryWasmSmart(contract string, msg string, result any) err return nil } +func (n *NodeConfig) QueryProposal(proposalNumber int) (govtypesv1.QueryProposalResponse, error) { + path := fmt.Sprintf("cosmos/gov/v1beta1/proposals/%d", proposalNumber) + bz, err := n.QueryGRPCGateway(path, url.Values{}) + require.NoError(n.t, err) + + var resp govtypesv1.QueryProposalResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + if err != nil { + return resp, err + } + + return resp, nil +} + +func (n *NodeConfig) QueryProposals() govtypesv1.QueryProposalsResponse { + bz, err := n.QueryGRPCGateway("cosmos/gov/v1beta1/proposals", url.Values{}) + require.NoError(n.t, err) + + var resp govtypesv1.QueryProposalsResponse + err = util.Cdc.UnmarshalJSON(bz, &resp) + require.NoError(n.t, err) + + return resp +} + func (n *NodeConfig) QueryWasmSmartObject(contract string, msg string) (resultObject map[string]interface{}, err error) { err = n.QueryWasmSmart(contract, msg, &resultObject) if err != nil { From 666a2a38ef66ec899c7c4c011671e8f54934a325 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 17:16:13 -0300 Subject: [PATCH 05/10] feat: add tx gov submit prop in container CLI --- test/e2e/configurer/chain/commands.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/e2e/configurer/chain/commands.go b/test/e2e/configurer/chain/commands.go index 8d8c59b1a..6f4efc165 100644 --- a/test/e2e/configurer/chain/commands.go +++ b/test/e2e/configurer/chain/commands.go @@ -349,6 +349,25 @@ func (n *NodeConfig) TxMultisignBroadcast(walletNameMultisig, txFileFullPath str n.TxBroadcast(signedTxToBroadcast) } +func (n *NodeConfig) TxGovPropSubmitProposal(proposalJsonFilePath, from string, overallFlags ...string) int { + n.LogActionF("submitting new v1 proposal type %s", proposalJsonFilePath) + + cmd := []string{ + "babylond", "tx", "gov", "submit-proposal", proposalJsonFilePath, + fmt.Sprintf("--from=%s", from), + n.FlagChainID(), + } + + _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) + require.NoError(n.t, err) + + n.WaitForNextBlocks(2) + props := n.QueryProposals() + + n.LogActionF("successfully submitted new v1 proposal type") + return int(props.Proposals[len(props.Proposals)-1].ProposalId) +} + // WriteFile writes a new file in the config dir of the node where it is volume mounted to the // babylon home inside the container and returns the full file path inside the container. func (n *NodeConfig) WriteFile(fileName, content string) (fullFilePathInContainer string) { From 22258b1d2685fe45dfd6234938f0198868e02e1a Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 21:40:06 -0300 Subject: [PATCH 06/10] feat: add query for tx debug --- test/e2e/configurer/chain/queries.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index 969ef69bb..8b652181b 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -439,3 +439,19 @@ func (n *NodeConfig) QueryWasmSmartObject(contract string, msg string) (resultOb } return resultObject, nil } + +func (n *NodeConfig) QueryTx(txHash string, overallFlags ...string) sdk.TxResponse { + cmd := []string{ + "babylond", "q", "tx", "--type=hash", txHash, "--output=json", + n.FlagChainID(), + } + + out, _, err := n.containerManager.ExecCmd(n.t, n.Name, append(cmd, overallFlags...), "") + require.NoError(n.t, err) + + var txResp sdk.TxResponse + err = util.Cdc.UnmarshalJSON(out.Bytes(), &txResp) + require.NoError(n.t, err) + + return txResp +} From 8263d1e3c9e7f507af119b3eb0b382ea6b847411 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 21:40:55 -0300 Subject: [PATCH 07/10] fix: set min deposit to ubbn token --- test/e2e/initialization/config.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/e2e/initialization/config.go b/test/e2e/initialization/config.go index 9e5f95a16..a2f282d24 100644 --- a/test/e2e/initialization/config.go +++ b/test/e2e/initialization/config.go @@ -6,7 +6,7 @@ import ( "path/filepath" "time" - "cosmossdk.io/math" + sdkmath "cosmossdk.io/math" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -17,6 +17,8 @@ import ( crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/gogoproto/proto" @@ -67,9 +69,9 @@ const ( ) var ( - StakeAmountIntA = math.NewInt(StakeAmountA) + StakeAmountIntA = sdkmath.NewInt(StakeAmountA) StakeAmountCoinA = sdk.NewCoin(BabylonDenom, StakeAmountIntA) - StakeAmountIntB = math.NewInt(StakeAmountB) + StakeAmountIntB = sdkmath.NewInt(StakeAmountB) StakeAmountCoinB = sdk.NewCoin(BabylonDenom, StakeAmountIntB) InitBalanceStrA = fmt.Sprintf("%d%s", BabylonBalanceA, BabylonDenom) @@ -216,6 +218,11 @@ func initGenesis(chain *internalChain, votingPeriod, expeditedVotingPeriod time. return err } + err = updateModuleGenesis(appGenState, govtypes.ModuleName, &govv1beta1.GenesisState{}, updateGovGenesis) + if err != nil { + return err + } + err = updateModuleGenesis(appGenState, minttypes.ModuleName, &minttypes.GenesisState{}, updateMintGenesis) if err != nil { return err @@ -288,6 +295,10 @@ func updateBankGenesis(bankGenState *banktypes.GenesisState) { }) } +func updateGovGenesis(govGenState *govv1beta1.GenesisState) { + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(BabylonDenom, sdkmath.NewInt(100))) +} + func updateMintGenesis(mintGenState *minttypes.GenesisState) { mintGenState.Params.MintDenom = BabylonDenom } @@ -299,7 +310,7 @@ func updateStakeGenesis(stakeGenState *staketypes.GenesisState) { MaxEntries: 7, HistoricalEntries: 10000, UnbondingTime: staketypes.DefaultUnbondingTime, - MinCommissionRate: math.LegacyZeroDec(), + MinCommissionRate: sdkmath.LegacyZeroDec(), } } From 5e9d937078051027fc62bb690b5d5111c1063148 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 22:41:13 -0300 Subject: [PATCH 08/10] fix: set gov prop time in genstate gov --- test/e2e/configurer/chain/node.go | 9 +++++++++ test/e2e/initialization/config.go | 11 +++++++---- test/e2e/upgrades/vanilla.json | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index 8e185ec51..162bdeb31 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -153,6 +153,15 @@ func (n *NodeConfig) WaitForNextBlocks(numberOfBlocks uint64) { }, fmt.Sprintf("Timed out waiting for block %d. Current height is: %d", latest, blockToWait)) } +func (n *NodeConfig) WaitForBlockHeight(blkHeight uint64) { + latest := n.LatestBlockNumber() + if blkHeight < latest { + return + } + blocksToWait := blkHeight - latest + n.WaitForNextBlocks(blocksToWait) +} + func (n *NodeConfig) extractOperatorAddressIfValidator() error { if !n.IsValidator { n.t.Logf("node (%s) is not a validator, skipping", n.Name) diff --git a/test/e2e/initialization/config.go b/test/e2e/initialization/config.go index a2f282d24..9af54728e 100644 --- a/test/e2e/initialization/config.go +++ b/test/e2e/initialization/config.go @@ -18,7 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/cosmos/gogoproto/proto" @@ -218,7 +218,7 @@ func initGenesis(chain *internalChain, votingPeriod, expeditedVotingPeriod time. return err } - err = updateModuleGenesis(appGenState, govtypes.ModuleName, &govv1beta1.GenesisState{}, updateGovGenesis) + err = updateModuleGenesis(appGenState, govtypes.ModuleName, &govv1.GenesisState{}, updateGovGenesis) if err != nil { return err } @@ -295,8 +295,11 @@ func updateBankGenesis(bankGenState *banktypes.GenesisState) { }) } -func updateGovGenesis(govGenState *govv1beta1.GenesisState) { - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(BabylonDenom, sdkmath.NewInt(100))) +func updateGovGenesis(govGenState *govv1.GenesisState) { + govGenState.Params.MinDeposit = sdk.NewCoins(sdk.NewCoin(BabylonDenom, sdkmath.NewInt(100))) + + votingPeriod := time.Duration(time.Second * 10) + govGenState.Params.VotingPeriod = &votingPeriod } func updateMintGenesis(mintGenState *minttypes.GenesisState) { diff --git a/test/e2e/upgrades/vanilla.json b/test/e2e/upgrades/vanilla.json index 2b7f9ad39..674846739 100644 --- a/test/e2e/upgrades/vanilla.json +++ b/test/e2e/upgrades/vanilla.json @@ -5,7 +5,7 @@ { "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", - "plan": { "name": "vanilla", "info": "Msg info", "height": 14 } + "plan": { "name": "vanilla", "info": "Msg info", "height": 10 } } ], "deposit": "500000000ubbn", From de2aae7a10454e703aca011395dba24cb7fa26ec Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 22:43:15 -0300 Subject: [PATCH 09/10] chore: add vote to gov prop --- test/e2e/configurer/chain/chain.go | 11 +++++++- test/e2e/configurer/chain/commands.go | 23 ++++++++++++++-- ...oftware_upgrade_current_branch_e2e_test.go | 27 +++++++------------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/test/e2e/configurer/chain/chain.go b/test/e2e/configurer/chain/chain.go index 4d5e1ec03..2c16e9f4b 100644 --- a/test/e2e/configurer/chain/chain.go +++ b/test/e2e/configurer/chain/chain.go @@ -2,10 +2,12 @@ package chain import ( "fmt" - ibctesting "github.com/cosmos/ibc-go/v8/testing" "testing" "time" + govv1 "cosmossdk.io/api/cosmos/gov/v1" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + coretypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" @@ -173,3 +175,10 @@ func (c *Config) GetNodeAtIndex(nodeIndex int) (*NodeConfig, error) { } return c.NodeConfigs[nodeIndex], nil } + +// TxGovVoteFromAllNodes votes in a gov prop from all nodes wallet. +func (c *Config) TxGovVoteFromAllNodes(propID int, option govv1.VoteOption, overallFlags ...string) { + for _, n := range c.NodeConfigs { + n.TxGovVote(n.WalletName, propID, option, overallFlags...) + } +} diff --git a/test/e2e/configurer/chain/commands.go b/test/e2e/configurer/chain/commands.go index 6f4efc165..2922f5959 100644 --- a/test/e2e/configurer/chain/commands.go +++ b/test/e2e/configurer/chain/commands.go @@ -12,6 +12,7 @@ import ( "strings" "time" + govv1 "cosmossdk.io/api/cosmos/gov/v1" txformat "github.com/babylonchain/babylon/btctxformatter" "github.com/babylonchain/babylon/test/e2e/containers" "github.com/babylonchain/babylon/test/e2e/initialization" @@ -349,25 +350,43 @@ func (n *NodeConfig) TxMultisignBroadcast(walletNameMultisig, txFileFullPath str n.TxBroadcast(signedTxToBroadcast) } +// TxGovPropSubmitProposal submits a governance proposal from the file inside the container, +// if the file is local, remind to add it to the mounting point in container. func (n *NodeConfig) TxGovPropSubmitProposal(proposalJsonFilePath, from string, overallFlags ...string) int { n.LogActionF("submitting new v1 proposal type %s", proposalJsonFilePath) cmd := []string{ "babylond", "tx", "gov", "submit-proposal", proposalJsonFilePath, fmt.Sprintf("--from=%s", from), - n.FlagChainID(), } _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) require.NoError(n.t, err) - n.WaitForNextBlocks(2) + n.WaitForNextBlock() + props := n.QueryProposals() + require.GreaterOrEqual(n.t, len(props.Proposals), 1) n.LogActionF("successfully submitted new v1 proposal type") return int(props.Proposals[len(props.Proposals)-1].ProposalId) } +// TxGovVote votes in a governance proposal +func (n *NodeConfig) TxGovVote(from string, propID int, option govv1.VoteOption, overallFlags ...string) { + n.LogActionF("submitting vote %s to prop %d", option, propID) + + cmd := []string{ + "babylond", "tx", "gov", "vote", string(propID), option.String(), + fmt.Sprintf("--from=%s", from), + } + + _, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, append(cmd, overallFlags...)) + require.NoError(n.t, err) + + n.LogActionF("successfully submitted vote %s to prop %d", option, propID) +} + // WriteFile writes a new file in the config dir of the node where it is volume mounted to the // babylon home inside the container and returns the full file path inside the container. func (n *NodeConfig) WriteFile(fileName, content string) (fullFilePathInContainer string) { diff --git a/test/e2e/software_upgrade_current_branch_e2e_test.go b/test/e2e/software_upgrade_current_branch_e2e_test.go index bb319a841..731033bc9 100644 --- a/test/e2e/software_upgrade_current_branch_e2e_test.go +++ b/test/e2e/software_upgrade_current_branch_e2e_test.go @@ -1,25 +1,12 @@ package e2e import ( + govv1 "cosmossdk.io/api/cosmos/gov/v1" "github.com/stretchr/testify/suite" "github.com/babylonchain/babylon/test/e2e/configurer" ) -var ( -// r = rand.New(rand.NewSource(time.Now().Unix())) -// net = &chaincfg.SimNetParams -// // finality provider -// fpBTCSK, _, _ = datagen.GenRandomBTCKeyPair(r) -// cacheFP *bstypes.FinalityProvider -// // BTC delegation -// delBTCSK, delBTCPK, _ = datagen.GenRandomBTCKeyPair(r) -// // covenant -// covenantSKs, _, covenantQuorum = bstypes.DefaultCovenantCommittee() - -// stakingValue = int64(2 * 10e8) -) - const ( // Mount path in container is fmt.Sprintf("%s/upgrades:/upgrades", pwd) vanillaUpgradeFilePath = "/upgrades/vanilla.json" @@ -62,9 +49,15 @@ func (s *SoftwareUpgradeCurrentBranchTestSuite) Test1UpgradeVanilla() { nonValidatorNode, err := chainA.GetNodeAtIndex(2) s.NoError(err) + // software upgrade gov prop propID := nonValidatorNode.TxGovPropSubmitProposal(vanillaUpgradeFilePath, nonValidatorNode.WalletName) s.Equal(1, propID) - // run software upgrade gov prop - // waits for block to reach - // verifies if vanilla update was done + + // vote from all nodes + chainA.TxGovVoteFromAllNodes(propID, govv1.VoteOption_VOTE_OPTION_YES) + + // waits for block to reach + 1 + nonValidatorNode.WaitForBlockHeight(11) + + // verifies vanilla upgrade was completed } From 3cd33d4550292dc01132d583d4b45dd30df1e1a1 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 22 Jul 2024 23:16:19 -0300 Subject: [PATCH 10/10] test: upgrade fails due to BINARY UPDATED BEFORE TRIGGER --- test/e2e/configurer/chain/commands.go | 2 +- test/e2e/configurer/chain/node.go | 10 +++---- test/e2e/configurer/chain/queries.go | 8 +++--- test/e2e/e2e_test.go | 4 +-- ...oftware_upgrade_current_branch_e2e_test.go | 26 +++++++++++++++++-- test/e2e/upgrades/vanilla.json | 2 +- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/test/e2e/configurer/chain/commands.go b/test/e2e/configurer/chain/commands.go index 2922f5959..bb789ec4b 100644 --- a/test/e2e/configurer/chain/commands.go +++ b/test/e2e/configurer/chain/commands.go @@ -377,7 +377,7 @@ func (n *NodeConfig) TxGovVote(from string, propID int, option govv1.VoteOption, n.LogActionF("submitting vote %s to prop %d", option, propID) cmd := []string{ - "babylond", "tx", "gov", "vote", string(propID), option.String(), + "babylond", "tx", "gov", "vote", fmt.Sprintf("%d", propID), option.String(), fmt.Sprintf("--from=%s", from), } diff --git a/test/e2e/configurer/chain/node.go b/test/e2e/configurer/chain/node.go index 162bdeb31..2a8f1ccd5 100644 --- a/test/e2e/configurer/chain/node.go +++ b/test/e2e/configurer/chain/node.go @@ -154,12 +154,10 @@ func (n *NodeConfig) WaitForNextBlocks(numberOfBlocks uint64) { } func (n *NodeConfig) WaitForBlockHeight(blkHeight uint64) { - latest := n.LatestBlockNumber() - if blkHeight < latest { - return - } - blocksToWait := blkHeight - latest - n.WaitForNextBlocks(blocksToWait) + n.WaitForCondition(func() bool { + newLatest := n.LatestBlockNumber() + return newLatest > blkHeight + }, fmt.Sprintf("Timed out waiting for block %d.", blkHeight)) } func (n *NodeConfig) extractOperatorAddressIfValidator() error { diff --git a/test/e2e/configurer/chain/queries.go b/test/e2e/configurer/chain/queries.go index 8b652181b..f7b2c9cb5 100644 --- a/test/e2e/configurer/chain/queries.go +++ b/test/e2e/configurer/chain/queries.go @@ -407,18 +407,16 @@ func (n *NodeConfig) QueryWasmSmart(contract string, msg string, result any) err return nil } -func (n *NodeConfig) QueryProposal(proposalNumber int) (govtypesv1.QueryProposalResponse, error) { +func (n *NodeConfig) QueryProposal(proposalNumber int) govtypesv1.QueryProposalResponse { path := fmt.Sprintf("cosmos/gov/v1beta1/proposals/%d", proposalNumber) bz, err := n.QueryGRPCGateway(path, url.Values{}) require.NoError(n.t, err) var resp govtypesv1.QueryProposalResponse err = util.Cdc.UnmarshalJSON(bz, &resp) - if err != nil { - return resp, err - } + require.NoError(n.t, err) - return resp, nil + return resp } func (n *NodeConfig) QueryProposals() govtypesv1.QueryProposalsResponse { diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index d27b66acf..0eb9240dd 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -36,7 +36,7 @@ func TestBTCStakingTestSuite(t *testing.T) { suite.Run(t, new(BTCStakingTestSuite)) } -// TestSoftwareUpgradeTestSuite tests software upgrade protocol end-to-end -func TestSoftwareUpgradeTestSuite(t *testing.T) { +// TestSoftwareUpgradeCurrentBranchTestSuite tests software upgrade protocol end-to-end +func TestSoftwareUpgradeCurrentBranchTestSuite(t *testing.T) { suite.Run(t, new(SoftwareUpgradeCurrentBranchTestSuite)) } diff --git a/test/e2e/software_upgrade_current_branch_e2e_test.go b/test/e2e/software_upgrade_current_branch_e2e_test.go index 731033bc9..298285437 100644 --- a/test/e2e/software_upgrade_current_branch_e2e_test.go +++ b/test/e2e/software_upgrade_current_branch_e2e_test.go @@ -1,6 +1,8 @@ package e2e import ( + "fmt" + govv1 "cosmossdk.io/api/cosmos/gov/v1" "github.com/stretchr/testify/suite" @@ -49,6 +51,8 @@ func (s *SoftwareUpgradeCurrentBranchTestSuite) Test1UpgradeVanilla() { nonValidatorNode, err := chainA.GetNodeAtIndex(2) s.NoError(err) + fpsBeforeUpgrade := nonValidatorNode.QueryFinalityProviders() + // software upgrade gov prop propID := nonValidatorNode.TxGovPropSubmitProposal(vanillaUpgradeFilePath, nonValidatorNode.WalletName) s.Equal(1, propID) @@ -56,8 +60,26 @@ func (s *SoftwareUpgradeCurrentBranchTestSuite) Test1UpgradeVanilla() { // vote from all nodes chainA.TxGovVoteFromAllNodes(propID, govv1.VoteOption_VOTE_OPTION_YES) - // waits for block to reach + 1 - nonValidatorNode.WaitForBlockHeight(11) + tx := nonValidatorNode.QueryProposal(propID) + fmt.Printf("\n prop %+v", tx) + + // waits for block to reach from plan + 1 + // tricky to get current heigth and set it in the json, because the file is + // load at the mounting point of the node it could be created at runtime and + // stored in the filesystem of the container + nonValidatorNode.WaitForBlockHeight(21) + + tx = nonValidatorNode.QueryProposal(propID) + fmt.Printf("\n prop %+v", tx) // verifies vanilla upgrade was completed + fpsAfterUpgrade := nonValidatorNode.QueryFinalityProviders() + s.Equal(len(fpsBeforeUpgrade)+1, len(fpsAfterUpgrade)) + + // docker logs -f + // 2:09AM ERR BINARY UPDATED BEFORE TRIGGER! UPGRADE "vanilla" - in binary but not executed on chain. Downgrade your binary module=x/upgrade + // 2:09AM ERR error in proxyAppConn.FinalizeBlock err="BINARY UPDATED BEFORE TRIGGER! UPGRADE \"vanilla\" - in binary but not executed on chain. Downgrade your binary" module=state + tx = nonValidatorNode.QueryProposal(propID) + fmt.Printf("\n prop %+v", tx) + } diff --git a/test/e2e/upgrades/vanilla.json b/test/e2e/upgrades/vanilla.json index 674846739..c9fd6c9d3 100644 --- a/test/e2e/upgrades/vanilla.json +++ b/test/e2e/upgrades/vanilla.json @@ -5,7 +5,7 @@ { "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", - "plan": { "name": "vanilla", "info": "Msg info", "height": 10 } + "plan": { "name": "vanilla", "info": "Msg info", "height": 20 } } ], "deposit": "500000000ubbn",