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: adding Route, Type, GetSignBytes for all messages #743

Merged
merged 3 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 32 additions & 1 deletion modules/apps/29-fee/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

// msg types
const (
TypeMsgRegisterCounterpartyAddress = "registerCounterpartyAddress"
TypeMsgPayPacketFee = "payPacketFee"
TypeMsgPayPacketFeeAsync = "payPacketFeeAsync"
)

// NewMsgRegisterCounterpartyAddress creates a new instance of MsgRegisterCounterpartyAddress
Expand Down Expand Up @@ -101,6 +102,21 @@ func (msg MsgPayPacketFee) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

// Route implements sdk.Msg
func (msg MsgPayPacketFee) Route() string {
return RouterKey
}

// Type implements sdk.Msg
func (msg MsgPayPacketFee) Type() string {
return TypeMsgPayPacketFee
}

// GetSignBytes implements sdk.Msg.
func (msg MsgPayPacketFee) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
}

// NewMsgPayPacketAsync creates a new instance of MsgPayPacketFee
func NewMsgPayPacketFeeAsync(identifiedPacketFee IdentifiedPacketFee) *MsgPayPacketFeeAsync {
return &MsgPayPacketFeeAsync{
Expand Down Expand Up @@ -133,6 +149,21 @@ func (msg MsgPayPacketFeeAsync) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{signer}
}

// Route implements sdk.Msg
func (msg MsgPayPacketFeeAsync) Route() string {
return RouterKey
}

// Type implements sdk.Msg
func (msg MsgPayPacketFeeAsync) Type() string {
return TypeMsgPayPacketFeeAsync
}

// GetSignBytes implements sdk.Msg.
func (msg MsgPayPacketFeeAsync) GetSignBytes() []byte {
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&msg))
}

func NewIdentifiedPacketFee(packetId channeltypes.PacketId, fee Fee, refundAddr string, relayers []string) IdentifiedPacketFee {
return IdentifiedPacketFee{
PacketId: packetId,
Expand Down
94 changes: 94 additions & 0 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,50 @@ func TestPayPacketFeeGetSigners(t *testing.T) {
require.Equal(t, []sdk.AccAddress{addr}, res)
}

// TestMsgPayPacketFeeRoute tests Route for MsgPayPacketFee
func TestMsgPayPacketFeeRoute(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
signer := addr.String()
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil)

require.Equal(t, RouterKey, msg.Route())
}

// TestMsgPayPacketFeeType tests Type for MsgPayPacketFee
func TestMsgPayPacketFeeType(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
signer := addr.String()
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil)

require.Equal(t, "payPacketFee", msg.Type())
}

// TestMsgPayPacketFeeGetSignBytes tests that GetSignBytes does not panic
func TestMsgPayPacketFeeGetSignBytes(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
signer := addr.String()
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
msg := NewMsgPayPacketFee(fee, portID, channelID, signer, nil)

require.NotPanics(t, func() {
_ = msg.GetSignBytes()
})
}

// TestMsgPayPacketFeeAsyncValidation tests ValidateBasic
func TestMsgPayPacketFeeAsyncValidation(t *testing.T) {
var (
Expand Down Expand Up @@ -351,3 +395,53 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) {

require.Equal(t, []sdk.AccAddress{addr}, res)
}

// TestMsgPayPacketFeeAsyncRoute tests Route for MsgPayPacketFeeAsync
func TestMsgPayPacketFeeAsyncRoute(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
seq := uint64(1)
packetId := channeltypes.NewPacketId(channelID, portID, seq)
identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil}
msg := NewMsgPayPacketFeeAsync(identifiedPacketFee)

require.Equal(t, RouterKey, msg.Route())
}

// TestMsgPayPacketFeeAsyncType tests Type for MsgPayPacketFeeAsync
func TestMsgPayPacketFeeAsyncType(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
seq := uint64(1)
packetId := channeltypes.NewPacketId(channelID, portID, seq)
identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil}
msg := NewMsgPayPacketFeeAsync(identifiedPacketFee)

require.Equal(t, "payPacketFeeAsync", msg.Type())
}

// TestMsgPayPacketFeeAsyncGetSignBytes tests that GetSignBytes does not panic
func TestMsgPayPacketFeeAsyncGetSignBytes(t *testing.T) {
addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

// build message
channelID := validChannelID
portID := validPortID
fee := Fee{validCoins, validCoins, validCoins}
seq := uint64(1)
packetId := channeltypes.NewPacketId(channelID, portID, seq)
identifiedPacketFee := IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: addr.String(), Relayers: nil}
msg := NewMsgPayPacketFeeAsync(identifiedPacketFee)

require.NotPanics(t, func() {
_ = msg.GetSignBytes()
})
}