diff --git a/x/alliance/types/msg.go b/x/alliance/types/msg.go index 9d7fdffd..585883b3 100644 --- a/x/alliance/types/msg.go +++ b/x/alliance/types/msg.go @@ -2,6 +2,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -11,6 +12,11 @@ var ( _ sdk.Msg = &MsgRedelegate{} _ sdk.Msg = &MsgUndelegate{} _ sdk.Msg = &MsgClaimDelegationRewards{} + + _ legacytx.LegacyMsg = &MsgDelegate{} + _ legacytx.LegacyMsg = &MsgRedelegate{} + _ legacytx.LegacyMsg = &MsgUndelegate{} + _ legacytx.LegacyMsg = &MsgClaimDelegationRewards{} ) var ( @@ -32,22 +38,26 @@ func (msg MsgDelegate) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (m MsgDelegate) ValidateBasic() error { - if !m.Amount.Amount.GT(sdk.ZeroInt()) { +func (msg MsgDelegate) Route() string { + return sdk.MsgTypeURL(&msg) +} + +func (msg MsgDelegate) ValidateBasic() error { + if !msg.Amount.Amount.GT(sdk.ZeroInt()) { return status.Errorf(codes.InvalidArgument, "Alliance delegation amount must be more than zero") } return nil } -func (m MsgDelegate) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.DelegatorAddress) +func (msg MsgDelegate) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) if err != nil { panic("DelegatorAddress signer from MsgDelegate is not valid") } return []sdk.AccAddress{signer} } -func (msg MsgDelegate) Type() string { return MsgDelegateType } //nolint:revive // TODO: we should figure out how to differentiate this from MsgDelegate above. +func (msg MsgDelegate) Type() string { return MsgDelegateType } func NewMsgRedelegate(delegatorAddress, validatorSrcAddress, validatorDstAddress string, amount sdk.Coin) *MsgRedelegate { return &MsgRedelegate{ @@ -62,22 +72,26 @@ func (msg MsgRedelegate) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (m MsgRedelegate) ValidateBasic() error { - if m.Amount.Amount.LTE(sdk.ZeroInt()) { +func (msg MsgRedelegate) Route() string { + return sdk.MsgTypeURL(&msg) +} + +func (msg MsgRedelegate) ValidateBasic() error { + if msg.Amount.Amount.LTE(sdk.ZeroInt()) { return status.Errorf(codes.InvalidArgument, "Alliance redelegation amount must be more than zero") } return nil } -func (m MsgRedelegate) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.DelegatorAddress) +func (msg MsgRedelegate) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) if err != nil { panic("DelegatorAddress signer from MsgRedelegate is not valid") } return []sdk.AccAddress{signer} } -func (msg MsgRedelegate) Type() string { return MsgRedelegateType } //nolint:revive // should make receivers consistent +func (msg MsgRedelegate) Type() string { return MsgRedelegateType } func NewMsgUndelegate(delegatorAddress, validatorAddress string, amount sdk.Coin) *MsgUndelegate { return &MsgUndelegate{ @@ -91,40 +105,56 @@ func (msg MsgUndelegate) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (m MsgUndelegate) ValidateBasic() error { - if m.Amount.Amount.LTE(sdk.ZeroInt()) { +func (msg MsgUndelegate) Route() string { + return sdk.MsgTypeURL(&msg) +} + +func (msg MsgUndelegate) ValidateBasic() error { + if msg.Amount.Amount.LTE(sdk.ZeroInt()) { return status.Errorf(codes.InvalidArgument, "Alliance undelegate amount must be more than zero") } return nil } -func (m MsgUndelegate) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.DelegatorAddress) +func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) if err != nil { panic("DelegatorAddress signer from MsgUndelegate is not valid") } return []sdk.AccAddress{signer} } -func (msg MsgUndelegate) Type() string { return MsgUndelegateType } //nolint:revive // should make receivers consistent +func (msg MsgUndelegate) Type() string { return MsgUndelegateType } -func (m *MsgClaimDelegationRewards) ValidateBasic() error { - if m.Denom == "" { +func NewMsgClaimDelegationRewards(delegatorAddress, validatorAddress, denom string) *MsgClaimDelegationRewards { + return &MsgClaimDelegationRewards{ + DelegatorAddress: delegatorAddress, + ValidatorAddress: validatorAddress, + Denom: denom, + } +} + +func (msg *MsgClaimDelegationRewards) ValidateBasic() error { + if msg.Denom == "" { return status.Errorf(codes.InvalidArgument, "Alliance denom must have a value") } return nil } +func (msg MsgClaimDelegationRewards) Route() string { + return sdk.MsgTypeURL(&msg) +} + func (msg MsgClaimDelegationRewards) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (m *MsgClaimDelegationRewards) GetSigners() []sdk.AccAddress { - signer, err := sdk.AccAddressFromBech32(m.DelegatorAddress) +func (msg *MsgClaimDelegationRewards) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) if err != nil { panic("DelegatorAddress signer from MsgClaimDelegationRewards is not valid") } return []sdk.AccAddress{signer} } -func (msg MsgClaimDelegationRewards) Type() string { return MsgClaimDelegationRewardsType } //nolint:revive // should make receivers consistent +func (msg MsgClaimDelegationRewards) Type() string { return MsgClaimDelegationRewardsType } diff --git a/x/alliance/types/tests/types_test.go b/x/alliance/types/tests/types_test.go index 09bade55..03281623 100644 --- a/x/alliance/types/tests/types_test.go +++ b/x/alliance/types/tests/types_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -148,15 +149,28 @@ func TestInvalidProposalsContent(t *testing.T) { } } -func TestMsgSendGetSignBytes(t *testing.T) { - coins := sdk.NewCoin("uluna", sdk.OneInt()) - msg := types.NewMsgDelegate( - "terra...delegator", - "terra...validator", - coins, +func TestAminoJSON(t *testing.T) { + msgDelegate := types.NewMsgDelegate("delegator", "validator", sdk.NewCoin("Alliance", sdk.NewInt(1000000000000000000))) + require.Equal(t, + `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"alliance/MsgDelegate","value":{"amount":{"amount":"1000000000000000000","denom":"Alliance"},"delegator_address":"delegator","validator_address":"validator"}}],"sequence":"1","timeout_height":"1"}`, + string(legacytx.StdSignBytes("foo", 1, 1, 1, legacytx.StdFee{}, []sdk.Msg{msgDelegate}, "memo", nil)), ) - res := msg.GetSignBytes() - expected := `{"type":"alliance/MsgDelegate","value":{"amount":{"amount":"1","denom":"uluna"},"delegator_address":"terra...delegator","validator_address":"terra...validator"}}` - require.Equal(t, expected, string(res)) + msgUndelegate := types.NewMsgUndelegate("delegator", "validator", sdk.NewCoin("Alliance", sdk.NewInt(1000000000000000000))) + require.Equal(t, + `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"alliance/MsgUndelegate","value":{"amount":{"amount":"1000000000000000000","denom":"Alliance"},"delegator_address":"delegator","validator_address":"validator"}}],"sequence":"1","timeout_height":"1"}`, + string(legacytx.StdSignBytes("foo", 1, 1, 1, legacytx.StdFee{}, []sdk.Msg{msgUndelegate}, "memo", nil)), + ) + + msgRedelegate := types.NewMsgRedelegate("delegator", "validator", "validator1", sdk.NewCoin("Alliance", sdk.NewInt(1000000000000000000))) + require.Equal(t, + `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"alliance/MsgRedelegate","value":{"amount":{"amount":"1000000000000000000","denom":"Alliance"},"delegator_address":"delegator","validator_dst_address":"validator1","validator_src_address":"validator"}}],"sequence":"1","timeout_height":"1"}`, + string(legacytx.StdSignBytes("foo", 1, 1, 1, legacytx.StdFee{}, []sdk.Msg{msgRedelegate}, "memo", nil)), + ) + + msgClaimDelegationRewards := types.NewMsgClaimDelegationRewards("delegator", "validator", "Alliance") + require.Equal(t, + `{"account_number":"1","chain_id":"foo","fee":{"amount":[],"gas":"0"},"memo":"memo","msgs":[{"type":"alliance/MsgClaimDelegationRewards","value":{"delegator_address":"delegator","denom":"Alliance","validator_address":"validator"}}],"sequence":"1","timeout_height":"1"}`, + string(legacytx.StdSignBytes("foo", 1, 1, 1, legacytx.StdFee{}, []sdk.Msg{msgClaimDelegationRewards}, "memo", nil)), + ) }