-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
711 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
func CmdResumeHostZone() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "resume-host-zone [chainid]", | ||
Short: "Broadcast message resume-host-zone", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
argChainId := args[0] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgResumeHostZone( | ||
clientCtx.GetFromAddress().String(), | ||
argChainId, | ||
) | ||
if err := msg.ValidateBasic(); err != nil { | ||
return err | ||
} | ||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k msgServer) ResumeHostZone(goCtx context.Context, msg *types.MsgResumeHostZone) (*types.MsgResumeHostZoneResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// Get Host Zone | ||
hostZone, found := k.GetHostZone(ctx, msg.ChainId) | ||
if !found { | ||
errMsg := fmt.Sprintf("invalid chain id, zone for %s not found", msg.ChainId) | ||
k.Logger(ctx).Error(errMsg) | ||
return nil, errorsmod.Wrapf(types.ErrHostZoneNotFound, errMsg) | ||
} | ||
|
||
// Check the zone is halted | ||
if !hostZone.Halted { | ||
errMsg := fmt.Sprintf("invalid chain id, zone for %s not halted", msg.ChainId) | ||
k.Logger(ctx).Error(errMsg) | ||
return nil, errorsmod.Wrapf(types.ErrHostZoneNotHalted, errMsg) | ||
} | ||
|
||
// Resume zone | ||
hostZone.Halted = false | ||
k.SetHostZone(ctx, hostZone) | ||
|
||
return &types.MsgResumeHostZoneResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
_ "github.com/stretchr/testify/suite" | ||
|
||
stakeibctypes "github.com/Stride-Labs/stride/v15/x/stakeibc/types" | ||
) | ||
|
||
type ResumeHostZoneTestCase struct { | ||
validMsg stakeibctypes.MsgResumeHostZone | ||
zone stakeibctypes.HostZone | ||
} | ||
|
||
func (s *KeeperTestSuite) SetupResumeHostZone() ResumeHostZoneTestCase { | ||
// Register a host zone | ||
hostZone := stakeibctypes.HostZone{ | ||
ChainId: HostChainId, | ||
HostDenom: Atom, | ||
IbcDenom: IbcAtom, | ||
RedemptionRate: sdk.NewDec(1.0), | ||
MinRedemptionRate: sdk.NewDec(9).Quo(sdk.NewDec(10)), | ||
MaxRedemptionRate: sdk.NewDec(15).Quo(sdk.NewDec(10)), | ||
Halted: true, | ||
} | ||
|
||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, hostZone) | ||
|
||
defaultMsg := stakeibctypes.MsgResumeHostZone{ | ||
Creator: s.TestAccs[0].String(), | ||
ChainId: HostChainId, | ||
} | ||
|
||
return ResumeHostZoneTestCase{ | ||
validMsg: defaultMsg, | ||
zone: hostZone, | ||
} | ||
} | ||
|
||
// Verify that bounds can be set successfully | ||
func (s *KeeperTestSuite) TestResumeHostZone_Success() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &tc.validMsg) | ||
s.Require().NoError(err, "should not throw an error") | ||
|
||
// Confirm the inner bounds were set | ||
zone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, HostChainId) | ||
s.Require().True(found, "host zone should be in the store") | ||
|
||
s.Require().False(zone.Halted, "host zone should not be halted") | ||
} | ||
|
||
// verify that non-admins can't call the tx | ||
func (s *KeeperTestSuite) TestResumeHostZone_NonAdmin() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
invalidMsg := tc.validMsg | ||
invalidMsg.Creator = s.TestAccs[1].String() | ||
|
||
err := invalidMsg.ValidateBasic() | ||
s.Require().Error(err, "nonadmins shouldn't be able to call this tx") | ||
} | ||
|
||
// verify that the function can't be called on missing zones | ||
func (s *KeeperTestSuite) TestResumeHostZone_MissingZones() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
invalidMsg := tc.validMsg | ||
invalidChainId := "invalid-chain" | ||
invalidMsg.ChainId = invalidChainId | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &invalidMsg) | ||
|
||
s.Require().Error(err, "shouldn't be able to call tx on missing zones") | ||
expectedErrorMsg := fmt.Sprintf("invalid chain id, zone for %s not found: host zone not found", invalidChainId) | ||
s.Require().Equal(expectedErrorMsg, err.Error(), "should return correct error msg") | ||
} | ||
|
||
// verify that the function can't be called on unhalted zones | ||
func (s *KeeperTestSuite) TestResumeHostZone_UnhaltedZones() { | ||
tc := s.SetupResumeHostZone() | ||
|
||
zone, found := s.App.StakeibcKeeper.GetHostZone(s.Ctx, HostChainId) | ||
s.Require().True(found, "host zone should be in the store") | ||
s.Require().True(zone.Halted, "host zone should be halted") | ||
zone.Halted = false | ||
s.App.StakeibcKeeper.SetHostZone(s.Ctx, zone) | ||
|
||
// Set the inner bounds on the host zone | ||
_, err := s.GetMsgServer().ResumeHostZone(s.Ctx, &tc.validMsg) | ||
s.Require().Error(err, "shouldn't be able to call tx on unhalted zones") | ||
expectedErrorMsg := fmt.Sprintf("invalid chain id, zone for %s not halted: host zone is not halted", HostChainId) | ||
s.Require().Equal(expectedErrorMsg, err.Error(), "should return correct error msg") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package types | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
|
||
"github.com/Stride-Labs/stride/v15/utils" | ||
) | ||
|
||
const TypeMsgResumeHostZone = "resume_host_zone" | ||
|
||
var _ sdk.Msg = &MsgResumeHostZone{} | ||
|
||
func NewMsgResumeHostZone(creator string, chainId string) *MsgResumeHostZone { | ||
return &MsgResumeHostZone{ | ||
Creator: creator, | ||
ChainId: chainId, | ||
} | ||
} | ||
|
||
func (msg *MsgResumeHostZone) Route() string { | ||
return RouterKey | ||
} | ||
|
||
func (msg *MsgResumeHostZone) Type() string { | ||
return TypeMsgResumeHostZone | ||
} | ||
|
||
func (msg *MsgResumeHostZone) GetSigners() []sdk.AccAddress { | ||
creator, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return []sdk.AccAddress{creator} | ||
} | ||
|
||
func (msg *MsgResumeHostZone) GetSignBytes() []byte { | ||
bz := ModuleCdc.MustMarshalJSON(msg) | ||
return sdk.MustSortJSON(bz) | ||
} | ||
|
||
func (msg *MsgResumeHostZone) ValidateBasic() error { | ||
_, err := sdk.AccAddressFromBech32(msg.Creator) | ||
if err != nil { | ||
return errorsmod.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) | ||
} | ||
if err := utils.ValidateAdminAddress(msg.Creator); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.