Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 47 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ccb4311
remove account creation if account doesnt exist
tac0turtle Jan 23, 2024
668c961
address comment and remove set accounts in bank
tac0turtle Jan 23, 2024
403c4b4
remvoe vesting changes
tac0turtle Jan 23, 2024
ba1bb32
fix bank tests
tac0turtle Jan 23, 2024
e91220c
reget account if its been created
tac0turtle Jan 23, 2024
24840c7
more changes
tac0turtle Jan 23, 2024
89ddd38
Merge branch 'main' into marko/19092
tac0turtle Jan 29, 2024
4b66f08
further cleanup api
tac0turtle Jan 29, 2024
0e697b8
set account not created
tac0turtle Jan 29, 2024
3af1c1d
account for newly created accounts
tac0turtle Jan 29, 2024
ff2e36d
fix a test
tac0turtle Jan 29, 2024
2e33997
fix more tests
tac0turtle Jan 29, 2024
db651c7
fix mores tests
tac0turtle Jan 29, 2024
4c20c49
fix more tests
tac0turtle Jan 29, 2024
4edf881
fix integration tests
tac0turtle Jan 31, 2024
cf95cad
fix integration tests
tac0turtle Feb 1, 2024
c65ac18
push todo
tac0turtle Feb 1, 2024
d68dd33
remove todo
tac0turtle Feb 1, 2024
ee38e20
feegrant fixes
tac0turtle Feb 1, 2024
6d01885
Merge branch 'main' into marko/19092
tac0turtle Feb 1, 2024
46e9662
fix go mod
tac0turtle Feb 2, 2024
0a74d4c
small break
tac0turtle Feb 2, 2024
69e273c
remove account get from basic
tac0turtle Feb 2, 2024
895829e
fix gas tests
tac0turtle Feb 2, 2024
29eb7b9
remove comments
tac0turtle Feb 2, 2024
bc1c1fa
audit codebase for setaccount calls
tac0turtle Feb 2, 2024
92b51f9
remove set account in authz
tac0turtle Feb 2, 2024
4649384
broken
tac0turtle Feb 2, 2024
623c15b
fix authz tests
tac0turtle Feb 3, 2024
b7faac8
fix print
tac0turtle Feb 3, 2024
dec62e9
Merge branch 'main' into marko/19092
tac0turtle Feb 3, 2024
bc45772
fix comment
tac0turtle Feb 3, 2024
b89fc84
remove error check
tac0turtle Feb 4, 2024
2c15dda
Update x/auth/ante/sigverify.go
tac0turtle Feb 4, 2024
16e43a3
Update x/auth/ante/sigverify.go
tac0turtle Feb 4, 2024
c4b7838
Update x/auth/ante/sigverify.go
tac0turtle Feb 4, 2024
4cbfd64
Merge branch 'main' into marko/19092
alexanderbez Feb 5, 2024
9822b43
add changelog entires
tac0turtle Feb 5, 2024
c26ee9c
fix it
tac0turtle Feb 5, 2024
f0e8964
attempt
tac0turtle Feb 5, 2024
a5e4320
cleanup
tac0turtle Feb 5, 2024
4125905
revert error
tac0turtle Feb 5, 2024
3ab6f07
revert ensure exists error removal
tac0turtle Feb 5, 2024
f72d5d7
fix some tests
tac0turtle Feb 5, 2024
1a81a74
Merge branch 'main' into marko/19092
tac0turtle Feb 12, 2024
e4568b7
fix test
tac0turtle Feb 13, 2024
2b53269
fix test
tac0turtle Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type TestAccountRetriever struct {
func (t TestAccountRetriever) GetAccount(_ Context, addr sdk.AccAddress) (Account, error) {
acc, ok := t.Accounts[addr.String()]
if !ok {
return nil, fmt.Errorf("account %s not found", addr)
return nil, fmt.Errorf("account: account %s not found", addr)
}

return acc, nil
Expand All @@ -68,7 +68,7 @@ func (t TestAccountRetriever) GetAccountWithHeight(clientCtx Context, addr sdk.A
func (t TestAccountRetriever) EnsureExists(_ Context, addr sdk.AccAddress) error {
_, ok := t.Accounts[addr.String()]
if !ok {
return fmt.Errorf("account %s not found", addr)
return fmt.Errorf("ensureExists: account %s not found", addr)
}
return nil
}
Expand All @@ -77,7 +77,7 @@ func (t TestAccountRetriever) EnsureExists(_ Context, addr sdk.AccAddress) error
func (t TestAccountRetriever) GetAccountNumberSequence(_ Context, addr sdk.AccAddress) (accNum, accSeq uint64, err error) {
acc, ok := t.Accounts[addr.String()]
if !ok {
return 0, 0, fmt.Errorf("account %s not found", addr)
return 0, 0, fmt.Errorf("accountNumberSequence: account %s not found", addr)
}
return acc.Num, acc.Seq, nil
}
7 changes: 2 additions & 5 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,15 +505,12 @@ func (f Factory) Prepare(clientCtx client.Context) (Factory, error) {
fc := f
from := clientCtx.FromAddress

if err := fc.accountRetriever.EnsureExists(clientCtx, from); err != nil {
return fc, err
}

initNum, initSeq := fc.accountNumber, fc.sequence
if initNum == 0 || initSeq == 0 {
num, seq, err := fc.accountRetriever.GetAccountNumberSequence(clientCtx, from)
if err != nil {
return fc, err
// return early since account does not exist here.
return fc, nil
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
}

if initNum == 0 {
Expand Down
1 change: 0 additions & 1 deletion client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func GenerateOrBroadcastTxCLI(clientCtx client.Context, flagSet *pflag.FlagSet,
if err != nil {
return err
}

return GenerateOrBroadcastTxWithFactory(clientCtx, txf, msgs...)
}

Expand Down
3 changes: 3 additions & 0 deletions docs/architecture/adr-020-protobuf-transaction-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* 2021 Feb 24: The Cosmos SDK does not use Tendermint's `PubKey` interface anymore, but its own `cryptotypes.PubKey`. Updates to reflect this.
* 2021 May 3: Rename `clientCtx.JSONMarshaler` to `clientCtx.JSONCodec`.
* 2021 June 10: Add `clientCtx.Codec: codec.Codec`.
* 2024 February 5: Account creation step

## Status

Expand Down Expand Up @@ -317,6 +318,8 @@ the client logic will now need to take a codec interface that knows not only how
to handle all the types, but also knows how to generate transactions, signatures,
and messages.

If the account is sending its first transaction, the account number must be set to 0. This is due to the account not being created yet.

```go
type AccountRetriever interface {
GetAccount(clientCtx Context, addr sdk.AccAddress) (client.Account, error)
Expand Down
9 changes: 3 additions & 6 deletions tests/e2e/baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ func TestBaseApp_BlockGas(t *testing.T) {
err = bankKeeper.SendCoinsFromModuleToAccount(ctx, testutil.MintModuleName, addr1, feeAmount)
require.NoError(t, err)
require.Equal(t, feeCoin.Amount, bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount)
seq := accountKeeper.GetAccount(ctx, addr1).GetSequence()
require.Equal(t, uint64(0), seq)

// msg and signatures
msg := &baseapptestutil.MsgKeyValue{
Expand All @@ -152,8 +150,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
txBuilder.SetFeeAmount(feeAmount)
txBuilder.SetGasLimit(uint64(simtestutil.DefaultConsensusParams.Block.MaxGas))

senderAccountNumber := accountKeeper.GetAccount(ctx, addr1).GetAccountNumber()
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{senderAccountNumber}, []uint64{0}
privs, accNums, accSeqs := []cryptotypes.PrivKey{priv1}, []uint64{0}, []uint64{0}
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
_, txBytes, err := createTestTx(txConfig, txBuilder, privs, accNums, accSeqs, ctx.ChainID())
require.NoError(t, err)

Expand All @@ -176,7 +173,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
require.Equal(t, []byte("ok"), okValue)
}
// check block gas is always consumed
baseGas := uint64(38798) // baseGas is the gas consumed before tx msg
baseGas := uint64(38012) // baseGas is the gas consumed before tx msg
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > uint64(simtestutil.DefaultConsensusParams.Block.MaxGas) {
// capped by gasLimit
Expand All @@ -186,7 +183,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
// tx fee is always deducted
require.Equal(t, int64(0), bankKeeper.GetBalance(ctx, addr1, feeCoin.Denom).Amount.Int64())
// sender's sequence is always increased
seq = accountKeeper.GetAccount(ctx, addr1).GetSequence()
seq := accountKeeper.GetAccount(ctx, addr1).GetSequence()
require.NoError(t, err)
require.Equal(t, uint64(1), seq)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/bank/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestGRPCQuerySpendableBalances(t *testing.T) {
assert.NilError(t, err)

req := banktypes.NewQuerySpendableBalancesRequest(addr1, nil)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 2032, false)
testdata.DeterministicIterations(t, f.ctx, req, f.queryClient.SpendableBalances, 1777, false)
}

func TestGRPCQueryTotalSupply(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/distribution/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestGRPCValidatorOutstandingRewards(t *testing.T) {
// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestGRPCValidatorCommission(t *testing.T) {
// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestGRPCDelegationRewards(t *testing.T) {
// send funds to val addr
funds := f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, int64(1000))
assert.NilError(t, f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, types.ModuleName, sdk.AccAddress(f.valAddr), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, funds))))

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(f.valAddr)))
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
initialStake := int64(10)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
Expand Down
1 change: 1 addition & 0 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ func TestMsgDepositValidatorRewardsPool(t *testing.T) {
require.NoError(t, err)
// send funds from module to addr to perform DepositValidatorRewardsPool
err = f.bankKeeper.SendCoinsFromModuleToAccount(f.sdkCtx, distrtypes.ModuleName, addr, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, tokens)))
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(valAddr1)))
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
tstaking := stakingtestutil.NewHelper(t, f.sdkCtx, f.stakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDecWithPrec(5, 1), math.LegacyNewDec(0))
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type fixture struct {
sdkCtx sdk.Context
cdc codec.Codec

accountKeeper authkeeper.AccountKeeper
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
bankKeeper bankkeeper.Keeper
evidenceKeeper *keeper.Keeper
slashingKeeper slashingkeeper.Keeper
Expand Down Expand Up @@ -164,6 +165,7 @@ func initFixture(tb testing.TB) *fixture {
app: integrationApp,
sdkCtx: sdkCtx,
cdc: cdc,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
evidenceKeeper: evidenceKeeper,
slashingKeeper: slashingKeeper,
Expand All @@ -183,7 +185,7 @@ func TestHandleDoubleSign(t *testing.T) {
assert.NilError(t, err)
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for SetAccount call. Ensure error is checked to prevent potential issues with account setting.

- f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ if err != nil {
+     t.Fatalf("Failed to set account: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
if err != nil {
t.Fatalf("Failed to set account: %v", err)
}

selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)

// execute end-blocker and verify validator attributes
Expand Down Expand Up @@ -278,7 +280,7 @@ func TestHandleDoubleSign_TooOld(t *testing.T) {
operatorAddr, valpubkey := valAddresses[0], pubkeys[0]

tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for SetAccount call. Ensure error is checked to prevent potential issues with account setting.

- f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ if err != nil {
+     t.Fatalf("Failed to set account: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
if err != nil {
t.Fatalf("Failed to set account: %v", err)
}

amt := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)

// execute end-blocker and verify validator attributes
Expand Down Expand Up @@ -328,7 +330,7 @@ func TestHandleDoubleSignAfterRotation(t *testing.T) {

operatorAddr, valpubkey := valAddresses[0], pubkeys[0]
tstaking := stakingtestutil.NewHelper(t, ctx, f.stakingKeeper)

f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for SetAccount call. Ensure error is checked to prevent potential issues with account setting.

- f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
+ if err != nil {
+     t.Fatalf("Failed to set account: %v", err)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
err := f.accountKeeper.SetAccount(f.sdkCtx, f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(operatorAddr)))
if err != nil {
t.Fatalf("Failed to set account: %v", err)
}

selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, valpubkey, power, true)

// execute end-blocker and verify validator attributes
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/gov/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ func TestProposalPassedEndblocker(t *testing.T) {
stakingMsgSvr := stakingkeeper.NewMsgServerImpl(suite.StakingKeeper)
valAddr := sdk.ValAddress(addrs[0])
proposer := addrs[0]
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
suite.AccountKeeper.SetAccount(ctx, acc)
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved

createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
_, err := suite.StakingKeeper.EndBlocker(ctx)
Expand Down Expand Up @@ -421,6 +423,9 @@ func TestEndBlockerProposalHandlerFailed(t *testing.T) {
toAddrStr, err := ac.BytesToString(addrs[0])
require.NoError(t, err)

acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
suite.AccountKeeper.SetAccount(ctx, acc)

tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
_, err = suite.StakingKeeper.EndBlocker(ctx)
require.NoError(t, err)
Expand Down Expand Up @@ -499,6 +504,8 @@ func TestExpeditedProposal_PassAndConversionToRegular(t *testing.T) {
valAddr := sdk.ValAddress(addrs[0])
proposer := addrs[0]

acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addrs[0])
suite.AccountKeeper.SetAccount(ctx, acc)
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
// Create a validator so that able to vote on proposal.
createValidators(t, stakingMsgSvr, ctx, []sdk.ValAddress{valAddr}, []int64{10})
_, err = suite.StakingKeeper.EndBlocker(ctx)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val2))
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.ctx, val3))

for _, addr := range addrs {
f.accountKeeper.SetAccount(f.ctx, f.accountKeeper.NewAccountWithAddress(f.ctx, addr))
}

_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[0]), stakingtypes.Unbonded, val1, true)
_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[1]), stakingtypes.Unbonded, val2, true)
_, _ = f.stakingKeeper.Delegate(f.ctx, addrs[2], f.stakingKeeper.TokensFromConsensusPower(f.ctx, powers[2]), stakingtypes.Unbonded, val3, true)
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type fixture struct {
queryClient v1.QueryClient
legacyQueryClient v1beta1.QueryClient

accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
govKeeper *keeper.Keeper
Expand Down Expand Up @@ -153,6 +154,7 @@ func initFixture(tb testing.TB) *fixture {
ctx: sdkCtx,
queryClient: queryClient,
legacyQueryClient: legacyQueryClient,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
govKeeper: govKeeper,
Expand Down
1 change: 0 additions & 1 deletion tests/integration/gov/keeper/tally_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ func TestTallyDelgatorMultipleOverride(t *testing.T) {
assert.Assert(t, found)
val2, found := f.stakingKeeper.GetValidator(ctx, vals[1])
assert.Assert(t, found)

_, err := f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val1, true)
assert.NilError(t, err)
_, err = f.stakingKeeper.Delegate(ctx, addrs[3], delTokens, stakingtypes.Unbonded, val2, true)
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -35,6 +37,7 @@ func TestBeginBlocker(t *testing.T) {
depinject.Supply(log.NewNopLogger()),
),
&interfaceRegistry,
&accountKeeper,
&bankKeeper,
&stakingKeeper,
&slashingKeeper,
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type fixture struct {

ctx sdk.Context

accountKeeper authkeeper.AccountKeeper
bankKeeper bankkeeper.Keeper
slashingKeeper slashingkeeper.Keeper
stakingKeeper *stakingkeeper.Keeper
Expand Down Expand Up @@ -135,6 +136,7 @@ func initFixture(tb testing.TB) *fixture {
return &fixture{
app: integrationApp,
ctx: sdkCtx,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
slashingKeeper: slashingKeeper,
stakingKeeper: stakingKeeper,
Expand All @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val1))
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val2))

for _, addr := range addrs {
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
f.accountKeeper.SetAccount(f.sdkCtx, acc)
}

_, err := f.stakingKeeper.Delegate(f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[0]), types.Unbonded, val1, true)
assert.NilError(t, err)
_, err = f.stakingKeeper.Delegate(f.sdkCtx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[1]), types.Unbonded, val2, true)
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/staking/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {

// mature unbonding delegations
ctx = ctx.WithHeaderInfo(header.Info{Time: completionTime})
acc := f.accountKeeper.NewAccountWithAddress(ctx, addrDel)
f.accountKeeper.SetAccount(ctx, acc)
_, err = f.stakingKeeper.CompleteUnbonding(ctx, addrDel, addrVal)
assert.NilError(t, err)

Expand Down
Loading
Loading