Skip to content

Commit

Permalink
chore: addressing PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed Sep 26, 2022
1 parent 5ae13d3 commit e306637
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetQueryCmd() *cobra.Command {
func NewTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "host",
Short: "interchain-accounts host subcommands",
Short: "IBC interchain accounts host transaction",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
Expand Down
33 changes: 33 additions & 0 deletions modules/apps/27-interchain-accounts/host/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,39 @@ func generatePacketDataCmd() *cobra.Command {
into packet data which is outputted to stdout. It can be used in conjunction with send-tx"
which submits pre-built packet data containing messages to be executed on the host chain.
`,
Example: `<binary> tx interchain-accounts host generate-packet-data '{
"@type":"/cosmos.bank.v1beta1.MsgSend",
"from_address":"cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz",
"to_address":"cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw",
"amount": [
{
"denom": "stake",
"amount": "1000"
}
]
}' --memo memo
<binary> tx interchain-accounts host generate-packet-data '[{
"@type":"/cosmos.bank.v1beta1.MsgSend",
"from_address":"cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz",
"to_address":"cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw",
"amount": [
{
"denom": "stake",
"amount": "1000"
}
]
},
{
"@type": "/cosmos.staking.v1beta1.MsgDelegate",
"delegator_address": "cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz",
"validator_address": "cosmosvaloper1qnk2n4nlkpw9xfqntladh74w6ujtulwnmxnh3k",
"amount": {
"denom": "stake",
"amount": "1000"
}
}]'`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
Expand Down
18 changes: 9 additions & 9 deletions modules/apps/27-interchain-accounts/host/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestGeneratePacketData(t *testing.T) {
assertionFn func(t *testing.T, msgs []sdk.Msg)
}{
{
name: "multi message",
name: "packet data generation succeeds (MsgDelegate & MsgSend)",
memo: "",
expectedPass: true,
message: multiMsg,
Expand All @@ -57,8 +57,8 @@ func TestGeneratePacketData(t *testing.T) {
banktypes.RegisterInterfaces(registry)
},
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
assertMsgDelegate(t, msgs, 0)
assertMsgBankSend(t, msgs, 1)
assertMsgDelegate(t, msgs[0])
assertMsgBankSend(t, msgs[1])
},
},
{
Expand All @@ -68,7 +68,7 @@ func TestGeneratePacketData(t *testing.T) {
message: msgDelegateMessage,
registerInterfaceFn: stakingtypes.RegisterInterfaces,
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
assertMsgDelegate(t, msgs, 0)
assertMsgDelegate(t, msgs[0])
},
},
{
Expand All @@ -78,7 +78,7 @@ func TestGeneratePacketData(t *testing.T) {
message: bankSendMessage,
registerInterfaceFn: banktypes.RegisterInterfaces,
assertionFn: func(t *testing.T, msgs []sdk.Msg) {
assertMsgBankSend(t, msgs, 0)
assertMsgBankSend(t, msgs[0])
},
},
{
Expand Down Expand Up @@ -136,17 +136,17 @@ func TestGeneratePacketData(t *testing.T) {
}
}

func assertMsgBankSend(t *testing.T, msgs []sdk.Msg, idx int) {
bankSendMsg, ok := msgs[idx].(*banktypes.MsgSend)
func assertMsgBankSend(t *testing.T, msg sdk.Msg) {
bankSendMsg, ok := msg.(*banktypes.MsgSend)
require.True(t, ok)
require.Equal(t, "cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz", bankSendMsg.FromAddress)
require.Equal(t, "cosmos10h9stc5v6ntgeygf5xf945njqq5h32r53uquvw", bankSendMsg.ToAddress)
require.Equal(t, "stake", bankSendMsg.Amount.GetDenomByIndex(0))
require.Equal(t, uint64(1000), bankSendMsg.Amount[0].Amount.Uint64())
}

func assertMsgDelegate(t *testing.T, msgs []sdk.Msg, idx int) {
msgDelegate, ok := msgs[idx].(*stakingtypes.MsgDelegate)
func assertMsgDelegate(t *testing.T, msg sdk.Msg) {
msgDelegate, ok := msg.(*stakingtypes.MsgDelegate)
require.True(t, ok)
require.Equal(t, "cosmos15ccshhmp0gsx29qpqq6g4zmltnnvgmyu9ueuadh9y2nc5zj0szls5gtddz", msgDelegate.DelegatorAddress)
require.Equal(t, "cosmosvaloper1qnk2n4nlkpw9xfqntladh74w6ujtulwnmxnh3k", msgDelegate.ValidatorAddress)
Expand Down

0 comments on commit e306637

Please sign in to comment.