Skip to content

Commit

Permalink
fix: amino interfaces registry
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Apr 26, 2023
1 parent 6efa42d commit d81afcd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
29 changes: 29 additions & 0 deletions x/alliance/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 (
Expand All @@ -32,6 +38,10 @@ func (msg MsgDelegate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgDelegate) Route() string {
return sdk.MsgTypeURL(&msg)
}

func (m MsgDelegate) ValidateBasic() error {
if !m.Amount.Amount.GT(sdk.ZeroInt()) {
return status.Errorf(codes.InvalidArgument, "Alliance delegation amount must be more than zero")
Expand Down Expand Up @@ -62,6 +72,10 @@ func (msg MsgRedelegate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgRedelegate) Route() string {
return sdk.MsgTypeURL(&msg)
}

func (m MsgRedelegate) ValidateBasic() error {
if m.Amount.Amount.LTE(sdk.ZeroInt()) {
return status.Errorf(codes.InvalidArgument, "Alliance redelegation amount must be more than zero")
Expand Down Expand Up @@ -91,6 +105,10 @@ func (msg MsgUndelegate) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgUndelegate) Route() string {
return sdk.MsgTypeURL(&msg)
}

func (m MsgUndelegate) ValidateBasic() error {
if m.Amount.Amount.LTE(sdk.ZeroInt()) {
return status.Errorf(codes.InvalidArgument, "Alliance undelegate amount must be more than zero")
Expand All @@ -108,13 +126,24 @@ func (m MsgUndelegate) GetSigners() []sdk.AccAddress {

func (msg MsgUndelegate) Type() string { return MsgUndelegateType } //nolint:revive // should make receivers consistent

func NewMsgClaimDelegationRewards(delegatorAddress, validatorAddress, denom string) *MsgClaimDelegationRewards {
return &MsgClaimDelegationRewards{
DelegatorAddress: delegatorAddress,
ValidatorAddress: validatorAddress,
Denom: denom,
}
}
func (m *MsgClaimDelegationRewards) ValidateBasic() error {
if m.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))
}
Expand Down
32 changes: 23 additions & 9 deletions x/alliance/types/tests/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)),
)
}

0 comments on commit d81afcd

Please sign in to comment.