diff --git a/simapp/genesis_account.go b/simapp/genesis_account.go index d242ba57060c..78b252a79683 100644 --- a/simapp/genesis_account.go +++ b/simapp/genesis_account.go @@ -3,6 +3,7 @@ package simapp import ( "errors" + "cosmossdk.io/core/address" authtypes "cosmossdk.io/x/auth/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -28,7 +29,7 @@ type SimGenesisAccount struct { } // Validate checks for errors on the vesting and module account parameters -func (sga SimGenesisAccount) Validate() error { +func (sga SimGenesisAccount) Validate(addressCodec address.Codec) error { if !sga.OriginalVesting.IsZero() { if sga.StartTime >= sga.EndTime { return errors.New("vesting start-time cannot be before end-time") @@ -39,10 +40,10 @@ func (sga SimGenesisAccount) Validate() error { ma := authtypes.ModuleAccount{ BaseAccount: sga.BaseAccount, Name: sga.ModuleName, Permissions: sga.ModulePermissions, } - if err := ma.Validate(); err != nil { + if err := ma.Validate(addressCodec); err != nil { return err } } - return sga.BaseAccount.Validate() + return sga.BaseAccount.Validate(addressCodec) } diff --git a/simapp/genesis_account_test.go b/simapp/genesis_account_test.go index 0fe897c10749..cc416d583d21 100644 --- a/simapp/genesis_account_test.go +++ b/simapp/genesis_account_test.go @@ -10,14 +10,19 @@ import ( "cosmossdk.io/simapp" authtypes "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSimGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addr, err := ac.BytesToString(pubkey.Address()) + require.NoError(t, err) + modAddr, err := ac.BytesToString(crypto.AddressHash([]byte("testmod"))) + require.NoError(t, err) vestingStart := time.Now().UTC() coins := sdk.NewCoins(sdk.NewInt64Coin("test", 1000)) @@ -45,7 +50,7 @@ func TestSimGenesisAccountValidate(t *testing.T) { { "valid basic account with module name", simapp.SimGenesisAccount{ - BaseAccount: authtypes.NewBaseAccount(sdk.AccAddress(crypto.AddressHash([]byte("testmod"))), nil, 0, 0), + BaseAccount: authtypes.NewBaseAccount(modAddr, nil, 0, 0), ModuleName: "testmod", }, false, @@ -83,7 +88,7 @@ func TestSimGenesisAccountValidate(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - require.Equal(t, tc.wantErr, tc.sga.Validate() != nil) + require.Equal(t, tc.wantErr, tc.sga.Validate(ac) != nil) }) } } diff --git a/simapp/simd/cmd/testnet.go b/simapp/simd/cmd/testnet.go index 957cc455e51a..381033146b73 100644 --- a/simapp/simd/cmd/testnet.go +++ b/simapp/simd/cmd/testnet.go @@ -276,6 +276,10 @@ func initTestnetFiles( _ = os.RemoveAll(args.outputDir) return err } + addrStr, err := clientCtx.AddressCodec.BytesToString(addr) + if err != nil { + return err + } info := map[string]string{"secret": secret} @@ -296,8 +300,8 @@ func initTestnetFiles( sdk.NewCoin(sdk.DefaultBondDenom, accStakingTokens), } - genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: coins.Sort()}) - genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) + genBalances = append(genBalances, banktypes.Balance{Address: addrStr, Coins: coins.Sort()}) + genAccounts = append(genAccounts, authtypes.NewBaseAccount(addrStr, nil, 0, 0)) valStr, err := clientCtx.ValidatorAddressCodec.BytesToString(sdk.ValAddress(addr)) if err != nil { diff --git a/simapp/test_helpers.go b/simapp/test_helpers.go index 184a0ac5fdc9..6aa7e7042720 100644 --- a/simapp/test_helpers.go +++ b/simapp/test_helpers.go @@ -21,6 +21,7 @@ import ( bam "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/client/flags" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -65,7 +66,9 @@ func NewSimappWithCustomOptions(t *testing.T, isCheckTx bool, options SetupOptio // generate genesis account senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(senderPrivKey.PubKey().Address()) + require.NoError(t, err) + acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0) balance := banktypes.Balance{ Address: acc.GetAddress().String(), Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), @@ -107,7 +110,9 @@ func Setup(t *testing.T, isCheckTx bool) *SimApp { // generate genesis account senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(senderPrivKey.PubKey().Address()) + require.NoError(t, err) + acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0) balance := banktypes.Balance{ Address: acc.GetAddress().String(), Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000))), @@ -167,7 +172,9 @@ func GenesisStateWithSingleValidator(t *testing.T, app *SimApp) GenesisState { // generate genesis account senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + addr, err := app.AuthKeeper.AddressCodec().BytesToString(senderPrivKey.PubKey().Address()) + require.NoError(t, err) + acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0) balances := []banktypes.Balance{ { Address: acc.GetAddress().String(), diff --git a/tests/e2e/auth/suite.go b/tests/e2e/auth/suite.go index 1d5e6b7f2a34..2e381f1d67f8 100644 --- a/tests/e2e/auth/suite.go +++ b/tests/e2e/auth/suite.go @@ -230,41 +230,44 @@ func (s *E2ETestSuite) TestCLISignBatch() { defer outputFile.Close() clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) + valAddr, err := clientCtx.AddressCodec.BytesToString(val.GetAddress()) + s.Require().NoError(err) + // sign-batch file - offline is set but account-number and sequence are not - _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--offline") + _, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // sign-batch file - offline and sequence is set but account-number is not set - _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") + _, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\" not set") // sign-batch file - offline and account-number is set but sequence is not set - _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") + _, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") s.Require().EqualError(err, "required flag(s) \"sequence\" not set") // sign-batch file - sequence and account-number are set when offline is false - res, err := authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1")) + res, err := authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1")) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // sign-batch file - res, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID)) + res, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID)) s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // sign-batch file signature only - res, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") + res, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // Sign batch malformed tx file. malformedFile := testutil.WriteToNewTempFile(s.T(), fmt.Sprintf("malformed%s", generatedStd)) defer malformedFile.Close() - _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID)) + _, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID)) s.Require().Error(err) // Sign batch malformed tx file signature only. - _, err = authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") + _, err = authclitestutil.TxSignBatchExec(clientCtx, valAddr, malformedFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") s.Require().Error(err) // make a txn to increase the sequence of sender @@ -293,7 +296,7 @@ func (s *E2ETestSuite) TestCLISignBatch() { s.Require().Equal(seq+1, seq1) // signing sign-batch should start from the last sequence. - signed, err := authclitestutil.TxSignBatchExec(clientCtx, val.GetAddress(), outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") + signed, err := authclitestutil.TxSignBatchExec(clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--signature-only") s.Require().NoError(err) signedTxs := strings.Split(strings.Trim(signed.String(), "\n"), "\n") s.Require().GreaterOrEqual(len(signedTxs), 1) @@ -676,19 +679,22 @@ func (s *E2ETestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().EqualError(err, "signatures validation failed") s.Require().True(strings.Contains(res.String(), fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", val1.GetAddress().String()))) + val1Addr, err := clientCtx.AddressCodec.BytesToString(val1.GetAddress()) + s.Require().NoError(err) + // Test sign // Does not work in offline mode - _, err = authclitestutil.TxSignExec(clientCtx, val1.GetAddress(), unsignedTxFile.Name(), "--offline") + _, err = authclitestutil.TxSignExec(clientCtx, val1Addr, unsignedTxFile.Name(), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // But works offline if we set account number and sequence clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) - _, err = authclitestutil.TxSignExec(clientCtx, val1.GetAddress(), unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1") + _, err = authclitestutil.TxSignExec(clientCtx, val1Addr, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1") s.Require().NoError(err) // Sign transaction - signedTx, err := authclitestutil.TxSignExec(clientCtx, val1.GetAddress(), unsignedTxFile.Name()) + signedTx, err := authclitestutil.TxSignExec(clientCtx, val1Addr, unsignedTxFile.Name()) s.Require().NoError(err) signedFinalTx, err := txCfg.TxJSONDecoder()(signedTx.Bytes()) s.Require().NoError(err) @@ -802,7 +808,9 @@ func (s *E2ETestSuite) TestCLIMultisignInsufficientCosigners() { clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) addr1, err := account1.GetAddress() s.Require().NoError(err) - account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) + account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -924,8 +932,10 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { // Sign with account1 addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) - account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -934,7 +944,9 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { // Sign with account2 addr2, err := account2.GetAddress() s.Require().NoError(err) - account2Signature, err := authclitestutil.TxSignExec(clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + addr2Str, err := clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) + account2Signature, err := authclitestutil.TxSignExec(clientCtx, addr2Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) @@ -943,7 +955,9 @@ func (s *E2ETestSuite) TestCLIMultisignSortSignatures() { // Sign with dummy account dummyAddr, err := dummyAcc.GetAddress() s.Require().NoError(err) - _, err = authclitestutil.TxSignExec(clientCtx, dummyAddr, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + dummyAddrStr, err := clientCtx.AddressCodec.BytesToString(dummyAddr) + s.Require().NoError(err) + _, err = authclitestutil.TxSignExec(clientCtx, dummyAddrStr, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().Error(err) s.Require().Contains(err.Error(), "signing key is not a part of multisig key") @@ -1003,11 +1017,14 @@ func (s *E2ETestSuite) TestSignWithMultisig() { multiGeneratedTx2File := testutil.WriteToNewTempFile(s.T(), multisigTx.String()) defer multiGeneratedTx2File.Close() + addr1Str, err := s.ac.BytesToString(addr1) + s.Require().NoError(err) + // Sign using multisig. We're signing a tx on behalf of the multisig address, // even though the tx signer is NOT the multisig address. This is fine though, // as the main point of this test is to test the `--multisig` flag with an address // that is not in the keyring. - _, err = authclitestutil.TxSignExec(val1.GetClientCtx(), addr1, multiGeneratedTx2File.Name(), "--multisig", multisigAddr.String()) + _, err = authclitestutil.TxSignExec(val1.GetClientCtx(), addr1Str, multiGeneratedTx2File.Name(), "--multisig", multisigAddr.String()) s.Require().Contains(err.Error(), "error getting account from keybase") } @@ -1074,9 +1091,11 @@ func (s *E2ETestSuite) TestCLIMultisign() { addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) // Sign with account1 clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) - account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account1Signature, err := authclitestutil.TxSignExec(clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -1084,8 +1103,10 @@ func (s *E2ETestSuite) TestCLIMultisign() { addr2, err := account2.GetAddress() s.Require().NoError(err) + addr2Str, err := clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) // Sign with account2 - account2Signature, err := authclitestutil.TxSignExec(clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account2Signature, err := authclitestutil.TxSignExec(clientCtx, addr2Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) @@ -1175,8 +1196,10 @@ func (s *E2ETestSuite) TestSignBatchMultisig() { addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) // sign-batch file - res, err := authclitestutil.TxSignBatchExec(clientCtx, addr1, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") + res, err := authclitestutil.TxSignBatchExec(clientCtx, addr1Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file @@ -1185,8 +1208,10 @@ func (s *E2ETestSuite) TestSignBatchMultisig() { addr2, err := account2.GetAddress() s.Require().NoError(err) + addr2Str, err := clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) // sign-batch file with account2 - res, err = authclitestutil.TxSignBatchExec(clientCtx, addr2, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") + res, err = authclitestutil.TxSignBatchExec(clientCtx, addr2Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file2 @@ -1249,7 +1274,9 @@ func (s *E2ETestSuite) TestMultisignBatch() { // sign-batch file addr1, err := account1.GetAddress() s.Require().NoError(err) - res, err := authclitestutil.TxSignBatchExec(clientCtx, addr1, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence())), "--signature-only") + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) + res, err := authclitestutil.TxSignBatchExec(clientCtx, addr1Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence())), "--signature-only") s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file @@ -1259,7 +1286,9 @@ func (s *E2ETestSuite) TestMultisignBatch() { // sign-batch file with account2 addr2, err := account2.GetAddress() s.Require().NoError(err) - res, err = authclitestutil.TxSignBatchExec(clientCtx, addr2, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence())), "--signature-only") + addr2Str, err := clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) + res, err = authclitestutil.TxSignBatchExec(clientCtx, addr2Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), "--multisig", addr.String(), fmt.Sprintf("--%s", flags.FlagOffline), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, fmt.Sprint(account.GetAccountNumber())), fmt.Sprintf("--%s=%s", flags.FlagSequence, fmt.Sprint(account.GetSequence())), "--signature-only") s.Require().NoError(err) s.Require().Equal(3, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) @@ -1355,8 +1384,11 @@ func (s *E2ETestSuite) TestTxWithoutPublicKey() { unsignedTxFile := testutil.WriteToNewTempFile(s.T(), string(txJSON)) defer unsignedTxFile.Close() + val1Str, err := clientCtx.AddressCodec.BytesToString(val1.GetAddress()) + s.Require().NoError(err) + // Sign the file with the unsignedTx. - signedTx, err := authclitestutil.TxSignExec(clientCtx, val1.GetAddress(), unsignedTxFile.Name(), fmt.Sprintf("--%s=true", cli.FlagOverwrite)) + signedTx, err := authclitestutil.TxSignExec(clientCtx, val1Str, unsignedTxFile.Name(), fmt.Sprintf("--%s=true", cli.FlagOverwrite)) s.Require().NoError(err) // Remove the signerInfo's `public_key` field manually from the signedTx. @@ -1422,7 +1454,7 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { defer unsignedTxFile.Close() // Let val0 sign first the file with the unsignedTx. - signedByVal0, err := authclitestutil.TxSignExec(val0.GetClientCtx(), val0.GetAddress(), unsignedTxFile.Name(), "--overwrite", "--sign-mode=amino-json") + signedByVal0, err := authclitestutil.TxSignExec(val0.GetClientCtx(), val0Str, unsignedTxFile.Name(), "--overwrite", "--sign-mode=amino-json") require.NoError(err) signedByVal0File := testutil.WriteToNewTempFile(s.T(), signedByVal0.String()) defer signedByVal0File.Close() @@ -1433,7 +1465,7 @@ func (s *E2ETestSuite) TestSignWithMultiSignersAminoJSON() { signedTx, err := authclitestutil.TxSignExec( val1.GetClientCtx(), - val1.GetAddress(), + val1Str, signedByVal0File.Name(), "--offline", fmt.Sprintf("--account-number=%d", val1AccNum), diff --git a/tests/e2e/baseapp/utils.go b/tests/e2e/baseapp/utils.go index f776de1e03dc..a6614eb4f56a 100644 --- a/tests/e2e/baseapp/utils.go +++ b/tests/e2e/baseapp/utils.go @@ -39,7 +39,7 @@ func GenesisStateWithSingleValidator(t *testing.T, codec codec.Codec, builder *r // generate genesis account senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().String(), senderPrivKey.PubKey(), 0, 0) balances := []banktypes.Balance{ { Address: acc.GetAddress().String(), diff --git a/tests/e2e/tx/service_test.go b/tests/e2e/tx/service_test.go index b9c500cf53de..2176b7865af5 100644 --- a/tests/e2e/tx/service_test.go +++ b/tests/e2e/tx/service_test.go @@ -643,15 +643,19 @@ func (s *E2ETestSuite) TestSimMultiSigTx() { // Sign with account1 addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) clientCtx.HomeDir = strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1) - account1Signature, err := authtest.TxSignExec(clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account1Signature, err := authtest.TxSignExec(clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) // Sign with account2 addr2, err := account2.GetAddress() s.Require().NoError(err) - account2Signature, err := authtest.TxSignExec(clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + addr2Str, err := clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) + account2Signature, err := authtest.TxSignExec(clientCtx, addr2Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) diff --git a/tests/integration/auth/client/cli/suite_test.go b/tests/integration/auth/client/cli/suite_test.go index 963a313045c5..020031cd00bb 100644 --- a/tests/integration/auth/client/cli/suite_test.go +++ b/tests/integration/auth/client/cli/suite_test.go @@ -122,7 +122,10 @@ func (s *CLITestSuite) TestCLIValidateSignatures() { unsignedTx := testutil.WriteToNewTempFile(s.T(), res.String()) defer unsignedTx.Close() - res, err = authtestutil.TxSignExec(s.clientCtx, s.val, unsignedTx.Name()) + valStr, err := s.ac.BytesToString(s.val) + s.Require().NoError(err) + + res, err = authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTx.Name()) s.Require().NoError(err) signedTx, err := s.clientCtx.TxConfig.TxJSONDecoder()(res.Bytes()) s.Require().NoError(err) @@ -159,16 +162,19 @@ func (s *CLITestSuite) TestCLISignBatch() { defer outputFile.Close() s.clientCtx.HomeDir = strings.Replace(s.clientCtx.HomeDir, "simd", "simcli", 1) + valAddr, err := s.clientCtx.AddressCodec.BytesToString(s.val) + s.Require().NoError(err) + // sign-batch file - offline is set but account-number and sequence are not - _, err = authtestutil.TxSignBatchExec(s.clientCtx, s.val, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--offline") + _, err = authtestutil.TxSignBatchExec(s.clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // sign-batch file - offline and sequence is set but account-number is not set - _, err = authtestutil.TxSignBatchExec(s.clientCtx, s.val, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") + _, err = authtestutil.TxSignBatchExec(s.clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagSequence, "1"), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\" not set") // sign-batch file - offline and account-number is set but sequence is not set - _, err = authtestutil.TxSignBatchExec(s.clientCtx, s.val, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") + _, err = authtestutil.TxSignBatchExec(s.clientCtx, valAddr, outputFile.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), fmt.Sprintf("--%s=%s", flags.FlagAccountNumber, "1"), "--offline") s.Require().EqualError(err, "required flag(s) \"sequence\" not set") } @@ -450,19 +456,22 @@ func (s *CLITestSuite) TestCLISendGenerateSignAndBroadcast() { s.Require().EqualError(err, "signatures validation failed") s.Require().Contains(res.String(), fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n\n", s.val.String())) + valStr, err := s.ac.BytesToString(s.val) + s.Require().NoError(err) + // Test sign // Does not work in offline mode - _, err = authtestutil.TxSignExec(s.clientCtx, s.val, unsignedTxFile.Name(), "--offline") + _, err = authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTxFile.Name(), "--offline") s.Require().EqualError(err, "required flag(s) \"account-number\", \"sequence\" not set") // But works offline if we set account number and sequence s.clientCtx.HomeDir = strings.Replace(s.clientCtx.HomeDir, "simd", "simcli", 1) - _, err = authtestutil.TxSignExec(s.clientCtx, s.val, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1") + _, err = authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTxFile.Name(), "--offline", "--account-number", "1", "--sequence", "1") s.Require().NoError(err) // Sign transaction - signedTx, err := authtestutil.TxSignExec(s.clientCtx, s.val, unsignedTxFile.Name()) + signedTx, err := authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTxFile.Name()) s.Require().NoError(err) signedFinalTx, err := txCfg.TxJSONDecoder()(signedTx.Bytes()) s.Require().NoError(err) @@ -541,7 +550,9 @@ func (s *CLITestSuite) TestCLIMultisignInsufficientCosigners() { s.clientCtx.HomeDir = strings.Replace(s.clientCtx.HomeDir, "simd", "simcli", 1) addr1, err := account1.GetAddress() s.Require().NoError(err) - account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + addr1Str, err := s.ac.BytesToString(addr1) + s.Require().NoError(err) + account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -625,8 +636,10 @@ func (s *CLITestSuite) TestCLIMultisignSortSignatures() { // Sign with account1 addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := s.ac.BytesToString(addr1) + s.Require().NoError(err) s.clientCtx.HomeDir = strings.Replace(s.clientCtx.HomeDir, "simd", "simcli", 1) - account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -635,7 +648,9 @@ func (s *CLITestSuite) TestCLIMultisignSortSignatures() { // Sign with account2 addr2, err := account2.GetAddress() s.Require().NoError(err) - account2Signature, err := authtestutil.TxSignExec(s.clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + addr2Str, err := s.ac.BytesToString(addr2) + s.Require().NoError(err) + account2Signature, err := authtestutil.TxSignExec(s.clientCtx, addr2Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) @@ -644,7 +659,9 @@ func (s *CLITestSuite) TestCLIMultisignSortSignatures() { // Sign with dummy account dummyAddr, err := dummyAcc.GetAddress() s.Require().NoError(err) - _, err = authtestutil.TxSignExec(s.clientCtx, dummyAddr, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + dummyAddrStr, err := s.ac.BytesToString(dummyAddr) + s.Require().NoError(err) + _, err = authtestutil.TxSignExec(s.clientCtx, dummyAddrStr, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().Error(err) s.Require().Contains(err.Error(), "signing key is not a part of multisig key") @@ -670,6 +687,8 @@ func (s *CLITestSuite) TestSignWithMultisig() { addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := s.ac.BytesToString(addr1) + s.Require().NoError(err) // Create an address that is not in the keyring, will be used to simulate `--multisig` multisig := "cosmos1hd6fsrvnz6qkp87s3u86ludegq97agxsdkwzyh" @@ -694,7 +713,7 @@ func (s *CLITestSuite) TestSignWithMultisig() { // even though the tx signer is NOT the multisig address. This is fine though, // as the main point of this test is to test the `--multisig` flag with an address // that is not in the keyring. - _, err = authtestutil.TxSignExec(s.clientCtx, addr1, multiGeneratedTx2File.Name(), "--multisig", multisig) + _, err = authtestutil.TxSignExec(s.clientCtx, addr1Str, multiGeneratedTx2File.Name(), "--multisig", multisig) s.Require().Contains(err.Error(), "error getting account from keybase") } @@ -728,9 +747,11 @@ func (s *CLITestSuite) TestCLIMultisign() { addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := s.ac.BytesToString(addr1) + s.Require().NoError(err) // Sign with account1 s.clientCtx.HomeDir = strings.Replace(s.clientCtx.HomeDir, "simd", "simcli", 1) - account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account1Signature, err := authtestutil.TxSignExec(s.clientCtx, addr1Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign1File := testutil.WriteToNewTempFile(s.T(), account1Signature.String()) @@ -738,8 +759,10 @@ func (s *CLITestSuite) TestCLIMultisign() { addr2, err := account2.GetAddress() s.Require().NoError(err) + addr2Str, err := s.ac.BytesToString(addr2) + s.Require().NoError(err) // Sign with account2 - account2Signature, err := authtestutil.TxSignExec(s.clientCtx, addr2, multiGeneratedTxFile.Name(), "--multisig", addr.String()) + account2Signature, err := authtestutil.TxSignExec(s.clientCtx, addr2Str, multiGeneratedTxFile.Name(), "--multisig", addr.String()) s.Require().NoError(err) sign2File := testutil.WriteToNewTempFile(s.T(), account2Signature.String()) @@ -798,8 +821,10 @@ func (s *CLITestSuite) TestSignBatchMultisig() { addr1, err := account1.GetAddress() s.Require().NoError(err) + addr1Str, err := s.clientCtx.AddressCodec.BytesToString(addr1) + s.Require().NoError(err) // sign-batch file - res, err := authtestutil.TxSignBatchExec(s.clientCtx, addr1, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") + res, err := authtestutil.TxSignBatchExec(s.clientCtx, addr1Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file @@ -808,8 +833,10 @@ func (s *CLITestSuite) TestSignBatchMultisig() { addr2, err := account2.GetAddress() s.Require().NoError(err) + addr2Str, err := s.clientCtx.AddressCodec.BytesToString(addr2) + s.Require().NoError(err) // sign-batch file with account2 - res, err = authtestutil.TxSignBatchExec(s.clientCtx, addr2, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") + res, err = authtestutil.TxSignBatchExec(s.clientCtx, addr2Str, filename.Name(), fmt.Sprintf("--%s=%s", flags.FlagChainID, s.clientCtx.ChainID), "--multisig", addr.String(), "--signature-only") s.Require().NoError(err) s.Require().Equal(1, len(strings.Split(strings.Trim(res.String(), "\n"), "\n"))) // write sigs to file2 @@ -882,7 +909,7 @@ func (s *CLITestSuite) TestTxWithoutPublicKey() { defer unsignedTxFile.Close() // Sign the file with the unsignedTx. - signedTx, err := authtestutil.TxSignExec(s.clientCtx, s.val, unsignedTxFile.Name(), fmt.Sprintf("--%s=true", cli.FlagOverwrite)) + signedTx, err := authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTxFile.Name(), fmt.Sprintf("--%s=true", cli.FlagOverwrite)) s.Require().NoError(err) // Remove the signerInfo's `public_key` field manually from the signedTx. @@ -948,7 +975,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { defer unsignedTxFile.Close() // Let val0 sign first the file with the unsignedTx. - signedByVal0, err := authtestutil.TxSignExec(s.clientCtx, val0, unsignedTxFile.Name(), "--overwrite", "--sign-mode=amino-json") + signedByVal0, err := authtestutil.TxSignExec(s.clientCtx, valStr, unsignedTxFile.Name(), "--overwrite", "--sign-mode=amino-json") s.Require().NoError(err) signedByVal0File := testutil.WriteToNewTempFile(s.T(), signedByVal0.String()) defer signedByVal0File.Close() @@ -959,7 +986,7 @@ func (s *CLITestSuite) TestSignWithMultiSignersAminoJSON() { signedTx, err := authtestutil.TxSignExec( s.clientCtx, - val1, + val1Str, signedByVal0File.Name(), "--offline", fmt.Sprintf("--account-number=%d", val1AccNum), diff --git a/tests/integration/bank/app_test.go b/tests/integration/bank/app_test.go index d1b2e91dbe36..0c70d7edc9f4 100644 --- a/tests/integration/bank/app_test.go +++ b/tests/integration/bank/app_test.go @@ -86,7 +86,8 @@ func createTestSuite(t *testing.T, genesisAccounts []authtypes.GenesisAccount) s genAccounts = append(genAccounts, simtestutil.GenesisAccount{GenesisAccount: acc}) } - startupCfg := simtestutil.DefaultStartUpConfig() + startupCfg, err := simtestutil.DefaultStartUpConfig(cdctestutil.CodecOptions{}.GetAddressCodec()) + require.NoError(t, err) startupCfg.GenesisAccounts = genAccounts app, err := simtestutil.SetupWithConfiguration( @@ -333,8 +334,8 @@ func TestMsgMultiSendDependent(t *testing.T) { addr2Str, err := ac.BytesToString(addr2) require.NoError(t, err) - acc1 := authtypes.NewBaseAccountWithAddress(addr1) - acc2 := authtypes.NewBaseAccountWithAddress(addr2) + acc1 := authtypes.NewBaseAccountWithAddress(addr1Str) + acc2 := authtypes.NewBaseAccountWithAddress(addr2Str) err = acc2.SetAccountNumber(1) require.NoError(t, err) @@ -396,7 +397,7 @@ func TestMsgMultiSendDependent(t *testing.T) { } func TestMsgSetSendEnabled(t *testing.T) { - acc1 := authtypes.NewBaseAccountWithAddress(addr1) + acc1 := authtypes.NewBaseAccountWithAddress(addr1.String()) genAccs := []authtypes.GenesisAccount{acc1} s := createTestSuite(t, genAccs) diff --git a/tests/integration/gov/common_test.go b/tests/integration/gov/common_test.go index d5243c15e66f..05b9f13304f9 100644 --- a/tests/integration/gov/common_test.go +++ b/tests/integration/gov/common_test.go @@ -22,6 +22,7 @@ import ( _ "cosmossdk.io/x/staking" stakingtypes "cosmossdk.io/x/staking/types" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/configurator" @@ -102,6 +103,9 @@ func createTestSuite(t *testing.T) suite { t.Helper() res := suite{} + cfg, err := simtestutil.DefaultStartUpConfig(testutil.CodecOptions{}.GetAddressCodec()) + require.NoError(t, err) + app, err := simtestutil.SetupWithConfiguration( depinject.Configs( configurator.NewAppConfig( @@ -114,7 +118,7 @@ func createTestSuite(t *testing.T) suite { ), depinject.Supply(sdklog.NewNopLogger()), ), - simtestutil.DefaultStartUpConfig(), + cfg, &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, ) require.NoError(t, err) diff --git a/tests/integration/gov/genesis_test.go b/tests/integration/gov/genesis_test.go index 6cbe8e7be48c..bc9930835efd 100644 --- a/tests/integration/gov/genesis_test.go +++ b/tests/integration/gov/genesis_test.go @@ -28,6 +28,7 @@ import ( stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -58,13 +59,16 @@ var appConfig = configurator.NewAppConfig( func TestImportExportQueues(t *testing.T) { var err error + cfg, err := simtestutil.DefaultStartUpConfig(testutil.CodecOptions{}.GetAddressCodec()) + assert.NilError(t, err) + s1 := suite{} s1.app, err = simtestutil.SetupWithConfiguration( depinject.Configs( appConfig, depinject.Supply(log.NewNopLogger()), ), - simtestutil.DefaultStartUpConfig(), + cfg, &s1.AccountKeeper, &s1.BankKeeper, &s1.GovKeeper, &s1.StakingKeeper, &s1.cdc, &s1.appBuilder, ) assert.NilError(t, err) @@ -121,7 +125,8 @@ func TestImportExportQueues(t *testing.T) { s2 := suite{} db := dbm.NewMemDB() - conf2 := simtestutil.DefaultStartUpConfig() + conf2, err := simtestutil.DefaultStartUpConfig(testutil.CodecOptions{}.GetAddressCodec()) + assert.NilError(t, err) conf2.DB = db s2.app, err = simtestutil.SetupWithConfiguration( depinject.Configs( diff --git a/tests/integration/slashing/slashing_test.go b/tests/integration/slashing/slashing_test.go index 0ac41336231a..c1bb1db683f9 100644 --- a/tests/integration/slashing/slashing_test.go +++ b/tests/integration/slashing/slashing_test.go @@ -49,7 +49,8 @@ func TestSlashingMsgs(t *testing.T) { } accs := []sims.GenesisAccount{{GenesisAccount: acc1, Coins: sdk.Coins{genCoin}}} - startupCfg := sims.DefaultStartUpConfig() + startupCfg, err := sims.DefaultStartUpConfig(addrCodec) + require.NoError(t, err) startupCfg.GenesisAccounts = accs var ( diff --git a/tests/integration/staking/simulation/operations_test.go b/tests/integration/staking/simulation/operations_test.go index 38bfa26232ea..75a3c515c2e3 100644 --- a/tests/integration/staking/simulation/operations_test.go +++ b/tests/integration/staking/simulation/operations_test.go @@ -66,7 +66,9 @@ func (s *SimTestSuite) SetupTest() { // create genesis accounts senderPrivKey := secp256k1.GenPrivKey() - acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) + addr, err := s.accountKeeper.AddressCodec().BytesToString(senderPrivKey.PubKey().Address()) + require.NoError(s.T(), err) + acc := authtypes.NewBaseAccount(addr, senderPrivKey.PubKey(), 0, 0) accs := []simtestutil.GenesisAccount{ {GenesisAccount: acc, Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100000000000000)))}, } @@ -77,7 +79,8 @@ func (s *SimTestSuite) SetupTest() { require.NoError(s.T(), err) validator := cmttypes.NewValidator(cmtPk, 1) - startupCfg := simtestutil.DefaultStartUpConfig() + startupCfg, err := simtestutil.DefaultStartUpConfig(s.accountKeeper.AddressCodec()) + require.NoError(s.T(), err) startupCfg.GenesisAccounts = accs startupCfg.ValidatorSet = func() (*cmttypes.ValidatorSet, error) { return cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}), nil diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index c28ce9c0994f..dea8f24bcf8b 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -241,7 +241,7 @@ func TestAminoJSON_LegacyParity(t *testing.T) { "auth/params": {gogo: &authtypes.Params{TxSigLimit: 10}, pulsar: &authapi.Params{TxSigLimit: 10}}, "auth/module_account": { gogo: &authtypes.ModuleAccount{ - BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), Permissions: []string{}, + BaseAccount: authtypes.NewBaseAccountWithAddress(addr1.String()), Permissions: []string{}, }, pulsar: &authapi.ModuleAccount{ BaseAccount: &authapi.BaseAccount{Address: addr1.String()}, Permissions: []string{}, diff --git a/tests/sims/slashing/operations_test.go b/tests/sims/slashing/operations_test.go index 411308c2f06e..856be09d7eea 100644 --- a/tests/sims/slashing/operations_test.go +++ b/tests/sims/slashing/operations_test.go @@ -77,7 +77,8 @@ func (suite *SimTestSuite) SetupTest() { return cmttypes.NewValidatorSet([]*cmttypes.Validator{validator}), nil } - startupCfg := simtestutil.DefaultStartUpConfig() + startupCfg, err := simtestutil.DefaultStartUpConfig(suite.accountKeeper.AddressCodec()) + suite.Require().NoError(err) startupCfg.ValidatorSet = createValidator app, err := simtestutil.SetupWithConfiguration( diff --git a/testutil/network/network.go b/testutil/network/network.go index 8dca40ae5473..ba7e47835a44 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -485,7 +485,7 @@ func New(l Logger, baseDir string, cfg Config) (NetworkI, error) { genFiles = append(genFiles, cmtCfg.GenesisFile()) genBalances = append(genBalances, banktypes.Balance{Address: addr.String(), Coins: balances.Sort()}) - genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr, nil, 0, 0)) + genAccounts = append(genAccounts, authtypes.NewBaseAccount(addr.String(), nil, 0, 0)) commission, err := sdkmath.LegacyNewDecFromStr("0.5") if err != nil { diff --git a/testutil/sims/app_helpers.go b/testutil/sims/app_helpers.go index c97b70c0a0b0..fab3380caaea 100644 --- a/testutil/sims/app_helpers.go +++ b/testutil/sims/app_helpers.go @@ -11,6 +11,7 @@ import ( cmttypes "github.com/cometbft/cometbft/types" dbm "github.com/cosmos/cosmos-db" + "cosmossdk.io/core/address" coreheader "cosmossdk.io/core/header" "cosmossdk.io/depinject" sdkmath "cosmossdk.io/math" @@ -20,6 +21,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" @@ -82,28 +84,39 @@ type StartupConfig struct { DB dbm.DB } -func DefaultStartUpConfig() StartupConfig { +func DefaultStartUpConfig(addressCodec address.Codec) (StartupConfig, error) { priv := secp256k1.GenPrivKey() - ba := authtypes.NewBaseAccount(priv.PubKey().Address().Bytes(), priv.PubKey(), 0, 0) + addr, err := addressCodec.BytesToString(priv.PubKey().Address()) + if err != nil { + return StartupConfig{}, err + } + ba := authtypes.NewBaseAccount(addr, priv.PubKey(), 0, 0) ga := GenesisAccount{ba, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdkmath.NewInt(100000000000000)))} return StartupConfig{ ValidatorSet: CreateRandomValidatorSet, AtGenesis: false, GenesisAccounts: []GenesisAccount{ga}, DB: dbm.NewMemDB(), - } + }, nil } // Setup initializes a new runtime.App and can inject values into extraOutputs. // It uses SetupWithConfiguration under the hood. func Setup(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) { - return SetupWithConfiguration(appConfig, DefaultStartUpConfig(), extraOutputs...) + startupCfg, err := DefaultStartUpConfig(testutil.CodecOptions{}.GetAddressCodec()) + if err != nil { + return nil, err + } + return SetupWithConfiguration(appConfig, startupCfg, extraOutputs...) } // SetupAtGenesis initializes a new runtime.App at genesis and can inject values into extraOutputs. // It uses SetupWithConfiguration under the hood. func SetupAtGenesis(appConfig depinject.Config, extraOutputs ...interface{}) (*runtime.App, error) { - cfg := DefaultStartUpConfig() + cfg, err := DefaultStartUpConfig(testutil.CodecOptions{}.GetAddressCodec()) + if err != nil { + return nil, err + } cfg.AtGenesis = true return SetupWithConfiguration(appConfig, cfg, extraOutputs...) } diff --git a/x/accounts/defaults/lockup/lockup.go b/x/accounts/defaults/lockup/lockup.go index c3daa2eb48f7..71e7687c8428 100644 --- a/x/accounts/defaults/lockup/lockup.go +++ b/x/accounts/defaults/lockup/lockup.go @@ -6,6 +6,8 @@ import ( "fmt" "time" + "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/collections" collcodec "cosmossdk.io/collections/codec" "cosmossdk.io/core/address" @@ -15,9 +17,8 @@ import ( "cosmossdk.io/x/accounts/accountstd" lockuptypes "cosmossdk.io/x/accounts/defaults/lockup/types" banktypes "cosmossdk.io/x/bank/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/gogoproto/proto" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) diff --git a/x/accounts/defaults/lockup/protov2_wrapper.go b/x/accounts/defaults/lockup/protov2_wrapper.go index 782f9e301594..caee0c60398f 100644 --- a/x/accounts/defaults/lockup/protov2_wrapper.go +++ b/x/accounts/defaults/lockup/protov2_wrapper.go @@ -1,12 +1,14 @@ package lockup import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" + bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1" + sdk "github.com/cosmos/cosmos-sdk/types" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/runtime/protoiface" ) type ProtoMsg = protoiface.MessageV1 diff --git a/x/auth/CHANGELOG.md b/x/auth/CHANGELOG.md index 585075a9d39e..c3d8a483f73e 100644 --- a/x/auth/CHANGELOG.md +++ b/x/auth/CHANGELOG.md @@ -43,6 +43,12 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* [#19990](https://github.com/cosmos/cosmos-sdk/pull/19990) Removal of the Address.String() method and related changes: + * Changed `NewBaseAccount`, `NewBaseAccountWithAddress`, `GetAccountWithHeight` to accept a string instead of an `AccAddress`. + * Added an address codec as an argument to `NewBaseAccountWithPubKey` which also returns an error. + * Added an address codec as an argument to `ValidateGenAccounts` and `ValidateGenesis`. + * Changed `NewMsgCreateVestingAccount`, `NewMsgCreatePermanentLockedAccount`and `NewMsgCreatePeriodicVestingAccount` to accept strings instead of `AccAddress`. + * Added an address codec as an argument to `Validate` method of the `GenesisAccount` interface. * [#19447](https://github.com/cosmos/cosmos-sdk/pull/19447) Address and validator address codecs are now arguments of `NewTxConfig`. `NewDefaultSigningOptions` has been replaced with `NewSigningOptions` which takes address and validator address codecs as arguments. * [#17985](https://github.com/cosmos/cosmos-sdk/pull/17985) Remove `StdTxConfig` * [#19161](https://github.com/cosmos/cosmos-sdk/pull/19161) Remove `simulate` from `SetGasMeter` diff --git a/x/auth/ante/fee.go b/x/auth/ante/fee.go index 018b447c97e3..0134d7bd0189 100644 --- a/x/auth/ante/fee.go +++ b/x/auth/ante/fee.go @@ -109,11 +109,16 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee } } + deductFeesFromAddr, err := dfd.accountKeeper.AddressCodec().BytesToString(deductFeesFrom) + if err != nil { + return err + } + events := sdk.Events{ sdk.NewEvent( sdk.EventTypeTx, sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), - sdk.NewAttribute(sdk.AttributeKeyFeePayer, sdk.AccAddress(deductFeesFrom).String()), + sdk.NewAttribute(sdk.AttributeKeyFeePayer, deductFeesFromAddr), ), } ctx.EventManager().EmitEvents(events) diff --git a/x/auth/ante/feegrant_test.go b/x/auth/ante/feegrant_test.go index 80f858b042f6..7ae80757c6fd 100644 --- a/x/auth/ante/feegrant_test.go +++ b/x/auth/ante/feegrant_test.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,6 +28,7 @@ import ( ) func TestDeductFeesNoDelegation(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() cases := map[string]struct { fee int64 valid bool @@ -60,7 +62,9 @@ func TestDeductFeesNoDelegation(t *testing.T) { malleate: func(suite *AnteTestSuite) (TestAccount, sdk.AccAddress) { // Do not register the account priv, _, addr := testdata.KeyTestPubAddr() - acc := authtypes.NewBaseAccountWithAddress(addr) + addrStr, err := ac.BytesToString(addr) + require.NoError(t, err) + acc := authtypes.NewBaseAccountWithAddress(addrStr) suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), acc.GetAddress(), authtypes.FeeCollectorName, gomock.Any()).Return(nil).Times(2) return TestAccount{ acc: acc, @@ -82,8 +86,10 @@ func TestDeductFeesNoDelegation(t *testing.T) { malleate: func(suite *AnteTestSuite) (TestAccount, sdk.AccAddress) { // Do not register the account priv, _, addr := testdata.KeyTestPubAddr() + addrStr, err := ac.BytesToString(addr) + require.NoError(t, err) return TestAccount{ - acc: authtypes.NewBaseAccountWithAddress(addr), + acc: authtypes.NewBaseAccountWithAddress(addrStr), priv: priv, }, nil }, diff --git a/x/auth/ante/sigverify.go b/x/auth/ante/sigverify.go index facc160fcee3..ef1bf2642f94 100644 --- a/x/auth/ante/sigverify.go +++ b/x/auth/ante/sigverify.go @@ -339,8 +339,13 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sd anyPk, _ := codectypes.NewAnyWithValue(pubKey) + addr, err := svd.ak.AddressCodec().BytesToString(acc.GetAddress()) + if err != nil { + return err + } + signerData := txsigning.SignerData{ - Address: acc.GetAddress().String(), + Address: addr, ChainID: chainID, AccountNumber: accNum, Sequence: acc.GetSequence(), @@ -354,7 +359,7 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sd return fmt.Errorf("expected tx to implement V2AdaptableTx, got %T", tx) } txData := adaptableTx.GetSigningTxData() - err := authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) + err = authsigning.VerifySignature(ctx, pubKey, signerData, sig.Data, svd.signModeHandler, txData) if err != nil { var errMsg string if OnlyLegacyAminoSigners(sig.Data) { @@ -385,7 +390,11 @@ func (svd SigVerificationDecorator) setPubKey(ctx sdk.Context, acc sdk.AccountI, // if we're not in simulation mode, and we do not have a valid pubkey // for this signer, then we simply error. if ctx.ExecMode() != sdk.ExecModeSimulate { - return fmt.Errorf("the account %s is without a pubkey and did not provide a pubkey in the tx to set it", acc.GetAddress().String()) + addr, err := svd.ak.AddressCodec().BytesToString(acc.GetAddress()) + if err != nil { + return fmt.Errorf("could not convert address to string: %s", err.Error()) + } + return fmt.Errorf("the account %s is without a pubkey and did not provide a pubkey in the tx to set it", addr) } // if we're in simulation mode, then we can populate the pubkey with the // sim one and simply return. @@ -397,7 +406,11 @@ func (svd SigVerificationDecorator) setPubKey(ctx sdk.Context, acc sdk.AccountI, // if the address does not match the pubkey, then we error. // TODO: in the future the relationship between address and pubkey should be more flexible. if !acc.GetAddress().Equals(sdk.AccAddress(txPubKey.Address().Bytes())) { - return sdkerrors.ErrInvalidPubKey.Wrapf("the account %s cannot be claimed by public key with address %x", acc.GetAddress(), txPubKey.Address()) + addr, err := svd.ak.AddressCodec().BytesToString(acc.GetAddress()) + if err != nil { + return fmt.Errorf("could not convert address to string: %s", err.Error()) + } + return sdkerrors.ErrInvalidPubKey.Wrapf("the account %s cannot be claimed by public key with address %x", addr, txPubKey.Address()) } err := verifyIsOnCurve(txPubKey) diff --git a/x/auth/ante/sigverify_internal_test.go b/x/auth/ante/sigverify_internal_test.go index 3408b82f2634..833c14c08f94 100644 --- a/x/auth/ante/sigverify_internal_test.go +++ b/x/auth/ante/sigverify_internal_test.go @@ -5,21 +5,39 @@ import ( "github.com/stretchr/testify/require" + "cosmossdk.io/collections/colltest" + "cosmossdk.io/core/appmodule" authcodec "cosmossdk.io/x/auth/codec" + "cosmossdk.io/x/auth/keeper" authtypes "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSigVerify_setPubKey(t *testing.T) { - svd := SigVerificationDecorator{} + cdc := authcodec.NewBech32Codec("cosmos") + + maccPerms := map[string][]string{ + "fee_collector": nil, + "mint": {"minter"}, + "bonded_tokens_pool": {"burner", "staking"}, + "not_bonded_tokens_pool": {"burner", "staking"}, + "multiPerm": {"burner", "minter", "staking"}, + "random": {"random"}, + } + store, _ := colltest.MockStore() + authorityAddr, err := cdc.BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(t, err) + svd := SigVerificationDecorator{ak: keeper.NewAccountKeeper( + appmodule.Environment{KVStoreService: store}, codectestutil.CodecOptions{}.NewCodec(), + authtypes.ProtoBaseAccount, maccPerms, cdc, sdk.Bech32MainPrefix, authorityAddr, + )} alicePk := secp256k1.GenPrivKey().PubKey() bobPk := secp256k1.GenPrivKey().PubKey() - cdc := authcodec.NewBech32Codec("cosmos") - aliceAddr, err := cdc.BytesToString(alicePk.Address()) require.NoError(t, err) diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 1814e94f2b29..2560cc51c21c 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -79,12 +79,15 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { "random": {"random"}, } + ac := authcodec.NewBech32Codec("cosmos") + authorityAddr, err := ac.BytesToString(types.NewModuleAddress("gov")) + require.NoError(t, err) suite.accountKeeper = keeper.NewAccountKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec("cosmos"), - sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), + runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, + types.ProtoBaseAccount, maccPerms, ac, sdk.Bech32MainPrefix, authorityAddr, ) suite.accountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName) - err := suite.accountKeeper.Params.Set(suite.ctx, types.DefaultParams()) + err = suite.accountKeeper.Params.Set(suite.ctx, types.DefaultParams()) require.NoError(t, err) // We're using TestMsg encoding in some tests, so register it here. @@ -241,8 +244,12 @@ func (suite *AnteTestSuite) CreateTestTx( // Second round: all signer infos are set, so each signer can sign. sigsV2 = []signing.SignatureV2{} for i, priv := range privs { + addr, err := suite.accountKeeper.AddressCodec().BytesToString(priv.PubKey().Address()) + if err != nil { + return nil, err + } signerData := xauthsigning.SignerData{ - Address: sdk.AccAddress(priv.PubKey().Address()).String(), + Address: addr, ChainID: chainID, AccountNumber: accNums[i], Sequence: accSeqs[i], diff --git a/x/auth/client/cli/tx_multisign.go b/x/auth/client/cli/tx_multisign.go index 1789d9eb8e1d..003575bf7e02 100644 --- a/x/auth/client/cli/tx_multisign.go +++ b/x/auth/client/cli/tx_multisign.go @@ -136,11 +136,15 @@ func makeMultiSignCmd() func(cmd *cobra.Command, args []string) (err error) { if err != nil { return err } + sigAddr, err := clientCtx.AddressCodec.BytesToString(sig.PubKey.Address()) + if err != nil { + return err + } txSignerData := txsigning.SignerData{ ChainID: txFactory.ChainID(), AccountNumber: txFactory.AccountNumber(), Sequence: txFactory.Sequence(), - Address: sdk.AccAddress(sig.PubKey.Address()).String(), + Address: sigAddr, PubKey: &anypb.Any{ TypeUrl: anyPk.TypeUrl, Value: anyPk.Value, @@ -310,6 +314,11 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { multisigPub := pubKey.(*kmultisig.LegacyAminoPubKey) multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys)) + address, err := clientCtx.AddressCodec.BytesToString(pubKey.Address()) + if err != nil { + return err + } + anyPk, err := codectypes.NewAnyWithValue(multisigPub) if err != nil { return err @@ -318,7 +327,7 @@ func makeBatchMultisignCmd() func(cmd *cobra.Command, args []string) error { ChainID: txFactory.ChainID(), AccountNumber: txFactory.AccountNumber(), Sequence: txFactory.Sequence(), - Address: sdk.AccAddress(pubKey.Address()).String(), + Address: address, PubKey: &anypb.Any{ TypeUrl: anyPk.TypeUrl, Value: anyPk.Value, diff --git a/x/auth/client/cli/validate_sigs.go b/x/auth/client/cli/validate_sigs.go index 846fc8cee581..d732896793d0 100644 --- a/x/auth/client/cli/validate_sigs.go +++ b/x/auth/client/cli/validate_sigs.go @@ -109,6 +109,12 @@ func printAndValidateSigs( success = false } + sigStrAddr, err := clientCtx.AddressCodec.BytesToString(sigAddr) + if err != nil { + cmd.PrintErrf("failed to convert address to string: %s\n", sigAddr) + return false + } + // validate the actual signature over the transaction bytes since we can // reach out to a full node to query accounts. if !offline && success { @@ -119,7 +125,7 @@ func printAndValidateSigs( } signingData := authsigning.SignerData{ - Address: sigAddr.String(), + Address: sigStrAddr, ChainID: chainID, AccountNumber: accNum, Sequence: accSeq, @@ -155,7 +161,7 @@ func printAndValidateSigs( } } - cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigAddr.String(), sigSanity, multiSigHeader, multiSigMsg) + cmd.Printf(" %d: %s\t\t\t[%s]%s%s\n", i, sigStrAddr, sigSanity, multiSigHeader, multiSigMsg) } cmd.Println("") diff --git a/x/auth/client/testutil/helpers.go b/x/auth/client/testutil/helpers.go index 69d0b6ff380f..f26830fcad15 100644 --- a/x/auth/client/testutil/helpers.go +++ b/x/auth/client/testutil/helpers.go @@ -13,9 +13,9 @@ import ( clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" ) -func TxSignExec(clientCtx client.Context, from fmt.Stringer, filename string, extraArgs ...string) (testutil.BufferWriter, error) { +func TxSignExec(clientCtx client.Context, from, filename string, extraArgs ...string) (testutil.BufferWriter, error) { args := []string{ - fmt.Sprintf("--from=%s", from.String()), + fmt.Sprintf("--from=%s", from), fmt.Sprintf("--%s=%s", flags.FlagHome, strings.Replace(clientCtx.HomeDir, "simd", "simcli", 1)), fmt.Sprintf("--%s=%s", flags.FlagChainID, clientCtx.ChainID), filename, @@ -63,9 +63,9 @@ func TxMultiSignExec(clientCtx client.Context, from, filename string, extraArgs return clitestutil.ExecTestCLICmd(clientCtx, cli.GetMultiSignCommand(), append(args, extraArgs...)) } -func TxSignBatchExec(clientCtx client.Context, from fmt.Stringer, filename string, extraArgs ...string) (testutil.BufferWriter, error) { +func TxSignBatchExec(clientCtx client.Context, from, filename string, extraArgs ...string) (testutil.BufferWriter, error) { args := []string{ - fmt.Sprintf("--from=%s", from.String()), + fmt.Sprintf("--from=%s", from), filename, } diff --git a/x/auth/depinject.go b/x/auth/depinject.go index 67d75e7c902a..063afc044fce 100644 --- a/x/auth/depinject.go +++ b/x/auth/depinject.go @@ -53,7 +53,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := types.NewModuleAddress(GovModuleName) if in.Config.Authority != "" { - authority = types.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = types.NewModuleAddressOrBech32Address(in.Config.Authority, in.AddressCodec) } if in.RandomGenesisAccountsFn == nil { diff --git a/x/auth/keeper/deterministic_test.go b/x/auth/keeper/deterministic_test.go index 61baa01c2835..cb340e05896f 100644 --- a/x/auth/keeper/deterministic_test.go +++ b/x/auth/keeper/deterministic_test.go @@ -71,14 +71,18 @@ func (suite *DeterministicTestSuite) SetupTest() { randomPerm: {"random"}, } + ac := authcodec.NewBech32Codec("cosmos") + authorityAddr, err := ac.BytesToString(types.NewModuleAddress("gov")) + suite.Require().NoError(err) + suite.accountKeeper = keeper.NewAccountKeeper( env, suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, - authcodec.NewBech32Codec("cosmos"), + ac, "cosmos", - types.NewModuleAddress("gov").String(), + authorityAddr, ) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) @@ -112,7 +116,10 @@ func (suite *DeterministicTestSuite) createAndSetAccounts(t *rapid.T, count int) accNum := accNums[i] seq := rapid.Uint64().Draw(t, "sequence") - acc1 := types.NewBaseAccount(addr, &pub, accNum, seq) + baseAccAddr, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) + + acc1 := types.NewBaseAccount(baseAccAddr, &pub, accNum, seq) suite.accountKeeper.SetAccount(suite.ctx, acc1) accs = append(accs, acc1) } @@ -122,18 +129,25 @@ func (suite *DeterministicTestSuite) createAndSetAccounts(t *rapid.T, count int) func (suite *DeterministicTestSuite) TestGRPCQueryAccount() { rapid.Check(suite.T(), func(t *rapid.T) { accs := suite.createAndSetAccounts(t, 1) - req := &types.QueryAccountRequest{Address: accs[0].GetAddress().String()} + accAddr, err := suite.accountKeeper.AddressCodec().BytesToString(accs[0].GetAddress()) + suite.Require().NoError(err) + req := &types.QueryAccountRequest{Address: accAddr} testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Account, 0, true) }) // Regression tests accNum := uint64(10087) seq := uint64(98) + baseAccAddr, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) - acc1 := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, accNum, seq) + acc1 := types.NewBaseAccount(baseAccAddr, &secp256k1.PubKey{Key: pub}, accNum, seq) suite.accountKeeper.SetAccount(suite.ctx, acc1) - req := &types.QueryAccountRequest{Address: acc1.GetAddress().String()} + accAddr, err := suite.accountKeeper.AddressCodec().BytesToString(acc1.GetAddress()) + suite.Require().NoError(err) + + req := &types.QueryAccountRequest{Address: accAddr} testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.Account, 1543, false) } @@ -166,12 +180,16 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccounts() { suite.Require().NoError(err) accNum1 := uint64(107) seq1 := uint64(10001) + baseAccAddr1, err := suite.accountKeeper.AddressCodec().BytesToString(addr1) + suite.Require().NoError(err) accNum2 := uint64(100) seq2 := uint64(10) + baseAccAddr, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) - acc1 := types.NewBaseAccount(addr1, &secp256k1.PubKey{Key: pub1}, accNum1, seq1) - acc2 := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, accNum2, seq2) + acc1 := types.NewBaseAccount(baseAccAddr1, &secp256k1.PubKey{Key: pub1}, accNum1, seq1) + acc2 := types.NewBaseAccount(baseAccAddr, &secp256k1.PubKey{Key: pub}, accNum2, seq2) suite.accountKeeper.SetAccount(suite.ctx, acc1) suite.accountKeeper.SetAccount(suite.ctx, acc2) @@ -190,8 +208,10 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountAddressByID() { // Regression test accNum := uint64(10087) seq := uint64(0) + baseAccAddr, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) - acc1 := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, accNum, seq) + acc1 := types.NewBaseAccount(baseAccAddr, &secp256k1.PubKey{Key: pub}, accNum, seq) suite.accountKeeper.SetAccount(suite.ctx, acc1) req := &types.QueryAccountAddressByIDRequest{AccountId: accNum} @@ -229,18 +249,25 @@ func (suite *DeterministicTestSuite) TestGRPCQueryAccountInfo() { accs := suite.createAndSetAccounts(t, 1) suite.Require().Len(accs, 1) - req := &types.QueryAccountInfoRequest{Address: accs[0].GetAddress().String()} + acc0Addr, err := suite.accountKeeper.AddressCodec().BytesToString(accs[0].GetAddress()) + suite.Require().NoError(err) + + req := &types.QueryAccountInfoRequest{Address: acc0Addr} testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountInfo, 0, true) }) // Regression test accNum := uint64(10087) seq := uint64(10) + baseAccAddr, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) - acc := types.NewBaseAccount(addr, &secp256k1.PubKey{Key: pub}, accNum, seq) + acc := types.NewBaseAccount(baseAccAddr, &secp256k1.PubKey{Key: pub}, accNum, seq) + accAddr, err := suite.accountKeeper.AddressCodec().BytesToString(acc.GetAddress()) + suite.Require().NoError(err) suite.accountKeeper.SetAccount(suite.ctx, acc) - req := &types.QueryAccountInfoRequest{Address: acc.GetAddress().String()} + req := &types.QueryAccountInfoRequest{Address: accAddr} testdata.DeterministicIterations(suite.T(), suite.ctx, req, suite.queryClient.AccountInfo, 1543, false) } @@ -291,14 +318,17 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccounts() { maccPerms[maccs[i]] = mPerms } + authorityAddr, err := ac.BytesToString(types.NewModuleAddress("gov")) + suite.Require().NoError(err) + ak := keeper.NewAccountKeeper( suite.environment, suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, - authcodec.NewBech32Codec("cosmos"), + ac, "cosmos", - types.NewModuleAddress("gov").String(), + authorityAddr, ) suite.setModuleAccounts(suite.ctx, ak, maccs) @@ -338,14 +368,18 @@ func (suite *DeterministicTestSuite) TestGRPCQueryModuleAccountByName() { maccPerms[mName] = mPerms + ac := authcodec.NewBech32Codec("cosmos") + authorityAddr, err := ac.BytesToString(types.NewModuleAddress("gov")) + suite.Require().NoError(err) + ak := keeper.NewAccountKeeper( suite.environment, suite.encCfg.Codec, types.ProtoBaseAccount, maccPerms, - authcodec.NewBech32Codec("cosmos"), + ac, "cosmos", - types.NewModuleAddress("gov").String(), + authorityAddr, ) suite.setModuleAccounts(suite.ctx, ak, []string{mName}) diff --git a/x/auth/keeper/grpc_query_test.go b/x/auth/keeper/grpc_query_test.go index 3908455383f4..103a49ad713e 100644 --- a/x/auth/keeper/grpc_query_test.go +++ b/x/auth/keeper/grpc_query_test.go @@ -76,6 +76,8 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccounts() { func (suite *KeeperTestSuite) TestGRPCQueryAccount() { var req *types.QueryAccountRequest _, _, addr := testdata.KeyTestPubAddr() + addrString, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) testCases := []struct { msg string @@ -110,7 +112,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccount() { { "account not found", func() { - req = &types.QueryAccountRequest{Address: addr.String()} + req = &types.QueryAccountRequest{Address: addrString} }, false, func(res *types.QueryAccountResponse) {}, @@ -120,7 +122,7 @@ func (suite *KeeperTestSuite) TestGRPCQueryAccount() { func() { suite.accountKeeper.SetAccount(suite.ctx, suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr)) - req = &types.QueryAccountRequest{Address: addr.String()} + req = &types.QueryAccountRequest{Address: addrString} }, true, func(res *types.QueryAccountResponse) { @@ -508,13 +510,16 @@ func (suite *KeeperTestSuite) TestQueryAccountInfo() { suite.Require().NoError(acc.SetSequence(10)) suite.accountKeeper.SetAccount(suite.ctx, acc) + addrString, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) + res, err := suite.queryClient.AccountInfo(context.Background(), &types.QueryAccountInfoRequest{ - Address: addr.String(), + Address: addrString, }) suite.Require().NoError(err) suite.Require().NotNil(res.Info) - suite.Require().Equal(addr.String(), res.Info.Address) + suite.Require().Equal(addrString, res.Info.Address) suite.Require().Equal(acc.GetAccountNumber(), res.Info.AccountNumber) suite.Require().Equal(acc.GetSequence(), res.Info.Sequence) suite.Require().Equal("/"+proto.MessageName(pk), res.Info.PubKey.TypeUrl) @@ -526,13 +531,15 @@ func (suite *KeeperTestSuite) TestQueryAccountInfo() { func (suite *KeeperTestSuite) TestQueryAccountInfoWithoutPubKey() { acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr) suite.accountKeeper.SetAccount(suite.ctx, acc) + addrString, err := suite.accountKeeper.AddressCodec().BytesToString(addr) + suite.Require().NoError(err) res, err := suite.queryClient.AccountInfo(context.Background(), &types.QueryAccountInfoRequest{ - Address: addr.String(), + Address: addrString, }) suite.Require().NoError(err) suite.Require().NotNil(res.Info) - suite.Require().Equal(addr.String(), res.Info.Address) + suite.Require().Equal(addrString, res.Info.Address) suite.Require().Nil(res.Info.PubKey) } diff --git a/x/auth/keeper/keeper.go b/x/auth/keeper/keeper.go index 9f03b175fcb4..51d4950bd681 100644 --- a/x/auth/keeper/keeper.go +++ b/x/auth/keeper/keeper.go @@ -243,7 +243,10 @@ func (ak AccountKeeper) GetModuleAccountAndPermissions(ctx context.Context, modu } // create a new module account - macc := types.NewEmptyModuleAccount(moduleName, perms...) + macc, err := types.NewEmptyModuleAccount(ak.addressCodec, moduleName, perms...) + if err != nil { + panic(err) + } maccI := (ak.NewAccount(ctx, macc)).(sdk.ModuleAccountI) // set the account number ak.SetModuleAccount(ctx, maccI) diff --git a/x/auth/keeper/keeper_test.go b/x/auth/keeper/keeper_test.go index 02a25bb6ec83..7a13fa829175 100644 --- a/x/auth/keeper/keeper_test.go +++ b/x/auth/keeper/keeper_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/baseapp" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -31,8 +32,9 @@ const ( ) var ( - multiPermAcc = types.NewEmptyModuleAccount(multiPerm, types.Burner, types.Minter, types.Staking) - randomPermAcc = types.NewEmptyModuleAccount(randomPerm, "random") + ac = addresscodec.NewBech32Codec("cosmos") + multiPermAcc, _ = types.NewEmptyModuleAccount(ac, multiPerm, types.Burner, types.Minter, types.Staking) + randomPermAcc, _ = types.NewEmptyModuleAccount(ac, randomPerm, "random") ) type KeeperTestSuite struct { @@ -64,6 +66,9 @@ func (suite *KeeperTestSuite) SetupTest() { randomPerm: {"random"}, } + authorityAddr, err := ac.BytesToString(types.NewModuleAddress("gov")) + suite.Require().NoError(err) + suite.accountKeeper = keeper.NewAccountKeeper( env, suite.encCfg.Codec, @@ -71,7 +76,7 @@ func (suite *KeeperTestSuite) SetupTest() { maccPerms, authcodec.NewBech32Codec("cosmos"), "cosmos", - types.NewModuleAddress("gov").String(), + authorityAddr, ) suite.msgServer = keeper.NewMsgServerImpl(suite.accountKeeper) queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.encCfg.InterfaceRegistry) @@ -91,7 +96,8 @@ func (suite *KeeperTestSuite) TestSupply_ValidatePermissions() { suite.Require().NoError(err) // unregistered permissions - otherAcc := types.NewEmptyModuleAccount("other", "other") + otherAcc, err := types.NewEmptyModuleAccount(suite.accountKeeper.AddressCodec(), "other", "other") + suite.Require().NoError(err) err = suite.accountKeeper.ValidatePermissions(otherAcc) suite.Require().Error(err) } @@ -126,16 +132,24 @@ func (suite *KeeperTestSuite) TestInitGenesis() { // Fix duplicate account numbers pubKey1 := ed25519.GenPrivKey().PubKey() pubKey2 := ed25519.GenPrivKey().PubKey() + + pubKey1Addr, err := suite.accountKeeper.AddressCodec().BytesToString(pubKey1.Address()) + suite.Require().NoError(err) + pubKey2Addr, err := suite.accountKeeper.AddressCodec().BytesToString(pubKey2.Address()) + suite.Require().NoError(err) + moduleAddr, err := suite.accountKeeper.AddressCodec().BytesToString(types.NewModuleAddress("testing")) + suite.Require().NoError(err) + accts := []sdk.AccountI{ &types.BaseAccount{ - Address: sdk.AccAddress(pubKey1.Address()).String(), + Address: pubKey1Addr, PubKey: codectypes.UnsafePackAny(pubKey1), AccountNumber: 0, Sequence: 5, }, &types.ModuleAccount{ BaseAccount: &types.BaseAccount{ - Address: types.NewModuleAddress("testing").String(), + Address: moduleAddr, PubKey: nil, AccountNumber: 0, Sequence: 6, @@ -144,7 +158,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { Permissions: nil, }, &types.BaseAccount{ - Address: sdk.AccAddress(pubKey2.Address()).String(), + Address: pubKey2Addr, PubKey: codectypes.UnsafePackAny(pubKey2), AccountNumber: 5, Sequence: 7, @@ -171,6 +185,8 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().Equal(len(keeperAccts), len(accts)+1, "number of accounts in the keeper vs in genesis state") for i, genAcct := range accts { genAcctAddr := genAcct.GetAddress() + getAcctStrAddr, err := suite.accountKeeper.AddressCodec().BytesToString(genAcctAddr) + suite.Require().NoError(err) var keeperAcct sdk.AccountI for _, kacct := range keeperAccts { if genAcctAddr.Equals(kacct.GetAddress()) { @@ -178,11 +194,11 @@ func (suite *KeeperTestSuite) TestInitGenesis() { break } } - suite.Require().NotNilf(keeperAcct, "genesis account %s not in keeper accounts", genAcctAddr) + suite.Require().NotNilf(keeperAcct, "genesis account %s not in keeper accounts", getAcctStrAddr) suite.Require().Equal(genAcct.GetPubKey(), keeperAcct.GetPubKey()) suite.Require().Equal(genAcct.GetSequence(), keeperAcct.GetSequence()) if i == 1 { - suite.Require().Equalf(1, int(keeperAcct.GetAccountNumber()), genAcctAddr.String()) + suite.Require().Equalf(1, int(keeperAcct.GetAccountNumber()), getAcctStrAddr) } else { suite.Require().Equal(genAcct.GetSequence(), keeperAcct.GetSequence()) } @@ -203,7 +219,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { Params: types.DefaultParams(), Accounts: []*codectypes.Any{ codectypes.UnsafePackAny(&types.BaseAccount{ - Address: sdk.AccAddress(pubKey1.Address()).String(), + Address: pubKey1Addr, PubKey: codectypes.UnsafePackAny(pubKey1), AccountNumber: 0, Sequence: 5, diff --git a/x/auth/migrations/legacytx/stdtx_test.go b/x/auth/migrations/legacytx/stdtx_test.go index f49357ca6398..c52cc5c56ed4 100644 --- a/x/auth/migrations/legacytx/stdtx_test.go +++ b/x/auth/migrations/legacytx/stdtx_test.go @@ -15,6 +15,7 @@ import ( "cosmossdk.io/x/tx/signing/aminojson" "github.com/cosmos/cosmos-sdk/codec" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" @@ -31,6 +32,8 @@ var ( ) func TestStdSignBytes(t *testing.T) { + addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr) + require.NoError(t, err) type args struct { chainID string accnum uint64 @@ -72,17 +75,17 @@ func TestStdSignBytes(t *testing.T) { }, { "with fee granter, no fee payer (omitempty)", - args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Granter: addr.String()}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, + args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Granter: addrStr}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, fmt.Sprintf(`{"account_number":"3","chain_id":"1234","fee":{"amount":[{"amount":"150","denom":"atom"}],"gas":"100000","granter":"%s"},"memo":"memo","msgs":[%s],"sequence":"6"}`, addr, msgStr), }, { "with fee payer, no fee granter (omitempty)", - args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Payer: addr.String()}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, + args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Payer: addrStr}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, fmt.Sprintf(`{"account_number":"3","chain_id":"1234","fee":{"amount":[{"amount":"150","denom":"atom"}],"gas":"100000","payer":"%s"},"memo":"memo","msgs":[%s],"sequence":"6"}`, addr, msgStr), }, { "with fee payer and fee granter", - args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Payer: addr.String(), Granter: addr.String()}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, + args{"1234", 3, 6, 0, &txv1beta1.Fee{Amount: defaultFee.Amount, GasLimit: defaultFee.GasLimit, Payer: addrStr, Granter: addrStr}, []sdk.Msg{testdata.NewTestMsg(addr)}, "memo"}, fmt.Sprintf(`{"account_number":"3","chain_id":"1234","fee":{"amount":[{"amount":"150","denom":"atom"}],"gas":"100000","granter":"%s","payer":"%s"},"memo":"memo","msgs":[%s],"sequence":"6"}`, addr, addr, msgStr), }, } diff --git a/x/auth/module.go b/x/auth/module.go index 9adf511a096e..171d04dbe964 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -117,7 +117,7 @@ func (am AppModule) ValidateGenesis(bz json.RawMessage) error { return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } - return types.ValidateGenesis(data) + return types.ValidateGenesis(data, am.accountKeeper.AddressCodec()) } // InitGenesis performs genesis initialization for the auth module. diff --git a/x/auth/signing/adapter_test.go b/x/auth/signing/adapter_test.go index 432a0194ba77..b408a9f2b95e 100644 --- a/x/auth/signing/adapter_test.go +++ b/x/auth/signing/adapter_test.go @@ -18,14 +18,16 @@ func TestGetSignBytesAdapterNoPublicKey(t *testing.T) { encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) txConfig := encodingConfig.TxConfig _, _, addr := testdata.KeyTestPubAddr() + addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr) + require.NoError(t, err) signerData := authsign.SignerData{ - Address: addr.String(), + Address: addrStr, ChainID: "test-chain", AccountNumber: 11, Sequence: 15, } w := txConfig.NewTxBuilder() - _, err := authsign.GetSignBytesAdapter( + _, err = authsign.GetSignBytesAdapter( context.Background(), txConfig.SignModeHandler(), signing.SignMode_SIGN_MODE_DIRECT, diff --git a/x/auth/simulation/genesis.go b/x/auth/simulation/genesis.go index 87b5cb2a61a2..c5ba3265b04e 100644 --- a/x/auth/simulation/genesis.go +++ b/x/auth/simulation/genesis.go @@ -27,7 +27,11 @@ const ( func RandomGenesisAccounts(simState *module.SimulationState) types.GenesisAccounts { genesisAccs := make(types.GenesisAccounts, len(simState.Accounts)) for i, acc := range simState.Accounts { - bacc := types.NewBaseAccountWithAddress(acc.Address) + addr, err := simState.AddressCodec.BytesToString(acc.Address) + if err != nil { + panic(err) + } + bacc := types.NewBaseAccountWithAddress(addr) // Only consider making a vesting account once the initial bonded validator // set is exhausted due to needing to track DelegatedVesting. @@ -48,7 +52,7 @@ func RandomGenesisAccounts(simState *module.SimulationState) types.GenesisAccoun endTime = int64(simulation.RandIntBetween(simState.Rand, int(startTime)+1, int(startTime+(60*60*12)))) } - bva, err := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime) + bva, err := vestingtypes.NewBaseVestingAccount(bacc, initialVesting, endTime, simState.AddressCodec) if err != nil { panic(err) } diff --git a/x/auth/simulation/genesis_test.go b/x/auth/simulation/genesis_test.go index 2d6a63e4882c..f691d3d0c8cf 100644 --- a/x/auth/simulation/genesis_test.go +++ b/x/auth/simulation/genesis_test.go @@ -54,7 +54,9 @@ func TestRandomizedGenState(t *testing.T) { genAccounts, err := types.UnpackAccounts(authGenesis.Accounts) require.NoError(t, err) require.Len(t, genAccounts, 3) - require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", genAccounts[2].GetAddress().String()) + addr, err := simState.AddressCodec.BytesToString(genAccounts[2].GetAddress()) + require.NoError(t, err) + require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", addr) require.Equal(t, uint64(0), genAccounts[2].GetAccountNumber()) require.Equal(t, uint64(0), genAccounts[2].GetSequence()) } diff --git a/x/auth/simulation/proposals.go b/x/auth/simulation/proposals.go index 244acb1975e1..b41417921d92 100644 --- a/x/auth/simulation/proposals.go +++ b/x/auth/simulation/proposals.go @@ -31,10 +31,15 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { } // SimulateMsgUpdateParams returns a random MsgUpdateParams -func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) { +func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, ac coreaddress.Codec) (sdk.Msg, error) { // use the default gov module account address as authority var authority sdk.AccAddress = address.Module("gov") + addr, err := ac.BytesToString(authority) + if err != nil { + return nil, err + } + params := types.DefaultParams() params.MaxMemoCharacters = uint64(simtypes.RandIntBetween(r, 1, 1000)) params.TxSigLimit = uint64(simtypes.RandIntBetween(r, 1, 1000)) @@ -43,7 +48,7 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ []simtypes.Account, _ coreaddress.C params.SigVerifyCostSecp256k1 = uint64(simtypes.RandIntBetween(r, 1, 1000)) return &types.MsgUpdateParams{ - Authority: authority.String(), + Authority: addr, Params: params, }, nil } diff --git a/x/auth/simulation/proposals_test.go b/x/auth/simulation/proposals_test.go index bbe53b58ef48..4cdf56a5b24d 100644 --- a/x/auth/simulation/proposals_test.go +++ b/x/auth/simulation/proposals_test.go @@ -10,8 +10,6 @@ import ( "cosmossdk.io/x/auth/types" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/address" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -37,7 +35,9 @@ func TestProposalMsgs(t *testing.T) { msgUpdateParams, ok := msg.(*types.MsgUpdateParams) assert.Assert(t, ok) - assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + moduleAddr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(types.NewModuleAddress("gov")) + assert.NilError(t, err) + assert.Equal(t, moduleAddr, msgUpdateParams.Authority) assert.Equal(t, uint64(999), msgUpdateParams.Params.MaxMemoCharacters) assert.Equal(t, uint64(905), msgUpdateParams.Params.TxSigLimit) assert.Equal(t, uint64(151), msgUpdateParams.Params.TxSizeCostPerByte) diff --git a/x/auth/tx/aux_test.go b/x/auth/tx/aux_test.go index 4d1ae10b3271..efe1f2c43306 100644 --- a/x/auth/tx/aux_test.go +++ b/x/auth/tx/aux_test.go @@ -43,9 +43,15 @@ func TestBuilderWithAux(t *testing.T) { encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) interfaceRegistry := encodingConfig.InterfaceRegistry txConfig := encodingConfig.TxConfig + ac := codectestutil.CodecOptions{}.GetAddressCodec() testdata.RegisterInterfaces(interfaceRegistry) + aux2StrAddr, err := ac.BytesToString(aux2Addr) + require.NoError(t, err) + feePayerStrAddr, err := ac.BytesToString(feepayerAddr) + require.NoError(t, err) + // Create an AuxTxBuilder for tipper (1st signer) txBuilder, txSig := makeTxBuilder(t) txSignerData, err := txBuilder.GetAuxSignerData() @@ -53,7 +59,7 @@ func TestBuilderWithAux(t *testing.T) { // Create an AuxTxBuilder for aux2 (2nd signer) aux2Builder := clienttx.NewAuxTxBuilder() - aux2Builder.SetAddress(aux2Addr.String()) + aux2Builder.SetAddress(aux2StrAddr) aux2Builder.SetAccountNumber(11) aux2Builder.SetSequence(12) aux2Builder.SetTimeoutHeight(3) @@ -136,7 +142,7 @@ func TestBuilderWithAux(t *testing.T) { require.NoError(t, err) signerData := authsigning.SignerData{ - Address: feepayerAddr.String(), + Address: feePayerStrAddr, ChainID: chainID, AccountNumber: 11, Sequence: 15, @@ -194,14 +200,17 @@ func TestBuilderWithAux(t *testing.T) { func makeTxBuilder(t *testing.T) (clienttx.AuxTxBuilder, []byte) { t.Helper() + tipperStrAddr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(tipperAddr) + require.NoError(t, err) + txBuilder := clienttx.NewAuxTxBuilder() - txBuilder.SetAddress(tipperAddr.String()) + txBuilder.SetAddress(tipperStrAddr) txBuilder.SetAccountNumber(1) txBuilder.SetSequence(2) txBuilder.SetTimeoutHeight(3) txBuilder.SetMemo(memo) txBuilder.SetChainID(chainID) - err := txBuilder.SetMsgs(msg) + err = txBuilder.SetMsgs(msg) require.NoError(t, err) err = txBuilder.SetPubKey(tipperPk) require.NoError(t, err) diff --git a/x/auth/tx/testutil/suite.go b/x/auth/tx/testutil/suite.go index 4ed2cd7c3c76..230e59cf6720 100644 --- a/x/auth/tx/testutil/suite.go +++ b/x/auth/tx/testutil/suite.go @@ -10,6 +10,7 @@ import ( "cosmossdk.io/x/auth/signing" "github.com/cosmos/cosmos-sdk/client" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" "github.com/cosmos/cosmos-sdk/crypto/types/multisig" @@ -135,9 +136,15 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().Equal([][]byte{addr, msigAddr}, signers) s.Require().NoError(sigTx.ValidateBasic()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addrStr, err := ac.BytesToString(addr) + s.Require().NoError(err) + msigStrAddr, err := ac.BytesToString(msigAddr) + s.Require().NoError(err) + // sign transaction signerData := signing.SignerData{ - Address: addr.String(), + Address: addrStr, ChainID: "test", AccountNumber: 1, Sequence: seq1, @@ -150,7 +157,7 @@ func (s *TxConfigTestSuite) TestTxBuilderSetSignatures() { s.Require().NoError(err) signerData = signing.SignerData{ - Address: msigAddr.String(), + Address: msigStrAddr, ChainID: "test", AccountNumber: 3, Sequence: mseq, diff --git a/x/auth/types/account.go b/x/auth/types/account.go index 529fc28914b3..7b0eef543015 100644 --- a/x/auth/types/account.go +++ b/x/auth/types/account.go @@ -9,6 +9,8 @@ import ( "github.com/cometbft/cometbft/crypto" + coreaddress "cosmossdk.io/core/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -24,9 +26,9 @@ var ( ) // NewBaseAccount creates a new BaseAccount object. -func NewBaseAccount(address sdk.AccAddress, pubKey cryptotypes.PubKey, accountNumber, sequence uint64) *BaseAccount { +func NewBaseAccount(address string, pubKey cryptotypes.PubKey, accountNumber, sequence uint64) *BaseAccount { acc := &BaseAccount{ - Address: address.String(), + Address: address, AccountNumber: accountNumber, Sequence: sequence, } @@ -46,9 +48,9 @@ func ProtoBaseAccount() sdk.AccountI { // NewBaseAccountWithAddress - returns a new base account with a given address // leaving AccountNumber and Sequence to zero. -func NewBaseAccountWithAddress(addr sdk.AccAddress) *BaseAccount { +func NewBaseAccountWithAddress(addr string) *BaseAccount { return &BaseAccount{ - Address: addr.String(), + Address: addr, } } @@ -116,7 +118,7 @@ func (acc *BaseAccount) SetSequence(seq uint64) error { } // Validate checks for errors on the account fields -func (acc BaseAccount) Validate() error { +func (acc BaseAccount) Validate(addressCodec coreaddress.Codec) error { if acc.Address == "" || acc.PubKey == nil { return nil } @@ -145,8 +147,8 @@ func (acc BaseAccount) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { // NewModuleAddressOrBech32Address gets an input string and returns an AccAddress. // If the input is a valid address, it returns the address. // If the input is a module name, it returns the module address. -func NewModuleAddressOrBech32Address(input string) sdk.AccAddress { - if addr, err := sdk.AccAddressFromBech32(input); err == nil { +func NewModuleAddressOrBech32Address(input string, addressCodec coreaddress.Codec) sdk.AccAddress { + if addr, err := addressCodec.StringToBytes(input); err == nil { return addr } @@ -159,9 +161,13 @@ func NewModuleAddress(name string) sdk.AccAddress { } // NewEmptyModuleAccount creates a empty ModuleAccount from a string -func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { +func NewEmptyModuleAccount(addressCodec coreaddress.Codec, name string, permissions ...string) (*ModuleAccount, error) { moduleAddress := NewModuleAddress(name) - baseAcc := NewBaseAccountWithAddress(moduleAddress) + baseAddr, err := addressCodec.BytesToString(moduleAddress) + if err != nil { + return nil, err + } + baseAcc := NewBaseAccountWithAddress(baseAddr) if err := validatePermissions(permissions...); err != nil { panic(err) @@ -171,7 +177,7 @@ func NewEmptyModuleAccount(name string, permissions ...string) *ModuleAccount { BaseAccount: baseAcc, Name: name, Permissions: permissions, - } + }, nil } // NewModuleAccount creates a new ModuleAccount instance @@ -213,7 +219,7 @@ func (ma ModuleAccount) SetPubKey(pubKey cryptotypes.PubKey) error { } // Validate checks for errors on the account fields -func (ma ModuleAccount) Validate() error { +func (ma ModuleAccount) Validate(addressCodec coreaddress.Codec) error { if strings.TrimSpace(ma.Name) == "" { return errors.New("module account name cannot be blank") } @@ -222,31 +228,30 @@ func (ma ModuleAccount) Validate() error { return errors.New("uninitialized ModuleAccount: BaseAccount is nil") } - if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() { + addr, err := addressCodec.BytesToString(crypto.AddressHash([]byte(ma.Name))) + if err != nil { + return err + } + if ma.Address != addr { return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name) } - return ma.BaseAccount.Validate() + return ma.BaseAccount.Validate(addressCodec) } type moduleAccountPretty struct { - Address sdk.AccAddress `json:"address"` - PubKey string `json:"public_key"` - AccountNumber uint64 `json:"account_number"` - Sequence uint64 `json:"sequence"` - Name string `json:"name"` - Permissions []string `json:"permissions"` + Address string `json:"address"` + PubKey string `json:"public_key"` + AccountNumber uint64 `json:"account_number"` + Sequence uint64 `json:"sequence"` + Name string `json:"name"` + Permissions []string `json:"permissions"` } // MarshalJSON returns the JSON representation of a ModuleAccount. func (ma ModuleAccount) MarshalJSON() ([]byte, error) { - accAddr, err := sdk.AccAddressFromBech32(ma.Address) - if err != nil { - return nil, err - } - return json.Marshal(moduleAccountPretty{ - Address: accAddr, + Address: ma.Address, PubKey: "", AccountNumber: ma.AccountNumber, Sequence: ma.Sequence, @@ -308,5 +313,5 @@ func (ga GenesisAccounts) Contains(addr sdk.Address) bool { type GenesisAccount interface { sdk.AccountI - Validate() error + Validate(codec coreaddress.Codec) error } diff --git a/x/auth/types/account_retriever.go b/x/auth/types/account_retriever.go index 420b26bf31da..45a6afb07e6e 100644 --- a/x/auth/types/account_retriever.go +++ b/x/auth/types/account_retriever.go @@ -37,8 +37,13 @@ func (ar AccountRetriever) GetAccount(clientCtx client.Context, addr sdk.AccAddr func (ar AccountRetriever) GetAccountWithHeight(clientCtx client.Context, addr sdk.AccAddress) (client.Account, int64, error) { var header metadata.MD + addrStr, err := clientCtx.AddressCodec.BytesToString(addr) + if err != nil { + return nil, 0, err + } + queryClient := NewQueryClient(clientCtx) - res, err := queryClient.Account(context.Background(), &QueryAccountRequest{Address: addr.String()}, grpc.Header(&header)) + res, err := queryClient.Account(context.Background(), &QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) if err != nil { return nil, 0, err } diff --git a/x/auth/types/account_test.go b/x/auth/types/account_test.go index 3a4c16e8c462..83c16995e96c 100644 --- a/x/auth/types/account_test.go +++ b/x/auth/types/account_test.go @@ -10,22 +10,26 @@ import ( "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" ) func TestBaseAddressPubKey(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() _, pub1, addr1 := testdata.KeyTestPubAddr() + addr1Str, err := ac.BytesToString(addr1) + require.NoError(t, err) _, pub2, addr2 := testdata.KeyTestPubAddr() - acc := types.NewBaseAccountWithAddress(addr1) + + acc := types.NewBaseAccountWithAddress(addr1Str) // check the address (set) and pubkey (not set) require.EqualValues(t, addr1, acc.GetAddress()) require.EqualValues(t, nil, acc.GetPubKey()) // can't override address - err := acc.SetAddress(addr2) + err = acc.SetAddress(addr2) require.NotNil(t, err) require.EqualValues(t, addr1, acc.GetAddress()) @@ -54,17 +58,21 @@ func TestBaseAddressPubKey(t *testing.T) { func TestBaseSequence(t *testing.T) { _, _, addr := testdata.KeyTestPubAddr() - acc := types.NewBaseAccountWithAddress(addr) + addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(addr) + require.NoError(t, err) + acc := types.NewBaseAccountWithAddress(addrStr) seq := uint64(7) - err := acc.SetSequence(seq) + err = acc.SetSequence(seq) require.Nil(t, err) require.Equal(t, seq, acc.GetSequence()) } func TestGenesisAccountValidate(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addr, err := ac.BytesToString(pubkey.Address()) + require.NoError(t, err) baseAcc := types.NewBaseAccount(addr, pubkey, 0, 0) tests := []struct { @@ -88,17 +96,18 @@ func TestGenesisAccountValidate(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.expErr, tt.acc.Validate() != nil) + require.Equal(t, tt.expErr, tt.acc.Validate(ac) != nil) }) } } func TestModuleAccountString(t *testing.T) { name := "test" - moduleAcc := types.NewEmptyModuleAccount(name, types.Minter, types.Burner, types.Staking) + moduleAcc, err := types.NewEmptyModuleAccount(codectestutil.CodecOptions{}.GetAddressCodec(), name, types.Minter, types.Burner, types.Staking) + require.NoError(t, err) want := `base_account: name:"test" permissions:"minter" permissions:"burner" permissions:"staking" ` require.Equal(t, want, moduleAcc.String()) - err := moduleAcc.SetSequence(10) + err = moduleAcc.SetSequence(10) require.NoError(t, err) want = `base_account: name:"test" permissions:"minter" permissions:"burner" permissions:"staking" ` require.Equal(t, want, moduleAcc.String()) @@ -106,7 +115,8 @@ func TestModuleAccountString(t *testing.T) { func TestHasPermissions(t *testing.T) { name := "test" - macc := types.NewEmptyModuleAccount(name, types.Staking, types.Minter, types.Burner) + macc, err := types.NewEmptyModuleAccount(codectestutil.CodecOptions{}.GetAddressCodec(), name, types.Staking, types.Minter, types.Burner) + require.NoError(t, err) cases := []struct { permission string expectHas bool @@ -128,8 +138,12 @@ func TestHasPermissions(t *testing.T) { } func TestValidate(t *testing.T) { - addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addr, err := ac.BytesToString(secp256k1.GenPrivKey().PubKey().Address()) + require.NoError(t, err) baseAcc := types.NewBaseAccount(addr, nil, 0, 0) + emptyModuleAccount, err := types.NewEmptyModuleAccount(ac, "test") + require.NoError(t, err) tests := []struct { name string acc types.GenesisAccount @@ -137,7 +151,7 @@ func TestValidate(t *testing.T) { }{ { "valid module account", - types.NewEmptyModuleAccount("test"), + emptyModuleAccount, nil, }, { @@ -154,7 +168,7 @@ func TestValidate(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - err := tt.acc.Validate() + err := tt.acc.Validate(ac) require.Equal(t, tt.expErr, err) }) } @@ -162,7 +176,8 @@ func TestValidate(t *testing.T) { func TestModuleAccountJSON(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) + addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(pubkey.Address()) + require.NoError(t, err) baseAcc := types.NewBaseAccount(addr, nil, 10, 50) acc := types.NewModuleAccount(baseAcc, "test", "burner") @@ -180,7 +195,8 @@ func TestModuleAccountJSON(t *testing.T) { func TestGenesisAccountsContains(t *testing.T) { pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) + addr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(pubkey.Address()) + require.NoError(t, err) acc := types.NewBaseAccount(addr, secp256k1.GenPrivKey().PubKey(), 0, 0) genAccounts := types.GenesisAccounts{} @@ -191,12 +207,17 @@ func TestGenesisAccountsContains(t *testing.T) { } func TestNewModuleAddressOrBech32Address(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() input := "cosmos1cwwv22j5ca08ggdv9c2uky355k908694z577tv" - require.Equal(t, input, types.NewModuleAddressOrBech32Address(input).String()) - require.Equal(t, "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl", types.NewModuleAddressOrBech32Address("distribution").String()) + addr, err := ac.BytesToString(types.NewModuleAddressOrBech32Address(input, ac)) + require.NoError(t, err) + require.Equal(t, input, addr) + disAddr, err := ac.BytesToString(types.NewModuleAddressOrBech32Address("distribution", ac)) + require.NoError(t, err) + require.Equal(t, "cosmos1jv65s3grqf6v6jl3dp4t6c9t9rk99cd88lyufl", disAddr) } func TestModuleAccountValidateNilBaseAccount(t *testing.T) { ma := &types.ModuleAccount{Name: "foo"} - _ = ma.Validate() + _ = ma.Validate(codectestutil.CodecOptions{}.GetAddressCodec()) } diff --git a/x/auth/types/credentials.go b/x/auth/types/credentials.go index 4c63fc8d8c41..8347306535fe 100644 --- a/x/auth/types/credentials.go +++ b/x/auth/types/credentials.go @@ -4,23 +4,29 @@ import ( "bytes" "fmt" + coreaddress "cosmossdk.io/core/address" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/address" ) // NewBaseAccountWithPubKey creates an account with an a pubkey. -func NewBaseAccountWithPubKey(pubkey cryptotypes.PubKey) (*BaseAccount, error) { +func NewBaseAccountWithPubKey(pubkey cryptotypes.PubKey, addressCodec coreaddress.Codec) (*BaseAccount, error) { if pubkey == nil { return nil, fmt.Errorf("pubkey cannot be nil") } - baseAccount := NewBaseAccountWithAddress(sdk.AccAddress(pubkey.Address())) + addr, err := addressCodec.BytesToString(pubkey.Address()) + if err != nil { + return nil, err + } + + baseAccount := NewBaseAccountWithAddress(addr) if err := baseAccount.SetPubKey(pubkey); err != nil { return nil, fmt.Errorf("failed to create a valid account with credentials: %w", err) } - if err := baseAccount.Validate(); err != nil { + if err := baseAccount.Validate(addressCodec); err != nil { return nil, fmt.Errorf("failed to create a valid account with credentials: %w", err) } diff --git a/x/auth/types/credentials_test.go b/x/auth/types/credentials_test.go index 12ddf0a24fd5..9e822bbf41d3 100644 --- a/x/auth/types/credentials_test.go +++ b/x/auth/types/credentials_test.go @@ -7,11 +7,13 @@ import ( authtypes "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" ) func TestNewModuleCrendentials(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() // wrong derivation keys _, err := authtypes.NewModuleCredential("group", []byte{}) require.Error(t, err, "derivation keys must be non empty") @@ -27,7 +29,11 @@ func TestNewModuleCrendentials(t *testing.T) { require.NoError(t, err) addr, err := sdk.AccAddressFromHexUnsafe(credential.Address().String()) require.NoError(t, err) - require.Equal(t, expected.String(), addr.String()) + expectedAddr, err := ac.BytesToString(expected) + require.NoError(t, err) + addrStr, err := ac.BytesToString(addr) + require.NoError(t, err) + require.Equal(t, expectedAddr, addrStr) c, err := authtypes.NewModuleCredential("group", [][]byte{{0x20}, {0x0}}...) require.NoError(t, err) @@ -47,13 +53,13 @@ func TestNewBaseAccountWithPubKey(t *testing.T) { credential, err := authtypes.NewModuleCredential("group", [][]byte{{0x20}, {0x0}}...) require.NoError(t, err) - account, err := authtypes.NewBaseAccountWithPubKey(credential) + account, err := authtypes.NewBaseAccountWithPubKey(credential, codectestutil.CodecOptions{}.GetAddressCodec()) require.NoError(t, err) require.Equal(t, expected, account.GetAddress()) require.Equal(t, credential, account.GetPubKey()) } func TestNewBaseAccountWithPubKey_WrongCredentials(t *testing.T) { - _, err := authtypes.NewBaseAccountWithPubKey(cryptotypes.PubKey(nil)) + _, err := authtypes.NewBaseAccountWithPubKey(cryptotypes.PubKey(nil), codectestutil.CodecOptions{}.GetAddressCodec()) require.Error(t, err) } diff --git a/x/auth/types/genesis.go b/x/auth/types/genesis.go index 82a45779c3cb..692c7abd0c1c 100644 --- a/x/auth/types/genesis.go +++ b/x/auth/types/genesis.go @@ -8,6 +8,8 @@ import ( proto "github.com/cosmos/gogoproto/proto" + "cosmossdk.io/core/address" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -62,7 +64,7 @@ func GetGenesisStateFromAppState(cdc codec.Codec, appState map[string]json.RawMe // ValidateGenesis performs basic validation of auth genesis data returning an // error for any failed validation criteria. -func ValidateGenesis(data GenesisState) error { +func ValidateGenesis(data GenesisState, addressCodec address.Codec) error { if err := data.Params.Validate(); err != nil { return err } @@ -72,7 +74,7 @@ func ValidateGenesis(data GenesisState) error { return err } - return ValidateGenAccounts(genAccs) + return ValidateGenAccounts(genAccs, addressCodec) } // SanitizeGenesisAccounts sorts accounts and coin sets. @@ -123,12 +125,15 @@ func SanitizeGenesisAccounts(genAccs GenesisAccounts) GenesisAccounts { } // ValidateGenAccounts validates an array of GenesisAccounts and checks for duplicates -func ValidateGenAccounts(accounts GenesisAccounts) error { +func ValidateGenAccounts(accounts GenesisAccounts, addressCodec address.Codec) error { addrMap := make(map[string]bool, len(accounts)) for _, acc := range accounts { // check for duplicated accounts - addrStr := acc.GetAddress().String() + addrStr, err := addressCodec.BytesToString(acc.GetAddress()) + if err != nil { + return err + } if _, ok := addrMap[addrStr]; ok { return fmt.Errorf("duplicate account found in genesis state; address: %s", addrStr) } @@ -136,7 +141,7 @@ func ValidateGenAccounts(accounts GenesisAccounts) error { addrMap[addrStr] = true // check account specific validation - if err := acc.Validate(); err != nil { + if err := acc.Validate(addressCodec); err != nil { return fmt.Errorf("invalid account found in genesis state; address: %s, error: %w", addrStr, err) } } diff --git a/x/auth/types/genesis_test.go b/x/auth/types/genesis_test.go index c8be155e8ffa..11636eec0914 100644 --- a/x/auth/types/genesis_test.go +++ b/x/auth/types/genesis_test.go @@ -18,13 +18,18 @@ import ( ) func TestSanitize(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() addr1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc1 := types.NewBaseAccountWithAddress(addr1) - err := authAcc1.SetAccountNumber(1) + addr1Str, err := ac.BytesToString(addr1) + require.NoError(t, err) + authAcc1 := types.NewBaseAccountWithAddress(addr1Str) + err = authAcc1.SetAccountNumber(1) require.NoError(t, err) addr2 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) - authAcc2 := types.NewBaseAccountWithAddress(addr2) + addr2Str, err := ac.BytesToString(addr2) + require.NoError(t, err) + authAcc2 := types.NewBaseAccountWithAddress(addr2Str) genAccs := types.GenesisAccounts{authAcc1, authAcc2} @@ -45,21 +50,30 @@ var ( // require duplicate accounts fails validation func TestValidateGenesisDuplicateAccounts(t *testing.T) { - acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addr, err := ac.BytesToString(addr1) + require.NoError(t, err) + acc1 := types.NewBaseAccountWithAddress(addr) genAccs := make(types.GenesisAccounts, 2) genAccs[0] = acc1 genAccs[1] = acc1 - require.Error(t, types.ValidateGenAccounts(genAccs)) + require.Error(t, types.ValidateGenAccounts(genAccs, ac)) } func TestGenesisAccountIterator(t *testing.T) { encodingConfig := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}) cdc := encodingConfig.Codec - acc1 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) - acc2 := types.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + acc1Addr, err := ac.BytesToString(addr1) + require.NoError(t, err) + acc2Addr, err := ac.BytesToString(addr2) + require.NoError(t, err) + + acc1 := types.NewBaseAccountWithAddress(acc1Addr) + acc2 := types.NewBaseAccountWithAddress(acc2Addr) genAccounts := types.GenesisAccounts{acc1, acc2} diff --git a/x/auth/vesting/types/genesis_test.go b/x/auth/vesting/types/genesis_test.go index 94e9d492fe51..b981128d1944 100644 --- a/x/auth/vesting/types/genesis_test.go +++ b/x/auth/vesting/types/genesis_test.go @@ -7,6 +7,7 @@ import ( authtypes "cosmossdk.io/x/auth/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -20,26 +21,31 @@ var ( // require invalid vesting account fails validation func TestValidateGenesisInvalidAccounts(t *testing.T) { - acc1 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr1)) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + addr1Str, err := ac.BytesToString(addr1) + require.NoError(t, err) + acc1 := authtypes.NewBaseAccountWithAddress(addr1Str) acc1Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) - baseVestingAcc, err := NewBaseVestingAccount(acc1, acc1Balance, 1548775410) + baseVestingAcc, err := NewBaseVestingAccount(acc1, acc1Balance, 1548775410, ac) require.NoError(t, err) // invalid delegated vesting baseVestingAcc.DelegatedVesting = acc1Balance.Add(acc1Balance...) - acc2 := authtypes.NewBaseAccountWithAddress(sdk.AccAddress(addr2)) + addr2Str, err := ac.BytesToString(addr2) + require.NoError(t, err) + acc2 := authtypes.NewBaseAccountWithAddress(addr2Str) // acc2Balance := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 150)) genAccs := make([]authtypes.GenesisAccount, 2) genAccs[0] = baseVestingAcc genAccs[1] = acc2 - require.Error(t, authtypes.ValidateGenAccounts(genAccs)) + require.Error(t, authtypes.ValidateGenAccounts(genAccs, ac)) baseVestingAcc.DelegatedVesting = acc1Balance genAccs[0] = baseVestingAcc - require.NoError(t, authtypes.ValidateGenAccounts(genAccs)) + require.NoError(t, authtypes.ValidateGenAccounts(genAccs, ac)) // invalid start time genAccs[0] = NewContinuousVestingAccountRaw(baseVestingAcc, 1548888000) - require.Error(t, authtypes.ValidateGenAccounts(genAccs)) + require.Error(t, authtypes.ValidateGenAccounts(genAccs, ac)) } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 296fa8845921..67e91282371a 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -11,10 +11,10 @@ var ( ) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. -func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins, endTime int64, delayed bool) *MsgCreateVestingAccount { +func NewMsgCreateVestingAccount(fromAddr, toAddr string, amount sdk.Coins, endTime int64, delayed bool) *MsgCreateVestingAccount { return &MsgCreateVestingAccount{ - FromAddress: fromAddr.String(), - ToAddress: toAddr.String(), + FromAddress: fromAddr, + ToAddress: toAddr, Amount: amount, EndTime: endTime, Delayed: delayed, @@ -22,19 +22,19 @@ func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coin } // NewMsgCreatePermanentLockedAccount returns a reference to a new MsgCreatePermanentLockedAccount. -func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgCreatePermanentLockedAccount { +func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr string, amount sdk.Coins) *MsgCreatePermanentLockedAccount { return &MsgCreatePermanentLockedAccount{ - FromAddress: fromAddr.String(), - ToAddress: toAddr.String(), + FromAddress: fromAddr, + ToAddress: toAddr, Amount: amount, } } // NewMsgCreatePeriodicVestingAccount returns a reference to a new MsgCreatePeriodicVestingAccount. -func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTime int64, periods []Period) *MsgCreatePeriodicVestingAccount { +func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr string, startTime int64, periods []Period) *MsgCreatePeriodicVestingAccount { return &MsgCreatePeriodicVestingAccount{ - FromAddress: fromAddr.String(), - ToAddress: toAddr.String(), + FromAddress: fromAddr, + ToAddress: toAddr, StartTime: startTime, VestingPeriods: periods, } diff --git a/x/auth/vesting/types/vesting_account.go b/x/auth/vesting/types/vesting_account.go index e2b8fd40dd9b..5a198d5d30ab 100644 --- a/x/auth/vesting/types/vesting_account.go +++ b/x/auth/vesting/types/vesting_account.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "cosmossdk.io/core/address" "cosmossdk.io/math" authtypes "cosmossdk.io/x/auth/types" vestexported "cosmossdk.io/x/auth/vesting/exported" @@ -25,7 +26,7 @@ var ( // NewBaseVestingAccount creates a new BaseVestingAccount object. It is the // callers responsibility to ensure the base account has sufficient funds with // regards to the original vesting amount. -func NewBaseVestingAccount(baseAccount *authtypes.BaseAccount, originalVesting sdk.Coins, endTime int64) (*BaseVestingAccount, error) { +func NewBaseVestingAccount(baseAccount *authtypes.BaseAccount, originalVesting sdk.Coins, endTime int64, addressCodec address.Codec) (*BaseVestingAccount, error) { baseVestingAccount := &BaseVestingAccount{ BaseAccount: baseAccount, OriginalVesting: originalVesting, @@ -34,7 +35,7 @@ func NewBaseVestingAccount(baseAccount *authtypes.BaseAccount, originalVesting s EndTime: endTime, } - return baseVestingAccount, baseVestingAccount.Validate() + return baseVestingAccount, baseVestingAccount.Validate(addressCodec) } // LockedCoinsFromVesting returns all the coins that are not spendable (i.e. locked) @@ -146,7 +147,7 @@ func (bva BaseVestingAccount) GetEndTime() int64 { } // Validate checks for errors on the account fields -func (bva BaseVestingAccount) Validate() error { +func (bva BaseVestingAccount) Validate(addressCodec address.Codec) error { if bva.EndTime < 0 { return errors.New("end time cannot be negative") } @@ -159,7 +160,7 @@ func (bva BaseVestingAccount) Validate() error { return errors.New("delegated vesting amount cannot be greater than original vesting amount") } - return bva.BaseAccount.Validate() + return bva.BaseAccount.Validate(addressCodec) } // Continuous Vesting Account @@ -178,7 +179,9 @@ func NewContinuousVestingAccountRaw(bva *BaseVestingAccount, startTime int64) *C } // NewContinuousVestingAccount returns a new ContinuousVestingAccount -func NewContinuousVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, startTime, endTime int64) (*ContinuousVestingAccount, error) { +func NewContinuousVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, startTime, endTime int64, + addressCodec address.Codec, +) (*ContinuousVestingAccount, error) { baseVestingAcc := &BaseVestingAccount{ BaseAccount: baseAcc, OriginalVesting: originalVesting, @@ -190,7 +193,7 @@ func NewContinuousVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting BaseVestingAccount: baseVestingAcc, } - return continuousVestingAccount, continuousVestingAccount.Validate() + return continuousVestingAccount, continuousVestingAccount.Validate(addressCodec) } // GetVestedCoins returns the total number of vested coins. If no coins are vested, @@ -246,12 +249,12 @@ func (cva ContinuousVestingAccount) GetStartTime() int64 { } // Validate checks for errors on the account fields -func (cva ContinuousVestingAccount) Validate() error { +func (cva ContinuousVestingAccount) Validate(addressCodec address.Codec) error { if cva.GetStartTime() >= cva.GetEndTime() { return errors.New("vesting start-time cannot be before end-time") } - return cva.BaseVestingAccount.Validate() + return cva.BaseVestingAccount.Validate(addressCodec) } // Periodic Vesting Account @@ -271,7 +274,9 @@ func NewPeriodicVestingAccountRaw(bva *BaseVestingAccount, startTime int64, peri } // NewPeriodicVestingAccount returns a new PeriodicVestingAccount -func NewPeriodicVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, startTime int64, periods Periods) (*PeriodicVestingAccount, error) { +func NewPeriodicVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, startTime int64, periods Periods, + addressCodec address.Codec, +) (*PeriodicVestingAccount, error) { endTime := startTime for _, p := range periods { endTime += p.Length @@ -289,7 +294,7 @@ func NewPeriodicVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting s VestingPeriods: periods, } - return periodicVestingAccount, periodicVestingAccount.Validate() + return periodicVestingAccount, periodicVestingAccount.Validate(addressCodec) } // GetVestedCoins returns the total number of vested coins. If no coins are vested, @@ -356,7 +361,7 @@ func (pva PeriodicVestingAccount) GetVestingPeriods() Periods { } // Validate checks for errors on the account fields -func (pva PeriodicVestingAccount) Validate() error { +func (pva PeriodicVestingAccount) Validate(addressCodec address.Codec) error { if pva.GetStartTime() >= pva.GetEndTime() { return errors.New("vesting start-time cannot be before end-time") } @@ -384,7 +389,7 @@ func (pva PeriodicVestingAccount) Validate() error { return fmt.Errorf("original vesting coins (%v) does not match the sum of all coins in vesting periods (%v)", pva.OriginalVesting, originalVesting) } - return pva.BaseVestingAccount.Validate() + return pva.BaseVestingAccount.Validate(addressCodec) } // Delayed Vesting Account @@ -402,7 +407,7 @@ func NewDelayedVestingAccountRaw(bva *BaseVestingAccount) *DelayedVestingAccount } // NewDelayedVestingAccount returns a DelayedVestingAccount -func NewDelayedVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, endTime int64) (*DelayedVestingAccount, error) { +func NewDelayedVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sdk.Coins, endTime int64, addressCodec address.Codec) (*DelayedVestingAccount, error) { baseVestingAcc := &BaseVestingAccount{ BaseAccount: baseAcc, OriginalVesting: originalVesting, @@ -411,7 +416,7 @@ func NewDelayedVestingAccount(baseAcc *authtypes.BaseAccount, originalVesting sd delayedVestingAccount := &DelayedVestingAccount{baseVestingAcc} - return delayedVestingAccount, delayedVestingAccount.Validate() + return delayedVestingAccount, delayedVestingAccount.Validate(addressCodec) } // GetVestedCoins returns the total amount of vested coins for a delayed vesting @@ -449,8 +454,8 @@ func (dva DelayedVestingAccount) GetStartTime() int64 { } // Validate checks for errors on the account fields -func (dva DelayedVestingAccount) Validate() error { - return dva.BaseVestingAccount.Validate() +func (dva DelayedVestingAccount) Validate(addressCodec address.Codec) error { + return dva.BaseVestingAccount.Validate(addressCodec) } //----------------------------------------------------------------------------- @@ -462,7 +467,7 @@ var ( ) // NewPermanentLockedAccount returns a PermanentLockedAccount -func NewPermanentLockedAccount(baseAcc *authtypes.BaseAccount, coins sdk.Coins) (*PermanentLockedAccount, error) { +func NewPermanentLockedAccount(baseAcc *authtypes.BaseAccount, coins sdk.Coins, addressCodec address.Codec) (*PermanentLockedAccount, error) { baseVestingAcc := &BaseVestingAccount{ BaseAccount: baseAcc, OriginalVesting: coins, @@ -471,7 +476,7 @@ func NewPermanentLockedAccount(baseAcc *authtypes.BaseAccount, coins sdk.Coins) permanentLockedAccount := &PermanentLockedAccount{baseVestingAcc} - return permanentLockedAccount, permanentLockedAccount.Validate() + return permanentLockedAccount, permanentLockedAccount.Validate(addressCodec) } // GetVestedCoins returns the total amount of vested coins for a permanent locked vesting @@ -511,10 +516,10 @@ func (plva PermanentLockedAccount) GetEndTime() int64 { } // Validate checks for errors on the account fields -func (plva PermanentLockedAccount) Validate() error { +func (plva PermanentLockedAccount) Validate(addressCodec address.Codec) error { if plva.EndTime > 0 { return errors.New("permanently vested accounts cannot have an end-time") } - return plva.BaseVestingAccount.Validate() + return plva.BaseVestingAccount.Validate(addressCodec) } diff --git a/x/auth/vesting/types/vesting_account_test.go b/x/auth/vesting/types/vesting_account_test.go index 83273f32bbad..c7e264e3be3a 100644 --- a/x/auth/vesting/types/vesting_account_test.go +++ b/x/auth/vesting/types/vesting_account_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "cosmossdk.io/core/address" "cosmossdk.io/core/header" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -55,14 +56,18 @@ func (s *VestingAccountTestSuite) SetupTest() { "random": {"random"}, } + ac := authcodec.NewBech32Codec("cosmos") + authorityAddr, err := ac.BytesToString(authtypes.NewModuleAddress("gov")) + require.NoError(s.T(), err) + s.accountKeeper = keeper.NewAccountKeeper( env, encCfg.Codec, authtypes.ProtoBaseAccount, maccPerms, - authcodec.NewBech32Codec("cosmos"), + ac, "cosmos", - authtypes.NewModuleAddress("gov").String(), + authorityAddr, ) } @@ -70,9 +75,10 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) { now := time.Now() startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) - - bacc, origCoins := initBaseAccount() - cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix(), ac) require.NoError(t, err) // require no coins vested _before_ the start time of the vesting schedule @@ -107,8 +113,10 @@ func TestGetVestingCoinsContVestingAcc(t *testing.T) { startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() - cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix(), ac) require.NoError(t, err) // require all coins vesting before the start time of the vesting schedule @@ -139,8 +147,10 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { startTime := now.Add(24 * time.Hour) endTime := startTime.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() - cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix()) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + cva, err := types.NewContinuousVestingAccount(bacc, origCoins, startTime.Unix(), endTime.Unix(), ac) require.NoError(t, err) // require that all original coins are locked before the beginning of the vesting @@ -170,24 +180,26 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to delegate all vesting coins - cva, err := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, cva.DelegatedVesting) require.Nil(t, cva.DelegatedFree) // require the ability to delegate all vested coins - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, cva.DelegatedVesting) require.Equal(t, origCoins, cva.DelegatedFree) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedVesting) @@ -198,7 +210,7 @@ func TestTrackDelegationContVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, cva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) require.Panics(t, func() { cva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -211,10 +223,12 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to undelegate all vesting coins - cva, err := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(now, origCoins, origCoins) cva.TrackUndelegation(origCoins) @@ -222,7 +236,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Equal(t, emptyCoins, cva.DelegatedVesting) // require the ability to undelegate all vested coins - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(endTime, origCoins, origCoins) cva.TrackUndelegation(origCoins) @@ -230,7 +244,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // require no modifications when the undelegation amount is zero - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) require.Panics(t, func() { cva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -239,7 +253,7 @@ func TestTrackUndelegationContVestingAcc(t *testing.T) { require.Nil(t, cva.DelegatedVesting) // vest 50% and delegate to two validators - cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix()) + cva, err = types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix(), ac) require.NoError(t, err) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) cva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -259,10 +273,12 @@ func TestGetVestedCoinsDelVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require no coins are vested until schedule maturation - dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) vestedCoins := dva.GetVestedCoins(now) require.Nil(t, vestedCoins) @@ -276,10 +292,12 @@ func TestGetVestingCoinsDelVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require all coins vesting at the beginning of the schedule - dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) vestingCoins := dva.GetVestingCoins(now) require.Equal(t, origCoins, vestingCoins) @@ -293,11 +311,13 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require that all coins are locked in the beginning of the vesting // schedule - dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) lockedCoins := dva.LockedCoins(now) require.True(t, lockedCoins.Equal(origCoins)) @@ -323,17 +343,19 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to delegate all vesting coins - dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require the ability to delegate all vested coins - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, dva.DelegatedVesting) @@ -341,14 +363,14 @@ func TestTrackDelegationDelVestingAcc(t *testing.T) { // require the ability to delegate all coins half way through the vesting // schedule - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, origCoins) require.Equal(t, origCoins, dva.DelegatedVesting) require.Nil(t, dva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) require.Panics(t, func() { dva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -361,10 +383,12 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to undelegate all vesting coins - dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(now, origCoins, origCoins) dva.TrackUndelegation(origCoins) @@ -372,7 +396,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { require.Equal(t, emptyCoins, dva.DelegatedVesting) // require the ability to undelegate all vested coins - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(endTime, origCoins, origCoins) dva.TrackUndelegation(origCoins) @@ -380,7 +404,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { require.Nil(t, dva.DelegatedVesting) // require no modifications when the undelegation amount is zero - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) require.Panics(t, func() { dva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -389,7 +413,7 @@ func TestTrackUndelegationDelVestingAcc(t *testing.T) { require.Nil(t, dva.DelegatedVesting) // vest 50% and delegate to two validators - dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix()) + dva, err = types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix(), ac) require.NoError(t, err) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) dva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -415,8 +439,10 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - bacc, origCoins := initBaseAccount() - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) // require no coins vested at the beginning of the vesting schedule @@ -452,6 +478,7 @@ func TestGetVestedCoinsPeriodicVestingAcc(t *testing.T) { } func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() now := time.Now() tests := []struct { name string @@ -487,8 +514,9 @@ func TestOverflowAndNegativeVestedCoinsPeriods(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - bacc, origCoins := initBaseAccount() - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), tt.periods) + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), tt.periods, ac) if tt.wantErr != "" { require.ErrorContains(t, err, tt.wantErr) return @@ -511,8 +539,10 @@ func TestGetVestingCoinsPeriodicVestingAcc(t *testing.T) { types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - bacc, origCoins := initBaseAccount() - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) // require all coins vesting at the beginning of the vesting schedule @@ -549,8 +579,10 @@ func TestSpendableCoinsPeriodicVestingAcc(t *testing.T) { types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - bacc, origCoins := initBaseAccount() - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) // require that there exist no spendable coins at the beginning of the @@ -577,24 +609,26 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to delegate all vesting coins - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, pva.DelegatedVesting) require.Nil(t, pva.DelegatedFree) // require the ability to delegate all vested coins - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(endTime, origCoins, origCoins) require.Nil(t, pva.DelegatedVesting) require.Equal(t, origCoins, pva.DelegatedFree) // delegate half of vesting coins - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now, origCoins, periods[0].Amount) // require that all delegated coins are delegated vesting @@ -602,7 +636,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedFree) // delegate 75% of coins, split between vested and vesting - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, periods[0].Amount.Add(periods[1].Amount...)) // require that the maximum possible amount of vesting coins are chosen for delegation. @@ -610,7 +644,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, pva.DelegatedVesting, periods[0].Amount) // require the ability to delegate all vesting coins (50%) and all vested coins (50%) - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedVesting) @@ -621,7 +655,7 @@ func TestTrackDelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}, pva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) require.Panics(t, func() { pva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -639,10 +673,12 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { types.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, } - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to undelegate all vesting coins at the beginning of vesting - pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err := types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now, origCoins, origCoins) pva.TrackUndelegation(origCoins) @@ -650,7 +686,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Equal(t, emptyCoins, pva.DelegatedVesting) // require the ability to undelegate all vested coins at the end of vesting - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(endTime, origCoins, origCoins) pva.TrackUndelegation(origCoins) @@ -658,7 +694,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // require the ability to undelegate half of coins - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(endTime, origCoins, periods[0].Amount) pva.TrackUndelegation(periods[0].Amount) @@ -666,7 +702,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // require no modifications when the undelegation amount is zero - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) require.Panics(t, func() { pva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -675,7 +711,7 @@ func TestTrackUndelegationPeriodicVestingAcc(t *testing.T) { require.Nil(t, pva.DelegatedVesting) // vest 50% and delegate to two validators - pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods) + pva, err = types.NewPeriodicVestingAccount(bacc, origCoins, now.Unix(), periods, ac) require.NoError(t, err) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) pva.TrackDelegation(now.Add(12*time.Hour), origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -695,10 +731,12 @@ func TestGetVestedCoinsPermLockedVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require no coins are vested - plva, err := types.NewPermanentLockedAccount(bacc, origCoins) + plva, err := types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) vestedCoins := plva.GetVestedCoins(now) require.Nil(t, vestedCoins) @@ -712,10 +750,12 @@ func TestGetVestingCoinsPermLockedVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require all coins vesting at the beginning of the schedule - plva, err := types.NewPermanentLockedAccount(bacc, origCoins) + plva, err := types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) vestingCoins := plva.GetVestingCoins(now) require.Equal(t, origCoins, vestingCoins) @@ -729,11 +769,13 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require that all coins are locked in the beginning of the vesting // schedule - plva, err := types.NewPermanentLockedAccount(bacc, origCoins) + plva, err := types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) lockedCoins := plva.LockedCoins(now) require.True(t, lockedCoins.Equal(origCoins)) @@ -754,24 +796,26 @@ func TestTrackDelegationPermLockedVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to delegate all vesting coins - plva, err := types.NewPermanentLockedAccount(bacc, origCoins) + plva, err := types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) plva.TrackDelegation(now, origCoins, origCoins) require.Equal(t, origCoins, plva.DelegatedVesting) require.Nil(t, plva.DelegatedFree) // require the ability to delegate all vested coins at endTime - plva, err = types.NewPermanentLockedAccount(bacc, origCoins) + plva, err = types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) plva.TrackDelegation(endTime, origCoins, origCoins) require.Equal(t, origCoins, plva.DelegatedVesting) require.Nil(t, plva.DelegatedFree) // require no modifications when delegation amount is zero or not enough funds - plva, err = types.NewPermanentLockedAccount(bacc, origCoins) + plva, err = types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) require.Panics(t, func() { plva.TrackDelegation(endTime, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 1000000)}) @@ -784,10 +828,12 @@ func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { now := time.Now() endTime := now.Add(1000 * 24 * time.Hour) - bacc, origCoins := initBaseAccount() + ac := codectestutil.CodecOptions{}.GetAddressCodec() + bacc, origCoins, err := initBaseAccount(ac) + require.NoError(t, err) // require the ability to undelegate all vesting coins - plva, err := types.NewPermanentLockedAccount(bacc, origCoins) + plva, err := types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) plva.TrackDelegation(now, origCoins, origCoins) plva.TrackUndelegation(origCoins) @@ -795,7 +841,7 @@ func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { require.Equal(t, emptyCoins, plva.DelegatedVesting) // require the ability to undelegate all vesting coins at endTime - plva, err = types.NewPermanentLockedAccount(bacc, origCoins) + plva, err = types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) plva.TrackDelegation(endTime, origCoins, origCoins) plva.TrackUndelegation(origCoins) @@ -803,7 +849,7 @@ func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { require.Equal(t, emptyCoins, plva.DelegatedVesting) // require no modifications when the undelegation amount is zero - plva, err = types.NewPermanentLockedAccount(bacc, origCoins) + plva, err = types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) require.Panics(t, func() { plva.TrackUndelegation(sdk.Coins{sdk.NewInt64Coin(stakeDenom, 0)}) @@ -812,7 +858,7 @@ func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { require.Nil(t, plva.DelegatedVesting) // delegate to two validators - plva, err = types.NewPermanentLockedAccount(bacc, origCoins) + plva, err = types.NewPermanentLockedAccount(bacc, origCoins, ac) require.NoError(t, err) plva.TrackDelegation(now, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) plva.TrackDelegation(now, origCoins, sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)}) @@ -830,11 +876,13 @@ func TestTrackUndelegationPermLockedVestingAcc(t *testing.T) { } func TestGenesisAccountValidate(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() pubkey := secp256k1.GenPrivKey().PubKey() - addr := sdk.AccAddress(pubkey.Address()) + addr, err := ac.BytesToString(pubkey.Address()) + require.NoError(t, err) baseAcc := authtypes.NewBaseAccount(addr, pubkey, 0, 0) initialVesting := sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)) - baseVestingWithCoins, err := types.NewBaseVestingAccount(baseAcc, initialVesting, 100) + baseVestingWithCoins, err := types.NewBaseVestingAccount(baseAcc, initialVesting, 100, ac) require.NoError(t, err) tests := []struct { name string @@ -859,7 +907,7 @@ func TestGenesisAccountValidate(t *testing.T) { { "valid continuous vesting account", func() authtypes.GenesisAccount { - acc, _ := types.NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200) + acc, _ := types.NewContinuousVestingAccount(baseAcc, initialVesting, 100, 200, ac) return acc }(), false, @@ -867,7 +915,7 @@ func TestGenesisAccountValidate(t *testing.T) { { "invalid vesting times", func() authtypes.GenesisAccount { - acc, _ := types.NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078) + acc, _ := types.NewContinuousVestingAccount(baseAcc, initialVesting, 1654668078, 1554668078, ac) return acc }(), true, @@ -875,7 +923,7 @@ func TestGenesisAccountValidate(t *testing.T) { { "valid periodic vesting account", func() authtypes.GenesisAccount { - acc, _ := types.NewPeriodicVestingAccount(baseAcc, initialVesting, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}) + acc, _ := types.NewPeriodicVestingAccount(baseAcc, initialVesting, 0, types.Periods{types.Period{Length: int64(100), Amount: sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 50)}}}, ac) return acc }(), false, @@ -897,7 +945,7 @@ func TestGenesisAccountValidate(t *testing.T) { { "valid permanent locked vesting account", func() authtypes.GenesisAccount { - acc, _ := types.NewPermanentLockedAccount(baseAcc, initialVesting) + acc, _ := types.NewPermanentLockedAccount(baseAcc, initialVesting, ac) return acc }(), false, @@ -913,17 +961,21 @@ func TestGenesisAccountValidate(t *testing.T) { tt := tt t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.expErr, tt.acc.Validate() != nil) + require.Equal(t, tt.expErr, tt.acc.Validate(ac) != nil) }) } } -func initBaseAccount() (*authtypes.BaseAccount, sdk.Coins) { +func initBaseAccount(addressCodec address.Codec) (*authtypes.BaseAccount, sdk.Coins, error) { _, _, addr := testdata.KeyTestPubAddr() + addrStr, err := addressCodec.BytesToString(addr) + if err != nil { + return nil, nil, err + } origCoins := sdk.Coins{sdk.NewInt64Coin(feeDenom, 1000), sdk.NewInt64Coin(stakeDenom, 100)} - bacc := authtypes.NewBaseAccountWithAddress(addr) + bacc := authtypes.NewBaseAccountWithAddress(addrStr) - return bacc, origCoins + return bacc, origCoins, nil } func TestVestingAccountTestSuite(t *testing.T) { diff --git a/x/authz/keeper/msg_server_test.go b/x/authz/keeper/msg_server_test.go index 5e4a25279b87..e18baf570d10 100644 --- a/x/authz/keeper/msg_server_test.go +++ b/x/authz/keeper/msg_server_test.go @@ -17,9 +17,13 @@ import ( ) func (suite *TestSuite) createAccounts() []sdk.AccAddress { + addr0, err := suite.accountKeeper.AddressCodec().BytesToString(suite.addrs[0]) + suite.Require().NoError(err) + addr1, err := suite.accountKeeper.AddressCodec().BytesToString(suite.addrs[1]) + suite.Require().NoError(err) addrs := simtestutil.CreateIncrementalAccounts(2) - suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[0])).AnyTimes() - suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[1])).AnyTimes() + suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(addr0)).AnyTimes() + suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(addr1)).AnyTimes() return addrs } @@ -126,15 +130,14 @@ func (suite *TestSuite) TestGrant() { malleate: func() *authz.MsgGrant { newAcc := sdk.AccAddress("valid") suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), newAcc).Return(nil).AnyTimes() - acc := authtypes.NewBaseAccountWithAddress(newAcc) + addr, err := suite.accountKeeper.AddressCodec().BytesToString(newAcc) + suite.Require().NoError(err) + acc := authtypes.NewBaseAccountWithAddress(addr) suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), newAcc).Return(acc).AnyTimes() grant, err := authz.NewGrant(curBlockTime, banktypes.NewSendAuthorization(coins, nil, suite.accountKeeper.AddressCodec()), &oneYear) suite.Require().NoError(err) - addr, err := suite.accountKeeper.AddressCodec().BytesToString(newAcc) - suite.Require().NoError(err) - return &authz.MsgGrant{ Granter: granterStrAddr, Grantee: addr, diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index 53f0701f287e..4e0a3ab3d39b 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -45,12 +45,23 @@ func TestExpiredGrantsQueue(t *testing.T) { banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) + ac := codectestutil.CodecOptions{}.GetAddressCodec() addrs := simtestutil.CreateIncrementalAccounts(5) granter := addrs[0] + granterAddr, err := ac.BytesToString(granter) + require.NoError(t, err) grantee1 := addrs[1] + grantee1Addr, err := ac.BytesToString(grantee1) + require.NoError(t, err) grantee2 := addrs[2] + grantee2Addr, err := ac.BytesToString(grantee2) + require.NoError(t, err) grantee3 := addrs[3] + grantee3Addr, err := ac.BytesToString(grantee3) + require.NoError(t, err) grantee4 := addrs[4] + grantee4Addr, err := ac.BytesToString(grantee4) + require.NoError(t, err) expiration := ctx.HeaderInfo().Time.AddDate(0, 1, 0) expiration2 := expiration.AddDate(1, 0, 0) smallCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 10)) @@ -58,11 +69,11 @@ func TestExpiredGrantsQueue(t *testing.T) { ctrl := gomock.NewController(t) accountKeeper := authztestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetAccount(gomock.Any(), granter).Return(authtypes.NewBaseAccountWithAddress(granter)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee1).Return(authtypes.NewBaseAccountWithAddress(grantee1)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee2).Return(authtypes.NewBaseAccountWithAddress(grantee2)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee3).Return(authtypes.NewBaseAccountWithAddress(grantee3)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee4).Return(authtypes.NewBaseAccountWithAddress(grantee4)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), granter).Return(authtypes.NewBaseAccountWithAddress(granterAddr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee1).Return(authtypes.NewBaseAccountWithAddress(grantee1Addr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee2).Return(authtypes.NewBaseAccountWithAddress(grantee2Addr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee3).Return(authtypes.NewBaseAccountWithAddress(grantee3Addr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee4).Return(authtypes.NewBaseAccountWithAddress(grantee4Addr)).AnyTimes() accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() diff --git a/x/bank/depinject.go b/x/bank/depinject.go index 8a9d3efdd825..2566b08a978d 100644 --- a/x/bank/depinject.go +++ b/x/bank/depinject.go @@ -67,7 +67,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } authStr, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index a5b4e352c88c..f859f815bc31 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -196,7 +196,7 @@ func (suite *KeeperTestSuite) TestSpendableBalances() { CountTotal: false, } req := types.NewQuerySpendableBalancesRequest(addrStr, pageReq) - acc := authtypes.NewBaseAccountWithAddress(addr) + acc := authtypes.NewBaseAccountWithAddress(addrStr) suite.mockSpendableCoins(ctx, acc) res, err := queryClient.SpendableBalances(ctx, req) @@ -213,6 +213,7 @@ func (suite *KeeperTestSuite) TestSpendableBalances() { sdk.NewCoins(fooCoins), ctx.HeaderInfo().Time.Unix(), ctx.HeaderInfo().Time.Add(time.Hour).Unix(), + suite.authKeeper.AddressCodec(), ) suite.Require().NoError(err) @@ -247,7 +248,7 @@ func (suite *KeeperTestSuite) TestSpendableBalanceByDenom() { suite.Require().NoError(err) req := types.NewQuerySpendableBalanceByDenomRequest(addrStr, fooDenom) - acc := authtypes.NewBaseAccountWithAddress(addr) + acc := authtypes.NewBaseAccountWithAddress(addrStr) suite.mockSpendableCoins(ctx, acc) res, err := queryClient.SpendableBalanceByDenom(ctx, req) @@ -264,6 +265,7 @@ func (suite *KeeperTestSuite) TestSpendableBalanceByDenom() { sdk.NewCoins(fooCoins), ctx.HeaderInfo().Time.Unix(), ctx.HeaderInfo().Time.Add(time.Hour).Unix(), + suite.authKeeper.AddressCodec(), ) suite.Require().NoError(err) diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index 86043fc81074..13a993c5238a 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -49,14 +49,17 @@ const ( ) var ( - holderAcc = authtypes.NewEmptyModuleAccount(holder) - randomAcc = authtypes.NewEmptyModuleAccount(randomPerm) - burnerAcc = authtypes.NewEmptyModuleAccount(authtypes.Burner, authtypes.Burner, authtypes.Staking) - minterAcc = authtypes.NewEmptyModuleAccount(authtypes.Minter, authtypes.Minter) - mintAcc = authtypes.NewEmptyModuleAccount(banktypes.MintModuleName, authtypes.Minter) - multiPermAcc = authtypes.NewEmptyModuleAccount(multiPerm, authtypes.Burner, authtypes.Minter, authtypes.Staking) + ac = codectestutil.CodecOptions{}.GetAddressCodec() - baseAcc = authtypes.NewBaseAccountWithAddress(sdk.AccAddress([]byte("baseAcc"))) + holderAcc, _ = authtypes.NewEmptyModuleAccount(ac, holder) + randomAcc, _ = authtypes.NewEmptyModuleAccount(ac, randomPerm) + burnerAcc, _ = authtypes.NewEmptyModuleAccount(ac, authtypes.Burner, authtypes.Burner, authtypes.Staking) + minterAcc, _ = authtypes.NewEmptyModuleAccount(ac, authtypes.Minter, authtypes.Minter) + mintAcc, _ = authtypes.NewEmptyModuleAccount(ac, banktypes.MintModuleName, authtypes.Minter) + multiPermAcc, _ = authtypes.NewEmptyModuleAccount(ac, multiPerm, authtypes.Burner, authtypes.Minter, authtypes.Staking) + + baseAccStr, _ = ac.BytesToString([]byte("baseAcc")) + baseAcc = authtypes.NewBaseAccountWithAddress(baseAccStr) accAddrs = []sdk.AccAddress{ sdk.AccAddress([]byte("addr1_______________")), @@ -607,7 +610,10 @@ func (suite *KeeperTestSuite) TestSendCoinsNewAccount() { suite.mockFundAccount(accAddrs[0]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) acc1Balances := suite.bankKeeper.GetAllBalances(ctx, accAddrs[0]) require.Equal(balances, acc1Balances) @@ -645,7 +651,7 @@ func (suite *KeeperTestSuite) TestInputOutputNewAccount() { acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) suite.Require().NoError(err) - suite.mockInputOutputCoins([]sdk.AccountI{authtypes.NewBaseAccountWithAddress(accAddrs[0])}, []sdk.AccAddress{accAddrs[1]}) + suite.mockInputOutputCoins([]sdk.AccountI{authtypes.NewBaseAccountWithAddress(acc0StrAddr)}, []sdk.AccAddress{accAddrs[1]}) input := banktypes.Input{ Address: acc0StrAddr, Coins: sdk.NewCoins(newFooCoin(30), newBarCoin(10)), } @@ -665,8 +671,6 @@ func (suite *KeeperTestSuite) TestInputOutputCoins() { require := suite.Require() balances := sdk.NewCoins(newFooCoin(90), newBarCoin(30)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) suite.Require().NoError(err) acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) @@ -674,6 +678,8 @@ func (suite *KeeperTestSuite) TestInputOutputCoins() { acc2StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[2]) suite.Require().NoError(err) + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + input := banktypes.Input{ Address: acc0StrAddr, Coins: sdk.NewCoins(newFooCoin(60), newBarCoin(20)), } @@ -781,7 +787,7 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { fromAddr := accAddrs[0] fromStrAddr, err := suite.authKeeper.AddressCodec().BytesToString(fromAddr) suite.Require().NoError(err) - fromAcc := authtypes.NewBaseAccountWithAddress(fromAddr) + fromAcc := authtypes.NewBaseAccountWithAddress(fromStrAddr) inputAccs := []sdk.AccountI{fromAcc} toAddr1 := accAddrs[1] toAddr1Str, err := suite.authKeeper.AddressCodec().BytesToString(toAddr1) @@ -1014,7 +1020,9 @@ func (suite *KeeperTestSuite) TestSendCoins() { require := suite.Require() balances := sdk.NewCoins(newFooCoin(100), newBarCoin(50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) suite.mockFundAccount(accAddrs[1]) require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], balances)) @@ -1096,7 +1104,9 @@ func (suite *KeeperTestSuite) TestSendCoinsWithRestrictions() { setupCtx := suite.ctx balances := sdk.NewCoins(newFooCoin(1000), newBarCoin(500)) fromAddr := accAddrs[0] - fromAcc := authtypes.NewBaseAccountWithAddress(fromAddr) + fromStrAddr, err := suite.authKeeper.AddressCodec().BytesToString(fromAddr) + suite.Require().NoError(err) + fromAcc := authtypes.NewBaseAccountWithAddress(fromStrAddr) toAddr1 := accAddrs[1] toAddr2 := accAddrs[2] @@ -1233,8 +1243,11 @@ func (suite *KeeperTestSuite) TestSendCoins_Invalid_SendLockedCoins() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[1]) @@ -1255,10 +1268,13 @@ func (suite *KeeperTestSuite) TestSendCoins_Invalid_NoSpendableCoins() { origCoins := coins sendCoins := coins - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) suite.mockFundAccount(accAddrs[0]) suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, accAddrs[0], balances)) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.authKeeper.EXPECT().GetAccount(suite.ctx, accAddrs[0]).Return(vacc) @@ -1276,7 +1292,10 @@ func (suite *KeeperTestSuite) TestValidateBalance() { now := time.Now() endTime := now.Add(24 * time.Hour) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) suite.authKeeper.EXPECT().GetAccount(suite.ctx, accAddrs[0]).Return(nil) require.Error(suite.bankKeeper.ValidateBalance(ctx, accAddrs[0])) @@ -1287,8 +1306,11 @@ func (suite *KeeperTestSuite) TestValidateBalance() { suite.mockValidateBalance(acc0) require.NoError(suite.bankKeeper.ValidateBalance(ctx, accAddrs[0])) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc1, balances.Add(balances...), now.Unix(), endTime.Unix()) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc1, balances.Add(balances...), now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[1]) @@ -1358,11 +1380,11 @@ func (suite *KeeperTestSuite) TestHasBalance() { func (suite *KeeperTestSuite) TestMsgSendEvents() { require := suite.Require() - - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) suite.Require().NoError(err) @@ -1399,10 +1421,6 @@ func (suite *KeeperTestSuite) TestMsgSendEvents() { func (suite *KeeperTestSuite) TestMsgMultiSendEvents() { ctx := sdk.UnwrapSDKContext(suite.ctx) require := suite.Require() - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - - require.NoError(suite.bankKeeper.SetParams(ctx, banktypes.DefaultParams())) - acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) suite.Require().NoError(err) acc2StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[2]) @@ -1410,6 +1428,10 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() { acc3StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[3]) suite.Require().NoError(err) + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + + require.NoError(suite.bankKeeper.SetParams(ctx, banktypes.DefaultParams())) + coins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100)) newCoins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50)) newCoins2 := sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100)) @@ -1490,9 +1512,14 @@ func (suite *KeeperTestSuite) TestSpendableCoins() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) lockedCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1524,8 +1551,11 @@ func (suite *KeeperTestSuite) TestVestingAccountSend() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1558,8 +1588,11 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() { vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, } - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods, suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1589,9 +1622,14 @@ func (suite *KeeperTestSuite) TestVestingAccountReceive() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1621,15 +1659,20 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) sendCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) periods := vesting.Periods{ vesting.Period{Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 50)}}, vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, vesting.Period{Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin("stake", 25)}}, } - vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods) + vacc, err := vesting.NewPeriodicVestingAccount(acc0, origCoins, now.Unix(), periods, suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1660,9 +1703,14 @@ func (suite *KeeperTestSuite) TestDelegateCoins() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.HeaderInfo().Time.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.HeaderInfo().Time.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1718,9 +1766,14 @@ func (suite *KeeperTestSuite) TestUndelegateCoins() { origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100)) delCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) - acc1 := authtypes.NewBaseAccountWithAddress(accAddrs[1]) - vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix()) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc1StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[1]) + suite.Require().NoError(err) + + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) + acc1 := authtypes.NewBaseAccountWithAddress(acc1StrAddr) + vacc, err := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix(), suite.authKeeper.AddressCodec()) suite.Require().NoError(err) suite.mockFundAccount(accAddrs[0]) @@ -1770,7 +1823,9 @@ func (suite *KeeperTestSuite) TestUndelegateCoins_Invalid() { origCoins := sdk.NewCoins(newFooCoin(100)) delCoins := sdk.NewCoins(newFooCoin(50)) - acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0]) + acc0StrAddr, err := suite.authKeeper.AddressCodec().BytesToString(accAddrs[0]) + suite.Require().NoError(err) + acc0 := authtypes.NewBaseAccountWithAddress(acc0StrAddr) suite.authKeeper.EXPECT().GetAccount(ctx, holderAcc.GetAddress()).Return(nil) require.Error(suite.bankKeeper.UndelegateCoins(ctx, holderAcc.GetAddress(), accAddrs[0], delCoins)) diff --git a/x/bank/keeper/msg_server_test.go b/x/bank/keeper/msg_server_test.go index ea27bbcbf1fc..19eb284ced97 100644 --- a/x/bank/keeper/msg_server_test.go +++ b/x/bank/keeper/msg_server_test.go @@ -4,10 +4,11 @@ import ( authtypes "cosmossdk.io/x/auth/types" banktypes "cosmossdk.io/x/bank/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" sdk "github.com/cosmos/cosmos-sdk/types" ) -var govAcc = authtypes.NewEmptyModuleAccount(banktypes.GovModuleName, authtypes.Minter) +var govAcc, _ = authtypes.NewEmptyModuleAccount(codectestutil.CodecOptions{}.GetAddressCodec(), banktypes.GovModuleName, authtypes.Minter) func (suite *KeeperTestSuite) TestMsgUpdateParams() { // default params diff --git a/x/circuit/depinject.go b/x/circuit/depinject.go index 1ec1d4d9662d..8bafde295654 100644 --- a/x/circuit/depinject.go +++ b/x/circuit/depinject.go @@ -48,7 +48,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress("gov") if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AddressCodec) } circuitkeeper := keeper.NewKeeper( diff --git a/x/consensus/depinject.go b/x/consensus/depinject.go index 695c609e172d..4cf8a5bf3557 100644 --- a/x/consensus/depinject.go +++ b/x/consensus/depinject.go @@ -2,6 +2,7 @@ package consensus import ( modulev1 "cosmossdk.io/api/cosmos/consensus/module/v1" + "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" @@ -28,9 +29,10 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Cdc codec.Codec - Environment appmodule.Environment + Config *modulev1.Module + Cdc codec.Codec + Environment appmodule.Environment + AddressCodec address.Codec } type ModuleOutputs struct { @@ -45,7 +47,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress("gov") if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AddressCodec) } k := keeper.NewKeeper(in.Cdc, in.Environment, authority.String()) diff --git a/x/crisis/depinject.go b/x/crisis/depinject.go index 3879333c1602..704e1dcc6fd8 100644 --- a/x/crisis/depinject.go +++ b/x/crisis/depinject.go @@ -63,7 +63,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AddressCodec) } k := keeper.NewKeeper( diff --git a/x/distribution/depinject.go b/x/distribution/depinject.go index 299f750c60c7..916dbd8c41b0 100644 --- a/x/distribution/depinject.go +++ b/x/distribution/depinject.go @@ -54,7 +54,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } authorityAddr, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index 22d5bea88860..0a9318ef00a4 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -107,7 +107,9 @@ func TestAllocateTokensToManyValidators(t *testing.T) { accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) poolKeeper := distrtestutil.NewMockPoolKeeper(ctrl) - feeCollectorAcc := authtypes.NewEmptyModuleAccount("fee_collector") + feeCollectorAcc, err := authtypes.NewEmptyModuleAccount(cdcOpts.GetAddressCodec(), "fee_collector") + require.NoError(t, err) + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), "fee_collector").Return(feeCollectorAcc) stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec("cosmosvaloper")).AnyTimes() @@ -247,7 +249,9 @@ func TestAllocateTokensTruncation(t *testing.T) { accountKeeper := distrtestutil.NewMockAccountKeeper(ctrl) poolKeeper := distrtestutil.NewMockPoolKeeper(ctrl) - feeCollectorAcc := authtypes.NewEmptyModuleAccount("fee_collector") + feeCollectorAcc, err := authtypes.NewEmptyModuleAccount(cdcOpts.GetAddressCodec(), "fee_collector") + require.NoError(t, err) + accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress()) accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), "fee_collector").Return(feeCollectorAcc) stakingKeeper.EXPECT().ValidatorAddressCodec().Return(address.NewBech32Codec("cosmosvaloper")).AnyTimes() diff --git a/x/distribution/keeper/common_test.go b/x/distribution/keeper/common_test.go index 47445e4a0850..6374ab0bed29 100644 --- a/x/distribution/keeper/common_test.go +++ b/x/distribution/keeper/common_test.go @@ -4,6 +4,7 @@ import ( authtypes "cosmossdk.io/x/auth/types" "cosmossdk.io/x/distribution/types" + codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -19,5 +20,5 @@ var ( valConsAddr1 = sdk.ConsAddress(valConsPk1.Address()) valConsAddr2 = sdk.ConsAddress(valConsPk2.Address()) - distrAcc = authtypes.NewEmptyModuleAccount(types.ModuleName) + distrAcc, _ = authtypes.NewEmptyModuleAccount(codectestutil.CodecOptions{}.GetAddressCodec(), types.ModuleName) ) diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index 7158037befe5..35f6ec2a2601 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -91,15 +91,16 @@ func TestFundsMigration(t *testing.T) { err = distrKeeper.FeePool.Set(ctx, feepool) require.NoError(t, err) - distrAcc := authtypes.NewEmptyModuleAccount(disttypes.ModuleName) - + distrAcc, err := authtypes.NewEmptyModuleAccount(accountKeeper.AddressCodec(), disttypes.ModuleName) + require.NoError(t, err) // mint coins in distribution module account distrModBal := sdk.NewCoins(sdk.NewInt64Coin("test", 10000000)) err = bankKeeper.MintCoins(ctx, distrAcc.GetName(), distrModBal) require.NoError(t, err) // Set pool module account - poolAcc := authtypes.NewEmptyModuleAccount(pooltypes.ModuleName) + poolAcc, err := authtypes.NewEmptyModuleAccount(accountKeeper.AddressCodec(), pooltypes.ModuleName) + require.NoError(t, err) // migrate feepool funds from distribution module account to pool module account _, err = v4.MigrateFunds(ctx, bankKeeper, feepool, distrAcc, poolAcc) diff --git a/x/epochs/go.mod b/x/epochs/go.mod index f712b61afd92..b1d0a5d783f3 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -56,7 +56,7 @@ require ( github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v2 v2.2007.4 // indirect github.com/dgraph-io/ristretto v0.1.1 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index dfef53b3919b..d684704ea3a4 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -162,6 +162,7 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= diff --git a/x/feegrant/keeper/genesis_test.go b/x/feegrant/keeper/genesis_test.go index 9d321fe11518..f180c1ac85fe 100644 --- a/x/feegrant/keeper/genesis_test.go +++ b/x/feegrant/keeper/genesis_test.go @@ -60,7 +60,10 @@ func initFixture(t *testing.T) *genesisFixture { func TestImportExportGenesis(t *testing.T) { f := initFixture(t) - f.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() + granterStrAddr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(granteeAddr) + assert.NilError(t, err) + + f.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAddr).Return(authtypes.NewBaseAccountWithAddress(granterStrAddr)).AnyTimes() coins := sdk.NewCoins(sdk.NewCoin("foo", math.NewInt(1_000))) now := f.ctx.HeaderInfo().Time @@ -68,7 +71,7 @@ func TestImportExportGenesis(t *testing.T) { msgSrvr := keeper.NewMsgServerImpl(f.feegrantKeeper) allowance := &feegrant.BasicAllowance{SpendLimit: coins, Expiration: &oneYear} - err := f.feegrantKeeper.GrantAllowance(f.ctx, granterAddr, granteeAddr, allowance) + err = f.feegrantKeeper.GrantAllowance(f.ctx, granterAddr, granteeAddr, allowance) assert.NilError(t, err) genesis, err := f.feegrantKeeper.ExportGenesis(f.ctx) diff --git a/x/feegrant/keeper/keeper_test.go b/x/feegrant/keeper/keeper_test.go index 64e3dd711a54..ba4437f5a965 100644 --- a/x/feegrant/keeper/keeper_test.go +++ b/x/feegrant/keeper/keeper_test.go @@ -50,11 +50,13 @@ func (suite *KeeperTestSuite) SetupTest() { // setup gomock and initialize some globally expected executions ctrl := gomock.NewController(suite.T()) suite.accountKeeper = feegranttestutil.NewMockAccountKeeper(ctrl) + ac := codecaddress.NewBech32Codec("cosmos") for i := 0; i < len(suite.addrs); i++ { - suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[i])).AnyTimes() + addr, err := ac.BytesToString(suite.addrs[i]) + suite.Require().NoError(err) + suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(addr)).AnyTimes() } - ac := codecaddress.NewBech32Codec("cosmos") suite.accountKeeper.EXPECT().AddressCodec().Return(ac).AnyTimes() for _, addr := range suite.addrs { str, err := ac.BytesToString(addr) @@ -182,7 +184,7 @@ func (suite *KeeperTestSuite) TestKeeperCrud() { address := "cosmos1rxr4mq58w3gtnx5tsc438mwjjafv3mja7k5pnu" accAddr, err := codecaddress.NewBech32Codec("cosmos").StringToBytes(address) suite.Require().NoError(err) - suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() + suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(address)).AnyTimes() // let's grant and revoke authorization to non existing account err = suite.feegrantKeeper.GrantAllowance(suite.ctx, suite.addrs[3], accAddr, basic2) diff --git a/x/feegrant/keeper/msg_server_test.go b/x/feegrant/keeper/msg_server_test.go index 46bde3e93e2f..f6d61575748f 100644 --- a/x/feegrant/keeper/msg_server_test.go +++ b/x/feegrant/keeper/msg_server_test.go @@ -72,7 +72,7 @@ func (suite *KeeperTestSuite) TestGrantAllowance() { suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), granteeAccAddr).Return(nil).AnyTimes() - acc := authtypes.NewBaseAccountWithAddress(granteeAccAddr) + acc := authtypes.NewBaseAccountWithAddress(grantee) add, err := addressCodec.StringToBytes(grantee) suite.Require().NoError(err) diff --git a/x/feegrant/module/abci_test.go b/x/feegrant/module/abci_test.go index 9676ae4ffd83..38c341dcf3f2 100644 --- a/x/feegrant/module/abci_test.go +++ b/x/feegrant/module/abci_test.go @@ -30,30 +30,38 @@ func TestFeegrantPruning(t *testing.T) { key := storetypes.NewKVStoreKey(feegrant.StoreKey) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) + ac := address.NewBech32Codec("cosmos") addrs := simtestutil.CreateIncrementalAccounts(4) granter1 := addrs[0] + granter1Addr, err := ac.BytesToString(granter1) + require.NoError(t, err) granter2 := addrs[1] + granter2Addr, err := ac.BytesToString(granter2) + require.NoError(t, err) granter3 := addrs[2] + granter3Addr, err := ac.BytesToString(granter3) + require.NoError(t, err) grantee := addrs[3] + granteeAddr, err := ac.BytesToString(grantee) + require.NoError(t, err) spendLimit := sdk.NewCoins(sdk.NewCoin("stake", sdkmath.NewInt(1000))) now := testCtx.Ctx.HeaderInfo().Time oneDay := now.AddDate(0, 0, 1) ctrl := gomock.NewController(t) accountKeeper := feegranttestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee).Return(authtypes.NewBaseAccountWithAddress(grantee)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), granter1).Return(authtypes.NewBaseAccountWithAddress(granter1)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3)).AnyTimes() - ac := address.NewBech32Codec("cosmos") + accountKeeper.EXPECT().GetAccount(gomock.Any(), grantee).Return(authtypes.NewBaseAccountWithAddress(granteeAddr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), granter1).Return(authtypes.NewBaseAccountWithAddress(granter1Addr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), granter2).Return(authtypes.NewBaseAccountWithAddress(granter2Addr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), granter3).Return(authtypes.NewBaseAccountWithAddress(granter3Addr)).AnyTimes() accountKeeper.EXPECT().AddressCodec().Return(ac).AnyTimes() env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()) feegrantKeeper := keeper.NewKeeper(env, encCfg.Codec, accountKeeper) - err := feegrantKeeper.GrantAllowance( + err = feegrantKeeper.GrantAllowance( testCtx.Ctx, granter1, grantee, diff --git a/x/genutil/genaccounts.go b/x/genutil/genaccounts.go index 4c09ac71b1c5..d93a22d13948 100644 --- a/x/genutil/genaccounts.go +++ b/x/genutil/genaccounts.go @@ -50,10 +50,10 @@ func AddGenesisAccount( var genAccount authtypes.GenesisAccount balances := banktypes.Balance{Address: addr, Coins: coins.Sort()} - baseAccount := authtypes.NewBaseAccount(accAddr, nil, 0, 0) + baseAccount := authtypes.NewBaseAccount(addr, nil, 0, 0) if !vestingAmt.IsZero() { - baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd) + baseVestingAccount, err := authvesting.NewBaseVestingAccount(baseAccount, vestingAmt.Sort(), vestingEnd, addressCodec) if err != nil { return fmt.Errorf("failed to create base vesting account: %w", err) } @@ -74,12 +74,15 @@ func AddGenesisAccount( return errors.New("invalid vesting parameters; must supply start and end time or end time") } } else if moduleName != "" { - genAccount = authtypes.NewEmptyModuleAccount(moduleName, authtypes.Burner, authtypes.Minter) + genAccount, err = authtypes.NewEmptyModuleAccount(addressCodec, moduleName, authtypes.Burner, authtypes.Minter) + if err != nil { + return err + } } else { genAccount = baseAccount } - if err := genAccount.Validate(); err != nil { + if err := genAccount.Validate(addressCodec); err != nil { return fmt.Errorf("failed to validate new genesis account: %w", err) } @@ -98,7 +101,7 @@ func AddGenesisAccount( bankGenState := banktypes.GetGenesisStateFromAppState(cdc, appState) if accs.Contains(accAddr) { if !appendAcct { - return fmt.Errorf(" Account %s already exists\nUse `append` flag to append account at existing address", accAddr) + return fmt.Errorf(" Account %s already exists\nUse `append` flag to append account at existing address", addr) } genesisB := banktypes.GetGenesisStateFromAppState(cdc, appState) diff --git a/x/gov/depinject.go b/x/gov/depinject.go index 72f9b4767169..c5185519049e 100644 --- a/x/gov/depinject.go +++ b/x/gov/depinject.go @@ -74,7 +74,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(govtypes.ModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } authorityAddr, err := in.AccountKeeper.AddressCodec().BytesToString(authority) if err != nil { diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index 3e1be306d15f..8d0972b51244 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -77,10 +77,15 @@ type mocks struct { } func mockAccountKeeperExpectations(ctx sdk.Context, m mocks) { + ac := address.NewBech32Codec("cosmos") + emptyModuleAcc, err := authtypes.NewEmptyModuleAccount(ac, types.ModuleName) + if err != nil { + panic(err) + } m.acctKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(govAcct).AnyTimes() m.acctKeeper.EXPECT().GetModuleAddress(protocolModuleName).Return(poolAcct).AnyTimes() - m.acctKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.ModuleName).Return(authtypes.NewEmptyModuleAccount(types.ModuleName)).AnyTimes() - m.acctKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() + m.acctKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.ModuleName).Return(emptyModuleAcc).AnyTimes() + m.acctKeeper.EXPECT().AddressCodec().Return(ac).AnyTimes() } func mockDefaultExpectations(ctx sdk.Context, m mocks) error { @@ -177,9 +182,14 @@ func trackMockBalances(bankKeeper *govtestutil.MockBankKeeper) error { balances := make(map[string]sdk.Coins) balances[poolAcctStr] = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(0))) + emptyModuleAcc, err := authtypes.NewEmptyModuleAccount(addressCdc, types.ModuleName) + if err != nil { + return err + } + // We don't track module account balances. bankKeeper.EXPECT().MintCoins(gomock.Any(), mintModuleName, gomock.Any()).AnyTimes() - bankKeeper.EXPECT().BurnCoins(gomock.Any(), authtypes.NewEmptyModuleAccount(types.ModuleName).GetAddress(), gomock.Any()).AnyTimes() + bankKeeper.EXPECT().BurnCoins(gomock.Any(), emptyModuleAcc.GetAddress(), gomock.Any()).AnyTimes() bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), mintModuleName, types.ModuleName, gomock.Any()).AnyTimes() // But we do track normal account balances. diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 9e61244079b3..3c602d276c9e 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -56,11 +56,17 @@ func (s *GenesisTestSuite) SetupTest() { storeService := runtime.NewKVStoreService(key) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, module.AppModule{}) + ac := codectestutil.CodecOptions{}.GetAddressCodec() + + accAddrStr, err := ac.BytesToString(accAddr) + s.Require().NoError(err) + memberAddrStr, err := ac.BytesToString(memberAddr) + s.Require().NoError(err) ctrl := gomock.NewController(s.T()) accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddr)).AnyTimes() - accountKeeper.EXPECT().GetAccount(gomock.Any(), memberAddr).Return(authtypes.NewBaseAccountWithAddress(memberAddr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), accAddr).Return(authtypes.NewBaseAccountWithAddress(accAddrStr)).AnyTimes() + accountKeeper.EXPECT().GetAccount(gomock.Any(), memberAddr).Return(authtypes.NewBaseAccountWithAddress(memberAddrStr)).AnyTimes() accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() bApp := baseapp.NewBaseApp( diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index d8da1ad1fc54..ee052421c0f1 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -64,7 +64,9 @@ func initKeeper(t *testing.T) *fixture { accountKeeper := grouptestutil.NewMockAccountKeeper(ctrl) var err error for i, addr := range accAddrs { - accountKeeper.EXPECT().GetAccount(gomock.Any(), addr).Return(authtypes.NewBaseAccountWithAddress(addr)).AnyTimes() + addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(accAddr) + require.NoError(t, err) + accountKeeper.EXPECT().GetAccount(gomock.Any(), addr).Return(authtypes.NewBaseAccountWithAddress(addrStr)).AnyTimes() addrs[i], err = addressCodec.BytesToString(addr) require.NoError(t, err) } diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index b6a61d186689..69ec5eb32212 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -67,7 +67,9 @@ func (s *TestSuite) SetupTest() { s.accountKeeper = grouptestutil.NewMockAccountKeeper(ctrl) var err error for i := range s.addrs { - s.accountKeeper.EXPECT().GetAccount(gomock.Any(), s.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(s.addrs[i])).AnyTimes() + addrStr, err := codectestutil.CodecOptions{}.GetAddressCodec().BytesToString(s.addrs[i]) + s.Require().NoError(err) + s.accountKeeper.EXPECT().GetAccount(gomock.Any(), s.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(addrStr)).AnyTimes() s.addrsStr[i], err = addressCodec.BytesToString(s.addrs[i]) s.Require().NoError(err) } @@ -147,10 +149,10 @@ func (s *TestSuite) setNextAccount() { ac, err := authtypes.NewModuleCredential(group.ModuleName, []byte{keeper.GroupPolicyTablePrefix}, derivationKey) s.Require().NoError(err) - groupPolicyAcc, err := authtypes.NewBaseAccountWithPubKey(ac) + groupPolicyAcc, err := authtypes.NewBaseAccountWithPubKey(ac, s.accountKeeper.AddressCodec()) s.Require().NoError(err) - groupPolicyAccBumpAccountNumber, err := authtypes.NewBaseAccountWithPubKey(ac) + groupPolicyAccBumpAccountNumber, err := authtypes.NewBaseAccountWithPubKey(ac, s.accountKeeper.AddressCodec()) s.Require().NoError(err) err = groupPolicyAccBumpAccountNumber.SetAccountNumber(nextAccVal) s.Require().NoError(err) diff --git a/x/group/keeper/msg_server.go b/x/group/keeper/msg_server.go index caf0a1a47b3d..87de167af59a 100644 --- a/x/group/keeper/msg_server.go +++ b/x/group/keeper/msg_server.go @@ -390,7 +390,7 @@ func (k Keeper) CreateGroupPolicy(ctx context.Context, msg *group.MsgCreateGroup } // group policy accounts are unclaimable base accounts - account, err := authtypes.NewBaseAccountWithPubKey(ac) + account, err := authtypes.NewBaseAccountWithPubKey(ac, k.accKeeper.AddressCodec()) if err != nil { return nil, errorsmod.Wrap(err, "could not create group policy account") } diff --git a/x/group/migrations/v2/gen_state.go b/x/group/migrations/v2/gen_state.go index 10918441a475..e9da21e118c5 100644 --- a/x/group/migrations/v2/gen_state.go +++ b/x/group/migrations/v2/gen_state.go @@ -45,7 +45,7 @@ func MigrateGenState(oldState *authtypes.GenesisState, addressCodec address.Code if err != nil { panic(err) } - baseAccount, err := authtypes.NewBaseAccountWithPubKey(cred) + baseAccount, err := authtypes.NewBaseAccountWithPubKey(cred, addressCodec) if err != nil { panic(err) } diff --git a/x/group/migrations/v2/gen_state_test.go b/x/group/migrations/v2/gen_state_test.go index 05b4d2393539..b7f3d752b43d 100644 --- a/x/group/migrations/v2/gen_state_test.go +++ b/x/group/migrations/v2/gen_state_test.go @@ -14,6 +14,7 @@ import ( ) func TestMigrateGenState(t *testing.T) { + ac := codectestutil.CodecOptions{}.GetAddressCodec() tests := []struct { name string oldState *authtypes.GenesisState @@ -74,10 +75,10 @@ func TestMigrateGenState(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - require.Error(t, authtypes.ValidateGenesis(*tc.oldState)) - actualState := v2.MigrateGenState(tc.oldState, codectestutil.CodecOptions{}.GetAddressCodec()) + require.Error(t, authtypes.ValidateGenesis(*tc.oldState, ac)) + actualState := v2.MigrateGenState(tc.oldState, ac) require.Equal(t, tc.newState, actualState) - require.NoError(t, authtypes.ValidateGenesis(*actualState)) + require.NoError(t, authtypes.ValidateGenesis(*actualState, ac)) }) } } diff --git a/x/group/migrations/v2/migrate.go b/x/group/migrations/v2/migrate.go index c2db30443269..83d444531670 100644 --- a/x/group/migrations/v2/migrate.go +++ b/x/group/migrations/v2/migrate.go @@ -74,7 +74,7 @@ func Migrate( if err != nil { return err } - baseAccount, err := authtypes.NewBaseAccountWithPubKey(ac) + baseAccount, err := authtypes.NewBaseAccountWithPubKey(ac, accountKeeper.AddressCodec()) if err != nil { return fmt.Errorf("failed to create new group policy account: %w", err) } diff --git a/x/mint/depinject.go b/x/mint/depinject.go index 556a7c4b7a81..b78dcd767fc6 100644 --- a/x/mint/depinject.go +++ b/x/mint/depinject.go @@ -53,7 +53,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } as, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/mint/keeper/genesis_test.go b/x/mint/keeper/genesis_test.go index 4dce9bf881da..12894498d67f 100644 --- a/x/mint/keeper/genesis_test.go +++ b/x/mint/keeper/genesis_test.go @@ -24,7 +24,7 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) -var minterAcc = authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter) +var minterAcc, _ = authtypes.NewEmptyModuleAccount(codectestutil.CodecOptions{}.GetAddressCodec(), types.ModuleName, authtypes.Minter) type GenesisTestSuite struct { suite.Suite diff --git a/x/protocolpool/depinject.go b/x/protocolpool/depinject.go index bf141436b5bb..fe2f9ec7bd6a 100644 --- a/x/protocolpool/depinject.go +++ b/x/protocolpool/depinject.go @@ -50,7 +50,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress("gov") if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } authorityAddr, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/protocolpool/keeper/keeper_test.go b/x/protocolpool/keeper/keeper_test.go index 6df649c7b782..2cb75148ab23 100644 --- a/x/protocolpool/keeper/keeper_test.go +++ b/x/protocolpool/keeper/keeper_test.go @@ -27,8 +27,9 @@ import ( ) var ( - poolAcc = authtypes.NewEmptyModuleAccount(types.ModuleName) - streamAcc = authtypes.NewEmptyModuleAccount(types.StreamAccount) + ac = codectestutil.CodecOptions{}.GetAddressCodec() + poolAcc, _ = authtypes.NewEmptyModuleAccount(ac, types.ModuleName) + streamAcc, _ = authtypes.NewEmptyModuleAccount(ac, types.StreamAccount) ) type KeeperTestSuite struct { diff --git a/x/slashing/depinject.go b/x/slashing/depinject.go index 60f865aff140..e99faf1f3d23 100644 --- a/x/slashing/depinject.go +++ b/x/slashing/depinject.go @@ -54,7 +54,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } authStr, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/staking/depinject.go b/x/staking/depinject.go index 1eaf44baa87e..8d83277abc38 100644 --- a/x/staking/depinject.go +++ b/x/staking/depinject.go @@ -58,7 +58,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AccountKeeper.AddressCodec()) } as, err := in.AccountKeeper.AddressCodec().BytesToString(authority) diff --git a/x/staking/keeper/cons_pubkey_test.go b/x/staking/keeper/cons_pubkey_test.go index 6404f3edccae..7e6e90b50de3 100644 --- a/x/staking/keeper/cons_pubkey_test.go +++ b/x/staking/keeper/cons_pubkey_test.go @@ -110,7 +110,8 @@ func (s *KeeperTestSuite) TestValidatorIdentifier() { s.Require().NoError(err) s.Require().Nil(oldPk) - bondedPool := authtypes.NewEmptyModuleAccount(types.BondedPoolName) + bondedPool, err := authtypes.NewEmptyModuleAccount(s.accountKeeper.AddressCodec(), types.BondedPoolName) + s.Require().NoError(err) accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.BondedPoolName).Return(bondedPool).AnyTimes() bankKeeper.EXPECT().GetBalance(gomock.Any(), bondedPool.GetAddress(), sdk.DefaultBondDenom).Return(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000)).AnyTimes() diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 4039aa0c3aba..1e07fbac207a 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -32,9 +32,10 @@ import ( ) var ( - bondedAcc = authtypes.NewEmptyModuleAccount(stakingtypes.BondedPoolName) - notBondedAcc = authtypes.NewEmptyModuleAccount(stakingtypes.NotBondedPoolName) - PKs = simtestutil.CreateTestPubKeys(500) + ac = codectestutil.CodecOptions{}.GetAddressCodec() + bondedAcc, _ = authtypes.NewEmptyModuleAccount(ac, stakingtypes.BondedPoolName) + notBondedAcc, _ = authtypes.NewEmptyModuleAccount(ac, stakingtypes.NotBondedPoolName) + PKs = simtestutil.CreateTestPubKeys(500) ) type KeeperTestSuite struct { diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go index f4719364f619..370d2f598b2c 100644 --- a/x/staking/keeper/msg_server_test.go +++ b/x/staking/keeper/msg_server_test.go @@ -1205,7 +1205,8 @@ func (s *KeeperTestSuite) TestConsKeyRotn() { existingPubkey, ok := validators[1].ConsensusPubkey.GetCachedValue().(cryptotypes.PubKey) s.Require().True(ok) - bondedPool := authtypes.NewEmptyModuleAccount(types.BondedPoolName) + bondedPool, err := authtypes.NewEmptyModuleAccount(s.accountKeeper.AddressCodec(), types.BondedPoolName) + s.Require().NoError(err) accountKeeper.EXPECT().GetModuleAccount(gomock.Any(), types.BondedPoolName).Return(bondedPool).AnyTimes() bankKeeper.EXPECT().GetBalance(gomock.Any(), bondedPool.GetAddress(), sdk.DefaultBondDenom).Return(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000)).AnyTimes() diff --git a/x/staking/keeper/validator_test.go b/x/staking/keeper/validator_test.go index d6f0655e981b..aa3fdf4be253 100644 --- a/x/staking/keeper/validator_test.go +++ b/x/staking/keeper/validator_test.go @@ -496,7 +496,8 @@ func (s *KeeperTestSuite) TestValidatorConsPubKeyUpdate() { powers := []int64{10, 20} var validators [2]stakingtypes.Validator - bonedPool := authtypes.NewEmptyModuleAccount(stakingtypes.BondedPoolName) + bonedPool, err := authtypes.NewEmptyModuleAccount(s.accountKeeper.AddressCodec(), stakingtypes.BondedPoolName) + s.Require().NoError(err) ak.EXPECT().GetModuleAccount(gomock.Any(), stakingtypes.BondedPoolName).Return(bonedPool).AnyTimes() bk.EXPECT().GetBalance(gomock.Any(), bonedPool.GetAddress(), sdk.DefaultBondDenom).Return(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000000)).AnyTimes() diff --git a/x/upgrade/depinject.go b/x/upgrade/depinject.go index 29fbce81ad16..6569b60dcad3 100644 --- a/x/upgrade/depinject.go +++ b/x/upgrade/depinject.go @@ -68,7 +68,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { // default to governance authority if not provided authority := authtypes.NewModuleAddress(types.GovModuleName) if in.Config.Authority != "" { - authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority) + authority = authtypes.NewModuleAddressOrBech32Address(in.Config.Authority, in.AddressCodec) } authorityStr, err := in.AddressCodec.BytesToString(authority)