refactor(bank, feegrant, authz): avoid creating baseaccount (#19188)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Marko
2024-02-13 12:52:06 +00:00
committed by GitHub
co-authored by Aleksandr Bezobchuk
parent 26d30f2111
commit 869c96c403
43 changed files with 228 additions and 133 deletions
+5
View File
@@ -9,6 +9,7 @@ import (
"cosmossdk.io/core/comet"
"cosmossdk.io/depinject"
"cosmossdk.io/log"
authkeeper "cosmossdk.io/x/auth/keeper"
bankkeeper "cosmossdk.io/x/bank/keeper"
"cosmossdk.io/x/slashing"
slashingkeeper "cosmossdk.io/x/slashing/keeper"
@@ -24,6 +25,7 @@ import (
func TestBeginBlocker(t *testing.T) {
var (
interfaceRegistry codectypes.InterfaceRegistry
accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
slashingKeeper slashingkeeper.Keeper
@@ -35,6 +37,7 @@ func TestBeginBlocker(t *testing.T) {
depinject.Supply(log.NewNopLogger()),
),
&interfaceRegistry,
&accountKeeper,
&bankKeeper,
&stakingKeeper,
&slashingKeeper,
@@ -50,6 +53,8 @@ func TestBeginBlocker(t *testing.T) {
// bond the validator
power := int64(100)
acc := accountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(addr))
accountKeeper.SetAccount(ctx, acc)
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
_, err = stakingKeeper.EndBlocker(ctx)
require.NoError(t, err)
@@ -41,6 +41,7 @@ type fixture struct {
ctx sdk.Context
accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
slashingKeeper slashingkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
@@ -135,6 +136,7 @@ func initFixture(tb testing.TB) *fixture {
return &fixture{
app: integrationApp,
ctx: sdkCtx,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
slashingKeeper: slashingKeeper,
stakingKeeper: stakingKeeper,
@@ -157,6 +159,8 @@ func TestUnJailNotBonded(t *testing.T) {
// create max (5) validators all with the same power
for i := uint32(0); i < p.MaxValidators; i++ {
addr, val := f.valAddrs[i], pks[i]
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
f.accountKeeper.SetAccount(f.ctx, acc)
tstaking.CreateValidatorWithValPower(addr, val, 100, true)
}
@@ -166,6 +170,8 @@ func TestUnJailNotBonded(t *testing.T) {
// create a 6th validator with less power than the cliff validator (won't be bonded)
addr, val := f.valAddrs[5], pks[5]
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
f.accountKeeper.SetAccount(f.ctx, acc)
amt := f.stakingKeeper.TokensFromConsensusPower(f.ctx, 50)
msg := tstaking.CreateValidatorMsg(addr, val, amt)
msg.MinSelfDelegation = amt
@@ -246,6 +252,8 @@ func TestHandleNewValidator(t *testing.T) {
assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, sdk.ConsAddress(valpubkey.Address()), info))
// Validator created
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
f.accountKeeper.SetAccount(f.ctx, acc)
amt := tstaking.CreateValidatorWithValPower(addr, valpubkey, 100, true)
_, err = f.stakingKeeper.EndBlocker(f.ctx)
@@ -303,6 +311,9 @@ func TestHandleAlreadyJailed(t *testing.T) {
info := slashingtypes.NewValidatorSigningInfo(consaddr, f.ctx.BlockHeight(), int64(0), time.Unix(0, 0), false, int64(0))
assert.NilError(t, f.slashingKeeper.ValidatorSigningInfo.Set(f.ctx, sdk.ConsAddress(val.Address()), info))
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(addr))
f.accountKeeper.SetAccount(f.ctx, acc)
amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
_, err = f.stakingKeeper.EndBlocker(f.ctx)
@@ -366,6 +377,10 @@ func TestValidatorDippingInAndOut(t *testing.T) {
pks := simtestutil.CreateTestPubKeys(3)
simtestutil.AddTestAddrsFromPubKeys(f.bankKeeper, f.stakingKeeper, f.ctx, pks, f.stakingKeeper.TokensFromConsensusPower(f.ctx, 200))
for _, pk := range pks {
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, sdk.AccAddress(pk.Address()))
f.accountKeeper.SetAccount(f.ctx, acc)
}
addr, val := pks[0].Address(), pks[0]
consAddr := sdk.ConsAddress(addr)