From 93fc9d83cdf6303b2efe8a2063845b7c11b0f42c Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 12:27:21 -0300 Subject: [PATCH 1/6] chore: remove vanilla upgrade --- .github/workflows/ci.yml | 41 ------- Makefile | 3 - app/e2e_include_upgrades.go | 3 +- app/upgrades/vanilla/README.md | 4 - app/upgrades/vanilla/upgrades.go | 97 ---------------- app/upgrades/vanilla/upgrades_test.go | 105 ------------------ contrib/images/Makefile | 2 +- test/e2e/configurer/config/constants.go | 1 - test/e2e/e2e_test.go | 5 - test/e2e/software_upgrade_e2e_vanilla_test.go | 53 --------- test/e2e/upgrades/vanilla.json | 14 --- 11 files changed, 2 insertions(+), 326 deletions(-) delete mode 100644 app/upgrades/vanilla/README.md delete mode 100644 app/upgrades/vanilla/upgrades.go delete mode 100644 app/upgrades/vanilla/upgrades_test.go delete mode 100644 test/e2e/software_upgrade_e2e_vanilla_test.go delete mode 100644 test/e2e/upgrades/vanilla.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b301b791a..0bffc4f3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -213,47 +213,6 @@ jobs: run: | make test-e2e-cache-btc-staking - e2e-run-upgrade-vanilla: - needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain] - runs-on: ubuntu-22.04 - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Download babylon artifact - uses: actions/download-artifact@v4 - with: - name: babylond-${{ github.sha }} - path: /tmp - - name: Download babylond-before-upgrade artifact - uses: actions/download-artifact@v4 - with: - name: babylond-before-upgrade - path: /tmp - - name: Download init-chain artifact - uses: actions/download-artifact@v4 - with: - name: init-chain - path: /tmp - - name: Docker load babylond - run: | - docker load < /tmp/docker-babylond.tar.gz - - - name: Docker load babylond-before-upgrade - run: | - docker load < /tmp/docker-babylond-before-upgrade.tar.gz - - - name: Docker load init chain - run: | - docker load < /tmp/docker-init-chain.tar.gz - - - name: Cache Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - name: Run e2e TestSoftwareUpgradeTestSuite - run: | - sudo make test-e2e-cache-upgrade-vanilla - e2e-run-upgrade-signet: needs: [e2e-docker-build-babylon, e2e-docker-build-babylon-before-upgrade, e2e-docker-build-e2e-init-chain] runs-on: ubuntu-22.04 diff --git a/Makefile b/Makefile index d1105b12a..cb948bb78 100644 --- a/Makefile +++ b/Makefile @@ -274,9 +274,6 @@ test-e2e-cache-btc-timestamping-phase-2-rly: test-e2e-cache-btc-staking: go test -run TestBTCStakingTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e -test-e2e-cache-upgrade-vanilla: - go test -run TestSoftwareUpgradeTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e - test-e2e-cache-upgrade-signet: go test -run TestSoftwareUpgradeSignetLaunchTestSuite -mod=readonly -timeout=60m -v $(PACKAGES_E2E) --tags=e2e diff --git a/app/e2e_include_upgrades.go b/app/e2e_include_upgrades.go index 75e5d89de..d709c20bd 100644 --- a/app/e2e_include_upgrades.go +++ b/app/e2e_include_upgrades.go @@ -4,9 +4,8 @@ package app import ( "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" - "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" ) func init() { - Upgrades = append(Upgrades, vanilla.Upgrade, signetlaunch.Upgrade) + Upgrades = append(Upgrades, signetlaunch.Upgrade) } diff --git a/app/upgrades/vanilla/README.md b/app/upgrades/vanilla/README.md deleted file mode 100644 index 3909ea3f3..000000000 --- a/app/upgrades/vanilla/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# vanilla - -This folder contains a vanilla software upgrade for testing purposes. -DO NOT USE IN PRODUCTION! diff --git a/app/upgrades/vanilla/upgrades.go b/app/upgrades/vanilla/upgrades.go deleted file mode 100644 index 99522243e..000000000 --- a/app/upgrades/vanilla/upgrades.go +++ /dev/null @@ -1,97 +0,0 @@ -// This code is only for testing purposes. -// DO NOT USE IN PRODUCTION! - -package vanilla - -import ( - "context" - - store "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/babylonlabs-io/babylon/app/keepers" - "github.com/babylonlabs-io/babylon/app/upgrades" - bbn "github.com/babylonlabs-io/babylon/types" - btcstakingkeeper "github.com/babylonlabs-io/babylon/x/btcstaking/keeper" - bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - "github.com/btcsuite/btcd/btcec/v2" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: "vanilla", - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: store.StoreUpgrades{}, -} - -func CreateUpgradeHandler( - mm *module.Manager, - cfg module.Configurator, - _ upgrades.BaseAppParamManager, - keepers *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(context context.Context, _plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx := sdk.UnwrapSDKContext(context) - - migrations, err := mm.RunMigrations(ctx, cfg, fromVM) - if err != nil { - return nil, err - } - - propVanilla(ctx, &keepers.AccountKeeper, &keepers.BTCStakingKeeper) - - return migrations, nil - } -} - -func propVanilla( - ctx sdk.Context, - accountKeeper *authkeeper.AccountKeeper, - bsKeeper *btcstakingkeeper.Keeper, -) { - // remove the account with higher number and the lowest is the new fp addr - allAccounts := accountKeeper.GetAllAccounts(ctx) - var ( - accToRemove sdk.AccountI - accFp sdk.AccountI - ) - heighestAccNumber, lowestAccNumber := uint64(0), uint64(len(allAccounts)) - - for _, acc := range allAccounts { - accNumber := acc.GetAccountNumber() - if accNumber > heighestAccNumber { - heighestAccNumber = accNumber - accToRemove = acc - } - if accNumber < lowestAccNumber { - lowestAccNumber = accNumber - accFp = acc - } - } - - accountKeeper.RemoveAccount(ctx, accToRemove) - - // insert a FP from predefined public key - pk, err := btcec.ParsePubKey( - []byte{0x06, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, - 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, - 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, - 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, - 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, - 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, 0x48, - 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, 0x8f, 0xfb, - 0x10, 0xd4, 0xb8, - }, - ) - if err != nil { - panic(err) - } - - btcPK := bbn.NewBIP340PubKeyFromBTCPK(pk) - fp := &bstypes.FinalityProvider{ - Addr: accFp.GetAddress().String(), - BtcPk: btcPK, - } - bsKeeper.SetFinalityProvider(ctx, fp) -} diff --git a/app/upgrades/vanilla/upgrades_test.go b/app/upgrades/vanilla/upgrades_test.go deleted file mode 100644 index 19511629f..000000000 --- a/app/upgrades/vanilla/upgrades_test.go +++ /dev/null @@ -1,105 +0,0 @@ -package vanilla_test - -import ( - "fmt" - "testing" - "time" - - "cosmossdk.io/core/appmodule" - "cosmossdk.io/core/header" - "cosmossdk.io/x/upgrade" - upgradetypes "cosmossdk.io/x/upgrade/types" - "github.com/babylonlabs-io/babylon/app" - v1 "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" - bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/suite" -) - -const ( - DummyUpgradeHeight = 5 -) - -type UpgradeTestSuite struct { - suite.Suite - - ctx sdk.Context - app *app.BabylonApp - preModule appmodule.HasPreBlocker -} - -func (s *UpgradeTestSuite) SetupTest() { - // add the upgrade plan - app.Upgrades = append(app.Upgrades, v1.Upgrade) - - // set up app - s.app = app.Setup(s.T(), false) - s.ctx = s.app.BaseApp.NewContextLegacy(false, tmproto.Header{Height: 1, ChainID: "babylon-1", Time: time.Now().UTC()}) - s.preModule = upgrade.NewAppModule(s.app.UpgradeKeeper, s.app.AccountKeeper.AddressCodec()) -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(UpgradeTestSuite)) -} - -func (s *UpgradeTestSuite) TestUpgradePayments() { - oldAcctNum := 0 - - testCases := []struct { - msg string - pre_update func() - update func() - post_update func() - expPass bool - }{ - { - "Test vanilla software upgrade gov prop", - func() { - allAccounts := s.app.AccountKeeper.GetAllAccounts(s.ctx) - oldAcctNum = len(allAccounts) - }, - func() { - // inject upgrade plan - s.ctx = s.ctx.WithBlockHeight(DummyUpgradeHeight - 1) - plan := upgradetypes.Plan{Name: v1.Upgrade.UpgradeName, Height: DummyUpgradeHeight} - err := s.app.UpgradeKeeper.ScheduleUpgrade(s.ctx, plan) - s.NoError(err) - - // ensure upgrade plan exists - actualPlan, err := s.app.UpgradeKeeper.GetUpgradePlan(s.ctx) - s.NoError(err) - s.Equal(plan, actualPlan) - - // execute upgrade - s.ctx = s.ctx.WithHeaderInfo(header.Info{Height: DummyUpgradeHeight, Time: s.ctx.BlockTime().Add(time.Second)}).WithBlockHeight(DummyUpgradeHeight) - s.NotPanics(func() { - _, err := s.preModule.PreBlock(s.ctx) - s.NoError(err) - }) - }, - func() { - // ensure the account is removed - allAccounts := s.app.AccountKeeper.GetAllAccounts(s.ctx) - newAcctNum := len(allAccounts) - s.Equal(newAcctNum, oldAcctNum-1) - - // ensure finality provider is inserted - resp, err := s.app.BTCStakingKeeper.FinalityProviders(s.ctx, &bstypes.QueryFinalityProvidersRequest{}) - s.NoError(err) - s.Len(resp.FinalityProviders, 1) - }, - true, - }, - } - - for _, tc := range testCases { - s.Run(fmt.Sprintf("Case %s", tc.msg), func() { - s.SetupTest() // reset - - tc.pre_update() - tc.update() - tc.post_update() - }) - } -} diff --git a/contrib/images/Makefile b/contrib/images/Makefile index 47febc890..1c0260999 100644 --- a/contrib/images/Makefile +++ b/contrib/images/Makefile @@ -1,6 +1,6 @@ RELAYER_TAG := $(shell grep '^ENV RELAYER_TAG' cosmos-relayer/Dockerfile | cut -f3 -d\ ) BABYLON_FULL_PATH := $(shell git rev-parse --show-toplevel) -BABYLON_VERSION_BEFORE_UPGRADE ?= v0.9.0 +BABYLON_VERSION_BEFORE_UPGRADE ?= v0.9.1 all: babylond cosmos-relayer diff --git a/test/e2e/configurer/config/constants.go b/test/e2e/configurer/config/constants.go index 75a5815c5..af9e03e6e 100644 --- a/test/e2e/configurer/config/constants.go +++ b/test/e2e/configurer/config/constants.go @@ -16,6 +16,5 @@ const ( // PropSubmitBlocks estimated number of blocks it takes to submit for a proposal PropSubmitBlocks float32 = 1 // Upgrade prop files json - UpgradeVanillaFilePath = "/upgrades/vanilla.json" UpgradeSignetLaunchFilePath = "/upgrades/signet-launch.json" ) diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 801e6d511..d5096131f 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -36,11 +36,6 @@ 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(SoftwareUpgradeVanillaTestSuite)) -} - // TestSoftwareUpgradeSignetLaunchTestSuite tests software upgrade of signet launch end-to-end func TestSoftwareUpgradeSignetLaunchTestSuite(t *testing.T) { suite.Run(t, new(SoftwareUpgradeSignetLaunchTestSuite)) diff --git a/test/e2e/software_upgrade_e2e_vanilla_test.go b/test/e2e/software_upgrade_e2e_vanilla_test.go deleted file mode 100644 index 5dba61c1f..000000000 --- a/test/e2e/software_upgrade_e2e_vanilla_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package e2e - -import ( - "github.com/stretchr/testify/suite" - - v1 "github.com/babylonlabs-io/babylon/app/upgrades/vanilla" - "github.com/babylonlabs-io/babylon/test/e2e/configurer" - "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" -) - -type SoftwareUpgradeVanillaTestSuite struct { - suite.Suite - - configurer configurer.Configurer -} - -func (s *SoftwareUpgradeVanillaTestSuite) SetupSuite() { - s.T().Log("setting up e2e integration test suite...") - var err error - - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeVanillaFilePath, nil) - s.NoError(err) - err = s.configurer.ConfigureChains() - s.NoError(err) - err = s.configurer.RunSetup() // upgrade happens at the setup of configurer. - s.NoError(err) -} - -func (s *SoftwareUpgradeVanillaTestSuite) TearDownSuite() { - err := s.configurer.ClearResources() - if err != nil { - s.T().Logf("error to clear resources %s", err.Error()) - } -} - -// TestUpgradeVanilla only checks that new fp was added. -func (s *SoftwareUpgradeVanillaTestSuite) TestUpgradeVanilla() { - // chain is already upgraded, only checks for differences in state are expected - chainA := s.configurer.GetChainConfig(0) - chainA.WaitUntilHeight(30) // five blocks more than upgrade - - n, err := chainA.GetDefaultNode() - s.NoError(err) - - expectedUpgradeHeight := int64(25) - - // makes sure that the upgrade was actually executed - resp := n.QueryAppliedPlan(v1.Upgrade.UpgradeName) - s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") - - fps := n.QueryFinalityProviders() - s.Len(fps, 1, "it should have one finality provider, since the vanilla upgrade just added a new one") -} diff --git a/test/e2e/upgrades/vanilla.json b/test/e2e/upgrades/vanilla.json deleted file mode 100644 index 7461f0b22..000000000 --- a/test/e2e/upgrades/vanilla.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "title": "any title", - "summary": "any summary", - "messages": [ - { - "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", - "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", - "plan": { "name": "vanilla", "info": "Msg info", "height": 25 } - } - ], - "deposit": "500000000ubbn", - "initial_deposit": "500000000ubbn", - "initialDeposit": "500000000ubbn" -} \ No newline at end of file From 6ea859b034f84c6a0bac833ff91163a0464fcb39 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 14:43:48 -0300 Subject: [PATCH 2/6] chore: e2e upgrade read height from proposal file --- test/e2e/configurer/upgrade.go | 83 ++++++++++++++++++- test/e2e/configurer/upgrade_test.go | 24 ++++++ ...software_upgrade_e2e_signet_launch_test.go | 19 +++-- test/e2e/upgrades/signet-launch.json | 4 +- 4 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 test/e2e/configurer/upgrade_test.go diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 1218f242b..815fc7a49 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -4,14 +4,18 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "sync" "testing" "time" govv1 "cosmossdk.io/api/cosmos/gov/v1" sdkmath "cosmossdk.io/math" + upgradetypes "cosmossdk.io/x/upgrade/types" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/babylonlabs-io/babylon/app" appparams "github.com/babylonlabs-io/babylon/app/params" "github.com/babylonlabs-io/babylon/test/e2e/configurer/chain" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" @@ -196,9 +200,13 @@ func (uc *UpgradeConfigurer) runProposalUpgrade() error { // } // TODO: need to make a way to update proposal height // chainConfig.UpgradePropHeight = currentHeight + int64(chainConfig.VotingPeriod) + int64(config.PropSubmitBlocks) + int64(config.PropBufferBlocks) - chainConfig.UpgradePropHeight = 25 // at least read from the prop plan file - propID := node.TxGovPropSubmitProposal(uc.upgradeJsonFilePath, node.WalletName) + msgProp, err := uc.ParseGovPropFromFile() + if err != nil { + return err + } + chainConfig.UpgradePropHeight = msgProp.Plan.Height + propID := node.TxGovPropSubmitProposal(uc.upgradeJsonFilePath, node.WalletName) chainConfig.TxGovVoteFromAllNodes(propID, govv1.VoteOption_VOTE_OPTION_YES) } @@ -252,3 +260,74 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe uc.t.Logf("upgrade successful on chain %s", chainConfig.Id) return nil } + +// ParseGovPropFromFile loads the proposal from the UpgradeSignetLaunchFilePath +func (uc *UpgradeConfigurer) ParseGovPropFromFile() (*upgradetypes.MsgSoftwareUpgrade, error) { + pwd, err := os.Getwd() + if err != nil { + return nil, err + } + + upgradePath := filepath.Join(pwd, uc.upgradeJsonFilePath) + return ParseGovPropFromFile(upgradePath) +} + +// ParseGovPropFromFile loads from the file the Upgrade msg. +func ParseGovPropFromFile(propFilePath string) (*upgradetypes.MsgSoftwareUpgrade, error) { + _, msgs, _, err := parseSubmitProposal(app.NewTmpBabylonApp().AppCodec(), propFilePath) + if err != nil { + return nil, err + } + + upgradeMsg, ok := msgs[0].(*upgradetypes.MsgSoftwareUpgrade) + if !ok { + return nil, fmt.Errorf("unable to parse msg to upgradetypes.MsgSoftwareUpgrade") + } + return upgradeMsg, nil +} + +// Copy from https://github.com/cosmos/cosmos-sdk/blob/4251905d56e0e7a3350145beedceafe786953295/x/gov/client/cli/util.go#L83 +// Not exported structure and file +// proposal defines the new Msg-based proposal. +type proposal struct { + // Msgs defines an array of sdk.Msgs proto-JSON-encoded as Anys. + Messages []json.RawMessage `json:"messages,omitempty"` + Metadata string `json:"metadata"` + Deposit string `json:"deposit"` + Title string `json:"title"` + Summary string `json:"summary"` + Expedited bool `json:"expedited"` +} + +// parseSubmitProposal reads and parses the proposal. +func parseSubmitProposal(cdc codec.Codec, path string) (proposal, []sdk.Msg, sdk.Coins, error) { + var proposal proposal + + contents, err := os.ReadFile(path) + if err != nil { + return proposal, nil, nil, err + } + + err = json.Unmarshal(contents, &proposal) + if err != nil { + return proposal, nil, nil, err + } + + msgs := make([]sdk.Msg, len(proposal.Messages)) + for i, anyJSON := range proposal.Messages { + var msg sdk.Msg + err := cdc.UnmarshalInterfaceJSON(anyJSON, &msg) + if err != nil { + return proposal, nil, nil, err + } + + msgs[i] = msg + } + + deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit) + if err != nil { + return proposal, nil, nil, err + } + + return proposal, msgs, deposit, nil +} diff --git a/test/e2e/configurer/upgrade_test.go b/test/e2e/configurer/upgrade_test.go new file mode 100644 index 000000000..e8015ce12 --- /dev/null +++ b/test/e2e/configurer/upgrade_test.go @@ -0,0 +1,24 @@ +package configurer_test + +import ( + "os" + "path/filepath" + "testing" + + v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" + "github.com/babylonlabs-io/babylon/test/e2e/configurer" + "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" + "github.com/stretchr/testify/require" +) + +func TestParseGovPropFromFile(t *testing.T) { + pwd, err := os.Getwd() + require.NoError(t, err) + upgradePath := filepath.Join(pwd, "../", config.UpgradeSignetLaunchFilePath) + + prop, err := configurer.ParseGovPropFromFile(upgradePath) + require.NoError(t, err) + + require.Equal(t, prop.Plan.Name, v1.Upgrade.UpgradeName) + require.Equal(t, prop.Plan.Height, int64(25)) +} diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index 96c85980c..f0db79694 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -14,7 +14,7 @@ import ( type SoftwareUpgradeSignetLaunchTestSuite struct { suite.Suite - configurer configurer.Configurer + configurer *configurer.UpgradeConfigurer } func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { @@ -23,17 +23,22 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { btcHeaderGenesis, err := app.SignetBtcHeaderGenesis(app.NewTmpBabylonApp().AppCodec()) s.NoError(err) - s.configurer, err = configurer.NewSoftwareUpgradeConfigurer(s.T(), false, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderGenesis}) + + cfg, err := configurer.NewSoftwareUpgradeConfigurer(s.T(), true, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderGenesis}) s.NoError(err) + s.configurer = cfg.(*configurer.UpgradeConfigurer) + err = s.configurer.ConfigureChains() s.NoError(err) err = s.configurer.RunSetup() // upgrade happens at the setup of configurer. - s.NoError(err) + s.Require().NoError(err) } func (s *SoftwareUpgradeSignetLaunchTestSuite) TearDownSuite() { err := s.configurer.ClearResources() - s.Require().NoError(err) + if err != nil { + s.T().Logf("error to clear resources %s", err.Error()) + } } // TestUpgradeSignetLaunch Checks if the BTC Headers were inserted. @@ -45,11 +50,13 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) TestUpgradeSignetLaunch() { n, err := chainA.GetDefaultNode() s.NoError(err) - expectedUpgradeHeight := int64(25) + govProp, err := s.configurer.ParseGovPropFromFile() + s.NoError(err) // makes sure that the upgrade was actually executed + expectedUpgradeHeight := govProp.Plan.Height resp := n.QueryAppliedPlan(v1.Upgrade.UpgradeName) - s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height 25") + s.EqualValues(expectedUpgradeHeight, resp.Height, "the plan should be applied at the height %d", expectedUpgradeHeight) btcHeadersInserted, err := v1.LoadBTCHeadersFromData() s.NoError(err) diff --git a/test/e2e/upgrades/signet-launch.json b/test/e2e/upgrades/signet-launch.json index de4638b31..4c2387c5a 100644 --- a/test/e2e/upgrades/signet-launch.json +++ b/test/e2e/upgrades/signet-launch.json @@ -8,7 +8,5 @@ "plan": { "name": "signet-launch", "info": "Msg info", "height": 25 } } ], - "deposit": "500000000ubbn", - "initial_deposit": "500000000ubbn", - "initialDeposit": "500000000ubbn" + "deposit": "500000000ubbn" } \ No newline at end of file From 120c88298fcbb24877a42aa44fb8e4d2de4f8227 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 22:32:13 -0300 Subject: [PATCH 3/6] chore: e2e upgrade write height to proposal file accordingly with the chain config setup --- test/e2e/configurer/config/constants.go | 4 +- test/e2e/configurer/upgrade.go | 82 ++++++++++++++++++++----- test/e2e/configurer/upgrade_test.go | 40 ++++++++++-- test/e2e/upgrades/signet-launch.json | 16 +++-- 4 files changed, 115 insertions(+), 27 deletions(-) diff --git a/test/e2e/configurer/config/constants.go b/test/e2e/configurer/config/constants.go index af9e03e6e..685866478 100644 --- a/test/e2e/configurer/config/constants.go +++ b/test/e2e/configurer/config/constants.go @@ -2,11 +2,11 @@ package config const ( // PropDepositBlocks estimated number of blocks it takes to deposit for a proposal - PropDepositBlocks float32 = 10 + PropDepositBlocks float32 = 6 // PropVoteBlocks number of blocks it takes to vote for a single validator to vote for a proposal PropVoteBlocks float32 = 1.2 // PropBufferBlocks number of blocks used as a calculation buffer - PropBufferBlocks float32 = 6 + PropBufferBlocks float32 = 5 // Upgrades // ForkHeightPreUpgradeOffset how many blocks we allow for fork to run pre upgrade state creation diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 815fc7a49..8e1d6b231 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -189,22 +189,22 @@ func (uc *UpgradeConfigurer) RunUpgrade() error { func (uc *UpgradeConfigurer) runProposalUpgrade() error { // submit, deposit, and vote for upgrade proposal // prop height = current height + voting period + time it takes to submit proposal + small buffer - for _, chainConfig := range uc.chainConfigs { + for _, chainConfig := range uc.chainConfigs { // runs the same upgrade for each chain config node, err := chainConfig.GetDefaultNode() if err != nil { return err } - // currentHeight, err := node.QueryCurrentHeight() - // if err != nil { - // return err - // } - // TODO: need to make a way to update proposal height - // chainConfig.UpgradePropHeight = currentHeight + int64(chainConfig.VotingPeriod) + int64(config.PropSubmitBlocks) + int64(config.PropBufferBlocks) - msgProp, err := uc.ParseGovPropFromFile() + + currentHeight, err := node.QueryCurrentHeight() + if err != nil { + return err + } + + chainConfig.UpgradePropHeight = currentHeight + int64(chainConfig.VotingPeriod) + int64(config.PropSubmitBlocks) + int64(config.PropBufferBlocks) + err = uc.SetGovPropUpgradeHeight(chainConfig.UpgradePropHeight) if err != nil { return err } - chainConfig.UpgradePropHeight = msgProp.Plan.Height propID := node.TxGovPropSubmitProposal(uc.upgradeJsonFilePath, node.WalletName) chainConfig.TxGovVoteFromAllNodes(propID, govv1.VoteOption_VOTE_OPTION_YES) @@ -268,22 +268,62 @@ func (uc *UpgradeConfigurer) ParseGovPropFromFile() (*upgradetypes.MsgSoftwareUp return nil, err } + cdc := app.NewTmpBabylonApp().AppCodec() upgradePath := filepath.Join(pwd, uc.upgradeJsonFilePath) - return ParseGovPropFromFile(upgradePath) + + _, msgSoftwareUpgrade, err := parseGovPropFromFile(cdc, upgradePath) + return msgSoftwareUpgrade, err } -// ParseGovPropFromFile loads from the file the Upgrade msg. -func ParseGovPropFromFile(propFilePath string) (*upgradetypes.MsgSoftwareUpgrade, error) { - _, msgs, _, err := parseSubmitProposal(app.NewTmpBabylonApp().AppCodec(), propFilePath) +// SetGovPropUpgradeHeight loads the proposal from the UpgradeSignetLaunchFilePath +func (uc *UpgradeConfigurer) SetGovPropUpgradeHeight(newUpgradeHeight int64) error { + cdc := app.NewTmpBabylonApp().AppCodec() + upgradePath, err := uc.UpgradeFilePath() if err != nil { - return nil, err + return err + } + + prop, msgSoftwareUpgrade, err := parseGovPropFromFile(cdc, upgradePath) + if err != nil { + return err + } + msgSoftwareUpgrade.Plan.Height = newUpgradeHeight + + return writeGovPropToFile(cdc, upgradePath, *prop, *msgSoftwareUpgrade) +} + +// UpgradeFilePath returns the local full path of the upgrade file +func (uc *UpgradeConfigurer) UpgradeFilePath() (string, error) { + pwd, err := os.Getwd() + if err != nil { + return "", err + } + return filepath.Join(pwd, uc.upgradeJsonFilePath), nil +} + +// parseGovPropFromFile loads from the file the Upgrade msg. +func parseGovPropFromFile(cdc codec.Codec, propFilePath string) (*proposal, *upgradetypes.MsgSoftwareUpgrade, error) { + prop, msgs, _, err := parseSubmitProposal(cdc, propFilePath) + if err != nil { + return nil, nil, err } upgradeMsg, ok := msgs[0].(*upgradetypes.MsgSoftwareUpgrade) if !ok { - return nil, fmt.Errorf("unable to parse msg to upgradetypes.MsgSoftwareUpgrade") + return nil, nil, fmt.Errorf("unable to parse msg to upgradetypes.MsgSoftwareUpgrade") } - return upgradeMsg, nil + return &prop, upgradeMsg, nil +} + +// writeGovPropToFile loads from the file the Upgrade msg as json. +func writeGovPropToFile(cdc codec.Codec, propFilePath string, prop proposal, msgSoftwareUpgrade upgradetypes.MsgSoftwareUpgrade) error { + bz, err := cdc.MarshalInterfaceJSON(&msgSoftwareUpgrade) + if err != nil { + return err + } + prop.Messages = []json.RawMessage{bz} + + return writeProposalToFile(cdc, propFilePath, prop) } // Copy from https://github.com/cosmos/cosmos-sdk/blob/4251905d56e0e7a3350145beedceafe786953295/x/gov/client/cli/util.go#L83 @@ -331,3 +371,13 @@ func parseSubmitProposal(cdc codec.Codec, path string) (proposal, []sdk.Msg, sdk return proposal, msgs, deposit, nil } + +// writeProposalToFile marshal the prop as json to the file. +func writeProposalToFile(cdc codec.Codec, path string, prop proposal) error { + bz, err := json.MarshalIndent(&prop, "", " ") + if err != nil { + return err + } + + return os.WriteFile(path, bz, 0644) +} diff --git a/test/e2e/configurer/upgrade_test.go b/test/e2e/configurer/upgrade_test.go index e8015ce12..323839b7a 100644 --- a/test/e2e/configurer/upgrade_test.go +++ b/test/e2e/configurer/upgrade_test.go @@ -1,24 +1,54 @@ -package configurer_test +package configurer import ( + "math/rand" "os" "path/filepath" "testing" + "time" + "github.com/babylonlabs-io/babylon/app" v1 "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" - "github.com/babylonlabs-io/babylon/test/e2e/configurer" "github.com/babylonlabs-io/babylon/test/e2e/configurer/config" "github.com/stretchr/testify/require" ) func TestParseGovPropFromFile(t *testing.T) { + cdc := app.NewTmpBabylonApp().AppCodec() + + pwd, err := os.Getwd() + require.NoError(t, err) + upgradePath := filepath.Join(pwd, "../", config.UpgradeSignetLaunchFilePath) + + _, msgProp, err := parseGovPropFromFile(cdc, upgradePath) + require.NoError(t, err) + + require.Equal(t, msgProp.Plan.Name, v1.Upgrade.UpgradeName) + require.Equal(t, msgProp.Plan.Height, int64(25)) +} + +func TestWriteGovPropToFile(t *testing.T) { + cdc := app.NewTmpBabylonApp().AppCodec() + pwd, err := os.Getwd() require.NoError(t, err) upgradePath := filepath.Join(pwd, "../", config.UpgradeSignetLaunchFilePath) - prop, err := configurer.ParseGovPropFromFile(upgradePath) + prop, msgProp, err := parseGovPropFromFile(cdc, upgradePath) + require.NoError(t, err) + + r := rand.New(rand.NewSource(time.Now().Unix())) + newPropHeight := int64(r.Int63()) + msgProp.Plan.Height = newPropHeight + + tempFilePath := filepath.Join(t.TempDir(), filepath.Base(config.UpgradeSignetLaunchFilePath)) + + err = writeGovPropToFile(cdc, tempFilePath, *prop, *msgProp) + require.NoError(t, err) + + _, updatedProp, err := parseGovPropFromFile(cdc, tempFilePath) require.NoError(t, err) - require.Equal(t, prop.Plan.Name, v1.Upgrade.UpgradeName) - require.Equal(t, prop.Plan.Height, int64(25)) + require.Equal(t, updatedProp.Plan.Name, msgProp.Plan.Name) + require.Equal(t, updatedProp.Plan.Height, newPropHeight) } diff --git a/test/e2e/upgrades/signet-launch.json b/test/e2e/upgrades/signet-launch.json index 4c2387c5a..f1be8ba79 100644 --- a/test/e2e/upgrades/signet-launch.json +++ b/test/e2e/upgrades/signet-launch.json @@ -1,12 +1,20 @@ { - "title": "any title", - "summary": "any summary", "messages": [ { "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", "authority": "bbn10d07y265gmmuvt4z0w9aw880jnsr700jduz5f2", - "plan": { "name": "signet-launch", "info": "Msg info", "height": 25 } + "plan": { + "name": "signet-launch", + "time": "0001-01-01T00:00:00Z", + "height": "23", + "info": "Msg info", + "upgraded_client_state": null + } } ], - "deposit": "500000000ubbn" + "metadata": "", + "deposit": "500000000ubbn", + "title": "any title", + "summary": "any summary", + "expedited": false } \ No newline at end of file From aaf14954e4d06b92c90b701e8f2864be11da5c90 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 22:58:05 -0300 Subject: [PATCH 4/6] fix: remove check for height in test --- test/e2e/configurer/upgrade_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/test/e2e/configurer/upgrade_test.go b/test/e2e/configurer/upgrade_test.go index 323839b7a..b2acf9992 100644 --- a/test/e2e/configurer/upgrade_test.go +++ b/test/e2e/configurer/upgrade_test.go @@ -24,7 +24,6 @@ func TestParseGovPropFromFile(t *testing.T) { require.NoError(t, err) require.Equal(t, msgProp.Plan.Name, v1.Upgrade.UpgradeName) - require.Equal(t, msgProp.Plan.Height, int64(25)) } func TestWriteGovPropToFile(t *testing.T) { From 746b5839f2edd6f95d13267a39089f07e0c9b57d Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 23:02:48 -0300 Subject: [PATCH 5/6] chore: NewUpgradeConfigurer returns UpgradeConfigurer --- test/e2e/configurer/factory.go | 2 +- test/e2e/configurer/upgrade.go | 4 ++-- test/e2e/software_upgrade_e2e_signet_launch_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/configurer/factory.go b/test/e2e/configurer/factory.go index 1580903f7..36c39d7f9 100644 --- a/test/e2e/configurer/factory.go +++ b/test/e2e/configurer/factory.go @@ -209,7 +209,7 @@ func NewBTCStakingConfigurer(t *testing.T, isDebugLogEnabled bool) (Configurer, } // NewSoftwareUpgradeConfigurer returns a new Configurer for Software Upgrade testing -func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string, btcHeaders []*btclighttypes.BTCHeaderInfo) (Configurer, error) { +func NewSoftwareUpgradeConfigurer(t *testing.T, isDebugLogEnabled bool, upgradePath string, btcHeaders []*btclighttypes.BTCHeaderInfo) (*UpgradeConfigurer, error) { identifier := identifierName(t) containerManager, err := containers.NewManager(identifier, isDebugLogEnabled, false, true) if err != nil { diff --git a/test/e2e/configurer/upgrade.go b/test/e2e/configurer/upgrade.go index 8e1d6b231..65acb3204 100644 --- a/test/e2e/configurer/upgrade.go +++ b/test/e2e/configurer/upgrade.go @@ -40,7 +40,7 @@ var _ Configurer = (*UpgradeConfigurer)(nil) // NewUpgradeConfigurer returns a upgrade configurer, if forkHeight is bigger // than 0 it implies that it is a fork upgrade that does not pass by a gov prop // if it is set to zero it runs the upgrade by the gov prop. -func NewUpgradeConfigurer(t *testing.T, chainConfigs []*chain.Config, setupTests setupFn, containerManager *containers.Manager, upgradePlanFilePath string, forkHeight int64) Configurer { +func NewUpgradeConfigurer(t *testing.T, chainConfigs []*chain.Config, setupTests setupFn, containerManager *containers.Manager, upgradePlanFilePath string, forkHeight int64) *UpgradeConfigurer { t.Helper() return &UpgradeConfigurer{ baseConfigurer: baseConfigurer{ @@ -301,7 +301,7 @@ func (uc *UpgradeConfigurer) UpgradeFilePath() (string, error) { return filepath.Join(pwd, uc.upgradeJsonFilePath), nil } -// parseGovPropFromFile loads from the file the Upgrade msg. +// parseGovPropFromFile loads from the file and parse it to the upgrade msg. func parseGovPropFromFile(cdc codec.Codec, propFilePath string) (*proposal, *upgradetypes.MsgSoftwareUpgrade, error) { prop, msgs, _, err := parseSubmitProposal(cdc, propFilePath) if err != nil { diff --git a/test/e2e/software_upgrade_e2e_signet_launch_test.go b/test/e2e/software_upgrade_e2e_signet_launch_test.go index f0db79694..b750ce5d7 100644 --- a/test/e2e/software_upgrade_e2e_signet_launch_test.go +++ b/test/e2e/software_upgrade_e2e_signet_launch_test.go @@ -26,7 +26,7 @@ func (s *SoftwareUpgradeSignetLaunchTestSuite) SetupSuite() { cfg, err := configurer.NewSoftwareUpgradeConfigurer(s.T(), true, config.UpgradeSignetLaunchFilePath, []*btclighttypes.BTCHeaderInfo{btcHeaderGenesis}) s.NoError(err) - s.configurer = cfg.(*configurer.UpgradeConfigurer) + s.configurer = cfg err = s.configurer.ConfigureChains() s.NoError(err) From 51486e5ef71d1b005842615a8cd70a75c1d392b4 Mon Sep 17 00:00:00 2001 From: RafilxTenfen Date: Mon, 19 Aug 2024 23:20:53 -0300 Subject: [PATCH 6/6] chore: add comment for init to be removed --- app/e2e_include_upgrades.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/e2e_include_upgrades.go b/app/e2e_include_upgrades.go index d709c20bd..6f5770be5 100644 --- a/app/e2e_include_upgrades.go +++ b/app/e2e_include_upgrades.go @@ -6,6 +6,8 @@ import ( "github.com/babylonlabs-io/babylon/app/upgrades/signetlaunch" ) +// init is used to include signet upgrade used for e2e testing +// this file should be removed once the upgrade testing with signet ends. func init() { Upgrades = append(Upgrades, signetlaunch.Upgrade) }