Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cli for canceling a software upgrade #5

Merged
merged 7 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .changelog/v1.0.1/improvements/4-add-helper-commands.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- Add helper commands for broadcasting software upgrade and recover client
messages. ([\#4](https://github.com/noble-assets/authority/pull/4))
- Add helper commands for broadcasting software upgrade and recover client messages. ([#4](https://github.com/noble-assets/authority/pull/4))
1 change: 1 addition & 0 deletions .changelog/v1.0.2/improvements/5-add-helper-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add helper command for broadcasting a cancel software upgrade message. ([#5](https://github.com/noble-assets/authority/pull/5))
3 changes: 3 additions & 0 deletions .changelog/v1.0.2/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*Feb 10, 2024*

This is a non-consensus breaking patch release to the v1 line.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## v1.0.2

*Feb 10, 2024*

This is a non-consensus breaking patch release to the v1 line.

### IMPROVEMENTS

- Add helper command for broadcasting a cancel software upgrade message. ([#5](https://github.com/noble-assets/authority/pull/5))

## v1.0.1

*Dec 6, 2024*
Expand All @@ -8,8 +18,7 @@ This is a non-consensus breaking patch release to the v1 line.

### IMPROVEMENTS

- Add helper commands for broadcasting software upgrade and recover client
messages. ([\#4](https://github.com/noble-assets/authority/pull/4))
- Add helper commands for broadcasting software upgrade and recover client messages. ([#4](https://github.com/noble-assets/authority/pull/4))

## v1.0.0

Expand Down
33 changes: 33 additions & 0 deletions client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func GetTxCmd() *cobra.Command {

cmd.AddCommand(NewCmdExecute())
cmd.AddCommand(NewCmdSoftwareUpgrade())
cmd.AddCommand(NewCmdCancelSoftwareUpgrade())
cmd.AddCommand(NewCmdRecoverClient())

return cmd
Expand Down Expand Up @@ -157,6 +158,38 @@ func NewCmdSoftwareUpgrade() *cobra.Command {
return cmd
}

// NewCmdCancelSoftwareUpgrade is a helper for cancelling the currently scheduled software upgrade.
//
// This command has been adapted from the Cosmos SDK implementation.
// https://github.com/cosmos/cosmos-sdk/blob/x/upgrade/v0.1.4/x/upgrade/client/cli/tx.go#L135-L182
func NewCmdCancelSoftwareUpgrade() *cobra.Command {
cmd := &cobra.Command{
Use: "cancel-software-upgrade [flags]",
Args: cobra.NoArgs,
Short: "Helper for cancelling the currently scheduled software upgrade",
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msgExecute := types.NewMsgExecute(
clientCtx.FromAddress.String(),
[]sdk.Msg{
&upgradetypes.MsgCancelUpgrade{
Authority: types.ModuleAddress.String(),
},
})

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msgExecute)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

// NewCmdRecoverClient is a helper for recovering an expired client.
//
// This command has been adapted from the IBC-Go implementation.
Expand Down
27 changes: 23 additions & 4 deletions e2e/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"github.com/stretchr/testify/require"
)

// TestScheduleUpgrade tests the module's ability to schedule an upgrade on-chain.
func TestScheduleUpgrade(t *testing.T) {
// TestScheduleAndCancelUpgrade tests the module's ability to schedule and cancel an upgrade on-chain.
func TestScheduleAndCancelUpgrade(t *testing.T) {
t.Parallel()

var wrapper Wrapper
Expand All @@ -41,8 +41,7 @@ func TestScheduleUpgrade(t *testing.T) {

EnsureUpgrade(t, wrapper, ctx, "", 0)

cmd := []string{"authority", "software-upgrade", "v2", "--upgrade-height", "50",
"--chain-id", wrapper.chain.Config().ChainID, "--no-validate"}
cmd := []string{"authority", "software-upgrade", "v2", "--upgrade-height", "50", "--no-validate"}

// broadcast from un-authorized account
_, err := validator.ExecTx(
Expand All @@ -61,4 +60,24 @@ func TestScheduleUpgrade(t *testing.T) {
require.NoError(t, err)

EnsureUpgrade(t, wrapper, ctx, "v2", 50)

cmd = []string{"authority", "cancel-software-upgrade"}

// broadcast from un-authorized account
_, err = validator.ExecTx(
ctx,
notAuthorized.KeyName(),
cmd...,
)
require.ErrorContains(t, err, "signer is not authority")

// broadcast from authorized authority account
_, err = validator.ExecTx(
ctx,
wrapper.owner.KeyName(),
cmd...,
)
require.NoError(t, err)

EnsureUpgrade(t, wrapper, ctx, "", 0)
}