refactor(bank, feegrant, authz): avoid creating baseaccount (#19188)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
26d30f2111
commit
869c96c403
@ -48,7 +48,7 @@ type TestAccountRetriever struct {
|
||||
func (t TestAccountRetriever) GetAccount(_ Context, addr sdk.AccAddress) (Account, error) {
|
||||
acc, ok := t.Accounts[addr.String()]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("account %s not found", addr)
|
||||
return nil, fmt.Errorf("account: account %s not found", addr)
|
||||
}
|
||||
|
||||
return acc, nil
|
||||
@ -68,7 +68,7 @@ func (t TestAccountRetriever) GetAccountWithHeight(clientCtx Context, addr sdk.A
|
||||
func (t TestAccountRetriever) EnsureExists(_ Context, addr sdk.AccAddress) error {
|
||||
_, ok := t.Accounts[addr.String()]
|
||||
if !ok {
|
||||
return fmt.Errorf("account %s not found", addr)
|
||||
return fmt.Errorf("ensureExists: account %s not found", addr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -77,7 +77,7 @@ func (t TestAccountRetriever) EnsureExists(_ Context, addr sdk.AccAddress) error
|
||||
func (t TestAccountRetriever) GetAccountNumberSequence(_ Context, addr sdk.AccAddress) (accNum, accSeq uint64, err error) {
|
||||
acc, ok := t.Accounts[addr.String()]
|
||||
if !ok {
|
||||
return 0, 0, fmt.Errorf("account %s not found", addr)
|
||||
return 0, 0, fmt.Errorf("accountNumberSequence: account %s not found", addr)
|
||||
}
|
||||
return acc.Num, acc.Seq, nil
|
||||
}
|
||||
|
||||
@ -505,10 +505,6 @@ func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
|
||||
fc := f
|
||||
from := clientCtx.FromAddress
|
||||
|
||||
if err := fc.accountRetriever.EnsureExists(clientCtx, from); err != nil {
|
||||
return fc, err
|
||||
}
|
||||
|
||||
initNum, initSeq := fc.accountNumber, fc.sequence
|
||||
if initNum == 0 || initSeq == 0 {
|
||||
num, seq, err := fc.accountRetriever.GetAccountNumberSequence(clientCtx, from)
|
||||
|
||||
@ -29,7 +29,6 @@ func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
* 2021 Feb 24: The Cosmos SDK does not use Tendermint's `PubKey` interface anymore, but its own `cryptotypes.PubKey`. Updates to reflect this.
|
||||
* 2021 May 3: Rename `clientCtx.JSONMarshaler` to `clientCtx.JSONCodec`.
|
||||
* 2021 June 10: Add `clientCtx.Codec: codec.Codec`.
|
||||
* 2024 February 5: Account creation step
|
||||
|
||||
## Status
|
||||
|
||||
@ -317,6 +318,8 @@ the client logic will now need to take a codec interface that knows not only how
|
||||
to handle all the types, but also knows how to generate transactions, signatures,
|
||||
and messages.
|
||||
|
||||
If the account is sending its first transaction, the account number must be set to 0. This is due to the account not being created yet.
|
||||
|
||||
```go
|
||||
type AccountRetriever interface {
|
||||
GetAccount(clientCtx Context, addr sdk.AccAddress) (client.Account, error)
|
||||
|
||||
@ -136,8 +136,6 @@ func TestBaseApp_BlockGas(t *testing.T) {
|
||||
err = bankKeeper.SendCoinsFromModuleToAccount(ctx, testutil.MintModuleName, addr1, feeAmount)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, feeCoin.Amount, bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount)
|
||||
seq := accountKeeper.GetAccount(ctx, addr1).GetSequence()
|
||||
require.Equal(t, uint64(0), seq)
|
||||
|
||||
// msg and signatures
|
||||
msg := &baseapptestutil.MsgKeyValue{
|
||||
@ -152,8 +150,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
|
||||
txBuilder.SetFeeAmount(feeAmount)
|
||||
txBuilder.SetGasLimit(uint64(simtestutil.DefaultConsensusParams.Block.MaxGas))
|
||||
|
||||
senderAccountNumber := accountKeeper.GetAccount(ctx, addr1).GetAccountNumber()
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{senderAccountNumber}, []uint64{0}
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
|
||||
_, txBytes, err := createTestTx(txConfig, txBuilder, privs, accNums, accSeqs, ctx.ChainID())
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -176,7 +173,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
|
||||
require.Equal(t, []byte("ok"), okValue)
|
||||
}
|
||||
// check block gas is always consumed
|
||||
baseGas := uint64(38798) // baseGas is the gas consumed before tx msg
|
||||
baseGas := uint64(38012) // baseGas is the gas consumed before tx msg
|
||||
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
|
||||
if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) {
|
||||
// capped by gasLimit
|
||||
@ -186,7 +183,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
|
||||
// tx fee is always deducted
|
||||
require.Equal(t, int64(0), bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount.Int64())
|
||||
// sender's sequence is always increased
|
||||
seq = accountKeeper.GetAccount(ctx, addr1).GetSequence()
|
||||
seq := accountKeeper.GetAccount(ctx, addr1).GetSequence()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(1), seq)
|
||||
})
|
||||
|
||||
@ -224,7 +224,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
|
||||
req := banktypes.NewQuerySpendableBalancesRequest(addr1, nil)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 2032, false)
|
||||
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 1777, false)
|
||||
}
|
||||
|
||||
func TestGRPCQueryTotalSupply(t *testing.T) {
|
||||
|
||||
@ -95,7 +95,7 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {
|
||||
// send funds to val addr
|
||||
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
|
||||
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
|
||||
initialStake := int64(10)
|
||||
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
|
||||
@ -167,7 +167,7 @@ func TestGRPCValidatorCommission(t *testing.T) {
|
||||
// send funds to val addr
|
||||
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
|
||||
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
|
||||
initialStake := int64(10)
|
||||
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
|
||||
@ -498,7 +498,7 @@ func TestGRPCDelegationRewards(t *testing.T) {
|
||||
// send funds to val addr
|
||||
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
|
||||
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
|
||||
initialStake := int64(10)
|
||||
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
|
||||
|
||||
@ -910,6 +910,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
// send funds from module to addr to perform DepositValidatorRewardsPool
|
||||
err = f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, distrtypes.ModuleName, addr, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, tokens)))
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(valAddr1)))
|
||||
require.NoError(t, err)
|
||||
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
|
||||
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
|
||||
|
||||
@ -75,6 +75,7 @@ type fixture struct {
|
||||
sdkCtx sdk.Context
|
||||
cdc codec.Codec
|
||||
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
evidenceKeeper *keeper.Keeper
|
||||
slashingKeeper slashingkeeper.Keeper
|
||||
@ -164,6 +165,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
app: integrationApp,
|
||||
sdkCtx: sdkCtx,
|
||||
cdc: cdc,
|
||||
accountKeeper: accountKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
evidenceKeeper: evidenceKeeper,
|
||||
slashingKeeper: slashingKeeper,
|
||||
@ -183,7 +185,7 @@ func TestHandleDoubleSign(t *testing.T) {
|
||||
assert.NilError(t, err)
|
||||
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
|
||||
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
|
||||
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
@ -278,7 +280,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
|
||||
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
|
||||
|
||||
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
|
||||
amt := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
@ -328,7 +330,7 @@ func TestHandleDoubleSignAfterRotation(t *testing.T) {
|
||||
|
||||
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
|
||||
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)
|
||||
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
|
||||
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)
|
||||
|
||||
// execute end-blocker and verify validator attributes
|
||||
|
||||
@ -360,6 +360,8 @@ func TestProposalPassedEndblocker(t *testing.T) {
|
||||
stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper)
|
||||
valAddr := sdk.ValAddress(addrs[0])
|
||||
proposer := addrs[0]
|
||||
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
|
||||
suite.AccountKeeper.SetAccount(ctx, acc)
|
||||
|
||||
createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
|
||||
_, err := suite.StakingKeeper.EndBlocker(ctx)
|
||||
@ -421,6 +423,9 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
|
||||
toAddrStr, err := ac.BytesToString(addrs[0])
|
||||
require.NoError(t, err)
|
||||
|
||||
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
|
||||
suite.AccountKeeper.SetAccount(ctx, acc)
|
||||
|
||||
createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
|
||||
_, err = suite.StakingKeeper.EndBlocker(ctx)
|
||||
require.NoError(t, err)
|
||||
@ -499,6 +504,8 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) {
|
||||
valAddr := sdk.ValAddress(addrs[0])
|
||||
proposer := addrs[0]
|
||||
|
||||
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
|
||||
suite.AccountKeeper.SetAccount(ctx, acc)
|
||||
// Create a validator so that able to vote on proposal.
|
||||
createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
|
||||
_, err = suite.StakingKeeper.EndBlocker(ctx)
|
||||
|
||||
@ -58,6 +58,10 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val2))
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val3))
|
||||
|
||||
for _, addr := range addrs {
|
||||
f.accountKeeper.SetAccount(f.ctx, f.accountKeeper.NewAccountWithAddress(f.ctx, addr))
|
||||
}
|
||||
|
||||
_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[0]), stakingtypes.Unbonded, val1, true)
|
||||
_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[1]), stakingtypes.Unbonded, val2, true)
|
||||
_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[2], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[2]), stakingtypes.Unbonded, val3, true)
|
||||
|
||||
@ -41,6 +41,7 @@ type fixture struct {
|
||||
queryClient v1.QueryClient
|
||||
legacyQueryClient v1beta1.QueryClient
|
||||
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
stakingKeeper *stakingkeeper.Keeper
|
||||
govKeeper *keeper.Keeper
|
||||
@ -153,6 +154,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
ctx: sdkCtx,
|
||||
queryClient: queryClient,
|
||||
legacyQueryClient: legacyQueryClient,
|
||||
accountKeeper: accountKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
stakingKeeper: stakingKeeper,
|
||||
govKeeper: govKeeper,
|
||||
|
||||
@ -356,7 +356,6 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
|
||||
assert.Assert(t, found)
|
||||
val2, found := f.stakingKeeper.GetValidator(ctx, vals[1])
|
||||
assert.Assert(t, found)
|
||||
|
||||
_, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true)
|
||||
assert.NilError(t, err)
|
||||
_, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"cosmossdk.io/core/comet"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
authkeeper "cosmossdk.io/x/auth/keeper"
|
||||
bankkeeper "cosmossdk.io/x/bank/keeper"
|
||||
"cosmossdk.io/x/slashing"
|
||||
slashingkeeper "cosmossdk.io/x/slashing/keeper"
|
||||
@ -24,6 +25,7 @@ import (
|
||||
func TestBeginBlocker(t *testing.T) {
|
||||
var (
|
||||
interfaceRegistry codectypes.InterfaceRegistry
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
stakingKeeper *stakingkeeper.Keeper
|
||||
slashingKeeper slashingkeeper.Keeper
|
||||
@ -35,6 +37,7 @@ func TestBeginBlocker(t *testing.T) {
|
||||
depinject.Supply(log.NewNopLogger()),
|
||||
),
|
||||
&interfaceRegistry,
|
||||
&accountKeeper,
|
||||
&bankKeeper,
|
||||
&stakingKeeper,
|
||||
&slashingKeeper,
|
||||
@ -50,6 +53,8 @@ func TestBeginBlocker(t *testing.T) {
|
||||
|
||||
// bond the validator
|
||||
power := int64(100)
|
||||
acc := accountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(addr))
|
||||
accountKeeper.SetAccount(ctx, acc)
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
|
||||
_, err = stakingKeeper.EndBlocker(ctx)
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -41,6 +41,7 @@ type fixture struct {
|
||||
|
||||
ctx sdk.Context
|
||||
|
||||
accountKeeper authkeeper.AccountKeeper
|
||||
bankKeeper bankkeeper.Keeper
|
||||
slashingKeeper slashingkeeper.Keeper
|
||||
stakingKeeper *stakingkeeper.Keeper
|
||||
@ -135,6 +136,7 @@ func initFixture(tb testing.TB) *fixture {
|
||||
return &fixture{
|
||||
app: integrationApp,
|
||||
ctx: sdkCtx,
|
||||
accountKeeper: accountKeeper,
|
||||
bankKeeper: bankKeeper,
|
||||
slashingKeeper: slashingKeeper,
|
||||
stakingKeeper: stakingKeeper,
|
||||
@ -157,6 +159,8 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
// create max (5) validators all with the same power
|
||||
for i := uint32(0); i < p.MaxValidators; i++ {
|
||||
addr, val := f.valAddrs[i], pks[i]
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
tstaking.CreateValidatorWithValPower(addr, val, 100, true)
|
||||
}
|
||||
|
||||
@ -166,6 +170,8 @@ func TestUnJailNotBonded(t *testing.T) {
|
||||
|
||||
// create a 6th validator with less power than the cliff validator (won't be bonded)
|
||||
addr, val := f.valAddrs[5], pks[5]
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 50)
|
||||
msg := tstaking.CreateValidatorMsg(addr, val, amt)
|
||||
msg.MinSelfDelegation = amt
|
||||
@ -246,6 +252,8 @@ func TestHandleNewValidator(t *testing.T) {
|
||||
assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, sdk.ConsAddress(valpubkey.Address()), info))
|
||||
|
||||
// Validator created
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, valpubkey, 100, true)
|
||||
|
||||
_, err = f.stakingKeeper.EndBlocker(f.ctx)
|
||||
@ -303,6 +311,9 @@ func TestHandleAlreadyJailed(t *testing.T) {
|
||||
info := slashingtypes.NewValidatorSigningInfo(consaddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
|
||||
assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, sdk.ConsAddress(val.Address()), info))
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
|
||||
amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
|
||||
|
||||
_, err = f.stakingKeeper.EndBlocker(f.ctx)
|
||||
@ -366,6 +377,10 @@ func TestValidatorDippingInAndOut(t *testing.T) {
|
||||
|
||||
pks := simtestutil.CreateTestPubKeys(3)
|
||||
simtestutil.AddTestAddrsFromPubKeys(f.bankKeeper, f.stakingKeeper, f.ctx, pks, f.stakingKeeper.TokensFromConsensusPower(f.ctx, 200))
|
||||
for _, pk := range pks {
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(pk.Address()))
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
}
|
||||
|
||||
addr, val := pks[0].Address(), pks[0]
|
||||
consAddr := sdk.ConsAddress(addr)
|
||||
|
||||
@ -82,6 +82,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val1))
|
||||
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val2))
|
||||
|
||||
for _, addr := range addrs {
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, acc)
|
||||
}
|
||||
|
||||
_, err := f.stakingKeeper.Delegate(f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[0]), types.Unbonded, val1, true)
|
||||
assert.NilError(t, err)
|
||||
_, err = f.stakingKeeper.Delegate(f.sdkCtx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[1]), types.Unbonded, val2, true)
|
||||
|
||||
@ -95,6 +95,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||
|
||||
// mature unbonding delegations
|
||||
ctx = ctx.WithHeaderInfo(header.Info{Time: completionTime})
|
||||
acc := f.accountKeeper.NewAccountWithAddress(ctx, addrDel)
|
||||
f.accountKeeper.SetAccount(ctx, acc)
|
||||
_, err = f.stakingKeeper.CompleteUnbonding(ctx, addrDel, addrVal)
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@ -245,6 +245,9 @@ func setValidator(t *testing.T, f *deterministicFixture, validator stakingtypes.
|
||||
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, validator.BondedTokens()))
|
||||
assert.NilError(t, banktestutil.FundAccount(f.ctx, f.bankKeeper, delegatorAddress, coins))
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddress)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
|
||||
_, err = f.stakingKeeper.Delegate(f.ctx, delegatorAddress, validator.BondedTokens(), stakingtypes.Unbonded, validator, true)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
@ -396,6 +399,8 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
|
||||
for i := 0; i < numDels; i++ {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
@ -412,9 +417,13 @@ func TestGRPCValidatorDelegations(t *testing.T) {
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
acc = f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr2)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err = fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -435,6 +444,8 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
|
||||
for i := 0; i < numDels; i++ {
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
valbz, err := f.stakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
|
||||
@ -454,12 +465,16 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
acc = f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr2)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares2, err := fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -480,6 +495,8 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -494,6 +511,8 @@ func TestGRPCDelegation(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -512,6 +531,8 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
rapid.Check(t, func(rt *rapid.T) {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -531,6 +552,8 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -555,6 +578,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
@ -570,6 +595,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -588,6 +615,8 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -602,6 +631,8 @@ func TestGRPCDelegatorValidator(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
|
||||
assert.NilError(t, err)
|
||||
@ -624,6 +655,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
valbz, err := f.stakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
|
||||
@ -643,6 +676,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -707,6 +742,8 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
|
||||
for i := 0; i < numVals; i++ {
|
||||
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
@ -722,7 +759,8 @@ func TestGRPCDelegatorValidators(t *testing.T) {
|
||||
f = initDeterministicFixture(t) // reset
|
||||
|
||||
validator := getStaticValidator(t, f)
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -761,6 +799,8 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels")
|
||||
|
||||
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -795,6 +835,8 @@ func TestGRPCRedelegations(t *testing.T) {
|
||||
validator := getStaticValidator(t, f)
|
||||
_ = getStaticValidator2(t, f)
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
|
||||
f.accountKeeper.SetAccount(f.ctx, acc)
|
||||
shares, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
|
||||
assert.NilError(t, err)
|
||||
|
||||
|
||||
@ -205,7 +205,8 @@ func TestRotateConsPubKey(t *testing.T) {
|
||||
// create 5 validators
|
||||
for i := 0; i < 5; i++ {
|
||||
comm := types.NewCommissionRates(math.LegacyNewDec(0), math.LegacyNewDec(0), math.LegacyNewDec(0))
|
||||
|
||||
acc := f.accountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(valAddrs[i]))
|
||||
f.accountKeeper.SetAccount(ctx, acc)
|
||||
msg, err := types.NewMsgCreateValidator(valAddrs[i].String(), PKs[i], sdk.NewCoin(sdk.DefaultBondDenom, stakingKeeper.TokensFromConsensusPower(ctx, 30)),
|
||||
types.Description{Moniker: "NewVal"}, comm, math.OneInt())
|
||||
assert.NilError(t, err)
|
||||
|
||||
@ -384,6 +384,10 @@ func TestUnbondingDelegationOnHold1(t *testing.T) {
|
||||
|
||||
// _, app, ctx := createTestInput(t)
|
||||
bondDenom, addrDels, addrVals := SetupUnbondingTests(t, f, &hookCalled, &ubdeID)
|
||||
for _, addr := range addrDels {
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, acc)
|
||||
}
|
||||
completionTime, bondedAmt1, notBondedAmt1 := doUnbondingDelegation(t, f.stakingKeeper, f.bankKeeper, f.sdkCtx, bondDenom, addrDels, addrVals, &hookCalled)
|
||||
|
||||
// CONSUMER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
@ -423,6 +427,10 @@ func TestUnbondingDelegationOnHold2(t *testing.T) {
|
||||
|
||||
// _, app, ctx := createTestInput(t)
|
||||
bondDenom, addrDels, addrVals := SetupUnbondingTests(t, f, &hookCalled, &ubdeID)
|
||||
for _, addr := range addrDels {
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, acc)
|
||||
}
|
||||
completionTime, bondedAmt1, notBondedAmt1 := doUnbondingDelegation(t, f.stakingKeeper, f.bankKeeper, f.sdkCtx, bondDenom, addrDels, addrVals, &hookCalled)
|
||||
|
||||
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
|
||||
|
||||
@ -40,6 +40,8 @@ func TestValidateVoteExtensions(t *testing.T) {
|
||||
vals := []stakingtypes.Validator{}
|
||||
for _, v := range privKeys {
|
||||
valAddr := sdk.ValAddress(v.PubKey().Address())
|
||||
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(v.PubKey().Address()))
|
||||
f.accountKeeper.SetAccount(f.sdkCtx, acc)
|
||||
simtestutil.AddTestAddrsFromPubKeys(f.bankKeeper, f.stakingKeeper, f.sdkCtx, []cryptotypes.PubKey{v.PubKey()}, math.NewInt(100000000000))
|
||||
vals = append(vals, testutil.NewValidator(t, valAddr, v.PubKey()))
|
||||
}
|
||||
|
||||
@ -153,7 +153,8 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
||||
{
|
||||
"unrecognized account",
|
||||
func(suite *AnteTestSuite) TestCaseArgs {
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0, priv1, priv2}, []uint64{0, 1, 2}, []uint64{0, 0, 0}
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0, priv1, priv2}, []uint64{0, 0, 0}, []uint64{0, 0, 0}
|
||||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
|
||||
|
||||
return TestCaseArgs{
|
||||
accNums: accNums,
|
||||
@ -163,8 +164,26 @@ func TestAnteHandlerSigErrors(t *testing.T) {
|
||||
}
|
||||
},
|
||||
false,
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"unrecognized account2",
|
||||
func(suite *AnteTestSuite) TestCaseArgs {
|
||||
suite.accountKeeper.SetAccount(suite.ctx, suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr1))
|
||||
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv0, priv1, priv2}, []uint64{0, 1, 0}, []uint64{0, 0, 0}
|
||||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
|
||||
|
||||
return TestCaseArgs{
|
||||
accNums: accNums,
|
||||
accSeqs: accSeqs,
|
||||
msgs: msgs,
|
||||
privs: privs,
|
||||
}
|
||||
},
|
||||
false,
|
||||
sdkerrors.ErrUnknownAddress,
|
||||
true,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"save all the accounts, should pass",
|
||||
|
||||
@ -109,12 +109,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
|
||||
}
|
||||
n := len(sigs)
|
||||
|
||||
signers, err := sigTx.GetSigners()
|
||||
if err != nil {
|
||||
return sdk.Context{}, err
|
||||
}
|
||||
|
||||
for i, signer := range signers {
|
||||
for i, signer := range sigs {
|
||||
// if signature is already filled in, no need to simulate gas cost
|
||||
if i < n && !isIncompleteSignature(sigs[i].Data) {
|
||||
continue
|
||||
@ -122,13 +117,11 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
|
||||
|
||||
var pubkey cryptotypes.PubKey
|
||||
|
||||
acc := cgts.ak.GetAccount(ctx, signer)
|
||||
|
||||
// use placeholder simSecp256k1Pubkey if sig is nil
|
||||
if acc == nil || acc.GetPubKey() == nil {
|
||||
if signer.PubKey == nil {
|
||||
pubkey = simSecp256k1Pubkey
|
||||
} else {
|
||||
pubkey = acc.GetPubKey()
|
||||
pubkey = signer.PubKey
|
||||
}
|
||||
|
||||
// use stdsignature to mock the size of a full signature
|
||||
|
||||
@ -112,7 +112,7 @@ func TestConsumeGasForTxSize(t *testing.T) {
|
||||
name string
|
||||
sigV2 signing.SignatureV2
|
||||
}{
|
||||
{"SingleSignatureData", signing.SignatureV2{PubKey: priv1.PubKey()}},
|
||||
{"SingleSignatureData", signing.SignatureV2{PubKey: priv1.PubKey(), Data: &signing.SingleSignatureData{}}}, // single signature
|
||||
{"MultiSignatureData", signing.SignatureV2{PubKey: priv1.PubKey(), Data: multisig.NewMultisig(2)}},
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ type AccountKeeper interface {
|
||||
SetAccount(ctx context.Context, acc sdk.AccountI)
|
||||
GetModuleAddress(moduleName string) sdk.AccAddress
|
||||
AddressCodec() address.Codec
|
||||
NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
|
||||
}
|
||||
|
||||
// FeegrantKeeper defines the expected feegrant keeper.
|
||||
|
||||
@ -101,14 +101,9 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee
|
||||
deductFeesFrom = feeGranterAddr
|
||||
}
|
||||
|
||||
deductFeesFromAcc := dfd.accountKeeper.GetAccount(ctx, deductFeesFrom)
|
||||
if deductFeesFromAcc == nil {
|
||||
return sdkerrors.ErrUnknownAddress.Wrapf("fee payer address: %s does not exist", deductFeesFrom)
|
||||
}
|
||||
|
||||
// deduct the fees
|
||||
if !fee.IsZero() {
|
||||
err := DeductFees(dfd.bankKeeper, ctx, deductFeesFromAcc, fee)
|
||||
err := DeductFees(dfd.bankKeeper, ctx, deductFeesFrom, fee)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -127,12 +122,12 @@ func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee
|
||||
}
|
||||
|
||||
// DeductFees deducts fees from the given account.
|
||||
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc sdk.AccountI, fees sdk.Coins) error {
|
||||
func DeductFees(bankKeeper types.BankKeeper, ctx sdk.Context, acc []byte, fees sdk.Coins) error {
|
||||
if !fees.IsValid() {
|
||||
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
|
||||
}
|
||||
|
||||
err := bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), types.FeeCollectorName, fees)
|
||||
err := bankKeeper.SendCoinsFromAccountToModule(ctx, sdk.AccAddress(acc), types.FeeCollectorName, fees)
|
||||
if err != nil {
|
||||
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
|
||||
}
|
||||
|
||||
@ -56,13 +56,14 @@ func TestDeductFeesNoDelegation(t *testing.T) {
|
||||
},
|
||||
"paying with no account": {
|
||||
fee: 1,
|
||||
valid: false,
|
||||
err: sdkerrors.ErrUnknownAddress,
|
||||
valid: true,
|
||||
malleate: func(suite *AnteTestSuite) (TestAccount, sdk.AccAddress) {
|
||||
// Do not register the account
|
||||
priv, _, addr := testdata.KeyTestPubAddr()
|
||||
acc := authtypes.NewBaseAccountWithAddress(addr)
|
||||
suite.bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), acc.GetAddress(), authtypes.FeeCollectorName, gomock.Any()).Return(nil).Times(2)
|
||||
return TestAccount{
|
||||
acc: authtypes.NewBaseAccountWithAddress(addr),
|
||||
acc: acc,
|
||||
priv: priv,
|
||||
}, nil
|
||||
},
|
||||
@ -77,8 +78,7 @@ func TestDeductFeesNoDelegation(t *testing.T) {
|
||||
},
|
||||
"no fee with no account": {
|
||||
fee: 0,
|
||||
valid: false,
|
||||
err: sdkerrors.ErrUnknownAddress,
|
||||
valid: true,
|
||||
malleate: func(suite *AnteTestSuite) (TestAccount, sdk.AccAddress) {
|
||||
// Do not register the account
|
||||
priv, _, addr := testdata.KeyTestPubAddr()
|
||||
|
||||
@ -210,26 +210,34 @@ func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
|
||||
|
||||
// authenticate the authentication of the TX for a specific tx signer.
|
||||
func (svd SigVerificationDecorator) authenticate(ctx sdk.Context, tx authsigning.Tx, signer []byte, sig signing.SignatureV2, txPubKey cryptotypes.PubKey) error {
|
||||
acc, err := GetSignerAcc(ctx, svd.ak, signer)
|
||||
if err != nil {
|
||||
return err
|
||||
// newlyCreated is a flag that indicates if the account was newly created.
|
||||
// This is only the case when the user is sending their first tx.
|
||||
newlyCreated := false
|
||||
acc := GetSignerAcc(ctx, svd.ak, signer)
|
||||
if acc == nil {
|
||||
// If the account is nil, we assume this is the account's first tx. In this case, the account needs to be
|
||||
// created, but the sign doc should use account number 0. This is because the account number is
|
||||
// not known until the account is created when the tx was signed, the account number was unknown
|
||||
// and 0 was set.
|
||||
acc = svd.ak.NewAccountWithAddress(ctx, txPubKey.Address().Bytes())
|
||||
newlyCreated = true
|
||||
}
|
||||
|
||||
// the account is without a pubkey, let's attempt to check if in the
|
||||
// tx we were correctly provided a valid pubkey.
|
||||
if acc.GetPubKey() == nil {
|
||||
err = svd.setPubKey(ctx.IsSigverifyTx(), ctx.ExecMode() == sdk.ExecModeSimulate, acc, txPubKey)
|
||||
err := svd.setPubKey(ctx, acc, txPubKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = svd.consumeSignatureGas(ctx, acc.GetPubKey(), sig)
|
||||
err := svd.consumeSignatureGas(ctx, acc.GetPubKey(), sig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = svd.verifySig(ctx, tx, acc, sig)
|
||||
err = svd.verifySig(ctx, tx, acc, sig, newlyCreated)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -268,7 +276,7 @@ func (svd SigVerificationDecorator) consumeSignatureGas(
|
||||
}
|
||||
|
||||
// verifySig will verify the signature of the provided signer account.
|
||||
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2) error {
|
||||
func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sdk.AccountI, sig signing.SignatureV2, newlyCreated bool) error {
|
||||
if sig.Sequence != acc.GetSequence() {
|
||||
return errorsmod.Wrapf(
|
||||
sdkerrors.ErrWrongSequence,
|
||||
@ -293,10 +301,19 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sd
|
||||
genesis := ctx.BlockHeight() == 0
|
||||
chainID := ctx.ChainID()
|
||||
var accNum uint64
|
||||
// if we are not in genesis use the account number from the account
|
||||
if !genesis {
|
||||
accNum = acc.GetAccountNumber()
|
||||
}
|
||||
|
||||
// if the account number is 0 and the account is signing, the sign doc will not have an account number
|
||||
if acc.GetSequence() == 0 && newlyCreated {
|
||||
// If the account sequence is 0, and we're in genesis, then we're
|
||||
// dealing with an account that has been generated but never used.
|
||||
// in this case, we should not verify signatures.
|
||||
accNum = 0
|
||||
}
|
||||
|
||||
anyPk, _ := codectypes.NewAnyWithValue(pubKey)
|
||||
|
||||
signerData := txsigning.SignerData{
|
||||
@ -332,18 +349,19 @@ func (svd SigVerificationDecorator) verifySig(ctx sdk.Context, tx sdk.Tx, acc sd
|
||||
|
||||
// setPubKey will attempt to set the pubkey for the account given the list of available public keys.
|
||||
// This must be called only in case the account has not a pubkey set yet.
|
||||
func (svd SigVerificationDecorator) setPubKey(isSigVerifyTx, simulate bool, acc sdk.AccountI, txPubKey cryptotypes.PubKey) error {
|
||||
func (svd SigVerificationDecorator) setPubKey(ctx sdk.Context, acc sdk.AccountI, txPubKey cryptotypes.PubKey) error {
|
||||
// if we're not in sig verify then we can just skip.
|
||||
if !isSigVerifyTx {
|
||||
if !ctx.IsSigverifyTx() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// if the pubkey is nil then we don't have any pubkey to set
|
||||
// for this account, which alwo means we cannot do signature
|
||||
// for this account, which also means we cannot do signature
|
||||
// verification.
|
||||
if txPubKey == nil {
|
||||
// if we're not in simulation mode, and we do not have a valid pubkey
|
||||
// for this signer, then we simply error.
|
||||
if !simulate {
|
||||
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())
|
||||
}
|
||||
// if we're in simulation mode, then we can populate the pubkey with the
|
||||
@ -352,9 +370,9 @@ func (svd SigVerificationDecorator) setPubKey(isSigVerifyTx, simulate bool, acc
|
||||
return acc.SetPubKey(txPubKey)
|
||||
}
|
||||
|
||||
// NOTE(tip): this is a way to claim the account, in a context in which the
|
||||
// account was created in an implicit way.
|
||||
// TODO(tip): considering moving account initialization logic: https://github.com/cosmos/cosmos-sdk/issues/19092
|
||||
// this code path is taken when a user has received tokens but not submitted their first transaction
|
||||
// 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())
|
||||
}
|
||||
@ -515,12 +533,8 @@ func multisignatureSimulationVerificationGas(
|
||||
|
||||
// GetSignerAcc returns an account for a given address that is expected to sign
|
||||
// a transaction.
|
||||
func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) (sdk.AccountI, error) {
|
||||
if acc := ak.GetAccount(ctx, addr); acc != nil {
|
||||
return acc, nil
|
||||
}
|
||||
|
||||
return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
|
||||
func GetSignerAcc(ctx sdk.Context, ak AccountKeeper, addr sdk.AccAddress) sdk.AccountI {
|
||||
return ak.GetAccount(ctx, addr)
|
||||
}
|
||||
|
||||
// CountSubKeys counts the total number of keys for a multi-sig public key.
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
authtypes "cosmossdk.io/x/auth/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func TestSigVerify_setPubKey(t *testing.T) {
|
||||
@ -22,36 +23,43 @@ func TestSigVerify_setPubKey(t *testing.T) {
|
||||
aliceAddr, err := cdc.BytesToString(alicePk.Address())
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := sdk.NewContext(nil, false, nil)
|
||||
|
||||
t.Run("on not sig verify tx - skip", func(t *testing.T) {
|
||||
acc := &authtypes.BaseAccount{}
|
||||
err := svd.setPubKey(false, false, acc, nil)
|
||||
ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(false)
|
||||
err := svd.setPubKey(ctx, acc, nil)
|
||||
require.NoError(t, err)
|
||||
})
|
||||
|
||||
t.Run("on sim, populate with sim key, if pubkey is nil", func(t *testing.T) {
|
||||
acc := &authtypes.BaseAccount{Address: aliceAddr}
|
||||
err := svd.setPubKey(true, true, acc, nil)
|
||||
ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(true)
|
||||
err := svd.setPubKey(ctx, acc, nil)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, acc.PubKey.GetCachedValue(), simSecp256k1Pubkey)
|
||||
})
|
||||
|
||||
t.Run("on sim, populate with real pub key, if pubkey is not nil", func(t *testing.T) {
|
||||
acc := &authtypes.BaseAccount{Address: aliceAddr}
|
||||
err := svd.setPubKey(true, true, acc, alicePk)
|
||||
ctx = ctx.WithExecMode(sdk.ExecModeSimulate).WithIsSigverifyTx(true)
|
||||
err := svd.setPubKey(ctx, acc, alicePk)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, acc.PubKey.GetCachedValue(), alicePk)
|
||||
})
|
||||
|
||||
t.Run("not on sim, populate the address", func(t *testing.T) {
|
||||
acc := &authtypes.BaseAccount{Address: aliceAddr}
|
||||
err := svd.setPubKey(true, false, acc, alicePk)
|
||||
ctx = ctx.WithExecMode(sdk.ExecModeFinalize).WithIsSigverifyTx(true)
|
||||
err := svd.setPubKey(ctx, acc, alicePk)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, acc.PubKey.GetCachedValue(), alicePk)
|
||||
})
|
||||
|
||||
t.Run("not on sim, fail on invalid pubkey.address", func(t *testing.T) {
|
||||
acc := &authtypes.BaseAccount{Address: aliceAddr}
|
||||
err := svd.setPubKey(true, false, acc, bobPk)
|
||||
ctx = ctx.WithExecMode(sdk.ExecModeFinalize).WithIsSigverifyTx(true)
|
||||
err := svd.setPubKey(ctx, acc, bobPk)
|
||||
require.ErrorContains(t, err, "cannot be claimed")
|
||||
})
|
||||
}
|
||||
|
||||
@ -93,6 +93,20 @@ func (mr *MockAccountKeeperMockRecorder) GetParams(ctx interface{}) *gomock.Call
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetParams", reflect.TypeOf((*MockAccountKeeper)(nil).GetParams), ctx)
|
||||
}
|
||||
|
||||
// NewAccountWithAddress mocks base method.
|
||||
func (m *MockAccountKeeper) NewAccountWithAddress(ctx context.Context, addr types0.AccAddress) types0.AccountI {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "NewAccountWithAddress", ctx, addr)
|
||||
ret0, _ := ret[0].(types0.AccountI)
|
||||
return ret0
|
||||
}
|
||||
|
||||
// NewAccountWithAddress indicates an expected call of NewAccountWithAddress.
|
||||
func (mr *MockAccountKeeperMockRecorder) NewAccountWithAddress(ctx, addr interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAccountWithAddress", reflect.TypeOf((*MockAccountKeeper)(nil).NewAccountWithAddress), ctx, addr)
|
||||
}
|
||||
|
||||
// SetAccount mocks base method.
|
||||
func (m *MockAccountKeeper) SetAccount(ctx context.Context, acc types0.AccountI) {
|
||||
m.ctrl.T.Helper()
|
||||
|
||||
@ -6,7 +6,9 @@ import (
|
||||
"strconv"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -73,6 +75,9 @@ func (ar AccountRetriever) EnsureExists(clientCtx client.Context, addr sdk.AccAd
|
||||
func (ar AccountRetriever) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) {
|
||||
acc, err := ar.GetAccount(clientCtx, addr)
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.NotFound {
|
||||
return 0, 0, nil
|
||||
}
|
||||
return 0, 0, err
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Consens Breaking Changes
|
||||
|
||||
* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
|
||||
|
||||
### Features
|
||||
|
||||
* [#18737](https://github.com/cosmos/cosmos-sdk/pull/18737) Added a limit of 200 grants pruned per `BeginBlock` and the `PruneExpiredGrants` message that prunes 75 expired grants on every run.
|
||||
|
||||
@ -13,7 +13,6 @@ type AccountKeeper interface {
|
||||
AddressCodec() address.Codec
|
||||
GetAccount(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
|
||||
NewAccountWithAddress(ctx context.Context, addr sdk.AccAddress) sdk.AccountI
|
||||
SetAccount(ctx context.Context, acc sdk.AccountI)
|
||||
}
|
||||
|
||||
// BankKeeper defines the expected interface needed to retrieve account balances.
|
||||
|
||||
@ -34,13 +34,6 @@ func (k Keeper) Grant(ctx context.Context, msg *authz.MsgGrant) (*authz.MsgGrant
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create the account if it is not in account state
|
||||
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
|
||||
if granteeAcc == nil {
|
||||
granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
|
||||
k.authKeeper.SetAccount(ctx, granteeAcc)
|
||||
}
|
||||
|
||||
authorization, err := msg.GetAuthorization()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -124,7 +124,6 @@ func (suite *TestSuite) TestGrant() {
|
||||
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), newAcc).Return(nil).AnyTimes()
|
||||
acc := authtypes.NewBaseAccountWithAddress(newAcc)
|
||||
suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), newAcc).Return(acc).AnyTimes()
|
||||
suite.accountKeeper.EXPECT().SetAccount(gomock.Any(), acc).Return()
|
||||
|
||||
grant, err := authz.NewGrant(curBlockTime, banktypes.NewSendAuthorization(coins, nil), &oneYear)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
@ -78,18 +78,6 @@ func (mr *MockAccountKeeperMockRecorder) NewAccountWithAddress(ctx, addr interfa
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewAccountWithAddress", reflect.TypeOf((*MockAccountKeeper)(nil).NewAccountWithAddress), ctx, addr)
|
||||
}
|
||||
|
||||
// SetAccount mocks base method.
|
||||
func (m *MockAccountKeeper) SetAccount(ctx context.Context, acc types.AccountI) {
|
||||
m.ctrl.T.Helper()
|
||||
m.ctrl.Call(m, "SetAccount", ctx, acc)
|
||||
}
|
||||
|
||||
// SetAccount indicates an expected call of SetAccount.
|
||||
func (mr *MockAccountKeeperMockRecorder) SetAccount(ctx, acc interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetAccount", reflect.TypeOf((*MockAccountKeeper)(nil).SetAccount), ctx, acc)
|
||||
}
|
||||
|
||||
// MockBankKeeper is a mock of BankKeeper interface.
|
||||
type MockBankKeeper struct {
|
||||
ctrl *gomock.Controller
|
||||
|
||||
@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Consens Breaking Changes
|
||||
|
||||
* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
|
||||
|
||||
### Features
|
||||
|
||||
* [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn`, to burn coins.
|
||||
|
||||
@ -386,7 +386,7 @@ func (k BaseKeeper) MintCoins(ctx context.Context, moduleName string, amounts sd
|
||||
return nil
|
||||
}
|
||||
|
||||
// BurnCoins burns coins deletes coins from the balance of the module account.
|
||||
// BurnCoins burns coins deletes coins from the balance of an account.
|
||||
// An error is returned if the module account does not exist or is unauthorized.
|
||||
func (k BaseKeeper) BurnCoins(ctx context.Context, address []byte, amounts sdk.Coins) error {
|
||||
acc := k.ak.GetAccount(ctx, address)
|
||||
@ -454,7 +454,7 @@ func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, ba
|
||||
return nil
|
||||
}
|
||||
|
||||
// trackUndelegation trakcs undelegation of the given account if it is a vesting account
|
||||
// trackUndelegation tracks undelegation of the given account if it is a vesting account
|
||||
func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error {
|
||||
acc := k.ak.GetAccount(ctx, addr)
|
||||
if acc == nil {
|
||||
|
||||
@ -172,7 +172,6 @@ func (suite *KeeperTestSuite) mockMintCoins(moduleAcc *authtypes.ModuleAccount)
|
||||
func (suite *KeeperTestSuite) mockSendCoinsFromModuleToAccount(moduleAcc *authtypes.ModuleAccount, accAddr sdk.AccAddress) {
|
||||
suite.authKeeper.EXPECT().GetModuleAddress(moduleAcc.Name).Return(moduleAcc.GetAddress())
|
||||
suite.authKeeper.EXPECT().GetAccount(suite.ctx, moduleAcc.GetAddress()).Return(moduleAcc)
|
||||
suite.authKeeper.EXPECT().HasAccount(suite.ctx, accAddr).Return(true)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) mockBurnCoins(moduleAcc *authtypes.ModuleAccount) {
|
||||
@ -183,18 +182,15 @@ func (suite *KeeperTestSuite) mockSendCoinsFromModuleToModule(sender, receiver *
|
||||
suite.authKeeper.EXPECT().GetModuleAddress(sender.Name).Return(sender.GetAddress())
|
||||
suite.authKeeper.EXPECT().GetModuleAccount(suite.ctx, receiver.Name).Return(receiver)
|
||||
suite.authKeeper.EXPECT().GetAccount(suite.ctx, sender.GetAddress()).Return(sender)
|
||||
suite.authKeeper.EXPECT().HasAccount(suite.ctx, receiver.GetAddress()).Return(true)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) mockSendCoinsFromAccountToModule(acc *authtypes.BaseAccount, moduleAcc *authtypes.ModuleAccount) {
|
||||
suite.authKeeper.EXPECT().GetModuleAccount(suite.ctx, moduleAcc.Name).Return(moduleAcc)
|
||||
suite.authKeeper.EXPECT().GetAccount(suite.ctx, acc.GetAddress()).Return(acc)
|
||||
suite.authKeeper.EXPECT().HasAccount(suite.ctx, moduleAcc.GetAddress()).Return(true)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) mockSendCoins(ctx context.Context, sender sdk.AccountI, receiver sdk.AccAddress) {
|
||||
suite.authKeeper.EXPECT().GetAccount(ctx, sender.GetAddress()).Return(sender)
|
||||
suite.authKeeper.EXPECT().HasAccount(ctx, receiver).Return(true)
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) mockFundAccount(receiver sdk.AccAddress) {
|
||||
@ -206,9 +202,6 @@ func (suite *KeeperTestSuite) mockInputOutputCoins(inputs []sdk.AccountI, output
|
||||
for _, input := range inputs {
|
||||
suite.authKeeper.EXPECT().GetAccount(suite.ctx, input.GetAddress()).Return(input)
|
||||
}
|
||||
for _, output := range outputs {
|
||||
suite.authKeeper.EXPECT().HasAccount(suite.ctx, output).Return(true)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) mockValidateBalance(acc sdk.AccountI) {
|
||||
|
||||
@ -12,7 +12,6 @@ import (
|
||||
"cosmossdk.io/x/bank/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
)
|
||||
@ -183,15 +182,6 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
|
||||
),
|
||||
)
|
||||
|
||||
// Create account if recipient does not exist.
|
||||
//
|
||||
// NOTE: This should ultimately be removed in favor a more flexible approach
|
||||
// such as delegated fee messages.
|
||||
accExists := k.ak.HasAccount(ctx, outAddress)
|
||||
if !accExists {
|
||||
defer telemetry.IncrCounter(1, "new", "account")
|
||||
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, outAddress))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -216,16 +206,6 @@ func (k BaseSendKeeper) SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccA
|
||||
return err
|
||||
}
|
||||
|
||||
// Create account if recipient does not exist.
|
||||
//
|
||||
// NOTE: This should ultimately be removed in favor a more flexible approach
|
||||
// such as delegated fee messages.
|
||||
accExists := k.ak.HasAccount(ctx, toAddr)
|
||||
if !accExists {
|
||||
defer telemetry.IncrCounter(1, "new", "account")
|
||||
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr))
|
||||
}
|
||||
|
||||
fromAddrString, err := k.ak.AddressCodec().BytesToString(fromAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Consens Breaking Changes
|
||||
|
||||
* [#19188](https://github.com/cosmos/cosmos-sdk/pull/19188) Remove creation of `BaseAccount` when sending a message to an account that does not exist
|
||||
|
||||
### Features
|
||||
|
||||
* [#14649](https://github.com/cosmos/cosmos-sdk/pull/14649) The `x/feegrant` module is extracted to have a separate go.mod file which allows it to be a standalone module.
|
||||
|
||||
@ -69,13 +69,6 @@ func (k Keeper) GrantAllowance(ctx context.Context, granter, grantee sdk.AccAddr
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fee allowance already exists")
|
||||
}
|
||||
|
||||
// create the account if it is not in account state
|
||||
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
|
||||
if granteeAcc == nil {
|
||||
granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
|
||||
k.authKeeper.SetAccount(ctx, granteeAcc)
|
||||
}
|
||||
|
||||
exp, err := feeAllowance.ExpiresAt()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -77,7 +77,6 @@ func (suite *KeeperTestSuite) TestGrantAllowance() {
|
||||
suite.Require().NoError(err)
|
||||
|
||||
suite.accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), add).Return(acc).AnyTimes()
|
||||
suite.accountKeeper.EXPECT().SetAccount(gomock.Any(), acc).Return()
|
||||
|
||||
suite.Require().NoError(err)
|
||||
return &feegrant.MsgGrantAllowance{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user