-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bank/v2): Add MsgSend handler (#21736)
- Loading branch information
Showing
17 changed files
with
2,239 additions
and
93 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,59 @@ | ||
//go:build system_test | ||
|
||
package systemtests | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tidwall/gjson" | ||
) | ||
|
||
func TestBankV2SendTxCmd(t *testing.T) { | ||
// Currently only run with app v2 | ||
if !isV2() { | ||
t.Skip() | ||
} | ||
// scenario: test bank send command | ||
// given a running chain | ||
|
||
sut.ResetChain(t) | ||
cli := NewCLIWrapper(t, sut, verbose) | ||
|
||
// get validator address | ||
valAddr := gjson.Get(cli.Keys("keys", "list"), "1.address").String() | ||
require.NotEmpty(t, valAddr) | ||
|
||
// add new key | ||
receiverAddr := cli.AddKey("account1") | ||
denom := "stake" | ||
sut.StartChain(t) | ||
|
||
// query validator balance and make sure it has enough balance | ||
var transferAmount int64 = 1000 | ||
raw := cli.CustomQuery("q", "bankv2", "balance", valAddr, denom) | ||
valBalance := gjson.Get(raw, "balance.amount").Int() | ||
|
||
require.Greater(t, valBalance, transferAmount, "not enough balance found with validator") | ||
|
||
bankSendCmdArgs := []string{"tx", "bankv2", "send", valAddr, receiverAddr, fmt.Sprintf("%d%s", transferAmount, denom)} | ||
|
||
// test valid transaction | ||
rsp := cli.Run(append(bankSendCmdArgs, "--fees=1stake")...) | ||
txResult, found := cli.AwaitTxCommitted(rsp) | ||
require.True(t, found) | ||
RequireTxSuccess(t, txResult) | ||
|
||
// Check balance after send | ||
valRaw := cli.CustomQuery("q", "bankv2", "balance", valAddr, denom) | ||
valBalanceAfer := gjson.Get(valRaw, "balance.amount").Int() | ||
|
||
// TODO: Make DeductFee ante handler work with bank/v2 | ||
require.Equal(t, valBalanceAfer, valBalance - transferAmount) | ||
|
||
receiverRaw := cli.CustomQuery("q", "bankv2", "balance", receiverAddr, denom) | ||
receiverBalance := gjson.Get(receiverRaw, "balance.amount").Int() | ||
require.Equal(t, receiverBalance, transferAmount) | ||
|
||
} |
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,79 @@ | ||
package cli | ||
|
||
import ( | ||
"errors" | ||
|
||
gogoproto "github.com/cosmos/gogoproto/proto" | ||
"github.com/spf13/cobra" | ||
|
||
"cosmossdk.io/x/bank/v2/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
const ( | ||
FlagDenom = "denom" | ||
) | ||
|
||
// GetQueryCmd returns the parent command for all x/bank CLi query commands. The | ||
// provided clientCtx should have, at a minimum, a verifier, Tendermint RPC client, | ||
// and marshaler set. | ||
func GetQueryCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Querying commands for the bank module", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
cmd.AddCommand( | ||
GetBalanceCmd(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func GetBalanceCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "balance [address] [denom]", | ||
Short: "Query an account balance by address and denom", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
denom := args[1] | ||
if denom == "" { | ||
return errors.New("empty denom") | ||
} | ||
|
||
addr, err := sdk.AccAddressFromBech32(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctx := cmd.Context() | ||
|
||
req := types.NewQueryBalanceRequest(addr.String(), denom) | ||
out := new(types.QueryBalanceResponse) | ||
|
||
err = clientCtx.Invoke(ctx, gogoproto.MessageName(&types.QueryBalanceRequest{}), req, out) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(out) | ||
}, | ||
} | ||
|
||
cmd.Flags().String(FlagDenom, "", "The specific balance denomination to query for") | ||
flags.AddQueryFlagsToCmd(cmd) | ||
flags.AddPaginationFlagsToCmd(cmd, "all balances") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.