refactor(bank): migrate bech32 encoding (#15567)
This commit is contained in:
parent
6cee22df52
commit
571c13ea84
@ -200,6 +200,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* The signature of `NewSigVerificationDecorator` has been changed to accept a `x/tx/signing.HandlerMap`.
|
||||
* The signature of `VerifySignature` has been changed to accept a `x/tx/signing.HandlerMap` and other structs from `x/tx` as arguments.
|
||||
* The signature of `NewTxConfigWithTextual` has been deprecated and its signature changed to accept a `SignModeOptions`.
|
||||
* (x/bank) [#15567](https://github.com/cosmos/cosmos-sdk/pull/15567) `GenesisBalance.GetAddress` now returns a string instead of `sdk.AccAddress`
|
||||
* `MsgSendExec` test helper function now takes a address.Codec
|
||||
* (x/genutil) [#15567](https://github.com/cosmos/cosmos-sdk/pull/15567) `CollectGenTxsCmd` & `GenTxCmd` takes a address.Codec to be able to decode addresses
|
||||
* (x/genutil) [#15999](https://github.com/cosmos/cosmos-sdk/pull/15999) Genutil now takes the `GenesisTxHanlder` interface instead of deliverTx. The interface is implemented on baseapp
|
||||
* (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16040) Remove unused aliases in math.go
|
||||
* (x/gov) [#16106](https://github.com/cosmos/cosmos-sdk/pull/16106) Remove gRPC query methods from Keeper
|
||||
@ -215,6 +218,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
* Remove: errors unused errors
|
||||
|
||||
* (sims) [#16155](https://github.com/cosmos/cosmos-sdk/pull/16155)
|
||||
* `simulation.NewOperationMsg` now marshals the operation msg as proto bytes instead of legacy amino JSON bytes.
|
||||
* `simulation.NewOperationMsg` is now 2-arity instead of 3-arity with the obsolete argument `codec.ProtoCodec` removed.
|
||||
* The field `OperationMsg.Msg` is now of type `[]byte` instead of `json.RawMessage`.
|
||||
* (cli) [#16209](https://github.com/cosmos/cosmos-sdk/pull/16209) Add API `StartCmdWithOptions` to create customized start command.
|
||||
|
||||
* `simulation.NewOperationMsg` now marshals the operation msg as proto bytes instead of legacy amino JSON bytes.
|
||||
* `simulation.NewOperationMsg` is now 2-arity instead of 3-arity with the obsolete argument `codec.ProtoCodec` removed.
|
||||
|
||||
@ -7,16 +7,13 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/simapp"
|
||||
"cosmossdk.io/simapp/params"
|
||||
confixcmd "cosmossdk.io/tools/confix/cmd"
|
||||
rosettaCmd "cosmossdk.io/tools/rosetta/cmd"
|
||||
cmtcfg "github.com/cometbft/cometbft/config"
|
||||
dbm "github.com/cosmos/cosmos-db"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/config"
|
||||
"github.com/cosmos/cosmos-sdk/client/debug"
|
||||
@ -39,6 +36,8 @@ import (
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// NewRootCmd creates a new root command for simd. It is called once in the
|
||||
@ -201,12 +200,11 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b
|
||||
rootCmd.AddCommand(
|
||||
rpc.StatusCommand(),
|
||||
genesisCommand(encodingConfig, basicManager),
|
||||
queryCommand(),
|
||||
txCommand(),
|
||||
queryCommand(),
|
||||
keys.Commands(simapp.DefaultNodeHome),
|
||||
)
|
||||
|
||||
// add rosetta
|
||||
rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
@ -143,7 +143,7 @@ func (s *E2ETestSuite) TestCLISignGenOnly() {
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
}
|
||||
generatedStd, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||
generatedStd, err := clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(addresscodec.NewBech32Codec("cosmos")), args)
|
||||
s.Require().NoError(err)
|
||||
opFile := testutil.WriteToNewTempFile(s.T(), generatedStd.String())
|
||||
defer opFile.Close()
|
||||
@ -691,7 +691,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(0, len(sigs))
|
||||
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address)
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
@ -756,7 +756,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
// Ensure foo has right amount of funds
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address)
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
||||
@ -778,7 +778,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||
|
||||
// Ensure destiny account state
|
||||
err = s.network.RetryForBlocks(func() error {
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
return err
|
||||
}, 3)
|
||||
s.Require().NoError(err)
|
||||
@ -788,7 +788,7 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() {
|
||||
s.Require().Equal(sendTokens.Amount, balRes.Balances.AmountOf(s.cfg.BondDenom))
|
||||
|
||||
// Ensure origin account state
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address)
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, val1.Address, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
||||
@ -826,6 +826,7 @@ func (s *E2ETestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -909,7 +910,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() {
|
||||
|
||||
addr, err := multisigRecord.GetAddress()
|
||||
s.Require().NoError(err)
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
@ -927,7 +928,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
|
||||
resp, err = clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
||||
@ -943,6 +944,7 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -1020,6 +1022,7 @@ func (s *E2ETestSuite) TestSignWithMultisig() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -1067,7 +1070,7 @@ func (s *E2ETestSuite) TestCLIMultisign() {
|
||||
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
err = s.network.RetryForBlocks(func() error {
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr)
|
||||
resp, err := clitestutil.QueryBalancesExec(val1.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1084,6 +1087,7 @@ func (s *E2ETestSuite) TestCLIMultisign() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -1177,6 +1181,7 @@ func (s *E2ETestSuite) TestSignBatchMultisig() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -1242,6 +1247,7 @@ func (s *E2ETestSuite) TestMultisignBatch() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -1254,7 +1260,7 @@ func (s *E2ETestSuite) TestMultisignBatch() {
|
||||
defer filename.Close()
|
||||
val.ClientCtx.HomeDir = strings.Replace(val.ClientCtx.HomeDir, "simd", "simcli", 1)
|
||||
|
||||
queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr, address.NewBech32Codec("cosmos"))
|
||||
queryResJSON, err := authclitestutil.QueryAccountExec(val.ClientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
var account sdk.AccountI
|
||||
s.Require().NoError(val.ClientCtx.Codec.UnmarshalInterfaceJSON(queryResJSON.Bytes(), &account))
|
||||
@ -1322,7 +1328,7 @@ func (s *E2ETestSuite) TestGetAccountCmd() {
|
||||
s.Run(tc.name, func() {
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := authclitestutil.QueryAccountExec(clientCtx, tc.address, address.NewBech32Codec("cosmos"))
|
||||
out, err := authclitestutil.QueryAccountExec(clientCtx, tc.address, addresscodec.NewBech32Codec("cosmos"))
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
s.Require().NotEqual("internal", err.Error())
|
||||
@ -1618,7 +1624,7 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() {
|
||||
require.Equal(uint32(0), txRes.Code, txRes.RawLog)
|
||||
|
||||
// Make sure the addr1's balance got funded.
|
||||
queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1)
|
||||
queryResJSON, err := clitestutil.QueryBalancesExec(val0.ClientCtx, addr1, addresscodec.NewBech32Codec("cosmos"))
|
||||
require.NoError(err)
|
||||
var queryRes banktypes.QueryAllBalancesResponse
|
||||
err = val0.ClientCtx.Codec.UnmarshalJSON(queryResJSON.Bytes(), &queryRes)
|
||||
@ -1950,11 +1956,11 @@ func (s *E2ETestSuite) createBankMsg(val *network.Validator, toAddr sdk.AccAddre
|
||||
}
|
||||
|
||||
flags = append(flags, extraFlags...)
|
||||
return clitestutil.MsgSendExec(val.ClientCtx, val.Address, toAddr, amount, flags...)
|
||||
return clitestutil.MsgSendExec(val.ClientCtx, val.Address, toAddr, amount, addresscodec.NewBech32Codec("cosmos"), flags...)
|
||||
}
|
||||
|
||||
func (s *E2ETestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int {
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, addr)
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
// without this import amino json encoding will fail when resolving any types
|
||||
_ "cosmossdk.io/api/cosmos/authz/v1beta1"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -149,7 +149,7 @@ func (s *E2ETestSuite) msgSendExec(grantee sdk.AccAddress) {
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
grantee,
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
)
|
||||
@ -308,7 +308,7 @@ func (s *E2ETestSuite) TestCmdRevokeAuthorizations() {
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.NewCmdRevokeAuthorization(address.NewBech32Codec("cosmos"))
|
||||
cmd := cli.NewCmdRevokeAuthorization(addresscodec.NewBech32Codec("cosmos"))
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
@ -501,6 +501,7 @@ func (s *E2ETestSuite) TestNewExecGrantAuthorized() {
|
||||
val.Address,
|
||||
grantee,
|
||||
tokens,
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -615,6 +616,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
|
||||
val.Address,
|
||||
allowedAddr,
|
||||
tokens,
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -629,6 +631,7 @@ func (s *E2ETestSuite) TestExecSendAuthzWithAllowList() {
|
||||
val.Address,
|
||||
notAllowedAddr,
|
||||
tokens,
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -153,7 +154,7 @@ func (s *E2ETestSuite) TestGetBalancesCmd() {
|
||||
tc := tc
|
||||
|
||||
s.Run(tc.name, func() {
|
||||
cmd := cli.GetBalancesCmd()
|
||||
cmd := cli.GetBalancesCmd(addresscodec.NewBech32Codec("cosmos"))
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, tc.args)
|
||||
|
||||
if tc.expectErr {
|
||||
@ -384,7 +385,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdGenOnly() {
|
||||
fmt.Sprintf("--%s=true", flags.FlagGenerateOnly),
|
||||
}
|
||||
|
||||
bz, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...)
|
||||
bz, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, addresscodec.NewBech32Codec("cosmos"), args...)
|
||||
s.Require().NoError(err)
|
||||
tx, err := s.cfg.TxConfig.TxJSONDecoder()(bz.Bytes())
|
||||
s.Require().NoError(err)
|
||||
@ -413,7 +414,7 @@ func (s *E2ETestSuite) TestNewSendTxCmdDryRun() {
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stderr = w
|
||||
|
||||
_, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, args...)
|
||||
_, err := clitestutil.MsgSendExec(clientCtx, from, to, amount, addresscodec.NewBech32Codec("cosmos"), args...)
|
||||
s.Require().NoError(err)
|
||||
|
||||
w.Close()
|
||||
@ -511,7 +512,7 @@ func (s *E2ETestSuite) TestNewSendTxCmd() {
|
||||
s.Run(tc.name, func() {
|
||||
clientCtx := val.ClientCtx
|
||||
|
||||
bz, err := clitestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, tc.args...)
|
||||
bz, err := clitestutil.MsgSendExec(clientCtx, tc.from, tc.to, tc.amount, addresscodec.NewBech32Codec("cosmos"), tc.args...)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
@ -674,5 +675,5 @@ func MsgMultiSendExec(clientCtx client.Context, from sdk.AccAddress, to []sdk.Ac
|
||||
args = append(args, amount.String())
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, cli.NewMultiSendTxCmd(), args)
|
||||
return clitestutil.ExecTestCLICmd(clientCtx, cli.NewMultiSendTxCmd(addresscodec.NewBech32Codec("cosmos")), args)
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -63,7 +64,7 @@ func (s *WithdrawAllTestSuite) TestNewWithdrawAllRewardsGenerateOnly() {
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
)
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -352,7 +353,7 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() {
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
var newBalance banktypes.QueryAllBalancesResponse
|
||||
if !tc.expectErr && tc.expectedCode == 0 {
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address)
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
||||
s.Require().NoError(err)
|
||||
@ -368,7 +369,7 @@ func (s *E2ETestSuite) TestNewCmdCancelProposal() {
|
||||
s.Require().NoError(clitestutil.CheckTxCode(s.network, clientCtx, resp.TxHash, tc.expectedCode))
|
||||
|
||||
if !tc.expectErr && tc.expectedCode == 0 {
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address)
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, val.Address, addresscodec.NewBech32Codec("cosmos"))
|
||||
s.Require().NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &newBalance)
|
||||
s.Require().NoError(err)
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
_ "cosmossdk.io/api/cosmos/group/v1"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -71,7 +72,9 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
account,
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2000))),
|
||||
address.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
)
|
||||
@ -279,6 +282,7 @@ func (s *E2ETestSuite) createGroupThresholdPolicyWithBalance(adminAddress, group
|
||||
s.Require().NoError(err)
|
||||
_, err = clitestutil.MsgSendExec(clientCtx, val.Address, addr,
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(tokens))),
|
||||
address.NewBech32Codec("cosmos"),
|
||||
s.commonFlags...,
|
||||
)
|
||||
s.Require().NoError(err)
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"cosmossdk.io/x/nft"
|
||||
"cosmossdk.io/x/nft/client/cli"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -157,6 +158,6 @@ func (s *E2ETestSuite) initAccount() {
|
||||
s.Require().NoError(err)
|
||||
|
||||
amount := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200)))
|
||||
_, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, args...)
|
||||
_, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, addresscodec.NewBech32Codec("cosmos"), args...)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
@ -104,7 +105,7 @@ func (s *E2ETestSuite) TestBlockResults() {
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200))), addresscodec.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
)
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
|
||||
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
|
||||
@ -74,6 +75,7 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -91,6 +93,7 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(1)),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s", flags.FlagOffline),
|
||||
fmt.Sprintf("--%s=0", flags.FlagAccountNumber),
|
||||
@ -597,6 +600,7 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
|
||||
val1.Address,
|
||||
addr,
|
||||
sdk.NewCoins(coins),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
@ -617,6 +621,7 @@ func (s *E2ETestSuite) TestSimMultiSigTx() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(s.cfg.BondDenom, 5),
|
||||
),
|
||||
addresscodec.NewBech32Codec("cosmos"),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
@ -29,16 +30,16 @@ func ExecTestCLICmd(clientCtx client.Context, cmd *cobra.Command, extraArgs []st
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
func MsgSendExec(clientCtx client.Context, from, to, amount fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{from.String(), to.String(), amount.String()}
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(), args)
|
||||
return ExecTestCLICmd(clientCtx, cli.NewSendTxCmd(ac), args)
|
||||
}
|
||||
|
||||
func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
func QueryBalancesExec(clientCtx client.Context, address fmt.Stringer, ac address.Codec, extraArgs ...string) (testutil.BufferWriter, error) {
|
||||
args := []string{address.String(), fmt.Sprintf("--%s=json", flags.FlagOutput)}
|
||||
args = append(args, extraArgs...)
|
||||
|
||||
return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(), args)
|
||||
return ExecTestCLICmd(clientCtx, cli.GetBalancesCmd(ac), args)
|
||||
}
|
||||
|
||||
@ -460,6 +460,7 @@ func (s *CLITestSuite) TestCLIMultisignInsufficientCosigners() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("stake", 5),
|
||||
),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
|
||||
@ -548,6 +549,7 @@ func (s *CLITestSuite) TestCLIMultisignSortSignatures() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("stake", 5),
|
||||
),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
|
||||
@ -621,6 +623,7 @@ func (s *CLITestSuite) TestSignWithMultisig() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("stake", 5),
|
||||
),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
|
||||
@ -662,6 +665,7 @@ func (s *CLITestSuite) TestCLIMultisign() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("stake", 5),
|
||||
),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
|
||||
@ -735,6 +739,7 @@ func (s *CLITestSuite) TestSignBatchMultisig() {
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin("stake", math.NewInt(1)),
|
||||
),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()),
|
||||
@ -1270,7 +1275,7 @@ func (s *CLITestSuite) TestAuxToFeeWithTips() {
|
||||
}
|
||||
|
||||
func (s *CLITestSuite) getBalances(clientCtx client.Context, addr sdk.AccAddress, denom string) math.Int {
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, addr)
|
||||
resp, err := clitestutil.QueryBalancesExec(clientCtx, addr, s.ac)
|
||||
s.Require().NoError(err)
|
||||
|
||||
var balRes banktypes.QueryAllBalancesResponse
|
||||
@ -1289,5 +1294,5 @@ func (s *CLITestSuite) createBankMsg(clientCtx client.Context, toAddr sdk.AccAdd
|
||||
}
|
||||
|
||||
flags = append(flags, extraFlags...)
|
||||
return clitestutil.MsgSendExec(clientCtx, s.val, toAddr, amount, flags...)
|
||||
return clitestutil.MsgSendExec(clientCtx, s.val, toAddr, amount, s.ac, flags...)
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
_ "cosmossdk.io/api/cosmos/authz/v1beta1"
|
||||
@ -49,6 +50,8 @@ type CLITestSuite struct {
|
||||
clientCtx client.Context
|
||||
grantee []sdk.AccAddress
|
||||
addrs []sdk.AccAddress
|
||||
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
func TestCLITestSuite(t *testing.T) {
|
||||
@ -67,6 +70,8 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
|
||||
s.ac = addresscodec.NewBech32Codec("cosmos")
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.ResponseQuery{
|
||||
@ -169,11 +174,14 @@ func (s *CLITestSuite) createAccount(uid string) sdk.AccAddress {
|
||||
func (s *CLITestSuite) msgSendExec(grantee sdk.AccAddress) {
|
||||
val := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
// Send some funds to the new account.
|
||||
s.ac.StringToBytes("cosmos16zex22087zs656t0vedytv5wqhm6axxd5679ry")
|
||||
out, err := clitestutil.MsgSendExec(
|
||||
s.clientCtx,
|
||||
val[0].Address,
|
||||
grantee,
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(200))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200))),
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
)
|
||||
@ -739,6 +747,7 @@ func (s *CLITestSuite) TestNewExecGrantAuthorized() {
|
||||
val[0].Address,
|
||||
grantee,
|
||||
tokens,
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
@ -836,6 +845,7 @@ func (s *CLITestSuite) TestExecSendAuthzWithAllowList() {
|
||||
val[0].Address,
|
||||
allowedAddr,
|
||||
tokens,
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
@ -850,6 +860,7 @@ func (s *CLITestSuite) TestExecSendAuthzWithAllowList() {
|
||||
val[0].Address,
|
||||
notAllowedAddr,
|
||||
tokens,
|
||||
s.ac,
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
|
||||
@ -4,11 +4,11 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
)
|
||||
@ -21,7 +21,7 @@ const (
|
||||
// GetQueryCmd returns the parent command for all x/bank CLi query commands. The
|
||||
// provided clientCtx should have, at a minimum, a verifier, CometBFT RPC client,
|
||||
// and marshaler set.
|
||||
func GetQueryCmd() *cobra.Command {
|
||||
func GetQueryCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Querying commands for the bank module",
|
||||
@ -31,8 +31,8 @@ func GetQueryCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
GetBalancesCmd(),
|
||||
GetSpendableBalancesCmd(),
|
||||
GetBalancesCmd(ac),
|
||||
GetSpendableBalancesCmd(ac),
|
||||
GetCmdQueryTotalSupply(),
|
||||
GetCmdDenomsMetadata(),
|
||||
GetCmdQuerySendEnabled(),
|
||||
@ -41,7 +41,7 @@ func GetQueryCmd() *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func GetBalancesCmd() *cobra.Command {
|
||||
func GetBalancesCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "balances [address]",
|
||||
Short: "Query for account balances by address",
|
||||
@ -70,7 +70,7 @@ Example:
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(args[0])
|
||||
addr, err := ac.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -117,7 +117,7 @@ Example:
|
||||
return cmd
|
||||
}
|
||||
|
||||
func GetSpendableBalancesCmd() *cobra.Command {
|
||||
func GetSpendableBalancesCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "spendable-balances [address]",
|
||||
Short: "Query for account spendable balances by address",
|
||||
@ -136,7 +136,7 @@ func GetSpendableBalancesCmd() *cobra.Command {
|
||||
|
||||
queryClient := types.NewQueryClient(clientCtx)
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(args[0])
|
||||
addr, err := ac.StringToBytes(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
@ -20,8 +21,7 @@ import (
|
||||
|
||||
func (s *CLITestSuite) TestGetBalancesCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
cmd := cli.GetBalancesCmd()
|
||||
cmd := cli.GetBalancesCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
testCases := []struct {
|
||||
@ -119,7 +119,7 @@ func (s *CLITestSuite) TestGetBalancesCmd() {
|
||||
func (s *CLITestSuite) TestGetSpendableBalancesCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
|
||||
cmd := cli.GetSpendableBalancesCmd()
|
||||
cmd := cli.GetSpendableBalancesCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
testCases := []struct {
|
||||
|
||||
@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -16,7 +17,7 @@ import (
|
||||
var FlagSplit = "split"
|
||||
|
||||
// NewTxCmd returns a root CLI command handler for all x/bank transaction commands.
|
||||
func NewTxCmd() *cobra.Command {
|
||||
func NewTxCmd(ac address.Codec) *cobra.Command {
|
||||
txCmd := &cobra.Command{
|
||||
Use: types.ModuleName,
|
||||
Short: "Bank transaction subcommands",
|
||||
@ -26,15 +27,15 @@ func NewTxCmd() *cobra.Command {
|
||||
}
|
||||
|
||||
txCmd.AddCommand(
|
||||
NewSendTxCmd(),
|
||||
NewMultiSendTxCmd(),
|
||||
NewSendTxCmd(ac),
|
||||
NewMultiSendTxCmd(ac),
|
||||
)
|
||||
|
||||
return txCmd
|
||||
}
|
||||
|
||||
// NewSendTxCmd returns a CLI command handler for creating a MsgSend transaction.
|
||||
func NewSendTxCmd() *cobra.Command {
|
||||
func NewSendTxCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "send [from_key_or_address] [to_address] [amount]",
|
||||
Short: "Send funds from one account to another.",
|
||||
@ -49,8 +50,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
toAddr, err := sdk.AccAddressFromBech32(args[1])
|
||||
toAddr, err := ac.StringToBytes(args[1])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -77,7 +77,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address.
|
||||
|
||||
// NewMultiSendTxCmd returns a CLI command handler for creating a MsgMultiSend transaction.
|
||||
// For a better UX this command is limited to send funds from one account to two or more accounts.
|
||||
func NewMultiSendTxCmd() *cobra.Command {
|
||||
func NewMultiSendTxCmd(ac address.Codec) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "multi-send [from_key_or_address] [to_address_1, to_address_2, ...] [amount]",
|
||||
Short: "Send funds from one account to two or more accounts.",
|
||||
@ -118,7 +118,7 @@ When using '--dry-run' a key name cannot be used, only a bech32 address.
|
||||
|
||||
var output []types.Output
|
||||
for _, arg := range args[1 : len(args)-1] {
|
||||
toAddr, err := sdk.AccAddressFromBech32(arg)
|
||||
toAddr, err := ac.StringToBytes(arg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
@ -18,7 +19,7 @@ import (
|
||||
|
||||
func (s *CLITestSuite) TestSendTxCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 1)
|
||||
cmd := cli.NewSendTxCmd()
|
||||
cmd := cli.NewSendTxCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
@ -104,7 +105,7 @@ func (s *CLITestSuite) TestSendTxCmd() {
|
||||
func (s *CLITestSuite) TestMultiSendTxCmd() {
|
||||
accounts := testutil.CreateKeyringAccounts(s.T(), s.kr, 3)
|
||||
|
||||
cmd := cli.NewMultiSendTxCmd()
|
||||
cmd := cli.NewMultiSendTxCmd(address.NewBech32Codec("cosmos"))
|
||||
cmd.SetOutput(io.Discard)
|
||||
|
||||
extraArgs := []string{
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
// GenesisBalance defines a genesis balance interface that allows for account
|
||||
// address and balance retrieval.
|
||||
type GenesisBalance interface {
|
||||
GetAddress() sdk.AccAddress
|
||||
GetAddress() string
|
||||
GetCoins() sdk.Coins
|
||||
}
|
||||
|
||||
|
||||
@ -26,9 +26,13 @@ func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisStat
|
||||
|
||||
for _, balance := range genState.Balances {
|
||||
addr := balance.GetAddress()
|
||||
bz, err := k.ak.AddressCodec().StringToBytes(addr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, coin := range balance.Coins {
|
||||
err := k.Balances.Set(ctx, collections.Join(addr, coin.Denom), coin.Amount)
|
||||
err := k.Balances.Set(ctx, collections.Join(sdk.AccAddress(bz), coin.Denom), coin.Amount)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest)
|
||||
}
|
||||
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
address, err := sdk.AccAddressFromBech32(req.Address)
|
||||
address, err := k.ak.AddressCodec().StringToBytes(req.Address)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
|
||||
}
|
||||
@ -53,7 +53,7 @@ func (k BaseKeeper) AllBalances(ctx context.Context, req *types.QueryAllBalances
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(req.Address)
|
||||
addr, err := k.ak.AddressCodec().StringToBytes(req.Address)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
|
||||
}
|
||||
@ -86,7 +86,7 @@ func (k BaseKeeper) SpendableBalances(ctx context.Context, req *types.QuerySpend
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(req.Address)
|
||||
addr, err := k.ak.AddressCodec().StringToBytes(req.Address)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
|
||||
}
|
||||
@ -121,7 +121,7 @@ func (k BaseKeeper) SpendableBalanceByDenom(ctx context.Context, req *types.Quer
|
||||
return nil, status.Error(codes.InvalidArgument, "empty request")
|
||||
}
|
||||
|
||||
addr, err := sdk.AccAddressFromBech32(req.Address)
|
||||
addr, err := k.ak.AddressCodec().StringToBytes(req.Address)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ func NewBaseKeeper(
|
||||
authority string,
|
||||
logger log.Logger,
|
||||
) BaseKeeper {
|
||||
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
|
||||
if _, err := ak.AddressCodec().StringToBytes(authority); err != nil {
|
||||
panic(fmt.Errorf("invalid bank authority address: %w", err))
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/runtime"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -135,7 +136,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
||||
// gomock initializations
|
||||
ctrl := gomock.NewController(suite.T())
|
||||
authKeeper := banktestutil.NewMockAccountKeeper(ctrl)
|
||||
|
||||
authKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
|
||||
suite.ctx = ctx
|
||||
suite.authKeeper = authKeeper
|
||||
suite.bankKeeper = keeper.NewBaseKeeper(
|
||||
@ -244,7 +245,7 @@ func (suite *KeeperTestSuite) TestGetAuthority() {
|
||||
return keeper.NewBaseKeeper(
|
||||
moduletestutil.MakeTestEncodingConfig().Codec,
|
||||
storeService,
|
||||
nil,
|
||||
suite.authKeeper,
|
||||
nil,
|
||||
authority,
|
||||
log.NewNopLogger(),
|
||||
|
||||
@ -27,14 +27,22 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {
|
||||
}
|
||||
|
||||
func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) {
|
||||
from, err := sdk.AccAddressFromBech32(msg.FromAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err)
|
||||
}
|
||||
var (
|
||||
from, to []byte
|
||||
err error
|
||||
)
|
||||
|
||||
to, err := sdk.AccAddressFromBech32(msg.ToAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err)
|
||||
if base, ok := k.Keeper.(BaseKeeper); ok {
|
||||
from, err = base.ak.AddressCodec().StringToBytes(msg.FromAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid from address: %s", err)
|
||||
}
|
||||
to, err = base.ak.AddressCodec().StringToBytes(msg.ToAddress)
|
||||
if err != nil {
|
||||
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid to address: %s", err)
|
||||
}
|
||||
} else {
|
||||
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid keeper type: %T", k.Keeper)
|
||||
}
|
||||
|
||||
if !msg.Amount.IsValid() {
|
||||
@ -101,10 +109,17 @@ func (k msgServer) MultiSend(goCtx context.Context, msg *types.MsgMultiSend) (*t
|
||||
}
|
||||
|
||||
for _, out := range msg.Outputs {
|
||||
accAddr := sdk.MustAccAddressFromBech32(out.Address)
|
||||
if base, ok := k.Keeper.(BaseKeeper); ok {
|
||||
accAddr, err := base.ak.AddressCodec().StringToBytes(out.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if k.BlockedAddr(accAddr) {
|
||||
return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address)
|
||||
if k.BlockedAddr(accAddr) {
|
||||
return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", out.Address)
|
||||
}
|
||||
} else {
|
||||
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid keeper type: %T", k.Keeper)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ func NewBaseSendKeeper(
|
||||
authority string,
|
||||
logger log.Logger,
|
||||
) BaseSendKeeper {
|
||||
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
|
||||
if _, err := ak.AddressCodec().StringToBytes(authority); err != nil {
|
||||
panic(fmt.Errorf("invalid bank authority address: %w", err))
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
|
||||
return err
|
||||
}
|
||||
|
||||
inAddress, err := sdk.AccAddressFromBech32(input.Address)
|
||||
inAddress, err := k.ak.AddressCodec().StringToBytes(input.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -144,7 +144,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
|
||||
)
|
||||
|
||||
for _, out := range outputs {
|
||||
outAddress, err := sdk.AccAddressFromBech32(out.Address)
|
||||
outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
modulev1 "cosmossdk.io/api/cosmos/bank/module/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
@ -45,6 +46,7 @@ var (
|
||||
// AppModuleBasic defines the basic application module used by the bank module.
|
||||
type AppModuleBasic struct {
|
||||
cdc codec.Codec
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
// Name returns the bank module's name.
|
||||
@ -79,13 +81,13 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *g
|
||||
}
|
||||
|
||||
// GetTxCmd returns the root tx command for the bank module.
|
||||
func (AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.NewTxCmd()
|
||||
func (ab AppModuleBasic) GetTxCmd() *cobra.Command {
|
||||
return cli.NewTxCmd(ab.ac)
|
||||
}
|
||||
|
||||
// GetQueryCmd returns no root query command for the bank module.
|
||||
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
return cli.GetQueryCmd()
|
||||
func (ab AppModuleBasic) GetQueryCmd() *cobra.Command {
|
||||
return cli.GetQueryCmd(ab.ac)
|
||||
}
|
||||
|
||||
// RegisterInterfaces registers interfaces and implementations of the bank module.
|
||||
@ -137,7 +139,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
// NewAppModule creates a new AppModule object
|
||||
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, ss exported.Subspace) AppModule {
|
||||
return AppModule{
|
||||
AppModuleBasic: AppModuleBasic{cdc: cdc},
|
||||
AppModuleBasic: AppModuleBasic{cdc: cdc, ac: accountKeeper.AddressCodec()},
|
||||
keeper: keeper,
|
||||
accountKeeper: accountKeeper,
|
||||
legacySubspace: ss,
|
||||
|
||||
@ -45,7 +45,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
assert.Equal(t, true, bankGenesis.Params.GetDefaultSendEnabled(), "Params.GetDefaultSendEnabled")
|
||||
assert.Len(t, bankGenesis.Params.GetSendEnabled(), 0, "Params.GetSendEnabled") //nolint:staticcheck // we're testing deprecated code here
|
||||
if assert.Len(t, bankGenesis.Balances, 3) {
|
||||
assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].GetAddress().String(), "Balances[2] address")
|
||||
assert.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", bankGenesis.Balances[2].Address, "Balances[2] address")
|
||||
assert.Equal(t, "1000stake", bankGenesis.Balances[2].GetCoins().String(), "Balances[2] coins")
|
||||
}
|
||||
assert.Equal(t, "6000stake", bankGenesis.Supply.String(), "Supply")
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package simulation_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
@ -37,7 +36,6 @@ func TestProposalMsgs(t *testing.T) {
|
||||
msgUpdateParams, ok := msg.(*types.MsgUpdateParams)
|
||||
assert.Assert(t, ok)
|
||||
|
||||
fmt.Println(msgUpdateParams)
|
||||
assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority)
|
||||
assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck // we're testing deprecated code here
|
||||
assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled)
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
context "context"
|
||||
reflect "reflect"
|
||||
|
||||
address "cosmossdk.io/core/address"
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
types0 "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
@ -36,6 +37,20 @@ func (m *MockAccountKeeper) EXPECT() *MockAccountKeeperMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AddressCodec mocks base method.
|
||||
func (m *MockAccountKeeper) AddressCodec() address.Codec {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AddressCodec")
|
||||
ret0, _ := ret[0].(address.Codec)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// AddressCodec indicates an expected call of AddressCodec.
|
||||
func (mr *MockAccountKeeperMockRecorder) AddressCodec() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressCodec", reflect.TypeOf((*MockAccountKeeper)(nil).AddressCodec))
|
||||
}
|
||||
|
||||
// GetAccount mocks base method.
|
||||
func (m *MockAccountKeeper) GetAccount(ctx context.Context, addr types.AccAddress) types.AccountI {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -13,8 +13,8 @@ import (
|
||||
var _ exported.GenesisBalance = (*Balance)(nil)
|
||||
|
||||
// GetAddress returns the account address of the Balance object.
|
||||
func (b Balance) GetAddress() sdk.AccAddress {
|
||||
return sdk.MustAccAddressFromBech32(b.Address)
|
||||
func (b Balance) GetAddress() string {
|
||||
return b.Address
|
||||
}
|
||||
|
||||
// GetCoins returns the account coins of the Balance object.
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package types_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
@ -118,9 +117,9 @@ func TestBalanceValidate(t *testing.T) {
|
||||
|
||||
func TestBalance_GetAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
Address string
|
||||
wantPanic bool
|
||||
name string
|
||||
Address string
|
||||
err bool
|
||||
}{
|
||||
{"empty address", "", true},
|
||||
{"malformed address", "invalid", true},
|
||||
@ -130,10 +129,10 @@ func TestBalance_GetAddress(t *testing.T) {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
b := bank.Balance{Address: tt.Address}
|
||||
if tt.wantPanic {
|
||||
require.Panics(t, func() { b.GetAddress() })
|
||||
if !tt.err {
|
||||
require.Equal(t, b.GetAddress(), tt.Address)
|
||||
} else {
|
||||
require.False(t, b.GetAddress().Empty())
|
||||
require.False(t, len(b.GetAddress()) != 0 && b.GetAddress() != tt.Address)
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -164,8 +163,7 @@ func TestSanitizeBalances(t *testing.T) {
|
||||
// Ensure that every single value that comes after i is less than it.
|
||||
for j := i + 1; j < len(sorted); j++ {
|
||||
aj := sorted[j]
|
||||
|
||||
if got := bytes.Compare(ai.GetAddress(), aj.GetAddress()); got > 0 {
|
||||
if ai.GetAddress() == aj.GetAddress() {
|
||||
t.Errorf("Balance(%d) > Balance(%d)", i, j)
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package types
|
||||
import (
|
||||
context "context"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
@ -10,6 +11,8 @@ import (
|
||||
// AccountKeeper defines the account contract that must be fulfilled when
|
||||
// creating a x/bank keeper.
|
||||
type AccountKeeper interface {
|
||||
AddressCodec() address.Codec
|
||||
|
||||
NewAccount(context.Context, sdk.AccountI) sdk.AccountI
|
||||
NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
|
||||
|
||||
|
||||
@ -86,7 +86,8 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
|
||||
genBalIterator.IterateGenesisBalances(
|
||||
cdc, appState,
|
||||
func(balance bankexported.GenesisBalance) (stop bool) {
|
||||
balancesMap[balance.GetAddress().String()] = balance
|
||||
addr := balance.GetAddress()
|
||||
balancesMap[addr] = balance
|
||||
return false
|
||||
},
|
||||
)
|
||||
@ -161,7 +162,7 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
|
||||
if delBal.GetCoins().AmountOf(msg.Value.Denom).LT(msg.Value.Amount) {
|
||||
return appGenTxs, persistentPeers, fmt.Errorf(
|
||||
"insufficient fund for delegation %v: %v < %v",
|
||||
delBal.GetAddress().String(), delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount,
|
||||
delBal.GetAddress(), delBal.GetCoins().AmountOf(msg.Value.Denom), msg.Value.Amount,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package genutil
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"cosmossdk.io/core/genesis"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -53,9 +54,8 @@ func ValidateAccountInGenesis(
|
||||
func(bal bankexported.GenesisBalance) (stop bool) {
|
||||
accAddress := bal.GetAddress()
|
||||
accCoins := bal.GetCoins()
|
||||
|
||||
// ensure that account is in genesis
|
||||
if accAddress.Equals(addr) {
|
||||
if strings.EqualFold(accAddress, addr.String()) {
|
||||
// ensure account contains enough funds of default bond denom
|
||||
if coins.AmountOf(bondDenom).GT(accCoins.AmountOf(bondDenom)) {
|
||||
err = fmt.Errorf(
|
||||
|
||||
@ -87,7 +87,7 @@ func TestGenesisStateFromGenFile(t *testing.T) {
|
||||
|
||||
require.True(t, bankGenesis.Params.DefaultSendEnabled)
|
||||
require.Equal(t, "1000nametoken,100000000stake", bankGenesis.Balances[0].GetCoins().String())
|
||||
require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0].GetAddress().String())
|
||||
require.Equal(t, "cosmos106vrzv5xkheqhjm023pxcxlqmcjvuhtfyachz4", bankGenesis.Balances[0].Address)
|
||||
require.Equal(t, "The native staking token of the Cosmos Hub.", bankGenesis.DenomMetadata[0].GetDescription())
|
||||
require.Equal(t, "uatom", bankGenesis.DenomMetadata[0].GetBase())
|
||||
require.Equal(t, "matom", bankGenesis.DenomMetadata[0].GetDenomUnits()[1].GetDenom())
|
||||
|
||||
@ -89,7 +89,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
s.clientCtx,
|
||||
val.Address,
|
||||
account,
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(2000))), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(2000))), address.NewBech32Codec("cosmos"), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(10))).String()),
|
||||
)
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -20,6 +21,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
testutilmod "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/x/nft"
|
||||
"cosmossdk.io/x/nft/client/cli"
|
||||
nftmodule "cosmossdk.io/x/nft/module"
|
||||
@ -74,6 +76,8 @@ type CLITestSuite struct {
|
||||
ctx context.Context
|
||||
|
||||
owner sdk.AccAddress
|
||||
|
||||
ac address.Codec
|
||||
}
|
||||
|
||||
func TestCLITestSuite(t *testing.T) {
|
||||
@ -118,6 +122,8 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
s.Require().NoError(err)
|
||||
genesisState[nft.ModuleName] = nftDataBz
|
||||
|
||||
s.ac = codecaddress.NewBech32Codec("cosmos")
|
||||
|
||||
s.initAccount()
|
||||
}
|
||||
|
||||
@ -227,6 +233,6 @@ func (s *CLITestSuite) initAccount() {
|
||||
s.Require().NoError(err)
|
||||
|
||||
amount := sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(200)))
|
||||
_, err = clitestutil.MsgSendExec(ctx, accounts[0].Address, s.owner, amount, args...)
|
||||
_, err = clitestutil.MsgSendExec(ctx, accounts[0].Address, s.owner, amount, s.ac, args...)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user