refactor!: use KVStoreService and context.Context in x/bank (#15891)

This commit is contained in:
Facundo Medica 2023-04-26 07:12:47 -03:00 committed by GitHub
parent e59c4a8577
commit 6dfe7351a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
78 changed files with 594 additions and 512 deletions

View File

@ -117,6 +117,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### API Breaking Changes
* (x/bank) [#15891](https://github.com/cosmos/cosmos-sdk/issues/15891) `NewKeeper` now takes a `KVStoreService` instead of a `StoreKey` and methods in the `Keeper` now take a `context.Context` instead of a `sdk.Context`. Also `FundAccount` and `FundModuleAccount` from the `testutil` package accept a `context.Context` instead of a `sdk.Context`, and it's position was moved to the first place.
* (x/bank) [#15818](https://github.com/cosmos/cosmos-sdk/issues/15818) `BaseViewKeeper`'s `Logger` method now doesn't require a context. `NewBaseKeeper`, `NewBaseSendKeeper` and `NewBaseViewKeeper` now also require a `log.Logger` to be passed in.
* (client) [#15597](https://github.com/cosmos/cosmos-sdk/pull/15597) `RegisterNodeService` now requires a config parameter.
* (x/*all*) [#15648](https://github.com/cosmos/cosmos-sdk/issues/15648) Make `SetParams` consistent across all modules and validate the params at the message handling instead of `SetParams` method.

View File

@ -71,6 +71,7 @@ This is no longer the case, the assertion has been loosened to only require modu
The following modules `NewKeeper` function now take a `KVStoreService` instead of a `StoreKey`:
* `x/auth`
* `x/bank`
* `x/consensus`
* `x/feegrant`
* `x/nft`

View File

@ -287,7 +287,7 @@ func NewSimApp(
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
keys[banktypes.StoreKey],
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
app.AccountKeeper,
BlockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),

View File

@ -91,7 +91,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
}
func fundAccount(f *deterministicFixture, addr sdk.AccAddress, coin ...sdk.Coin) {
err := banktestutil.FundAccount(f.bankKeeper, f.ctx, addr, sdk.NewCoins(coin...))
err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, sdk.NewCoins(coin...))
assert.NilError(&testing.T{}, err)
}
@ -174,7 +174,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
coins = sdk.NewCoins(append(coins, coin)...)
}
err := banktestutil.FundAccount(f.bankKeeper, f.ctx, addr, coins)
err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, coins)
assert.NilError(t, err)
req := banktypes.NewQuerySpendableBalancesRequest(addr, testdata.PaginationGenerator(rt, uint64(len(denoms))).Draw(rt, "pagination"))
@ -186,7 +186,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
sdk.NewCoin("denom", sdk.NewInt(100)),
)
err := banktestutil.FundAccount(f.bankKeeper, f.ctx, addr1, coins)
err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr1, coins)
assert.NilError(t, err)
req := banktypes.NewQuerySpendableBalancesRequest(addr1, nil)
@ -450,7 +450,7 @@ func TestGRPCDenomOwners(t *testing.T) {
sdk.NewInt(rapid.Int64Min(1).Draw(rt, "amount")),
)
err := banktestutil.FundAccount(f.bankKeeper, f.ctx, addr, sdk.NewCoins(coin))
err := banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, sdk.NewCoins(coin))
assert.NilError(t, err)
}
@ -476,7 +476,7 @@ func TestGRPCDenomOwners(t *testing.T) {
addr, err := sdk.AccAddressFromBech32(denomOwners[i].Address)
assert.NilError(t, err)
err = banktestutil.FundAccount(f.bankKeeper, f.ctx, addr, sdk.NewCoins(coin1))
err = banktestutil.FundAccount(f.ctx, f.bankKeeper, addr, sdk.NewCoins(coin1))
assert.NilError(t, err)
}

View File

@ -1,6 +1,7 @@
package keeper_test
import (
"context"
"fmt"
"reflect"
"strings"
@ -169,8 +170,10 @@ func initKeepersWithmAccPerms(f *fixture, blockedAddrs map[string]bool) (authkee
appCodec, storeService, authtypes.ProtoBaseAccount,
maccPerms, sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
bankStoreService := runtime.NewKVStoreService(f.fetchStoreKey(types.StoreKey).(*storetypes.KVStoreKey))
bankKeeper := keeper.NewBaseKeeper(
appCodec, f.fetchStoreKey(types.StoreKey), authKeeper, blockedAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String(), log.NewNopLogger(),
appCodec, bankStoreService, authKeeper, blockedAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String(), log.NewNopLogger(),
)
return authKeeper, bankKeeper
@ -390,7 +393,7 @@ func TestSendCoinsNewAccount(t *testing.T) {
addr1 := sdk.AccAddress([]byte("addr1_______________"))
acc1 := f.accountKeeper.NewAccountWithAddress(ctx, addr1)
f.accountKeeper.SetAccount(ctx, acc1)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, balances))
acc1Balances := f.bankKeeper.GetAllBalances(ctx, addr1)
assert.DeepEqual(t, balances, acc1Balances)
@ -423,7 +426,7 @@ func TestInputOutputNewAccount(t *testing.T) {
addr1 := sdk.AccAddress([]byte("addr1_______________"))
acc1 := f.accountKeeper.NewAccountWithAddress(ctx, addr1)
f.accountKeeper.SetAccount(ctx, acc1)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, balances))
acc1Balances := f.bankKeeper.GetAllBalances(ctx, addr1)
assert.DeepEqual(t, balances, acc1Balances)
@ -478,7 +481,7 @@ func TestInputOutputCoins(t *testing.T) {
assert.Error(t, f.bankKeeper.InputOutputCoins(ctx, input, []types.Output{}), "sum inputs != sum outputs")
assert.Error(t, f.bankKeeper.InputOutputCoins(ctx, input, outputs), "spendable balance is smaller than 20bar: insufficient funds")
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, balances))
insufficientInput := types.Input{
Address: addr1.String(),
@ -516,12 +519,12 @@ func TestSendCoins(t *testing.T) {
addr2 := sdk.AccAddress("addr2_______________")
acc2 := f.accountKeeper.NewAccountWithAddress(ctx, addr2)
f.accountKeeper.SetAccount(ctx, acc2)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, balances))
sendAmt := sdk.NewCoins(newFooCoin(50), newBarCoin(25))
assert.Error(t, f.bankKeeper.SendCoins(ctx, addr1, addr2, sendAmt), "spendable balance is smaller than 25bar: insufficient funds")
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, balances))
assert.NilError(t, f.bankKeeper.SendCoins(ctx, addr1, addr2, sendAmt))
acc1Balances := f.bankKeeper.GetAllBalances(ctx, addr1)
@ -560,14 +563,14 @@ func TestValidateBalance(t *testing.T) {
f.accountKeeper.SetAccount(ctx, acc)
balances := sdk.NewCoins(newFooCoin(100))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, balances))
assert.NilError(t, f.bankKeeper.ValidateBalance(ctx, addr1))
bacc := authtypes.NewBaseAccountWithAddress(addr2)
vacc := vesting.NewContinuousVestingAccount(bacc, balances.Add(balances...), now.Unix(), endTime.Unix())
f.accountKeeper.SetAccount(ctx, vacc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, balances))
assert.Error(t, f.bankKeeper.ValidateBalance(ctx, addr2), "vesting amount 200foo cannot be greater than total amount 100foo")
}
@ -590,7 +593,7 @@ func TestSendCoins_Invalid_SendLockedCoins(t *testing.T) {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix())
f.accountKeeper.SetAccount(ctx, vacc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, f.ctx, addr2, balances))
assert.NilError(t, banktestutil.FundAccount(f.ctx, f.bankKeeper, addr2, balances))
assert.Error(t, f.bankKeeper.SendCoins(ctx, addr, addr2, sendCoins), fmt.Sprintf("locked amount exceeds account balance funds: %s > 0stake: insufficient funds", origCoins))
}
@ -653,7 +656,7 @@ func TestHasBalance(t *testing.T) {
balances := sdk.NewCoins(newFooCoin(100))
assert.Assert(t, f.bankKeeper.HasBalance(ctx, addr, newFooCoin(99)) == false)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr, balances))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr, balances))
assert.Assert(t, f.bankKeeper.HasBalance(ctx, addr, newFooCoin(101)) == false)
assert.Assert(t, f.bankKeeper.HasBalance(ctx, addr, newFooCoin(100)))
assert.Assert(t, f.bankKeeper.HasBalance(ctx, addr, newFooCoin(1)))
@ -670,7 +673,7 @@ func TestMsgSendEvents(t *testing.T) {
f.accountKeeper.SetAccount(ctx, acc)
newCoins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr, newCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr, newCoins))
assert.NilError(t, f.bankKeeper.SendCoins(ctx, addr, addr2, newCoins))
event1 := sdk.Event{
@ -742,7 +745,7 @@ func TestMsgMultiSendEvents(t *testing.T) {
assert.Equal(t, 0, len(events))
// Set addr's coins but not addr2's coins
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr, sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100))))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr, sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100))))
assert.NilError(t, f.bankKeeper.InputOutputCoins(ctx, input, outputs))
events = ctx.EventManager().ABCIEvents()
@ -759,10 +762,10 @@ func TestMsgMultiSendEvents(t *testing.T) {
assert.DeepEqual(t, abci.Event(event1), events[7])
// Set addr's coins and addr2's coins
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr, sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr, sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))))
newCoins = sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr, sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr, sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))))
newCoins2 = sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))
assert.NilError(t, f.bankKeeper.InputOutputCoins(ctx, input, outputs))
@ -823,8 +826,8 @@ func TestSpendableCoins(t *testing.T) {
f.accountKeeper.SetAccount(ctx, macc)
f.accountKeeper.SetAccount(ctx, vacc)
f.accountKeeper.SetAccount(ctx, acc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, origCoins))
assert.DeepEqual(t, origCoins, f.bankKeeper.SpendableCoins(ctx, addr2))
assert.DeepEqual(t, origCoins[0], f.bankKeeper.SpendableCoin(ctx, addr2, "stake"))
@ -854,13 +857,13 @@ func TestVestingAccountSend(t *testing.T) {
vacc := vesting.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
f.accountKeeper.SetAccount(ctx, vacc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
// require that no coins be sendable at the beginning of the vesting schedule
assert.Error(t, f.bankKeeper.SendCoins(ctx, addr1, addr2, sendCoins), fmt.Sprintf("spendable balance is smaller than %s: insufficient funds", sendCoins))
// receive some coins
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, sendCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, sendCoins))
// require that all vested coins are spendable plus any received
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
assert.NilError(t, f.bankKeeper.SendCoins(ctx, addr1, addr2, sendCoins))
@ -889,13 +892,13 @@ func TestPeriodicVestingAccountSend(t *testing.T) {
vacc := vesting.NewPeriodicVestingAccount(bacc, origCoins, ctx.BlockHeader().Time.Unix(), periods)
f.accountKeeper.SetAccount(ctx, vacc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
// require that no coins be sendable at the beginning of the vesting schedule
assert.Error(t, f.bankKeeper.SendCoins(ctx, addr1, addr2, sendCoins), fmt.Sprintf("spendable balance is smaller than %s: insufficient funds", sendCoins))
// receive some coins
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, sendCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, sendCoins))
// require that all vested coins are spendable plus any received
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -924,8 +927,8 @@ func TestVestingAccountReceive(t *testing.T) {
f.accountKeeper.SetAccount(ctx, vacc)
f.accountKeeper.SetAccount(ctx, acc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, origCoins))
// send some coins to the vesting account
assert.NilError(t, f.bankKeeper.SendCoins(ctx, addr2, addr1, sendCoins))
@ -966,8 +969,8 @@ func TestPeriodicVestingAccountReceive(t *testing.T) {
f.accountKeeper.SetAccount(ctx, vacc)
f.accountKeeper.SetAccount(ctx, acc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, origCoins))
// send some coins to the vesting account
assert.NilError(t, f.bankKeeper.SendCoins(ctx, addr2, addr1, sendCoins))
@ -1006,8 +1009,8 @@ func TestDelegateCoins(t *testing.T) {
f.accountKeeper.SetAccount(ctx, vacc)
f.accountKeeper.SetAccount(ctx, acc)
f.accountKeeper.SetAccount(ctx, macc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, origCoins))
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -1076,8 +1079,8 @@ func TestUndelegateCoins(t *testing.T) {
f.accountKeeper.SetAccount(ctx, vacc)
f.accountKeeper.SetAccount(ctx, acc)
f.accountKeeper.SetAccount(ctx, macc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr2, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr2, origCoins))
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -1130,7 +1133,7 @@ func TestUndelegateCoins_Invalid(t *testing.T) {
assert.Error(t, f.bankKeeper.UndelegateCoins(ctx, addrModule, addr1, delCoins), fmt.Sprintf("module account %s does not exist: unknown address", addrModule.String()))
f.accountKeeper.SetAccount(ctx, macc)
assert.NilError(t, banktestutil.FundAccount(f.bankKeeper, ctx, addr1, origCoins))
assert.NilError(t, banktestutil.FundAccount(ctx, f.bankKeeper, addr1, origCoins))
assert.Error(t, f.bankKeeper.UndelegateCoins(ctx, addrModule, addr1, delCoins), fmt.Sprintf("spendable balance is smaller than %s: insufficient funds", delCoins))
f.accountKeeper.SetAccount(ctx, acc)
@ -1208,7 +1211,8 @@ func TestBalanceTrackingEvents(t *testing.T) {
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
f.bankKeeper = keeper.NewBaseKeeper(f.appCodec, f.fetchStoreKey(types.StoreKey),
bankStoreService := runtime.NewKVStoreService(f.fetchStoreKey(types.StoreKey).(*storetypes.KVStoreKey))
f.bankKeeper = keeper.NewBaseKeeper(f.appCodec, bankStoreService,
f.accountKeeper, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
log.NewNopLogger(),
)
@ -1329,7 +1333,7 @@ func TestMintCoinRestrictions(t *testing.T) {
f := initFixture(t)
t.Parallel()
type BankMintingRestrictionFn func(ctx sdk.Context, coins sdk.Coins) error
type BankMintingRestrictionFn func(ctx context.Context, coins sdk.Coins) error
maccPerms := make(map[string][]string)
maccPerms[multiPerm] = []string{authtypes.Burner, authtypes.Minter, authtypes.Staking}
@ -1354,7 +1358,7 @@ func TestMintCoinRestrictions(t *testing.T) {
}{
{
"restriction",
func(_ sdk.Context, coins sdk.Coins) error {
func(_ context.Context, coins sdk.Coins) error {
for _, coin := range coins {
if coin.Denom != fooDenom {
return fmt.Errorf("Module %s only has perms for minting %s coins, tried minting %s coins", types.ModuleName, fooDenom, coin.Denom)
@ -1376,7 +1380,8 @@ func TestMintCoinRestrictions(t *testing.T) {
}
for _, test := range tests {
f.bankKeeper = keeper.NewBaseKeeper(f.appCodec, f.fetchStoreKey(types.StoreKey),
bankStoreService := runtime.NewKVStoreService(f.fetchStoreKey(types.StoreKey).(*storetypes.KVStoreKey))
f.bankKeeper = keeper.NewBaseKeeper(f.appCodec, bankStoreService,
f.accountKeeper, nil, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
log.NewNopLogger(),
).WithMintCoinsRestriction(keeper.MintingRestrictionFn(test.restrictionFn))

View File

@ -88,7 +88,7 @@ func initFixture(t testing.TB) *fixture {
}
bankKeeper := bankkeeper.NewBaseKeeper(
cdc,
keys[banktypes.StoreKey],
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
accountKeeper,
blockedAddresses,
authority.String(),

View File

@ -99,7 +99,7 @@ func setAccountBalance(t *testing.T, f *fixture, addr sdk.AccAddress, amount int
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, addr)
f.accountKeeper.SetAccount(f.ctx, acc)
err := testutil.FundAccount(f.bankKeeper, f.ctx, addr, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, amount)})
err := testutil.FundAccount(f.ctx, f.bankKeeper, addr, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, amount)})
assert.NilError(t, err)
bankGenesisState := f.bankKeeper.ExportGenesis(f.ctx)

View File

@ -26,7 +26,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
bondDenom := app.StakingKeeper.BondDenom(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
// create a validator and a delegator to that validator

View File

@ -152,7 +152,7 @@ func setValidator(f *deterministicFixture, t *testing.T, validator stakingtypes.
delegatorAddress := sdk.AccAddress(validator.GetOperator())
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, validator.BondedTokens()))
banktestutil.FundAccount(f.bankKeeper, f.ctx, delegatorAddress, coins)
banktestutil.FundAccount(f.ctx, f.bankKeeper, delegatorAddress, coins)
_, err := f.stakingKeeper.Delegate(f.ctx, delegatorAddress, validator.BondedTokens(), stakingtypes.Unbonded, validator, true)
assert.NilError(t, err)
@ -237,7 +237,7 @@ func fundAccountAndDelegate(f *deterministicFixture, t *testing.T, delegator sdk
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amt))
assert.NilError(t, f.bankKeeper.MintCoins(f.ctx, minttypes.ModuleName, coins))
banktestutil.FundAccount(f.bankKeeper, f.ctx, delegator, coins)
banktestutil.FundAccount(f.ctx, f.bankKeeper, delegator, coins)
shares, err := f.stakingKeeper.Delegate(f.ctx, delegator, amt, stakingtypes.Unbonded, validator, true)
return shares, err

View File

@ -67,8 +67,8 @@ func TestInitGenesis(t *testing.T) {
i2 := len(validators) - 1 // -1 to exclude genesis validator
assert.NilError(t,
testutil.FundModuleAccount(
app.BankKeeper,
ctx,
app.BankKeeper,
types.BondedPoolName,
sdk.NewCoins(
sdk.NewCoin(params.BondDenom, valTokens.MulRaw((int64)(i2))),
@ -201,8 +201,8 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
// mint coins in the bonded pool representing the validators coins
assert.NilError(t,
testutil.FundModuleAccount(
app.BankKeeper,
ctx,
app.BankKeeper,
types.BondedPoolName,
sdk.NewCoins(sdk.NewCoin(params.BondDenom, bondedPoolAmt)),
),

View File

@ -50,7 +50,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
notBondedPool := stakingKeeper.GetNotBondedPool(ctx)
startTokens := stakingKeeper.TokensFromConsensusPower(ctx, 5)
assert.NilError(t, testutil.FundModuleAccount(bankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), startTokens))))
assert.NilError(t, testutil.FundModuleAccount(ctx, bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(stakingKeeper.BondDenom(ctx), startTokens))))
accountKeeper.SetModuleAccount(ctx, notBondedPool)
moduleBalance := bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), stakingKeeper.BondDenom(ctx))

View File

@ -27,7 +27,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context,
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), amt.MulRaw(int64(len(addrDels)))))
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), totalSupply))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
@ -37,7 +37,7 @@ func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context,
// set bonded pool balance
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), bondedCoins))
for i := int64(0); i < numVals; i++ {
validator := testutil.NewValidator(t, addrVals[i], PKs[i])
@ -103,7 +103,7 @@ func TestSlashRedelegation(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
_ = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), startCoins))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), startCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
// set a redelegation with an expiration timestamp beyond which the
@ -370,7 +370,7 @@ func TestSlashWithRedelegation(t *testing.T) {
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
rdCoins := sdk.NewCoins(sdk.NewCoin(bondDenom, rdTokens.MulRaw(2)))
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), rdCoins))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), rdCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@ -539,8 +539,8 @@ func TestSlashBoth(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), bondedCoins))
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), notBondedCoins))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), bondedCoins))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), notBondedCoins))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)

View File

@ -53,7 +53,7 @@ func SetupUnbondingTests(t *testing.T, app *simapp.SimApp, ctx sdk.Context, hook
bondDenom = app.StakingKeeper.BondDenom(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
app.BankKeeper.SendCoinsFromModuleToModule(ctx, types.BondedPoolName, types.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, startTokens)))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)

View File

@ -56,7 +56,7 @@ func BenchmarkGetValidatorDelegations(b *testing.B) {
for _, val := range valAddrs {
for i := 0; i < delegationsNum; i++ {
delegator := sdk.AccAddress(fmt.Sprintf("address%d", i))
banktestutil.FundAccount(app.BankKeeper, ctx, delegator,
banktestutil.FundAccount(ctx, app.BankKeeper, delegator,
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(i)))))
NewDel := types.NewDelegation(delegator, val, sdk.NewDec(int64(i)))
app.StakingKeeper.SetDelegation(ctx, NewDel)
@ -89,7 +89,7 @@ func BenchmarkGetValidatorDelegationsLegacy(b *testing.B) {
for _, val := range valAddrs {
for i := 0; i < delegationsNum; i++ {
delegator := sdk.AccAddress(fmt.Sprintf("address%d", i))
banktestutil.FundAccount(app.BankKeeper, ctx, delegator,
banktestutil.FundAccount(ctx, app.BankKeeper, delegator,
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(i)))))
NewDel := types.NewDelegation(delegator, val, sdk.NewDec(int64(i)))
app.StakingKeeper.SetDelegation(ctx, NewDel)

View File

@ -36,7 +36,7 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si
// set bonded pool supply
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), totalSupply))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), totalSupply))
// unbond genesis validator delegations
delegations := app.StakingKeeper.GetAllDelegations(ctx)
@ -81,8 +81,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
app.StakingKeeper.SetParams(ctx, params)
// create a random pool
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234)))))
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000)))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 1234)))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 10000)))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
@ -136,7 +136,7 @@ func TestSlashToZeroPowerRemoved(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), valTokens))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@ -243,8 +243,8 @@ func TestGetValidatorSortingMixed(t *testing.T) {
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501)))))
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0)))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 501)))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), app.StakingKeeper.TokensFromConsensusPower(ctx, 0)))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
@ -319,7 +319,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[i], _ = validators[i].AddTokensFromDel(tokens)
notBondedPool := app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, tokens))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[i] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[i], true)
}
@ -338,7 +338,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
newTokens := sdk.NewCoins()
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), newTokens))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
// test that the two largest validators are
@ -370,7 +370,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
newTokens = sdk.NewCoins(sdk.NewCoin(params.BondDenom, app.StakingKeeper.TokensFromConsensusPower(ctx, 1)))
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), newTokens))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), newTokens))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)
@ -385,7 +385,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[3], _ = validators[3].RemoveDelShares(math.LegacyNewDec(201))
bondedPool := app.StakingKeeper.GetBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, bondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, rmTokens))))
app.AccountKeeper.SetModuleAccount(ctx, bondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)
@ -399,7 +399,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
validators[3], _ = validators[3].AddTokensFromDel(sdk.NewInt(200))
notBondedPool = app.StakingKeeper.GetNotBondedPool(ctx)
assert.NilError(t, banktestutil.FundModuleAccount(app.BankKeeper, ctx, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200)))))
assert.NilError(t, banktestutil.FundModuleAccount(ctx, app.BankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(params.BondDenom, sdk.NewInt(200)))))
app.AccountKeeper.SetModuleAccount(ctx, notBondedPool)
validators[3] = keeper.TestingUpdateValidator(app.StakingKeeper, ctx, validators[3], true)

View File

@ -33,7 +33,7 @@ func (s *paginationTestSuite) TestFilteredPaginations() {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances))
s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances))
store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey))
// verify pagination with limit > total values
@ -106,7 +106,7 @@ func (s *paginationTestSuite) TestReverseFilteredPaginations() {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances))
s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances))
store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey))
// verify pagination with limit > total values
@ -184,7 +184,7 @@ func (s *paginationTestSuite) TestFilteredPaginate() {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
err := testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)
err := testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances)
if err != nil { // should return no error
fmt.Println(err)
}
@ -260,7 +260,7 @@ func (s *paginationTestSuite) TestFilteredPaginationsNextKey() {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances))
s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances))
store := s.ctx.KVStore(s.app.UnsafeFindStoreKey(types.StoreKey))
execFilterPaginate := func(store storetypes.KVStore, pageReq *query.PageRequest, appCodec codec.Codec) (balances sdk.Coins, res *query.PageResponse, err error) {

View File

@ -66,7 +66,7 @@ func FuzzPagination(f *testing.F) {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := suite.accountKeeper.NewAccountWithAddress(suite.ctx, addr1)
suite.accountKeeper.SetAccount(suite.ctx, acc1)
err := testutil.FundAccount(suite.bankKeeper, suite.ctx, addr1, balances)
err := testutil.FundAccount(suite.ctx, suite.bankKeeper, addr1, balances)
if err != nil { // should return no error
f.Fatal(err)
}

View File

@ -121,7 +121,7 @@ func (s *paginationTestSuite) TestPagination() {
addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances))
s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances))
s.T().Log("verify empty page request results a max of defaultLimit records and counts total records")
pageReq := &query.PageRequest{}
@ -229,7 +229,7 @@ func (s *paginationTestSuite) TestReversePagination() {
addr1 := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances))
s.Require().NoError(testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances))
s.T().Log("verify paginate with custom limit and countTotal, Reverse false")
pageReq := &query.PageRequest{Limit: 2, CountTotal: true, Reverse: true, Key: nil}
@ -348,7 +348,7 @@ func (s *paginationTestSuite) TestPaginate() {
addr1 := sdk.AccAddress([]byte("addr1"))
acc1 := s.accountKeeper.NewAccountWithAddress(s.ctx, addr1)
s.accountKeeper.SetAccount(s.ctx, acc1)
err := testutil.FundAccount(s.bankKeeper, s.ctx, addr1, balances)
err := testutil.FundAccount(s.ctx, s.bankKeeper, addr1, balances)
if err != nil { // should return no error
fmt.Println(err)
}

View File

@ -5,6 +5,7 @@
package testutil
import (
context "context"
reflect "reflect"
types "github.com/cosmos/cosmos-sdk/types"
@ -35,7 +36,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// IsSendEnabledCoins mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error {
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types.Coin) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range coins {
@ -54,7 +55,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins
}
// SendCoins mocks base method.
func (m *MockBankKeeper) SendCoins(ctx types.Context, from, to types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoins(ctx context.Context, from, to types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoins", ctx, from, to, amt)
ret0, _ := ret[0].(error)
@ -68,7 +69,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, from, to, amt interface{})
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)

View File

@ -1,12 +1,14 @@
package types
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BankKeeper defines the contract needed for supply related APIs (noalias)
type BankKeeper interface {
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
SendCoins(ctx context.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

View File

@ -5,6 +5,7 @@
package testutil
import (
context "context"
reflect "reflect"
types "github.com/cosmos/cosmos-sdk/types"
@ -49,7 +50,7 @@ func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call
}
// IsSendEnabledCoins mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error {
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types.Coin) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range coins {
@ -68,7 +69,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins
}
// SendCoins mocks base method.
func (m *MockBankKeeper) SendCoins(ctx types.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt)
ret0, _ := ret[0].(error)

View File

@ -1,13 +1,15 @@
package types
import (
context "context"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BankKeeper defines the expected interface contract the vesting module requires
// for creating vesting accounts with funds.
type BankKeeper interface {
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
BlockedAddr(addr sdk.AccAddress) bool
}

View File

@ -4,6 +4,7 @@ import (
context "context"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -18,6 +19,6 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
}

View File

@ -108,7 +108,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
for _, account := range accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -129,7 +129,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// IsSendEnabledCoins mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error {
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types.Coin) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range coins {
@ -148,7 +148,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -195,28 +195,28 @@ type Keeper interface {
SendKeeper
WithMintCoinsRestriction(MintingRestrictionFn) BaseKeeper
InitGenesis(sdk.Context, *types.GenesisState)
ExportGenesis(sdk.Context) *types.GenesisState
InitGenesis(context.Context, *types.GenesisState)
ExportGenesis(context.Context) *types.GenesisState
GetSupply(ctx sdk.Context, denom string) sdk.Coin
HasSupply(ctx sdk.Context, denom string) bool
GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bool)
GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool)
HasDenomMetaData(ctx sdk.Context, denom string) bool
SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata)
IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool)
GetSupply(ctx context.Context, denom string) sdk.Coin
HasSupply(ctx context.Context, denom string) bool
GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool)
GetDenomMetaData(ctx context.Context, denom string) (types.Metadata, bool)
HasDenomMetaData(ctx context.Context, denom string) bool
SetDenomMetaData(ctx context.Context, denomMetaData types.Metadata)
IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool)
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
// GetAuthority gets the address capable of executing governance proposal messages. Usually the gov module account.
GetAuthority() string
@ -236,21 +236,21 @@ accounts. The send keeper does not alter the total supply (mint or burn coins).
type SendKeeper interface {
ViewKeeper
InputOutputCoins(ctx sdk.Context, inputs types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
InputOutputCoins(ctx context.Context, inputs types.Input, outputs []types.Output) error
SendCoins(ctx context.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
GetParams(ctx sdk.Context) types.Params
SetParams(ctx sdk.Context, params types.Params) error
GetParams(ctx context.Context) types.Params
SetParams(ctx context.Context, params types.Params) error
IsSendEnabledDenom(ctx sdk.Context, denom string) bool
SetSendEnabled(ctx sdk.Context, denom string, value bool)
SetAllSendEnabled(ctx sdk.Context, sendEnableds []*types.SendEnabled)
DeleteSendEnabled(ctx sdk.Context, denom string)
IterateSendEnabledEntries(ctx sdk.Context, cb func(denom string, sendEnabled bool) (stop bool))
GetAllSendEnabledEntries(ctx sdk.Context) []types.SendEnabled
IsSendEnabledDenom(ctx context.Context, denom string) bool
SetSendEnabled(ctx context.Context, denom string, value bool)
SetAllSendEnabled(ctx context.Context, sendEnableds []*types.SendEnabled)
DeleteSendEnabled(ctx context.Context, denom string)
IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) (stop bool))
GetAllSendEnabledEntries(ctx context.Context) []types.SendEnabled
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
IsSendEnabledCoin(ctx context.Context, coin sdk.Coin) bool
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
BlockedAddr(addr sdk.AccAddress) bool
}
@ -264,18 +264,18 @@ The view keeper provides read-only access to account balances. The view keeper d
// ViewKeeper defines a module interface that facilitates read only access to
// account balances.
type ViewKeeper interface {
ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
ValidateBalance(ctx context.Context, addr sdk.AccAddress) error
HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAccountsBalances(ctx sdk.Context) []types.Balance
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoin(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetAccountsBalances(ctx context.Context) []types.Balance
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx sdk.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
IterateAccountBalances(ctx context.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx context.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
}
```

View File

@ -149,7 +149,7 @@ func TestSendNotEnoughBalance(t *testing.T) {
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false, cmtproto.Header{})
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
baseApp.Commit()
@ -186,7 +186,7 @@ func TestMsgMultiSendWithAccounts(t *testing.T) {
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false, cmtproto.Header{})
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 67))))
baseApp.Commit()
@ -266,9 +266,9 @@ func TestMsgMultiSendMultipleOut(t *testing.T) {
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false, cmtproto.Header{})
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr2, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
baseApp.Commit()
@ -311,7 +311,7 @@ func TestMsgMultiSendDependent(t *testing.T) {
baseApp := s.App.BaseApp
ctx := baseApp.NewContext(false, cmtproto.Header{})
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 42))))
baseApp.Commit()
@ -360,7 +360,7 @@ func TestMsgSetSendEnabled(t *testing.T) {
s := createTestSuite(t, genAccs)
ctx := s.App.BaseApp.NewContext(false, cmtproto.Header{})
require.NoError(t, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 101))))
require.NoError(t, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 101))))
addr1Str := addr1.String()
govAddr := s.BankKeeper.GetAuthority()
goodGovProp, err := govv1.NewMsgSubmitProposal(

View File

@ -73,7 +73,7 @@ func BenchmarkOneBankSendTxPerBlock(b *testing.B) {
ctx := baseApp.NewContext(false, cmtproto.Header{})
// some value conceivably higher than the benchmarks would ever go
require.NoError(b, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))
require.NoError(b, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))
baseApp.Commit()
txGen := moduletestutil.MakeTestTxConfig()
@ -118,7 +118,7 @@ func BenchmarkOneBankMultiSendTxPerBlock(b *testing.B) {
ctx := baseApp.NewContext(false, cmtproto.Header{})
// some value conceivably higher than the benchmarks would ever go
require.NoError(b, testutil.FundAccount(s.BankKeeper, ctx, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))
require.NoError(b, testutil.FundAccount(ctx, s.BankKeeper, addr1, sdk.NewCoins(sdk.NewInt64Coin("foocoin", 100000000000))))
baseApp.Commit()
txGen := moduletestutil.MakeTestTxConfig()

View File

@ -1,6 +1,7 @@
package keeper
import (
"context"
"fmt"
"cosmossdk.io/collections"
@ -11,7 +12,7 @@ import (
)
// InitGenesis initializes the bank module's state from a given genesis state.
func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
func (k BaseKeeper) InitGenesis(ctx context.Context, genState *types.GenesisState) {
if err := k.SetParams(ctx, genState.Params); err != nil {
panic(err)
}
@ -51,7 +52,7 @@ func (k BaseKeeper) InitGenesis(ctx sdk.Context, genState *types.GenesisState) {
}
// ExportGenesis returns the bank module's genesis state.
func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
func (k BaseKeeper) ExportGenesis(ctx context.Context) *types.GenesisState {
totalSupply, _, err := k.GetPaginatedTotalSupply(ctx, &query.PageRequest{Limit: query.MaxLimit})
if err != nil {
panic(fmt.Errorf("unable to fetch total supply %v", err))

View File

@ -10,6 +10,7 @@ import (
"cosmossdk.io/store/prefix"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/bank/types"
@ -172,9 +173,8 @@ func (k BaseKeeper) DenomsMetadata(c context.Context, req *types.QueryDenomsMeta
if req == nil {
return nil, status.Errorf(codes.InvalidArgument, "empty request")
}
ctx := sdk.UnwrapSDKContext(c)
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.DenomMetadataPrefix)
kvStore := runtime.KVStoreAdapter(k.storeService.OpenKVStore(c))
store := prefix.NewStore(kvStore, types.DenomMetadataPrefix)
metadatas := []types.Metadata{}
pageRes, err := query.Paginate(store, req.Pagination, func(_, value []byte) error {

View File

@ -38,7 +38,7 @@ func (suite *KeeperTestSuite) TestQueryBalance() {
origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30))
suite.mockFundAccount(addr)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, ctx, addr, origCoins))
suite.Require().NoError(testutil.FundAccount(ctx, suite.bankKeeper, addr, origCoins))
res, err = queryClient.Balance(gocontext.Background(), req)
suite.Require().NoError(err)
@ -70,7 +70,7 @@ func (suite *KeeperTestSuite) TestQueryAllBalances() {
origCoins := sdk.NewCoins(fooCoins, barCoins, ibcCoins)
suite.mockFundAccount(addr)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, ctx, addr, origCoins))
suite.Require().NoError(testutil.FundAccount(ctx, suite.bankKeeper, addr, origCoins))
addIBCMetadata(ctx, suite.bankKeeper)
@ -121,8 +121,9 @@ func (suite *KeeperTestSuite) TestQueryAllBalances() {
}
func (suite *KeeperTestSuite) TestSpendableBalances() {
ctx := suite.ctx
_, _, addr := testdata.KeyTestPubAddr()
ctx := sdk.UnwrapSDKContext(suite.ctx)
ctx = ctx.WithBlockTime(time.Now())
queryClient := suite.mockQueryClient(ctx)
@ -155,7 +156,7 @@ func (suite *KeeperTestSuite) TestSpendableBalances() {
)
suite.mockFundAccount(addr)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, suite.ctx, addr, origCoins))
suite.Require().NoError(testutil.FundAccount(suite.ctx, suite.bankKeeper, addr, origCoins))
// move time forward for some tokens to vest
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(30 * time.Minute))
@ -172,8 +173,9 @@ func (suite *KeeperTestSuite) TestSpendableBalances() {
}
func (suite *KeeperTestSuite) TestSpendableBalanceByDenom() {
ctx := suite.ctx
_, _, addr := testdata.KeyTestPubAddr()
ctx := sdk.UnwrapSDKContext(suite.ctx)
ctx = ctx.WithBlockTime(time.Now())
queryClient := suite.mockQueryClient(ctx)
@ -201,7 +203,7 @@ func (suite *KeeperTestSuite) TestSpendableBalanceByDenom() {
)
suite.mockFundAccount(addr)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, suite.ctx, addr, origCoins))
suite.Require().NoError(testutil.FundAccount(suite.ctx, suite.bankKeeper, addr, origCoins))
// move time forward for half of the tokens to vest
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(30 * time.Minute))

View File

@ -1,13 +1,14 @@
package keeper
import (
"context"
"fmt"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/math"
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -25,29 +26,29 @@ type Keeper interface {
SendKeeper
WithMintCoinsRestriction(MintingRestrictionFn) BaseKeeper
InitGenesis(sdk.Context, *types.GenesisState)
ExportGenesis(sdk.Context) *types.GenesisState
InitGenesis(context.Context, *types.GenesisState)
ExportGenesis(context.Context) *types.GenesisState
GetSupply(ctx sdk.Context, denom string) sdk.Coin
HasSupply(ctx sdk.Context, denom string) bool
GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bool)
GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool)
HasDenomMetaData(ctx sdk.Context, denom string) bool
SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata)
GetAllDenomMetaData(ctx sdk.Context) []types.Metadata
IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool)
GetSupply(ctx context.Context, denom string) sdk.Coin
HasSupply(ctx context.Context, denom string) bool
GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error)
IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool)
GetDenomMetaData(ctx context.Context, denom string) (types.Metadata, bool)
HasDenomMetaData(ctx context.Context, denom string) bool
SetDenomMetaData(ctx context.Context, denomMetaData types.Metadata)
GetAllDenomMetaData(ctx context.Context) []types.Metadata
IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool)
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
types.QueryServer
}
@ -58,15 +59,15 @@ type BaseKeeper struct {
ak types.AccountKeeper
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
storeService store.KVStoreService
mintCoinsRestrictionFn MintingRestrictionFn
logger log.Logger
}
type MintingRestrictionFn func(ctx sdk.Context, coins sdk.Coins) error
type MintingRestrictionFn func(ctx context.Context, coins sdk.Coins) error
// GetPaginatedTotalSupply queries for the supply, ignoring 0 coins, with a given pagination
func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) {
func (k BaseKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (sdk.Coins, *query.PageResponse, error) {
results, pageResp, err := query.CollectionPaginate[string, math.Int](ctx, k.Supply, pagination)
if err != nil {
return nil, nil, err
@ -87,7 +88,7 @@ func (k BaseKeeper) GetPaginatedTotalSupply(ctx sdk.Context, pagination *query.P
// by using a SendCoinsFromModuleToAccount execution.
func NewBaseKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
storeService store.KVStoreService,
ak types.AccountKeeper,
blockedAddrs map[string]bool,
authority string,
@ -101,11 +102,11 @@ func NewBaseKeeper(
logger = logger.With(log.ModuleKey, "x/"+types.ModuleName)
return BaseKeeper{
BaseSendKeeper: NewBaseSendKeeper(cdc, storeKey, ak, blockedAddrs, authority, logger),
BaseSendKeeper: NewBaseSendKeeper(cdc, storeService, ak, blockedAddrs, authority, logger),
ak: ak,
cdc: cdc,
storeKey: storeKey,
mintCoinsRestrictionFn: func(ctx sdk.Context, coins sdk.Coins) error { return nil },
storeService: storeService,
mintCoinsRestrictionFn: func(ctx context.Context, coins sdk.Coins) error { return nil },
logger: logger,
}
}
@ -117,7 +118,7 @@ func NewBaseKeeper(
// bankKeeper.WithMintCoinsRestriction(restriction1).WithMintCoinsRestriction(restriction2)
func (k BaseKeeper) WithMintCoinsRestriction(check MintingRestrictionFn) BaseKeeper {
oldRestrictionFn := k.mintCoinsRestrictionFn
k.mintCoinsRestrictionFn = func(ctx sdk.Context, coins sdk.Coins) error {
k.mintCoinsRestrictionFn = func(ctx context.Context, coins sdk.Coins) error {
err := check(ctx, coins)
if err != nil {
return err
@ -136,7 +137,7 @@ func (k BaseKeeper) WithMintCoinsRestriction(check MintingRestrictionFn) BaseKee
// vesting and vested coins. The coins are then transferred from the delegator
// address to a ModuleAccount address. If any of the delegation amounts are negative,
// an error is returned.
func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error {
moduleAcc := k.ak.GetAccount(ctx, moduleAccAddr)
if moduleAcc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleAccAddr)
@ -167,7 +168,8 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
return errorsmod.Wrap(err, "failed to track delegation")
}
// emit coin spent event
ctx.EventManager().EmitEvent(
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
types.NewCoinSpentEvent(delegatorAddr, amt),
)
@ -184,7 +186,7 @@ func (k BaseKeeper) DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr
// vesting and vested coins. The coins are then transferred from a ModuleAccount
// address to the delegator address. If any of the undelegation amounts are
// negative, an error is returned.
func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error {
moduleAcc := k.ak.GetAccount(ctx, moduleAccAddr)
if moduleAcc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleAccAddr)
@ -212,7 +214,7 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd
}
// GetSupply retrieves the Supply from store
func (k BaseKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
func (k BaseKeeper) GetSupply(ctx context.Context, denom string) sdk.Coin {
amt, err := k.Supply.Get(ctx, denom)
if err != nil {
return sdk.NewCoin(denom, math.ZeroInt())
@ -221,26 +223,26 @@ func (k BaseKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
}
// HasSupply checks if the supply coin exists in store.
func (k BaseKeeper) HasSupply(ctx sdk.Context, denom string) bool {
func (k BaseKeeper) HasSupply(ctx context.Context, denom string) bool {
has, err := k.Supply.Has(ctx, denom)
return has && err == nil
}
// GetDenomMetaData retrieves the denomination metadata. returns the metadata and true if the denom exists,
// false otherwise.
func (k BaseKeeper) GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool) {
func (k BaseKeeper) GetDenomMetaData(ctx context.Context, denom string) (types.Metadata, bool) {
m, err := k.BaseViewKeeper.DenomMetadata.Get(ctx, denom)
return m, err == nil
}
// HasDenomMetaData checks if the denomination metadata exists in store.
func (k BaseKeeper) HasDenomMetaData(ctx sdk.Context, denom string) bool {
func (k BaseKeeper) HasDenomMetaData(ctx context.Context, denom string) bool {
has, err := k.BaseViewKeeper.DenomMetadata.Has(ctx, denom)
return has && err == nil
}
// GetAllDenomMetaData retrieves all denominations metadata
func (k BaseKeeper) GetAllDenomMetaData(ctx sdk.Context) []types.Metadata {
func (k BaseKeeper) GetAllDenomMetaData(ctx context.Context) []types.Metadata {
denomMetaData := make([]types.Metadata, 0)
k.IterateAllDenomMetaData(ctx, func(metadata types.Metadata) bool {
denomMetaData = append(denomMetaData, metadata)
@ -253,14 +255,14 @@ func (k BaseKeeper) GetAllDenomMetaData(ctx sdk.Context) []types.Metadata {
// IterateAllDenomMetaData iterates over all the denominations metadata and
// provides the metadata to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseKeeper) IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool) {
func (k BaseKeeper) IterateAllDenomMetaData(ctx context.Context, cb func(types.Metadata) bool) {
_ = k.BaseViewKeeper.DenomMetadata.Walk(ctx, nil, func(_ string, metadata types.Metadata) bool {
return cb(metadata)
})
}
// SetDenomMetaData sets the denominations metadata
func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata) {
func (k BaseKeeper) SetDenomMetaData(ctx context.Context, denomMetaData types.Metadata) {
_ = k.BaseViewKeeper.DenomMetadata.Set(ctx, denomMetaData.Base, denomMetaData)
}
@ -268,7 +270,7 @@ func (k BaseKeeper) SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metada
// It will panic if the module account does not exist. An error is returned if
// the recipient address is black-listed or if sending the tokens fails.
func (k BaseKeeper) SendCoinsFromModuleToAccount(
ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error {
senderAddr := k.ak.GetModuleAddress(senderModule)
if senderAddr == nil {
@ -285,7 +287,7 @@ func (k BaseKeeper) SendCoinsFromModuleToAccount(
// SendCoinsFromModuleToModule transfers coins from a ModuleAccount to another.
// It will panic if either module account does not exist.
func (k BaseKeeper) SendCoinsFromModuleToModule(
ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins,
ctx context.Context, senderModule, recipientModule string, amt sdk.Coins,
) error {
senderAddr := k.ak.GetModuleAddress(senderModule)
if senderAddr == nil {
@ -303,7 +305,7 @@ func (k BaseKeeper) SendCoinsFromModuleToModule(
// SendCoinsFromAccountToModule transfers coins from an AccAddress to a ModuleAccount.
// It will panic if the module account does not exist.
func (k BaseKeeper) SendCoinsFromAccountToModule(
ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error {
recipientAcc := k.ak.GetModuleAccount(ctx, recipientModule)
if recipientAcc == nil {
@ -317,7 +319,7 @@ func (k BaseKeeper) SendCoinsFromAccountToModule(
// delegator account to a module account. It will panic if the module account
// does not exist or is unauthorized.
func (k BaseKeeper) DelegateCoinsFromAccountToModule(
ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins,
) error {
recipientAcc := k.ak.GetModuleAccount(ctx, recipientModule)
if recipientAcc == nil {
@ -335,7 +337,7 @@ func (k BaseKeeper) DelegateCoinsFromAccountToModule(
// them from a module account to the delegator account. It will panic if the
// module account does not exist or is unauthorized.
func (k BaseKeeper) UndelegateCoinsFromModuleToAccount(
ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins,
) error {
acc := k.ak.GetModuleAccount(ctx, senderModule)
if acc == nil {
@ -351,7 +353,9 @@ func (k BaseKeeper) UndelegateCoinsFromModuleToAccount(
// MintCoins creates new coins from thin air and adds it to the module account.
// It will panic if the module account does not exist or is unauthorized.
func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error {
func (k BaseKeeper) MintCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
err := k.mintCoinsRestrictionFn(ctx, amounts)
if err != nil {
k.logger.Error(fmt.Sprintf("Module %q attempted to mint coins %s it doesn't have permission for, error %v", moduleName, amounts, err))
@ -380,7 +384,7 @@ func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Co
k.logger.Debug("minted coins from module account", "amount", amounts.String(), "from", moduleName)
// emit mint event
ctx.EventManager().EmitEvent(
sdkCtx.EventManager().EmitEvent(
types.NewCoinMintEvent(acc.GetAddress(), amounts),
)
@ -389,7 +393,7 @@ func (k BaseKeeper) MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Co
// BurnCoins burns coins deletes coins from the balance of the module account.
// It will panic if the module account does not exist or is unauthorized.
func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error {
func (k BaseKeeper) BurnCoins(ctx context.Context, moduleName string, amounts sdk.Coins) error {
acc := k.ak.GetModuleAccount(ctx, moduleName)
if acc == nil {
panic(errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "module account %s does not exist", moduleName))
@ -413,7 +417,8 @@ func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Co
k.logger.Debug("burned tokens from module account", "amount", amounts.String(), "from", moduleName)
// emit burn event
ctx.EventManager().EmitEvent(
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
types.NewCoinBurnEvent(acc.GetAddress(), amounts),
)
@ -421,7 +426,7 @@ func (k BaseKeeper) BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Co
}
// setSupply sets the supply for the given coin
func (k BaseKeeper) setSupply(ctx sdk.Context, coin sdk.Coin) {
func (k BaseKeeper) setSupply(ctx context.Context, coin sdk.Coin) {
// Bank invariants and IBC requires to remove zero coins.
if coin.IsZero() {
_ = k.Supply.Remove(ctx, coin.Denom)
@ -431,7 +436,7 @@ func (k BaseKeeper) setSupply(ctx sdk.Context, coin sdk.Coin) {
}
// trackDelegation tracks the delegation of the given account if it is a vesting account
func (k BaseKeeper) trackDelegation(ctx sdk.Context, addr sdk.AccAddress, balance, amt sdk.Coins) error {
func (k BaseKeeper) trackDelegation(ctx context.Context, addr sdk.AccAddress, balance, amt sdk.Coins) error {
acc := k.ak.GetAccount(ctx, addr)
if acc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
@ -440,7 +445,8 @@ func (k BaseKeeper) trackDelegation(ctx sdk.Context, addr sdk.AccAddress, balanc
vacc, ok := acc.(types.VestingAccount)
if ok {
// TODO: return error on account.TrackDelegation
vacc.TrackDelegation(ctx.BlockHeader().Time, balance, amt)
sdkCtx := sdk.UnwrapSDKContext(ctx)
vacc.TrackDelegation(sdkCtx.BlockHeader().Time, balance, amt)
k.ak.SetAccount(ctx, acc)
}
@ -448,7 +454,7 @@ func (k BaseKeeper) trackDelegation(ctx sdk.Context, addr sdk.AccAddress, balanc
}
// trackUndelegation trakcs undelegation of the given account if it is a vesting account
func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseKeeper) trackUndelegation(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error {
acc := k.ak.GetAccount(ctx, addr)
if acc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)
@ -467,7 +473,7 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt
// IterateTotalSupply iterates over the total supply calling the given cb (callback) function
// with the balance of each coin.
// The iteration stops if the callback returns true.
func (k BaseViewKeeper) IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bool) {
func (k BaseViewKeeper) IterateTotalSupply(ctx context.Context, cb func(sdk.Coin) bool) {
_ = k.Supply.Walk(ctx, nil, func(s string, m math.Int) bool {
return cb(sdk.NewCoin(s, m))
})

View File

@ -1,6 +1,7 @@
package keeper_test
import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
@ -19,6 +20,7 @@ import (
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
@ -88,7 +90,7 @@ func getIBCHash(path, baseDenom string) []byte {
return hash[:]
}
func addIBCMetadata(ctx sdk.Context, k keeper.BaseKeeper) {
func addIBCMetadata(ctx context.Context, k keeper.BaseKeeper) {
metadata := banktypes.Metadata{
Description: fmt.Sprintf(metaDataDescription, ibcPath),
DenomUnits: []*banktypes.DenomUnit{
@ -108,7 +110,7 @@ func addIBCMetadata(ctx sdk.Context, k keeper.BaseKeeper) {
type KeeperTestSuite struct {
suite.Suite
ctx sdk.Context
ctx context.Context
bankKeeper keeper.BaseKeeper
authKeeper *banktestutil.MockAccountKeeper
@ -128,6 +130,8 @@ func (suite *KeeperTestSuite) SetupTest() {
ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
encCfg := moduletestutil.MakeTestEncodingConfig()
storeService := runtime.NewKVStoreService(key)
// gomock initializations
ctrl := gomock.NewController(suite.T())
authKeeper := banktestutil.NewMockAccountKeeper(ctrl)
@ -136,7 +140,7 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.authKeeper = authKeeper
suite.bankKeeper = keeper.NewBaseKeeper(
encCfg.Codec,
key,
storeService,
suite.authKeeper,
map[string]bool{accAddrs[4].String(): true},
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
@ -188,7 +192,7 @@ func (suite *KeeperTestSuite) mockSendCoinsFromAccountToModule(acc *authtypes.Ba
suite.authKeeper.EXPECT().HasAccount(suite.ctx, moduleAcc.GetAddress()).Return(true)
}
func (suite *KeeperTestSuite) mockSendCoins(ctx sdk.Context, sender sdk.AccountI, receiver sdk.AccAddress) {
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)
}
@ -215,7 +219,7 @@ func (suite *KeeperTestSuite) mockSpendableCoins(ctx sdk.Context, acc sdk.Accoun
suite.authKeeper.EXPECT().GetAccount(ctx, acc.GetAddress()).Return(acc)
}
func (suite *KeeperTestSuite) mockDelegateCoins(ctx sdk.Context, acc, mAcc sdk.AccountI) {
func (suite *KeeperTestSuite) mockDelegateCoins(ctx context.Context, acc, mAcc sdk.AccountI) {
vacc, ok := acc.(banktypes.VestingAccount)
if ok {
suite.authKeeper.EXPECT().SetAccount(ctx, vacc)
@ -224,7 +228,7 @@ func (suite *KeeperTestSuite) mockDelegateCoins(ctx sdk.Context, acc, mAcc sdk.A
suite.authKeeper.EXPECT().GetAccount(ctx, mAcc.GetAddress()).Return(mAcc)
}
func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx sdk.Context, acc, mAcc sdk.AccountI) {
func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx context.Context, acc, mAcc sdk.AccountI) {
vacc, ok := acc.(banktypes.VestingAccount)
if ok {
suite.authKeeper.EXPECT().SetAccount(ctx, vacc)
@ -235,10 +239,11 @@ func (suite *KeeperTestSuite) mockUnDelegateCoins(ctx sdk.Context, acc, mAcc sdk
}
func (suite *KeeperTestSuite) TestGetAuthority() {
storeService := runtime.NewKVStoreService(storetypes.NewKVStoreKey(banktypes.StoreKey))
NewKeeperWithAuthority := func(authority string) keeper.BaseKeeper {
return keeper.NewBaseKeeper(
moduletestutil.MakeTestEncodingConfig().Codec,
storetypes.NewKVStoreKey(banktypes.StoreKey),
storeService,
nil,
nil,
authority,
@ -360,7 +365,9 @@ func (suite *KeeperTestSuite) TestSupply_SendCoins() {
require.Equal(initCoins, keeper.GetAllBalances(ctx, baseAcc.GetAddress()))
suite.mockSendCoinsFromAccountToModule(baseAcc, burnerAcc)
require.NoError(keeper.SendCoinsFromAccountToModule(ctx, baseAcc.GetAddress(), authtypes.Burner, initCoins))
sdkCtx := sdk.UnwrapSDKContext(ctx)
require.NoError(keeper.SendCoinsFromAccountToModule(sdkCtx, baseAcc.GetAddress(), authtypes.Burner, initCoins))
require.Equal(sdk.NewCoins(), keeper.GetAllBalances(ctx, baseAcc.GetAddress()))
require.Equal(initCoins, keeper.GetAllBalances(ctx, burnerAcc.GetAddress()))
}
@ -471,7 +478,7 @@ func (suite *KeeperTestSuite) TestSendCoinsNewAccount() {
balances := sdk.NewCoins(newFooCoin(100), newBarCoin(50))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0])
acc1Balances := suite.bankKeeper.GetAllBalances(ctx, accAddrs[0])
@ -499,7 +506,7 @@ func (suite *KeeperTestSuite) TestInputOutputNewAccount() {
balances := sdk.NewCoins(newFooCoin(100), newBarCoin(50))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
acc1Balances := suite.bankKeeper.GetAllBalances(ctx, accAddrs[0])
require.Equal(balances, acc1Balances)
@ -541,7 +548,7 @@ func (suite *KeeperTestSuite) TestInputOutputCoins() {
require.Error(suite.bankKeeper.InputOutputCoins(ctx, input, outputs))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
insufficientInput := banktypes.Input{
Address: accAddrs[0].String(),
@ -576,14 +583,14 @@ func (suite *KeeperTestSuite) TestSendCoins() {
acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0])
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], balances))
sendAmt := sdk.NewCoins(newFooCoin(50), newBarCoin(25))
suite.authKeeper.EXPECT().GetAccount(suite.ctx, accAddrs[0]).Return(acc0)
require.Error(suite.bankKeeper.SendCoins(ctx, accAddrs[0], accAddrs[1], sendAmt))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
suite.mockSendCoins(ctx, acc0, accAddrs[1])
require.NoError(suite.bankKeeper.SendCoins(ctx, accAddrs[0], accAddrs[1], sendAmt))
@ -618,7 +625,7 @@ func (suite *KeeperTestSuite) TestSendCoins_Invalid_SendLockedCoins() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[1])
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, accAddrs[1], balances))
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, accAddrs[1], balances))
suite.authKeeper.EXPECT().GetAccount(suite.ctx, accAddrs[0]).Return(vacc)
suite.Require().Error(suite.bankKeeper.SendCoins(suite.ctx, accAddrs[0], accAddrs[1], sendCoins))
@ -636,7 +643,7 @@ func (suite *KeeperTestSuite) TestValidateBalance() {
balances := sdk.NewCoins(newFooCoin(100))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
suite.mockValidateBalance(acc0)
require.NoError(suite.bankKeeper.ValidateBalance(ctx, accAddrs[0]))
@ -645,7 +652,7 @@ func (suite *KeeperTestSuite) TestValidateBalance() {
vacc := vesting.NewContinuousVestingAccount(acc1, balances.Add(balances...), now.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], balances))
suite.mockValidateBalance(vacc)
require.Error(suite.bankKeeper.ValidateBalance(ctx, accAddrs[1]))
@ -703,20 +710,20 @@ func (suite *KeeperTestSuite) TestHasBalance() {
require.False(suite.bankKeeper.HasBalance(ctx, accAddrs[0], newFooCoin(99)))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], balances))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], balances))
require.False(suite.bankKeeper.HasBalance(ctx, accAddrs[0], newFooCoin(101)))
require.True(suite.bankKeeper.HasBalance(ctx, accAddrs[0], newFooCoin(100)))
require.True(suite.bankKeeper.HasBalance(ctx, accAddrs[0], newFooCoin(1)))
}
func (suite *KeeperTestSuite) TestMsgSendEvents() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0])
newCoins := sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], newCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], newCoins))
suite.mockSendCoins(ctx, acc0, accAddrs[1])
require.NoError(suite.bankKeeper.SendCoins(ctx, accAddrs[0], accAddrs[1], newCoins))
@ -754,7 +761,7 @@ func (suite *KeeperTestSuite) TestMsgSendEvents() {
}
func (suite *KeeperTestSuite) TestMsgMultiSendEvents() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
acc0 := authtypes.NewBaseAccountWithAddress(accAddrs[0])
@ -780,7 +787,7 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() {
// Set addr's coins but not accAddrs[1]'s coins
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100))))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50), sdk.NewInt64Coin(barDenom, 100))))
suite.mockInputOutputCoins([]sdk.AccountI{acc0}, accAddrs[2:4])
require.NoError(suite.bankKeeper.InputOutputCoins(ctx, input, outputs))
@ -800,11 +807,11 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() {
// Set addr's coins and accAddrs[1]'s coins
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))))
newCoins = sdk.NewCoins(sdk.NewInt64Coin(fooDenom, 50))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))))
newCoins2 = sdk.NewCoins(sdk.NewInt64Coin(barDenom, 100))
suite.mockInputOutputCoins([]sdk.AccountI{acc0}, accAddrs[2:4])
@ -843,7 +850,7 @@ func (suite *KeeperTestSuite) TestMsgMultiSendEvents() {
}
func (suite *KeeperTestSuite) TestSpendableCoins() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
endTime := now.Add(24 * time.Hour)
@ -856,10 +863,10 @@ func (suite *KeeperTestSuite) TestSpendableCoins() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], origCoins))
suite.mockSpendableCoins(ctx, acc1)
require.Equal(origCoins, suite.bankKeeper.SpendableCoins(ctx, accAddrs[1]))
@ -876,7 +883,7 @@ func (suite *KeeperTestSuite) TestSpendableCoins() {
}
func (suite *KeeperTestSuite) TestVestingAccountSend() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
endTime := now.Add(24 * time.Hour)
@ -888,7 +895,7 @@ func (suite *KeeperTestSuite) TestVestingAccountSend() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, now.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
// require that no coins be sendable at the beginning of the vesting schedule
suite.authKeeper.EXPECT().GetAccount(ctx, accAddrs[0]).Return(vacc)
@ -896,7 +903,7 @@ func (suite *KeeperTestSuite) TestVestingAccountSend() {
// receive some coins
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], sendCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], sendCoins))
// require that all vested coins are spendable plus any received
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
suite.mockSendCoins(ctx, vacc, accAddrs[1])
@ -905,7 +912,7 @@ func (suite *KeeperTestSuite) TestVestingAccountSend() {
}
func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
origCoins := sdk.NewCoins(sdk.NewInt64Coin("stake", 100))
@ -921,7 +928,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() {
vacc := vesting.NewPeriodicVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), periods)
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
// require that no coins be sendable at the beginning of the vesting schedule
suite.authKeeper.EXPECT().GetAccount(ctx, accAddrs[0]).Return(vacc)
@ -929,7 +936,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() {
// receive some coins
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], sendCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], sendCoins))
// require that all vested coins are spendable plus any received
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -939,7 +946,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountSend() {
}
func (suite *KeeperTestSuite) TestVestingAccountReceive() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
endTime := now.Add(24 * time.Hour)
@ -952,10 +959,10 @@ func (suite *KeeperTestSuite) TestVestingAccountReceive() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], origCoins))
// send some coins to the vesting account
suite.mockSendCoins(ctx, acc1, accAddrs[0])
@ -971,7 +978,7 @@ func (suite *KeeperTestSuite) TestVestingAccountReceive() {
}
func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
@ -989,10 +996,10 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() {
vacc := vesting.NewPeriodicVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), periods)
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], origCoins))
// send some coins to the vesting account
suite.mockSendCoins(ctx, acc1, accAddrs[0])
@ -1008,7 +1015,7 @@ func (suite *KeeperTestSuite) TestPeriodicVestingAccountReceive() {
}
func (suite *KeeperTestSuite) TestDelegateCoins() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
endTime := now.Add(24 * time.Hour)
@ -1021,10 +1028,10 @@ func (suite *KeeperTestSuite) TestDelegateCoins() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], origCoins))
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -1065,7 +1072,7 @@ func (suite *KeeperTestSuite) TestDelegateCoins_Invalid() {
}
func (suite *KeeperTestSuite) TestUndelegateCoins() {
ctx := suite.ctx
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
now := cmttime.Now()
endTime := now.Add(24 * time.Hour)
@ -1078,10 +1085,10 @@ func (suite *KeeperTestSuite) TestUndelegateCoins() {
vacc := vesting.NewContinuousVestingAccount(acc0, origCoins, ctx.BlockHeader().Time.Unix(), endTime.Unix())
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockFundAccount(accAddrs[1])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[1], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[1], origCoins))
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
@ -1130,7 +1137,7 @@ func (suite *KeeperTestSuite) TestUndelegateCoins_Invalid() {
require.Error(suite.bankKeeper.UndelegateCoins(ctx, holderAcc.GetAddress(), accAddrs[0], delCoins))
suite.mockFundAccount(accAddrs[0])
require.NoError(banktestutil.FundAccount(suite.bankKeeper, ctx, accAddrs[0], origCoins))
require.NoError(banktestutil.FundAccount(ctx, suite.bankKeeper, accAddrs[0], origCoins))
suite.mockDelegateCoins(ctx, acc0, holderAcc)
require.NoError(suite.bankKeeper.DelegateCoins(ctx, accAddrs[0], holderAcc.GetAddress(), delCoins))
@ -1230,7 +1237,9 @@ func (suite *KeeperTestSuite) TestBalanceTrackingEvents() {
balances := make(map[string]sdk.Coins)
for _, e := range suite.ctx.EventManager().ABCIEvents() {
ctx := sdk.UnwrapSDKContext(suite.ctx)
for _, e := range ctx.EventManager().ABCIEvents() {
switch e.Type {
case banktypes.EventTypeCoinBurn:
burnedCoins, err := sdk.ParseCoinsNormalized(e.Attributes[1].Value)
@ -1309,7 +1318,7 @@ func (suite *KeeperTestSuite) getTestMetadata() []banktypes.Metadata {
}
func (suite *KeeperTestSuite) TestMintCoinRestrictions() {
type BankMintingRestrictionFn func(ctx sdk.Context, coins sdk.Coins) error
type BankMintingRestrictionFn func(ctx context.Context, coins sdk.Coins) error
require := suite.Require()
type testCase struct {
@ -1324,7 +1333,7 @@ func (suite *KeeperTestSuite) TestMintCoinRestrictions() {
}{
{
"restriction",
func(_ sdk.Context, coins sdk.Coins) error {
func(_ context.Context, coins sdk.Coins) error {
for _, coin := range coins {
if coin.Denom != fooDenom {
return fmt.Errorf("Module %s only has perms for minting %s coins, tried minting %s coins", banktypes.ModuleName, fooDenom, coin.Denom)
@ -1734,7 +1743,8 @@ func (ms mockSubspace) GetParamSet(ctx sdk.Context, ps exported.ParamSet) {
}
func (suite *KeeperTestSuite) TestMigrator_Migrate3to4() {
ctx, bankKeeper := suite.ctx, suite.bankKeeper
bankKeeper := suite.bankKeeper
ctx := sdk.UnwrapSDKContext(suite.ctx)
require := suite.Require()
for _, def := range []bool{true, false} {

View File

@ -21,15 +21,15 @@ func NewMigrator(keeper BaseKeeper, legacySubspace exported.Subspace) Migrator {
// Migrate1to2 migrates from version 1 to 2.
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
return v2.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
}
// Migrate2to3 migrates x/bank storage from version 2 to 3.
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
return v3.MigrateStore(ctx, m.keeper.storeService, m.keeper.cdc)
}
// Migrate3to4 migrates x/bank storage from version 3 to 4.
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
return v4.MigrateStore(ctx, m.keeper.storeService, m.legacySubspace, m.keeper.cdc)
}

View File

@ -1,13 +1,14 @@
package keeper
import (
"context"
"fmt"
"cosmossdk.io/collections"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/telemetry"
@ -21,22 +22,22 @@ import (
type SendKeeper interface {
ViewKeeper
InputOutputCoins(ctx sdk.Context, inputs types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
InputOutputCoins(ctx context.Context, inputs types.Input, outputs []types.Output) error
SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
GetParams(ctx sdk.Context) types.Params
SetParams(ctx sdk.Context, params types.Params) error
GetParams(ctx context.Context) types.Params
SetParams(ctx context.Context, params types.Params) error
IsSendEnabledDenom(ctx sdk.Context, denom string) bool
GetSendEnabledEntry(ctx sdk.Context, denom string) (types.SendEnabled, bool)
SetSendEnabled(ctx sdk.Context, denom string, value bool)
SetAllSendEnabled(ctx sdk.Context, sendEnableds []*types.SendEnabled)
DeleteSendEnabled(ctx sdk.Context, denoms ...string)
IterateSendEnabledEntries(ctx sdk.Context, cb func(denom string, sendEnabled bool) (stop bool))
GetAllSendEnabledEntries(ctx sdk.Context) []types.SendEnabled
IsSendEnabledDenom(ctx context.Context, denom string) bool
GetSendEnabledEntry(ctx context.Context, denom string) (types.SendEnabled, bool)
SetSendEnabled(ctx context.Context, denom string, value bool)
SetAllSendEnabled(ctx context.Context, sendEnableds []*types.SendEnabled)
DeleteSendEnabled(ctx context.Context, denoms ...string)
IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) (stop bool))
GetAllSendEnabledEntries(ctx context.Context) []types.SendEnabled
IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
IsSendEnabledCoin(ctx context.Context, coin sdk.Coin) bool
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
BlockedAddr(addr sdk.AccAddress) bool
GetBlockedAddresses() map[string]bool
@ -51,10 +52,10 @@ var _ SendKeeper = (*BaseSendKeeper)(nil)
type BaseSendKeeper struct {
BaseViewKeeper
cdc codec.BinaryCodec
ak types.AccountKeeper
storeKey storetypes.StoreKey
logger log.Logger
cdc codec.BinaryCodec
ak types.AccountKeeper
storeService store.KVStoreService
logger log.Logger
// list of addresses that are restricted from receiving transactions
blockedAddrs map[string]bool
@ -66,7 +67,7 @@ type BaseSendKeeper struct {
func NewBaseSendKeeper(
cdc codec.BinaryCodec,
storeKey storetypes.StoreKey,
storeService store.KVStoreService,
ak types.AccountKeeper,
blockedAddrs map[string]bool,
authority string,
@ -77,10 +78,10 @@ func NewBaseSendKeeper(
}
return BaseSendKeeper{
BaseViewKeeper: NewBaseViewKeeper(cdc, storeKey, ak, logger),
BaseViewKeeper: NewBaseViewKeeper(cdc, storeService, ak, logger),
cdc: cdc,
ak: ak,
storeKey: storeKey,
storeService: storeService,
blockedAddrs: blockedAddrs,
authority: authority,
logger: logger,
@ -93,7 +94,7 @@ func (k BaseSendKeeper) GetAuthority() string {
}
// GetParams returns the total set of bank parameters.
func (k BaseSendKeeper) GetParams(ctx sdk.Context) (params types.Params) {
func (k BaseSendKeeper) GetParams(ctx context.Context) (params types.Params) {
p, _ := k.Params.Get(ctx)
return p
}
@ -101,7 +102,7 @@ func (k BaseSendKeeper) GetParams(ctx sdk.Context) (params types.Params) {
// SetParams sets the total set of bank parameters.
//
// Note: params.SendEnabled is deprecated but it should be here regardless.
func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) error {
func (k BaseSendKeeper) SetParams(ctx context.Context, params types.Params) error {
// Normally SendEnabled is deprecated but we still support it for backwards
// compatibility. Using params.Validate() would fail due to the SendEnabled
// deprecation.
@ -117,7 +118,7 @@ func (k BaseSendKeeper) SetParams(ctx sdk.Context, params types.Params) error {
// InputOutputCoins performs multi-send functionality. It accepts an
// input that corresponds to a series of outputs. It returns an error if the
// input and outputs don't line up or if any single transfer of tokens fails.
func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, outputs []types.Output) error {
func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, outputs []types.Output) error {
// Safety check ensuring that when sending coins the keeper must maintain the
// Check supply invariant and validity of Coins.
if err := types.ValidateInputOutputs(input, outputs); err != nil {
@ -134,7 +135,8 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, out
return err
}
ctx.EventManager().EmitEvent(
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, input.Address),
@ -151,7 +153,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, out
return err
}
ctx.EventManager().EmitEvent(
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, out.Address),
@ -175,7 +177,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, input types.Input, out
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseSendKeeper) SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error {
err := k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
@ -198,7 +200,8 @@ func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddre
// bech32 encoding is expensive! Only do it once for fromAddr
fromAddrString := fromAddr.String()
ctx.EventManager().EmitEvents(sdk.Events{
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, toAddr.String()),
@ -217,7 +220,7 @@ func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr, toAddr sdk.AccAddre
// subUnlockedCoins removes the unlocked amt coins of the given account. An error is
// returned if the resulting balance is negative or the initial amount is invalid.
// A coin_spent event is emitted after.
func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseSendKeeper) subUnlockedCoins(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error {
if !amt.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
@ -249,7 +252,8 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, a
}
}
ctx.EventManager().EmitEvent(
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
types.NewCoinSpentEvent(addr, amt),
)
@ -258,7 +262,7 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, a
// addCoins increase the addr balance by the given amt. Fails if the provided
// amt is invalid. It emits a coin received event.
func (k BaseSendKeeper) addCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) error {
func (k BaseSendKeeper) addCoins(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) error {
if !amt.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, amt.String())
}
@ -274,7 +278,8 @@ func (k BaseSendKeeper) addCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.C
}
// emit coin received event
ctx.EventManager().EmitEvent(
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
types.NewCoinReceivedEvent(addr, amt),
)
@ -282,7 +287,7 @@ func (k BaseSendKeeper) addCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.C
}
// setBalance sets the coin balance for an account by address.
func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance sdk.Coin) error {
func (k BaseSendKeeper) setBalance(ctx context.Context, addr sdk.AccAddress, balance sdk.Coin) error {
if !balance.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, balance.String())
}
@ -301,7 +306,7 @@ func (k BaseSendKeeper) setBalance(ctx sdk.Context, addr sdk.AccAddress, balance
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
// if any of the coins are not configured for sending. Returns nil if sending is
// enabled for all provided coins.
func (k BaseSendKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error {
func (k BaseSendKeeper) IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error {
if len(coins) == 0 {
return nil
}
@ -318,7 +323,7 @@ func (k BaseSendKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) e
}
// IsSendEnabledCoin returns the current SendEnabled status of the provided coin's denom
func (k BaseSendKeeper) IsSendEnabledCoin(ctx sdk.Context, coin sdk.Coin) bool {
func (k BaseSendKeeper) IsSendEnabledCoin(ctx context.Context, coin sdk.Coin) bool {
return k.IsSendEnabledDenom(ctx, coin.Denom)
}
@ -334,13 +339,13 @@ func (k BaseSendKeeper) GetBlockedAddresses() map[string]bool {
}
// IsSendEnabledDenom returns the current SendEnabled status of the provided denom.
func (k BaseSendKeeper) IsSendEnabledDenom(ctx sdk.Context, denom string) bool {
func (k BaseSendKeeper) IsSendEnabledDenom(ctx context.Context, denom string) bool {
return k.getSendEnabledOrDefault(ctx, denom, k.GetParams(ctx).DefaultSendEnabled)
}
// GetSendEnabledEntry gets a SendEnabled entry for the given denom.
// The second return argument is true iff a specific entry exists for the given denom.
func (k BaseSendKeeper) GetSendEnabledEntry(ctx sdk.Context, denom string) (types.SendEnabled, bool) {
func (k BaseSendKeeper) GetSendEnabledEntry(ctx context.Context, denom string) (types.SendEnabled, bool) {
sendEnabled, found := k.getSendEnabled(ctx, denom)
if !found {
return types.SendEnabled{}, false
@ -350,12 +355,12 @@ func (k BaseSendKeeper) GetSendEnabledEntry(ctx sdk.Context, denom string) (type
}
// SetSendEnabled sets the SendEnabled flag for a denom to the provided value.
func (k BaseSendKeeper) SetSendEnabled(ctx sdk.Context, denom string, value bool) {
func (k BaseSendKeeper) SetSendEnabled(ctx context.Context, denom string, value bool) {
_ = k.SendEnabled.Set(ctx, denom, value)
}
// SetAllSendEnabled sets all the provided SendEnabled entries in the bank store.
func (k BaseSendKeeper) SetAllSendEnabled(ctx sdk.Context, entries []*types.SendEnabled) {
func (k BaseSendKeeper) SetAllSendEnabled(ctx context.Context, entries []*types.SendEnabled) {
for _, entry := range entries {
_ = k.SendEnabled.Set(ctx, entry.Denom, entry.Enabled)
}
@ -363,20 +368,20 @@ func (k BaseSendKeeper) SetAllSendEnabled(ctx sdk.Context, entries []*types.Send
// DeleteSendEnabled deletes the SendEnabled flags for one or more denoms.
// If a denom is provided that doesn't have a SendEnabled entry, it is ignored.
func (k BaseSendKeeper) DeleteSendEnabled(ctx sdk.Context, denoms ...string) {
func (k BaseSendKeeper) DeleteSendEnabled(ctx context.Context, denoms ...string) {
for _, denom := range denoms {
_ = k.SendEnabled.Remove(ctx, denom)
}
}
// IterateSendEnabledEntries iterates over all the SendEnabled entries.
func (k BaseSendKeeper) IterateSendEnabledEntries(ctx sdk.Context, cb func(denom string, sendEnabled bool) bool) {
func (k BaseSendKeeper) IterateSendEnabledEntries(ctx context.Context, cb func(denom string, sendEnabled bool) bool) {
_ = k.SendEnabled.Walk(ctx, nil, cb)
}
// GetAllSendEnabledEntries gets all the SendEnabled entries that are stored.
// Any denominations not returned use the default value (set in Params).
func (k BaseSendKeeper) GetAllSendEnabledEntries(ctx sdk.Context) []types.SendEnabled {
func (k BaseSendKeeper) GetAllSendEnabledEntries(ctx context.Context) []types.SendEnabled {
var rv []types.SendEnabled
k.IterateSendEnabledEntries(ctx, func(denom string, sendEnabled bool) bool {
rv = append(rv, types.SendEnabled{Denom: denom, Enabled: sendEnabled})
@ -396,7 +401,7 @@ func (k BaseSendKeeper) GetAllSendEnabledEntries(ctx sdk.Context) []types.SendEn
// if !found {
// sendEnabled = DefaultSendEnabled
// }
func (k BaseSendKeeper) getSendEnabled(ctx sdk.Context, denom string) (bool, bool) {
func (k BaseSendKeeper) getSendEnabled(ctx context.Context, denom string) (bool, bool) {
has, err := k.SendEnabled.Has(ctx, denom)
if err != nil || !has {
return false, false
@ -412,7 +417,7 @@ func (k BaseSendKeeper) getSendEnabled(ctx sdk.Context, denom string) (bool, boo
// getSendEnabledOrDefault gets the SendEnabled value for a denom. If it's not
// in the store, this will return defaultVal.
func (k BaseSendKeeper) getSendEnabledOrDefault(ctx sdk.Context, denom string, defaultVal bool) bool {
func (k BaseSendKeeper) getSendEnabledOrDefault(ctx context.Context, denom string, defaultVal bool) bool {
sendEnabled, found := k.getSendEnabled(ctx, denom)
if found {
return sendEnabled

View File

@ -1,21 +1,20 @@
package keeper
import (
"context"
"fmt"
"cosmossdk.io/collections/indexes"
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"github.com/cockroachdb/errors"
"cosmossdk.io/collections"
"github.com/cosmos/cosmos-sdk/runtime"
"cosmossdk.io/math"
errorsmod "cosmossdk.io/errors"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -28,18 +27,18 @@ var _ ViewKeeper = (*BaseViewKeeper)(nil)
// ViewKeeper defines a module interface that facilitates read only access to
// account balances.
type ViewKeeper interface {
ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error
HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool
ValidateBalance(ctx context.Context, addr sdk.AccAddress) error
HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAccountsBalances(ctx sdk.Context) []types.Balance
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoin(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetAccountsBalances(ctx context.Context) []types.Balance
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx sdk.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
IterateAccountBalances(ctx context.Context, addr sdk.AccAddress, cb func(coin sdk.Coin) (stop bool))
IterateAllBalances(ctx context.Context, cb func(address sdk.AccAddress, coin sdk.Coin) (stop bool))
}
func newBalancesIndexes(sb *collections.SchemaBuilder) BalancesIndexes {
@ -61,10 +60,10 @@ func (b BalancesIndexes) IndexesList() []collections.Index[collections.Pair[sdk.
// BaseViewKeeper implements a read only keeper implementation of ViewKeeper.
type BaseViewKeeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
ak types.AccountKeeper
logger log.Logger
cdc codec.BinaryCodec
storeService store.KVStoreService
ak types.AccountKeeper
logger log.Logger
Schema collections.Schema
Supply collections.Map[string, math.Int]
@ -75,11 +74,11 @@ type BaseViewKeeper struct {
}
// NewBaseViewKeeper returns a new BaseViewKeeper.
func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak types.AccountKeeper, logger log.Logger) BaseViewKeeper {
sb := collections.NewSchemaBuilder(runtime.NewKVStoreService(storeKey.(*storetypes.KVStoreKey)))
func NewBaseViewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, ak types.AccountKeeper, logger log.Logger) BaseViewKeeper {
sb := collections.NewSchemaBuilder(storeService)
k := BaseViewKeeper{
cdc: cdc,
storeKey: storeKey,
storeService: storeService,
ak: ak,
logger: logger,
Supply: collections.NewMap(sb, types.SupplyKey, "supply", collections.StringKey, sdk.IntValue),
@ -98,7 +97,7 @@ func NewBaseViewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak t
}
// HasBalance returns whether or not an account has at least amt balance.
func (k BaseViewKeeper) HasBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coin) bool {
func (k BaseViewKeeper) HasBalance(ctx context.Context, addr sdk.AccAddress, amt sdk.Coin) bool {
return k.GetBalance(ctx, addr, amt.Denom).IsGTE(amt)
}
@ -108,7 +107,7 @@ func (k BaseViewKeeper) Logger() log.Logger {
}
// GetAllBalances returns all the account balances for the given account address.
func (k BaseViewKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
func (k BaseViewKeeper) GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins {
balances := sdk.NewCoins()
k.IterateAccountBalances(ctx, addr, func(balance sdk.Coin) bool {
balances = balances.Add(balance)
@ -119,7 +118,7 @@ func (k BaseViewKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk
}
// GetAccountsBalances returns all the accounts balances from the store.
func (k BaseViewKeeper) GetAccountsBalances(ctx sdk.Context) []types.Balance {
func (k BaseViewKeeper) GetAccountsBalances(ctx context.Context) []types.Balance {
balances := make([]types.Balance, 0)
mapAddressToBalancesIdx := make(map[string]int)
@ -146,7 +145,7 @@ func (k BaseViewKeeper) GetAccountsBalances(ctx sdk.Context) []types.Balance {
// GetBalance returns the balance of a specific denomination for a given account
// by address.
func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
func (k BaseViewKeeper) GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin {
amt, err := k.Balances.Get(ctx, collections.Join(addr, denom))
if err != nil {
return sdk.NewCoin(denom, sdk.ZeroInt())
@ -157,7 +156,7 @@ func (k BaseViewKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom s
// IterateAccountBalances iterates over the balances of a single account and
// provides the token balance to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) {
func (k BaseViewKeeper) IterateAccountBalances(ctx context.Context, addr sdk.AccAddress, cb func(sdk.Coin) bool) {
err := k.Balances.Walk(ctx, collections.NewPrefixedPairRange[sdk.AccAddress, string](addr), func(key collections.Pair[sdk.AccAddress, string], value math.Int) bool {
return cb(sdk.NewCoin(key.K2(), value))
})
@ -169,7 +168,7 @@ func (k BaseViewKeeper) IterateAccountBalances(ctx sdk.Context, addr sdk.AccAddr
// IterateAllBalances iterates over all the balances of all accounts and
// denominations that are provided to a callback. If true is returned from the
// callback, iteration is halted.
func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddress, sdk.Coin) bool) {
func (k BaseViewKeeper) IterateAllBalances(ctx context.Context, cb func(sdk.AccAddress, sdk.Coin) bool) {
err := k.Balances.Walk(ctx, nil, func(key collections.Pair[sdk.AccAddress, string], value math.Int) bool {
return cb(key.K1(), sdk.NewCoin(key.K2(), value))
})
@ -182,12 +181,13 @@ func (k BaseViewKeeper) IterateAllBalances(ctx sdk.Context, cb func(sdk.AccAddre
// account by address. For standard accounts, the result will always be no coins.
// For vesting accounts, LockedCoins is delegated to the concrete vesting account
// type.
func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
func (k BaseViewKeeper) LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins {
acc := k.ak.GetAccount(ctx, addr)
if acc != nil {
vacc, ok := acc.(types.VestingAccount)
if ok {
return vacc.LockedCoins(ctx.BlockTime())
sdkCtx := sdk.UnwrapSDKContext(ctx)
return vacc.LockedCoins(sdkCtx.BlockTime())
}
}
@ -197,7 +197,7 @@ func (k BaseViewKeeper) LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Co
// SpendableCoins returns the total balances of spendable coins for an account
// by address. If the account has no spendable coins, an empty Coins slice is
// returned.
func (k BaseViewKeeper) SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins {
func (k BaseViewKeeper) SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins {
spendable, _ := k.spendableCoins(ctx, addr)
return spendable
}
@ -205,7 +205,7 @@ func (k BaseViewKeeper) SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk
// SpendableCoin returns the balance of specific denomination of spendable coins
// for an account by address. If the account has no spendable coin, a zero Coin
// is returned.
func (k BaseViewKeeper) SpendableCoin(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
func (k BaseViewKeeper) SpendableCoin(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin {
balance := k.GetBalance(ctx, addr, denom)
locked := k.LockedCoins(ctx, addr)
return balance.SubAmount(locked.AmountOf(denom))
@ -213,7 +213,7 @@ func (k BaseViewKeeper) SpendableCoin(ctx sdk.Context, addr sdk.AccAddress, deno
// spendableCoins returns the coins the given address can spend alongside the total amount of coins it holds.
// It exists for gas efficiency, in order to avoid to have to get balance multiple times.
func (k BaseViewKeeper) spendableCoins(ctx sdk.Context, addr sdk.AccAddress) (spendable, total sdk.Coins) {
func (k BaseViewKeeper) spendableCoins(ctx context.Context, addr sdk.AccAddress) (spendable, total sdk.Coins) {
total = k.GetAllBalances(ctx, addr)
locked := k.LockedCoins(ctx, addr)
@ -233,7 +233,7 @@ func (k BaseViewKeeper) spendableCoins(ctx sdk.Context, addr sdk.AccAddress) (sp
// CONTRACT: ValidateBalance should only be called upon genesis state. In the
// case of vesting accounts, balances may change in a valid manner that would
// otherwise yield an error from this call.
func (k BaseViewKeeper) ValidateBalance(ctx sdk.Context, addr sdk.AccAddress) error {
func (k BaseViewKeeper) ValidateBalance(ctx context.Context, addr sdk.AccAddress) error {
acc := k.ak.GetAccount(ctx, addr)
if acc == nil {
return errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "account %s does not exist", addr)

View File

@ -1,12 +1,14 @@
package v2
import (
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
v1auth "github.com/cosmos/cosmos-sdk/x/auth/migrations/v1"
v1 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v1"
@ -80,8 +82,8 @@ func migrateBalanceKeys(store storetypes.KVStore, logger log.Logger) {
// - Change balances prefix to 1 byte
// - Change supply to be indexed by denom
// - Prune balances & supply with zero coins (ref: https://github.com/cosmos/cosmos-sdk/pull/9229)
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
store := ctx.KVStore(storeKey)
func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, cdc codec.BinaryCodec) error {
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
migrateBalanceKeys(store, ctx.Logger())
if err := pruneZeroBalances(store, cdc); err != nil {

View File

@ -9,6 +9,7 @@ import (
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -21,8 +22,9 @@ import (
func TestSupplyMigration(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
bankKey := storetypes.NewKVStoreKey("bank")
storeService := runtime.NewKVStoreService(bankKey)
ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test"))
store := ctx.KVStore(bankKey)
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
v1bank.RegisterInterfaces(encCfg.InterfaceRegistry)
@ -37,7 +39,7 @@ func TestSupplyMigration(t *testing.T) {
store.Set(v1bank.SupplyKey, oldSupplyBz)
// Run migration.
err = v2bank.MigrateStore(ctx, bankKey, encCfg.Codec)
err = v2bank.MigrateStore(ctx, storeService, encCfg.Codec)
require.NoError(t, err)
// New supply is indexed by denom.
@ -71,8 +73,9 @@ func TestSupplyMigration(t *testing.T) {
func TestBalanceKeysMigration(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
bankKey := storetypes.NewKVStoreKey("bank")
storeService := runtime.NewKVStoreService(bankKey)
ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test"))
store := ctx.KVStore(bankKey)
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
_, _, addr := testdata.KeyTestPubAddr()
@ -91,7 +94,7 @@ func TestBalanceKeysMigration(t *testing.T) {
store.Set(oldKeyFooBar, fooBarBz)
require.NotNil(t, store.Get(oldKeyFooBar)) // before store migation zero values can also exist in store.
err = v2bank.MigrateStore(ctx, bankKey, encCfg.Codec)
err = v2bank.MigrateStore(ctx, storeService, encCfg.Codec)
require.NoError(t, err)
newKey := v2bank.CreatePrefixedAccountStoreKey(addr, []byte(fooCoin.Denom))

View File

@ -1,11 +1,13 @@
package v3
import (
"cosmossdk.io/core/store"
"cosmossdk.io/log"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
v2 "github.com/cosmos/cosmos-sdk/x/bank/migrations/v2"
@ -18,8 +20,8 @@ import (
// - Migrate coin storage to save only amount.
// - Add an additional reverse index from denomination to address.
// - Remove duplicate denom from denom metadata store key.
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error {
store := ctx.KVStore(storeKey)
func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, cdc codec.BinaryCodec) error {
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
err := addDenomReverseIndex(store, cdc, ctx.Logger())
if err != nil {
return err

View File

@ -9,6 +9,7 @@ import (
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
@ -21,8 +22,9 @@ import (
func TestMigrateStore(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
bankKey := storetypes.NewKVStoreKey("bank")
storeService := runtime.NewKVStoreService(bankKey)
ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test"))
store := ctx.KVStore(bankKey)
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
addr := sdk.AccAddress([]byte("addr________________"))
prefixAccStore := prefix.NewStore(store, v2.CreateAccountBalancesPrefix(addr))
@ -39,7 +41,7 @@ func TestMigrateStore(t *testing.T) {
prefixAccStore.Set([]byte(b.Denom), bz)
}
require.NoError(t, v3.MigrateStore(ctx, bankKey, encCfg.Codec))
require.NoError(t, v3.MigrateStore(ctx, storeService, encCfg.Codec))
for _, b := range balances {
addrPrefixStore := prefix.NewStore(store, v3.CreateAccountBalancesPrefix(addr))
@ -59,8 +61,9 @@ func TestMigrateStore(t *testing.T) {
func TestMigrateDenomMetaData(t *testing.T) {
encCfg := moduletestutil.MakeTestEncodingConfig()
bankKey := storetypes.NewKVStoreKey("bank")
storeService := runtime.NewKVStoreService(bankKey)
ctx := testutil.DefaultContext(bankKey, storetypes.NewTransientStoreKey("transient_test"))
store := ctx.KVStore(bankKey)
store := runtime.KVStoreAdapter(storeService.OpenKVStore(ctx))
metaData := []types.Metadata{
{
Name: "Cosmos Hub Atom",
@ -98,7 +101,7 @@ func TestMigrateDenomMetaData(t *testing.T) {
denomMetadataStore.Set(key, bz)
}
require.NoError(t, v3.MigrateStore(ctx, bankKey, encCfg.Codec))
require.NoError(t, v3.MigrateStore(ctx, storeService, encCfg.Codec))
denomMetadataStore = prefix.NewStore(store, v2.DenomMetadataPrefix)
denomMetadataIter := denomMetadataStore.Iterator(nil, nil)

View File

@ -1,7 +1,7 @@
package v4
import (
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -17,8 +17,7 @@ var ParamsKey = []byte{0x05}
// version 4. Specifically, it takes the parameters that are currently stored
// and managed by the x/params module and stores them directly into the x/bank
// module state.
func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error {
store := ctx.KVStore(storeKey)
func MigrateStore(ctx sdk.Context, storeService store.KVStoreService, legacySubspace exported.Subspace, cdc codec.BinaryCodec) error {
var currParams types.Params
legacySubspace.GetParamSet(ctx, &currParams)
@ -31,7 +30,6 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace
return err
}
store.Set(ParamsKey, bz)
return nil
store := storeService.OpenKVStore(ctx)
return store.Set(ParamsKey, bz)
}

View File

@ -6,6 +6,7 @@ import (
storetypes "cosmossdk.io/store/types"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
@ -34,13 +35,16 @@ func TestMigrate(t *testing.T) {
storeKey := storetypes.NewKVStoreKey(v4.ModuleName)
tKey := storetypes.NewTransientStoreKey("transient_test")
ctx := testutil.DefaultContext(storeKey, tKey)
store := ctx.KVStore(storeKey)
storeService := runtime.NewKVStoreService(storeKey)
legacySubspace := newMockSubspace(types.DefaultParams())
require.NoError(t, v4.MigrateStore(ctx, storeKey, legacySubspace, cdc))
require.NoError(t, v4.MigrateStore(ctx, storeService, legacySubspace, cdc))
var res types.Params
bz := store.Get(v4.ParamsKey)
store := storeService.OpenKVStore(ctx)
bz, err := store.Get(v4.ParamsKey)
require.NoError(t, err)
require.NoError(t, cdc.Unmarshal(bz, &res))
require.Equal(t, legacySubspace.ps, res)
}

View File

@ -14,7 +14,7 @@ import (
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
store "cosmossdk.io/store/types"
corestore "cosmossdk.io/core/store"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
@ -210,10 +210,10 @@ func init() {
type ModuleInputs struct {
depinject.In
Config *modulev1.Module
Cdc codec.Codec
Key *store.KVStoreKey
Logger log.Logger
Config *modulev1.Module
Cdc codec.Codec
StoreService corestore.KVStoreService
Logger log.Logger
AccountKeeper types.AccountKeeper
@ -252,7 +252,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
bankKeeper := keeper.NewBaseKeeper(
in.Cdc,
in.Key,
in.StoreService,
in.AccountKeeper,
blockedAddresses,
authority.String(),

View File

@ -224,7 +224,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
for _, account := range accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(testutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -1,6 +1,8 @@
package testutil
import (
context "context"
sdk "github.com/cosmos/cosmos-sdk/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
@ -12,7 +14,7 @@ import (
//
// TODO: Instead of using the mint module account, which has the
// permission of minting, create a "faucet" account. (@fdymylja)
func FundAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins) error {
func FundAccount(ctx context.Context, bankKeeper bankkeeper.Keeper, addr sdk.AccAddress, amounts sdk.Coins) error {
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}
@ -26,7 +28,7 @@ func FundAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, addr sdk.AccAddr
//
// TODO: Instead of using the mint module account, which has the
// permission of minting, create a "faucet" account. (@fdymylja)
func FundModuleAccount(bankKeeper bankkeeper.Keeper, ctx sdk.Context, recipientMod string, amounts sdk.Coins) error {
func FundModuleAccount(ctx context.Context, bankKeeper bankkeeper.Keeper, recipientMod string, amounts sdk.Coins) error {
if err := bankKeeper.MintCoins(ctx, minttypes.ModuleName, amounts); err != nil {
return err
}

View File

@ -5,6 +5,7 @@
package testutil
import (
context "context"
reflect "reflect"
types "github.com/cosmos/cosmos-sdk/types"
@ -35,7 +36,7 @@ func (m *MockSupplyKeeper) EXPECT() *MockSupplyKeeperMockRecorder {
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockSupplyKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockSupplyKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)

View File

@ -1,10 +1,12 @@
package types
import (
context "context"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// SupplyKeeper defines the expected supply keeper (noalias)
type SupplyKeeper interface {
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

View File

@ -150,7 +150,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName
// set module account coins
distrAcc := suite.distrKeeper.GetDistributionAccount(suite.ctx)
suite.Require().NoError(banktestutil.FundModuleAccount(suite.bankKeeper, suite.ctx, distrAcc.GetName(), sdk.NewCoins(
suite.Require().NoError(banktestutil.FundModuleAccount(suite.ctx, suite.bankKeeper, distrAcc.GetName(), sdk.NewCoins(
sdk.NewCoin(tokenName, math.NewInt(10)),
sdk.NewCoin("stake", math.NewInt(5)),
)))
@ -269,7 +269,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
for _, account := range accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -158,7 +158,7 @@ func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -172,7 +172,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -186,7 +186,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -200,7 +200,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderMo
}
// SendCoinsFromModuleToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -214,7 +214,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToModule(ctx, senderMod
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -4,6 +4,7 @@ import (
context "context"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@ -23,13 +24,13 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BlockedAddr(addr sdk.AccAddress) bool
}

View File

@ -13,6 +13,8 @@ import (
"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"
_ "cosmossdk.io/api/cosmos/feegrant/v1beta1"
_ "cosmossdk.io/api/cosmos/gov/v1beta1"
"cosmossdk.io/x/feegrant"
"cosmossdk.io/x/feegrant/client/cli"
"cosmossdk.io/x/feegrant/module"

View File

@ -22,6 +22,6 @@ type AccountKeeper interface {
// BankKeeper defines the expected supply Keeper (noalias)
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
}

View File

@ -12,7 +12,7 @@ require (
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc
github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf
github.com/cosmos/gogoproto v1.4.8
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
@ -27,7 +27,7 @@ require (
require (
cosmossdk.io/collections v0.1.0 // indirect
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect
cosmossdk.io/x/tx v0.5.5 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
@ -93,6 +93,7 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect

View File

@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw=
cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM=
cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
@ -113,7 +113,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bits-and-blooms/bitset v1.6.0 h1:FVfaUsleKAUTJnaN9Fd1YFFi1S8vAX5xeXnXHFYOojM=
github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.1.2 h1:XLMbX8JQEiwMcYft2EGi8zPUkoa0abKIU6/BJSRsjzQ=
@ -187,8 +187,8 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9
github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4 h1:tZ2vcNWznBxIIK37nlgrh4n/n5aQv0KY6VzIb86xTNs=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4/go.mod h1:BPvKPN63ettXrpz67uM1rHEqX/UVVkAfceFCPyp217E=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf h1:uwoX+Bd0sr1RiiOPEDtt9g0eIgUOBhX0uWA6OFbbNa8=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf/go.mod h1:AD4IKrBq+M+oy1hlaBaDkyFcvoR82cLg0mS6lE2K0nU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
@ -494,6 +494,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=

View File

@ -5,7 +5,10 @@ import (
"testing"
"time"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
_ "cosmossdk.io/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/client"
_ "github.com/cosmos/cosmos-sdk/x/auth"
_ "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
@ -21,6 +24,8 @@ import (
"cosmossdk.io/x/feegrant/simulation"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/suite"
"github.com/cosmos/cosmos-sdk/codec"
codecaddress "github.com/cosmos/cosmos-sdk/codec/address"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@ -32,7 +37,6 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/stretchr/testify/suite"
)
type SimTestSuite struct {
@ -51,16 +55,20 @@ type SimTestSuite struct {
func (suite *SimTestSuite) SetupTest() {
var err error
suite.app, err = simtestutil.Setup(configurator.NewAppConfig(
configurator.AuthModule(),
configurator.BankModule(),
configurator.StakingModule(),
configurator.TxModule(),
configurator.ConsensusModule(),
configurator.ParamsModule(),
configurator.GenutilModule(),
configurator.FeegrantModule(),
),
suite.app, err = simtestutil.Setup(
depinject.Configs(
configurator.NewAppConfig(
configurator.AuthModule(),
configurator.BankModule(),
configurator.StakingModule(),
configurator.TxModule(),
configurator.ConsensusModule(),
configurator.ParamsModule(),
configurator.GenutilModule(),
configurator.FeegrantModule(),
),
depinject.Supply(log.NewNopLogger()),
),
&suite.feegrantKeeper,
&suite.bankKeeper,
&suite.accountKeeper,
@ -81,7 +89,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
// add coins to the accounts
for _, account := range accounts {
err := banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins)
err := banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins)
suite.Require().NoError(err)
}

View File

@ -157,7 +157,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -171,7 +171,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -421,7 +421,7 @@ func getTestingAccounts(
for _, account := range accounts {
acc := accountKeeper.NewAccountWithAddress(ctx, account.Address)
accountKeeper.SetAccount(ctx, acc)
require.NoError(t, testutil.FundAccount(bankKeeper, ctx, account.Address, initCoins))
require.NoError(t, testutil.FundAccount(ctx, bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -204,7 +204,7 @@ func (mr *MockBankKeeperMockRecorder) BlockedAddr(addr interface{}) *gomock.Call
}
// BurnCoins mocks base method.
func (m *MockBankKeeper) BurnCoins(ctx types.Context, moduleName string, amt types.Coins) error {
func (m *MockBankKeeper) BurnCoins(ctx context.Context, moduleName string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BurnCoins", ctx, moduleName, amt)
ret0, _ := ret[0].(error)
@ -218,7 +218,7 @@ func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, moduleName, amt interface{}
}
// DelegateCoins mocks base method.
func (m *MockBankKeeper) DelegateCoins(ctx types.Context, delegatorAddr, moduleAccAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DelegateCoins", ctx, delegatorAddr, moduleAccAddr, amt)
ret0, _ := ret[0].(error)
@ -232,7 +232,7 @@ func (mr *MockBankKeeperMockRecorder) DelegateCoins(ctx, delegatorAddr, moduleAc
}
// DelegateCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DelegateCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -246,7 +246,7 @@ func (mr *MockBankKeeperMockRecorder) DelegateCoinsFromAccountToModule(ctx, send
}
// DeleteSendEnabled mocks base method.
func (m *MockBankKeeper) DeleteSendEnabled(ctx types.Context, denoms ...string) {
func (m *MockBankKeeper) DeleteSendEnabled(ctx context.Context, denoms ...string) {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range denoms {
@ -308,7 +308,7 @@ func (mr *MockBankKeeperMockRecorder) DenomsMetadata(arg0, arg1 interface{}) *go
}
// ExportGenesis mocks base method.
func (m *MockBankKeeper) ExportGenesis(arg0 types.Context) *types0.GenesisState {
func (m *MockBankKeeper) ExportGenesis(arg0 context.Context) *types0.GenesisState {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ExportGenesis", arg0)
ret0, _ := ret[0].(*types0.GenesisState)
@ -322,7 +322,7 @@ func (mr *MockBankKeeperMockRecorder) ExportGenesis(arg0 interface{}) *gomock.Ca
}
// GetAccountsBalances mocks base method.
func (m *MockBankKeeper) GetAccountsBalances(ctx types.Context) []types0.Balance {
func (m *MockBankKeeper) GetAccountsBalances(ctx context.Context) []types0.Balance {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAccountsBalances", ctx)
ret0, _ := ret[0].([]types0.Balance)
@ -336,7 +336,7 @@ func (mr *MockBankKeeperMockRecorder) GetAccountsBalances(ctx interface{}) *gomo
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -350,7 +350,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// GetAllDenomMetaData mocks base method.
func (m *MockBankKeeper) GetAllDenomMetaData(ctx types.Context) []types0.Metadata {
func (m *MockBankKeeper) GetAllDenomMetaData(ctx context.Context) []types0.Metadata {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllDenomMetaData", ctx)
ret0, _ := ret[0].([]types0.Metadata)
@ -364,7 +364,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllDenomMetaData(ctx interface{}) *gomo
}
// GetAllSendEnabledEntries mocks base method.
func (m *MockBankKeeper) GetAllSendEnabledEntries(ctx types.Context) []types0.SendEnabled {
func (m *MockBankKeeper) GetAllSendEnabledEntries(ctx context.Context) []types0.SendEnabled {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllSendEnabledEntries", ctx)
ret0, _ := ret[0].([]types0.SendEnabled)
@ -392,7 +392,7 @@ func (mr *MockBankKeeperMockRecorder) GetAuthority() *gomock.Call {
}
// GetBalance mocks base method.
func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin {
func (m *MockBankKeeper) GetBalance(ctx context.Context, addr types.AccAddress, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom)
ret0, _ := ret[0].(types.Coin)
@ -420,7 +420,7 @@ func (mr *MockBankKeeperMockRecorder) GetBlockedAddresses() *gomock.Call {
}
// GetDenomMetaData mocks base method.
func (m *MockBankKeeper) GetDenomMetaData(ctx types.Context, denom string) (types0.Metadata, bool) {
func (m *MockBankKeeper) GetDenomMetaData(ctx context.Context, denom string) (types0.Metadata, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetDenomMetaData", ctx, denom)
ret0, _ := ret[0].(types0.Metadata)
@ -435,7 +435,7 @@ func (mr *MockBankKeeperMockRecorder) GetDenomMetaData(ctx, denom interface{}) *
}
// GetPaginatedTotalSupply mocks base method.
func (m *MockBankKeeper) GetPaginatedTotalSupply(ctx types.Context, pagination *query.PageRequest) (types.Coins, *query.PageResponse, error) {
func (m *MockBankKeeper) GetPaginatedTotalSupply(ctx context.Context, pagination *query.PageRequest) (types.Coins, *query.PageResponse, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPaginatedTotalSupply", ctx, pagination)
ret0, _ := ret[0].(types.Coins)
@ -451,7 +451,7 @@ func (mr *MockBankKeeperMockRecorder) GetPaginatedTotalSupply(ctx, pagination in
}
// GetParams mocks base method.
func (m *MockBankKeeper) GetParams(ctx types.Context) types0.Params {
func (m *MockBankKeeper) GetParams(ctx context.Context) types0.Params {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetParams", ctx)
ret0, _ := ret[0].(types0.Params)
@ -465,7 +465,7 @@ func (mr *MockBankKeeperMockRecorder) GetParams(ctx interface{}) *gomock.Call {
}
// GetSendEnabledEntry mocks base method.
func (m *MockBankKeeper) GetSendEnabledEntry(ctx types.Context, denom string) (types0.SendEnabled, bool) {
func (m *MockBankKeeper) GetSendEnabledEntry(ctx context.Context, denom string) (types0.SendEnabled, bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSendEnabledEntry", ctx, denom)
ret0, _ := ret[0].(types0.SendEnabled)
@ -480,7 +480,7 @@ func (mr *MockBankKeeperMockRecorder) GetSendEnabledEntry(ctx, denom interface{}
}
// GetSupply mocks base method.
func (m *MockBankKeeper) GetSupply(ctx types.Context, denom string) types.Coin {
func (m *MockBankKeeper) GetSupply(ctx context.Context, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSupply", ctx, denom)
ret0, _ := ret[0].(types.Coin)
@ -494,7 +494,7 @@ func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.
}
// HasBalance mocks base method.
func (m *MockBankKeeper) HasBalance(ctx types.Context, addr types.AccAddress, amt types.Coin) bool {
func (m *MockBankKeeper) HasBalance(ctx context.Context, addr types.AccAddress, amt types.Coin) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasBalance", ctx, addr, amt)
ret0, _ := ret[0].(bool)
@ -508,7 +508,7 @@ func (mr *MockBankKeeperMockRecorder) HasBalance(ctx, addr, amt interface{}) *go
}
// HasDenomMetaData mocks base method.
func (m *MockBankKeeper) HasDenomMetaData(ctx types.Context, denom string) bool {
func (m *MockBankKeeper) HasDenomMetaData(ctx context.Context, denom string) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasDenomMetaData", ctx, denom)
ret0, _ := ret[0].(bool)
@ -522,7 +522,7 @@ func (mr *MockBankKeeperMockRecorder) HasDenomMetaData(ctx, denom interface{}) *
}
// HasSupply mocks base method.
func (m *MockBankKeeper) HasSupply(ctx types.Context, denom string) bool {
func (m *MockBankKeeper) HasSupply(ctx context.Context, denom string) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "HasSupply", ctx, denom)
ret0, _ := ret[0].(bool)
@ -536,7 +536,7 @@ func (mr *MockBankKeeperMockRecorder) HasSupply(ctx, denom interface{}) *gomock.
}
// InitGenesis mocks base method.
func (m *MockBankKeeper) InitGenesis(arg0 types.Context, arg1 *types0.GenesisState) {
func (m *MockBankKeeper) InitGenesis(arg0 context.Context, arg1 *types0.GenesisState) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "InitGenesis", arg0, arg1)
}
@ -548,7 +548,7 @@ func (mr *MockBankKeeperMockRecorder) InitGenesis(arg0, arg1 interface{}) *gomoc
}
// InputOutputCoins mocks base method.
func (m *MockBankKeeper) InputOutputCoins(ctx types.Context, inputs types0.Input, outputs []types0.Output) error {
func (m *MockBankKeeper) InputOutputCoins(ctx context.Context, inputs types0.Input, outputs []types0.Output) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "InputOutputCoins", ctx, inputs, outputs)
ret0, _ := ret[0].(error)
@ -562,7 +562,7 @@ func (mr *MockBankKeeperMockRecorder) InputOutputCoins(ctx, inputs, outputs inte
}
// IsSendEnabledCoin mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoin(ctx types.Context, coin types.Coin) bool {
func (m *MockBankKeeper) IsSendEnabledCoin(ctx context.Context, coin types.Coin) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsSendEnabledCoin", ctx, coin)
ret0, _ := ret[0].(bool)
@ -576,7 +576,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoin(ctx, coin interface{}) *
}
// IsSendEnabledCoins mocks base method.
func (m *MockBankKeeper) IsSendEnabledCoins(ctx types.Context, coins ...types.Coin) error {
func (m *MockBankKeeper) IsSendEnabledCoins(ctx context.Context, coins ...types.Coin) error {
m.ctrl.T.Helper()
varargs := []interface{}{ctx}
for _, a := range coins {
@ -595,7 +595,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledCoins(ctx interface{}, coins
}
// IsSendEnabledDenom mocks base method.
func (m *MockBankKeeper) IsSendEnabledDenom(ctx types.Context, denom string) bool {
func (m *MockBankKeeper) IsSendEnabledDenom(ctx context.Context, denom string) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsSendEnabledDenom", ctx, denom)
ret0, _ := ret[0].(bool)
@ -609,7 +609,7 @@ func (mr *MockBankKeeperMockRecorder) IsSendEnabledDenom(ctx, denom interface{})
}
// IterateAccountBalances mocks base method.
func (m *MockBankKeeper) IterateAccountBalances(ctx types.Context, addr types.AccAddress, cb func(types.Coin) bool) {
func (m *MockBankKeeper) IterateAccountBalances(ctx context.Context, addr types.AccAddress, cb func(types.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAccountBalances", ctx, addr, cb)
}
@ -621,7 +621,7 @@ func (mr *MockBankKeeperMockRecorder) IterateAccountBalances(ctx, addr, cb inter
}
// IterateAllBalances mocks base method.
func (m *MockBankKeeper) IterateAllBalances(ctx types.Context, cb func(types.AccAddress, types.Coin) bool) {
func (m *MockBankKeeper) IterateAllBalances(ctx context.Context, cb func(types.AccAddress, types.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAllBalances", ctx, cb)
}
@ -633,7 +633,7 @@ func (mr *MockBankKeeperMockRecorder) IterateAllBalances(ctx, cb interface{}) *g
}
// IterateAllDenomMetaData mocks base method.
func (m *MockBankKeeper) IterateAllDenomMetaData(ctx types.Context, cb func(types0.Metadata) bool) {
func (m *MockBankKeeper) IterateAllDenomMetaData(ctx context.Context, cb func(types0.Metadata) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateAllDenomMetaData", ctx, cb)
}
@ -645,7 +645,7 @@ func (mr *MockBankKeeperMockRecorder) IterateAllDenomMetaData(ctx, cb interface{
}
// IterateSendEnabledEntries mocks base method.
func (m *MockBankKeeper) IterateSendEnabledEntries(ctx types.Context, cb func(string, bool) bool) {
func (m *MockBankKeeper) IterateSendEnabledEntries(ctx context.Context, cb func(string, bool) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateSendEnabledEntries", ctx, cb)
}
@ -657,7 +657,7 @@ func (mr *MockBankKeeperMockRecorder) IterateSendEnabledEntries(ctx, cb interfac
}
// IterateTotalSupply mocks base method.
func (m *MockBankKeeper) IterateTotalSupply(ctx types.Context, cb func(types.Coin) bool) {
func (m *MockBankKeeper) IterateTotalSupply(ctx context.Context, cb func(types.Coin) bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "IterateTotalSupply", ctx, cb)
}
@ -669,7 +669,7 @@ func (mr *MockBankKeeperMockRecorder) IterateTotalSupply(ctx, cb interface{}) *g
}
// LockedCoins mocks base method.
func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) LockedCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockedCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -683,7 +683,7 @@ func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock
}
// MintCoins mocks base method.
func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amt types.Coins) error {
func (m *MockBankKeeper) MintCoins(ctx context.Context, moduleName string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt)
ret0, _ := ret[0].(error)
@ -712,7 +712,7 @@ func (mr *MockBankKeeperMockRecorder) Params(arg0, arg1 interface{}) *gomock.Cal
}
// SendCoins mocks base method.
func (m *MockBankKeeper) SendCoins(ctx types.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoins(ctx context.Context, fromAddr, toAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoins", ctx, fromAddr, toAddr, amt)
ret0, _ := ret[0].(error)
@ -726,7 +726,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoins(ctx, fromAddr, toAddr, amt inter
}
// SendCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -740,7 +740,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(ctx, senderAd
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -754,7 +754,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderMo
}
// SendCoinsFromModuleToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -783,7 +783,7 @@ func (mr *MockBankKeeperMockRecorder) SendEnabled(arg0, arg1 interface{}) *gomoc
}
// SetAllSendEnabled mocks base method.
func (m *MockBankKeeper) SetAllSendEnabled(ctx types.Context, sendEnableds []*types0.SendEnabled) {
func (m *MockBankKeeper) SetAllSendEnabled(ctx context.Context, sendEnableds []*types0.SendEnabled) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetAllSendEnabled", ctx, sendEnableds)
}
@ -795,7 +795,7 @@ func (mr *MockBankKeeperMockRecorder) SetAllSendEnabled(ctx, sendEnableds interf
}
// SetDenomMetaData mocks base method.
func (m *MockBankKeeper) SetDenomMetaData(ctx types.Context, denomMetaData types0.Metadata) {
func (m *MockBankKeeper) SetDenomMetaData(ctx context.Context, denomMetaData types0.Metadata) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetDenomMetaData", ctx, denomMetaData)
}
@ -807,7 +807,7 @@ func (mr *MockBankKeeperMockRecorder) SetDenomMetaData(ctx, denomMetaData interf
}
// SetParams mocks base method.
func (m *MockBankKeeper) SetParams(ctx types.Context, params types0.Params) error {
func (m *MockBankKeeper) SetParams(ctx context.Context, params types0.Params) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SetParams", ctx, params)
ret0, _ := ret[0].(error)
@ -821,7 +821,7 @@ func (mr *MockBankKeeperMockRecorder) SetParams(ctx, params interface{}) *gomock
}
// SetSendEnabled mocks base method.
func (m *MockBankKeeper) SetSendEnabled(ctx types.Context, denom string, value bool) {
func (m *MockBankKeeper) SetSendEnabled(ctx context.Context, denom string, value bool) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SetSendEnabled", ctx, denom, value)
}
@ -863,7 +863,7 @@ func (mr *MockBankKeeperMockRecorder) SpendableBalances(arg0, arg1 interface{})
}
// SpendableCoin mocks base method.
func (m *MockBankKeeper) SpendableCoin(ctx types.Context, addr types.AccAddress, denom string) types.Coin {
func (m *MockBankKeeper) SpendableCoin(ctx context.Context, addr types.AccAddress, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoin", ctx, addr, denom)
ret0, _ := ret[0].(types.Coin)
@ -877,7 +877,7 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoin(ctx, addr, denom interface{}
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -921,7 +921,7 @@ func (mr *MockBankKeeperMockRecorder) TotalSupply(arg0, arg1 interface{}) *gomoc
}
// UndelegateCoins mocks base method.
func (m *MockBankKeeper) UndelegateCoins(ctx types.Context, moduleAccAddr, delegatorAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UndelegateCoins", ctx, moduleAccAddr, delegatorAddr, amt)
ret0, _ := ret[0].(error)
@ -935,7 +935,7 @@ func (mr *MockBankKeeperMockRecorder) UndelegateCoins(ctx, moduleAccAddr, delega
}
// UndelegateCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UndelegateCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -949,7 +949,7 @@ func (mr *MockBankKeeperMockRecorder) UndelegateCoinsFromModuleToAccount(ctx, se
}
// ValidateBalance mocks base method.
func (m *MockBankKeeper) ValidateBalance(ctx types.Context, addr types.AccAddress) error {
func (m *MockBankKeeper) ValidateBalance(ctx context.Context, addr types.AccAddress) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ValidateBalance", ctx, addr)
ret0, _ := ret[0].(error)

View File

@ -50,14 +50,14 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx context.Context, name string, amt sdk.Coins) error
}
// Event Hooks

View File

@ -4,6 +4,7 @@ import (
context "context"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -25,5 +26,5 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}

View File

@ -133,11 +133,11 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
groupPolicyAddr, err := s.addressCodec.StringToBytes(policyRes.Address)
s.Require().NoError(err)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, ctx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10000)}))
s.Require().NoError(testutil.FundAccount(ctx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10000)}))
groupPolicyAddr2, err := s.addressCodec.StringToBytes(policyRes2.Address)
s.Require().NoError(err)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, ctx, groupPolicyAddr2, sdk.Coins{sdk.NewInt64Coin("test", 10000)}))
s.Require().NoError(testutil.FundAccount(ctx, s.bankKeeper, groupPolicyAddr2, sdk.Coins{sdk.NewInt64Coin("test", 10000)}))
votingPeriod := policy.GetVotingPeriod()
@ -169,7 +169,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
sdkCtx := sdk.UnwrapSDKContext(ctx)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
s.Require().NoError(testutil.FundAccount(sdkCtx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
return pID
},
@ -185,7 +185,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
sdkCtx := sdk.UnwrapSDKContext(ctx)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
s.Require().NoError(testutil.FundAccount(sdkCtx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
return pID
},
@ -201,7 +201,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
sdkCtx := sdk.UnwrapSDKContext(ctx)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
s.Require().NoError(testutil.FundAccount(sdkCtx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
return pID
},
@ -216,7 +216,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().NoError(err)
sdkCtx := sdk.UnwrapSDKContext(ctx)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
s.Require().NoError(testutil.FundAccount(sdkCtx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
return pID
},
@ -236,7 +236,7 @@ func (s *IntegrationTestSuite) TestEndBlockerPruning() {
_, err = s.groupKeeper.Exec(ctx, &group.MsgExec{Executor: addr3.String(), ProposalId: pID})
s.Require().Error(err) // since proposal with status Aborted cannot be executed
sdkCtx := sdk.UnwrapSDKContext(ctx)
s.Require().NoError(testutil.FundAccount(s.bankKeeper, sdkCtx, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
s.Require().NoError(testutil.FundAccount(sdkCtx, s.bankKeeper, groupPolicyAddr, sdk.Coins{sdk.NewInt64Coin("test", 10002)}))
return pID
},

View File

@ -118,7 +118,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
for _, account := range accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(testutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -3,6 +3,8 @@
package testutil
import (
context "context"
sdk "github.com/cosmos/cosmos-sdk/types"
bank "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/group"
@ -18,7 +20,7 @@ type BankKeeper interface {
group.BankKeeper
bank.MsgServer
MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}

View File

@ -142,7 +142,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -156,7 +156,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// MintCoins mocks base method.
func (m *MockBankKeeper) MintCoins(ctx types.Context, moduleName string, amt types.Coins) error {
func (m *MockBankKeeper) MintCoins(ctx context.Context, moduleName string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MintCoins", ctx, moduleName, amt)
ret0, _ := ret[0].(error)
@ -200,7 +200,7 @@ func (mr *MockBankKeeperMockRecorder) Send(arg0, arg1 interface{}) *gomock.Call
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -229,7 +229,7 @@ func (mr *MockBankKeeperMockRecorder) SetSendEnabled(arg0, arg1 interface{}) *go
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -151,7 +151,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// MintCoins mocks base method.
func (m *MockBankKeeper) MintCoins(ctx types.Context, name string, amt types.Coins) error {
func (m *MockBankKeeper) MintCoins(ctx context.Context, name string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "MintCoins", ctx, name, amt)
ret0, _ := ret[0].(error)
@ -165,7 +165,7 @@ func (mr *MockBankKeeperMockRecorder) MintCoins(ctx, name, amt interface{}) *gom
}
// SendCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)
@ -179,7 +179,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(ctx, senderMo
}
// SendCoinsFromModuleToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderModule, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderModule, recipientModule, amt)
ret0, _ := ret[0].(error)

View File

@ -26,7 +26,7 @@ type AccountKeeper interface {
// BankKeeper defines the contract needed to be fulfilled for banking and supply
// dependencies.
type BankKeeper interface {
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderModule, recipientModule string, amt sdk.Coins) error
MintCoins(ctx context.Context, name string, amt sdk.Coins) error
}

View File

@ -4,13 +4,14 @@ import (
context "context"
"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// BankKeeper defines the contract needed to be fulfilled for banking and supply
// dependencies.
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}
// AccountKeeper defines the contract required for account APIs.

View File

@ -7,11 +7,12 @@ require (
cosmossdk.io/core v0.6.1
cosmossdk.io/depinject v1.0.0-alpha.3
cosmossdk.io/errors v1.0.0-beta.7
cosmossdk.io/log v1.0.0
cosmossdk.io/math v1.0.0
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc
github.com/cometbft/cometbft v0.37.1-0.20230411132551-3a91d155e664
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf
github.com/cosmos/gogoproto v1.4.8
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.3
@ -24,8 +25,7 @@ require (
require (
cosmossdk.io/collections v0.1.0 // indirect
cosmossdk.io/log v1.0.0 // indirect
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 // indirect
cosmossdk.io/x/tx v0.5.5 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
@ -90,6 +90,7 @@ require (
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect

View File

@ -51,8 +51,8 @@ cosmossdk.io/math v1.0.0 h1:ro9w7eKx23om2tZz/VM2Pf+z2WAbGX1yDQQOJ6iGeJw=
cosmossdk.io/math v1.0.0/go.mod h1:Ygz4wBHrgc7g0N+8+MrnTfS9LLn9aaTGa9hKopuym5k=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc h1:9piuA+NYmhe+SyMPtMoboLw/djgDbrI3dD5TG020Tnk=
cosmossdk.io/store v0.1.0-alpha.1.0.20230328185921-37ba88872dbc/go.mod h1:UFF5rmjN7WYVfxo6ArdY/l1+yyWMURBWOmSJypGqFHQ=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63 h1:zHqj2VwZ/MStFmR7SUe/7gErOFhL9v2rkjmWPB/st34=
cosmossdk.io/x/tx v0.5.1-0.20230407182919-057d2e09bd63/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
cosmossdk.io/x/tx v0.5.5 h1:9XG3KOrqObt7Rw7KhT7fiqRd6EepUfmA9ERa8CHj1WM=
cosmossdk.io/x/tx v0.5.5/go.mod h1:Oh3Kh+IPOfMEILNxVd2e8SLqRrIjYHpdGBfDg4ghU/k=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek=
filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
@ -113,7 +113,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bits-and-blooms/bitset v1.6.0 h1:FVfaUsleKAUTJnaN9Fd1YFFi1S8vAX5xeXnXHFYOojM=
github.com/bits-and-blooms/bitset v1.7.0 h1:YjAGVd3XmtK9ktAbX8Zg2g2PwLIMjGREZJHlV4j7NEo=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.1.2 h1:XLMbX8JQEiwMcYft2EGi8zPUkoa0abKIU6/BJSRsjzQ=
@ -182,8 +182,8 @@ github.com/cosmos/cosmos-db v1.0.0-rc.1 h1:SjnT8B6WKMW9WEIX32qMhnEEKcI7ZP0+G1Sa9
github.com/cosmos/cosmos-db v1.0.0-rc.1/go.mod h1:Dnmk3flSf5lkwCqvvjNpoxjpXzhxnCAFzKHlbaForso=
github.com/cosmos/cosmos-proto v1.0.0-beta.3 h1:VitvZ1lPORTVxkmF2fAp3IiA61xVwArQYKXTdEcpW6o=
github.com/cosmos/cosmos-proto v1.0.0-beta.3/go.mod h1:t8IASdLaAq+bbHbjq4p960BvcTqtwuAxid3b/2rOD6I=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4 h1:tZ2vcNWznBxIIK37nlgrh4n/n5aQv0KY6VzIb86xTNs=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230419124727-7b10ada768f4/go.mod h1:BPvKPN63ettXrpz67uM1rHEqX/UVVkAfceFCPyp217E=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf h1:uwoX+Bd0sr1RiiOPEDtt9g0eIgUOBhX0uWA6OFbbNa8=
github.com/cosmos/cosmos-sdk v0.46.0-beta2.0.20230425130609-df76824016cf/go.mod h1:AD4IKrBq+M+oy1hlaBaDkyFcvoR82cLg0mS6lE2K0nU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
@ -488,6 +488,8 @@ github.com/huandu/skiplist v1.2.0 h1:gox56QD77HzSC0w+Ws3MH3iie755GBJU1OER3h5VsYw
github.com/huandu/skiplist v1.2.0/go.mod h1:7v3iFjLcSAzO4fN5B8dvebvo/qsfumiLiDXMrPiHF9w=
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=

View File

@ -7,13 +7,16 @@ import (
"github.com/stretchr/testify/suite"
"cosmossdk.io/log"
abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"cosmossdk.io/depinject"
"cosmossdk.io/x/nft"
nftkeeper "cosmossdk.io/x/nft/keeper"
"cosmossdk.io/x/nft/simulation"
"cosmossdk.io/x/nft/testutil"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@ -44,7 +47,10 @@ type SimTestSuite struct {
func (suite *SimTestSuite) SetupTest() {
app, err := simtestutil.Setup(
testutil.AppConfig,
depinject.Configs(
testutil.AppConfig,
depinject.Supply(log.NewNopLogger()),
),
&suite.codec,
&suite.interfaceRegistry,
&suite.txConfig,
@ -106,7 +112,7 @@ func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Ac
for _, account := range accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
return accounts

View File

@ -36,7 +36,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -13,5 +13,5 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}

View File

@ -111,7 +111,7 @@ func (suite *SimTestSuite) SetupTest() {
for _, account := range suite.accounts {
acc := suite.accountKeeper.NewAccountWithAddress(suite.ctx, account.Address)
suite.accountKeeper.SetAccount(suite.ctx, acc)
suite.Require().NoError(banktestutil.FundAccount(suite.bankKeeper, suite.ctx, account.Address, initCoins))
suite.Require().NoError(banktestutil.FundAccount(suite.ctx, suite.bankKeeper, account.Address, initCoins))
}
suite.mintKeeper.SetParams(suite.ctx, minttypes.DefaultParams())

View File

@ -88,7 +88,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -102,7 +102,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// GetBalance mocks base method.
func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin {
func (m *MockBankKeeper) GetBalance(ctx context.Context, addr types.AccAddress, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom)
ret0, _ := ret[0].(types.Coin)
@ -116,7 +116,7 @@ func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) *
}
// LockedCoins mocks base method.
func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) LockedCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockedCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -130,7 +130,7 @@ func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)

View File

@ -18,10 +18,10 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
}
// ParamSubspace defines the expected Subspace interfacace

View File

@ -112,7 +112,7 @@ func (s *SimTestSuite) SetupTest() {
for _, account := range accounts[1:] {
acc := accountKeeper.NewAccountWithAddress(ctx, account.Address)
accountKeeper.SetAccount(ctx, acc)
s.Require().NoError(banktestutil.FundAccount(bankKeeper, ctx, account.Address, initCoins))
s.Require().NoError(banktestutil.FundAccount(ctx, bankKeeper, account.Address, initCoins))
}
s.accountKeeper = accountKeeper

View File

@ -208,7 +208,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder {
}
// BurnCoins mocks base method.
func (m *MockBankKeeper) BurnCoins(ctx types.Context, name string, amt types.Coins) error {
func (m *MockBankKeeper) BurnCoins(ctx context.Context, name string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "BurnCoins", ctx, name, amt)
ret0, _ := ret[0].(error)
@ -222,7 +222,7 @@ func (mr *MockBankKeeperMockRecorder) BurnCoins(ctx, name, amt interface{}) *gom
}
// DelegateCoinsFromAccountToModule mocks base method.
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx types.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
func (m *MockBankKeeper) DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr types.AccAddress, recipientModule string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "DelegateCoinsFromAccountToModule", ctx, senderAddr, recipientModule, amt)
ret0, _ := ret[0].(error)
@ -236,7 +236,7 @@ func (mr *MockBankKeeperMockRecorder) DelegateCoinsFromAccountToModule(ctx, send
}
// GetAllBalances mocks base method.
func (m *MockBankKeeper) GetAllBalances(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) GetAllBalances(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetAllBalances", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -250,7 +250,7 @@ func (mr *MockBankKeeperMockRecorder) GetAllBalances(ctx, addr interface{}) *gom
}
// GetBalance mocks base method.
func (m *MockBankKeeper) GetBalance(ctx types.Context, addr types.AccAddress, denom string) types.Coin {
func (m *MockBankKeeper) GetBalance(ctx context.Context, addr types.AccAddress, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBalance", ctx, addr, denom)
ret0, _ := ret[0].(types.Coin)
@ -264,7 +264,7 @@ func (mr *MockBankKeeperMockRecorder) GetBalance(ctx, addr, denom interface{}) *
}
// GetSupply mocks base method.
func (m *MockBankKeeper) GetSupply(ctx types.Context, denom string) types.Coin {
func (m *MockBankKeeper) GetSupply(ctx context.Context, denom string) types.Coin {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSupply", ctx, denom)
ret0, _ := ret[0].(types.Coin)
@ -278,7 +278,7 @@ func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock.
}
// LockedCoins mocks base method.
func (m *MockBankKeeper) LockedCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) LockedCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "LockedCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -292,7 +292,7 @@ func (mr *MockBankKeeperMockRecorder) LockedCoins(ctx, addr interface{}) *gomock
}
// SendCoinsFromModuleToModule mocks base method.
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx types.Context, senderPool, recipientPool string, amt types.Coins) error {
func (m *MockBankKeeper) SendCoinsFromModuleToModule(ctx context.Context, senderPool, recipientPool string, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SendCoinsFromModuleToModule", ctx, senderPool, recipientPool, amt)
ret0, _ := ret[0].(error)
@ -306,7 +306,7 @@ func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToModule(ctx, senderPoo
}
// SpendableCoins mocks base method.
func (m *MockBankKeeper) SpendableCoins(ctx types.Context, addr types.AccAddress) types.Coins {
func (m *MockBankKeeper) SpendableCoins(ctx context.Context, addr types.AccAddress) types.Coins {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "SpendableCoins", ctx, addr)
ret0, _ := ret[0].(types.Coins)
@ -320,7 +320,7 @@ func (mr *MockBankKeeperMockRecorder) SpendableCoins(ctx, addr interface{}) *gom
}
// UndelegateCoinsFromModuleToAccount mocks base method.
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx types.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
func (m *MockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr types.AccAddress, amt types.Coins) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "UndelegateCoinsFromModuleToAccount", ctx, senderModule, recipientAddr, amt)
ret0, _ := ret[0].(error)

View File

@ -31,18 +31,18 @@ type AccountKeeper interface {
// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetAllBalances(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx context.Context, addr sdk.AccAddress, denom string) sdk.Coin
LockedCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
GetSupply(ctx sdk.Context, denom string) sdk.Coin
GetSupply(ctx context.Context, denom string) sdk.Coin
SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx context.Context, senderPool, recipientPool string, amt sdk.Coins) error
UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BurnCoins(ctx sdk.Context, name string, amt sdk.Coins) error
BurnCoins(ctx context.Context, name string, amt sdk.Coins) error
}
// ValidatorSet expected properties for the set of all validators (noalias)