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
@@ -82,6 +82,11 @@ func createValidators(t *testing.T, f *fixture, powers []int64) ([]sdk.AccAddres
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val1))
assert.NilError(t, f.stakingKeeper.SetNewValidatorByPowerIndex(f.sdkCtx, val2))
for _, addr := range addrs {
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
f.accountKeeper.SetAccount(f.sdkCtx, acc)
}
_, err := f.stakingKeeper.Delegate(f.sdkCtx, addrs[0], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[0]), types.Unbonded, val1, true)
assert.NilError(t, err)
_, err = f.stakingKeeper.Delegate(f.sdkCtx, addrs[1], f.stakingKeeper.TokensFromConsensusPower(f.sdkCtx, powers[1]), types.Unbonded, val2, true)
@@ -95,6 +95,8 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
// mature unbonding delegations
ctx = ctx.WithHeaderInfo(header.Info{Time: completionTime})
acc := f.accountKeeper.NewAccountWithAddress(ctx, addrDel)
f.accountKeeper.SetAccount(ctx, acc)
_, err = f.stakingKeeper.CompleteUnbonding(ctx, addrDel, addrVal)
assert.NilError(t, err)
@@ -245,6 +245,9 @@ func setValidator(t *testing.T, f *deterministicFixture, validator stakingtypes.
coins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, validator.BondedTokens()))
assert.NilError(t, banktestutil.FundAccount(f.ctx, f.bankKeeper, delegatorAddress, coins))
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddress)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err = f.stakingKeeper.Delegate(f.ctx, delegatorAddress, validator.BondedTokens(), stakingtypes.Unbonded, validator, true)
assert.NilError(t, err)
}
@@ -396,6 +399,8 @@ func TestGRPCValidatorDelegations(t *testing.T) {
for i := 0; i < numDels; i++ {
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
}
@@ -412,9 +417,13 @@ func TestGRPCValidatorDelegations(t *testing.T) {
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
acc = f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr2)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err = fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
assert.NilError(t, err)
@@ -435,6 +444,8 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
for i := 0; i < numDels; i++ {
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
valbz, err := f.stakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
@@ -454,12 +465,16 @@ func TestGRPCValidatorUnbondingDelegations(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
_, _, err = f.stakingKeeper.Undelegate(f.ctx, delegatorAddr1, validatorAddr1, shares1)
assert.NilError(t, err)
acc = f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr2)
f.accountKeeper.SetAccount(f.ctx, acc)
shares2, err := fundAccountAndDelegate(t, f, delegatorAddr2, validator, f.amt2)
assert.NilError(t, err)
@@ -480,6 +495,8 @@ func TestGRPCDelegation(t *testing.T) {
rapid.Check(t, func(rt *rapid.T) {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
@@ -494,6 +511,8 @@ func TestGRPCDelegation(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -512,6 +531,8 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
rapid.Check(t, func(rt *rapid.T) {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
@@ -531,6 +552,8 @@ func TestGRPCUnbondingDelegation(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -555,6 +578,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
for i := 0; i < numVals; i++ {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
}
@@ -570,6 +595,8 @@ func TestGRPCDelegatorDelegations(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -588,6 +615,8 @@ func TestGRPCDelegatorValidator(t *testing.T) {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
@@ -602,6 +631,8 @@ func TestGRPCDelegatorValidator(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -624,6 +655,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
for i := 0; i < numVals; i++ {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
valbz, err := f.stakingKeeper.ValidatorAddressCodec().StringToBytes(validator.GetOperator())
@@ -643,6 +676,8 @@ func TestGRPCDelegatorUnbondingDelegations(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
shares1, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -707,6 +742,8 @@ func TestGRPCDelegatorValidators(t *testing.T) {
for i := 0; i < numVals; i++ {
validator := createAndSetValidatorWithStatus(t, rt, f, stakingtypes.Bonded)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
}
@@ -722,7 +759,8 @@ func TestGRPCDelegatorValidators(t *testing.T) {
f = initDeterministicFixture(t) // reset
validator := getStaticValidator(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
_, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -761,6 +799,8 @@ func TestGRPCRedelegations(t *testing.T) {
numDels := rapid.IntRange(1, 5).Draw(rt, "num-dels")
delegator := testdata.AddressGenerator(rt).Draw(rt, "delegator")
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegator)
f.accountKeeper.SetAccount(f.ctx, acc)
shares, err := createDelegationAndDelegate(t, rt, f, delegator, validator)
assert.NilError(t, err)
@@ -795,6 +835,8 @@ func TestGRPCRedelegations(t *testing.T) {
validator := getStaticValidator(t, f)
_ = getStaticValidator2(t, f)
acc := f.accountKeeper.NewAccountWithAddress(f.ctx, delegatorAddr1)
f.accountKeeper.SetAccount(f.ctx, acc)
shares, err := fundAccountAndDelegate(t, f, delegatorAddr1, validator, f.amt1)
assert.NilError(t, err)
@@ -205,7 +205,8 @@ func TestRotateConsPubKey(t *testing.T) {
// create 5 validators
for i := 0; i < 5; i++ {
comm := types.NewCommissionRates(math.LegacyNewDec(0), math.LegacyNewDec(0), math.LegacyNewDec(0))
acc := f.accountKeeper.NewAccountWithAddress(ctx, sdk.AccAddress(valAddrs[i]))
f.accountKeeper.SetAccount(ctx, acc)
msg, err := types.NewMsgCreateValidator(valAddrs[i].String(), PKs[i], sdk.NewCoin(sdk.DefaultBondDenom, stakingKeeper.TokensFromConsensusPower(ctx, 30)),
types.Description{Moniker: "NewVal"}, comm, math.OneInt())
assert.NilError(t, err)
@@ -384,6 +384,10 @@ func TestUnbondingDelegationOnHold1(t *testing.T) {
// _, app, ctx := createTestInput(t)
bondDenom, addrDels, addrVals := SetupUnbondingTests(t, f, &hookCalled, &ubdeID)
for _, addr := range addrDels {
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
f.accountKeeper.SetAccount(f.sdkCtx, acc)
}
completionTime, bondedAmt1, notBondedAmt1 := doUnbondingDelegation(t, f.stakingKeeper, f.bankKeeper, f.sdkCtx, bondDenom, addrDels, addrVals, &hookCalled)
// CONSUMER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
@@ -423,6 +427,10 @@ func TestUnbondingDelegationOnHold2(t *testing.T) {
// _, app, ctx := createTestInput(t)
bondDenom, addrDels, addrVals := SetupUnbondingTests(t, f, &hookCalled, &ubdeID)
for _, addr := range addrDels {
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, addr)
f.accountKeeper.SetAccount(f.sdkCtx, acc)
}
completionTime, bondedAmt1, notBondedAmt1 := doUnbondingDelegation(t, f.stakingKeeper, f.bankKeeper, f.sdkCtx, bondDenom, addrDels, addrVals, &hookCalled)
// PROVIDER CHAIN'S UNBONDING PERIOD ENDS - BUT UNBONDING CANNOT COMPLETE
@@ -40,6 +40,8 @@ func TestValidateVoteExtensions(t *testing.T) {
vals := []stakingtypes.Validator{}
for _, v := range privKeys {
valAddr := sdk.ValAddress(v.PubKey().Address())
acc := f.accountKeeper.NewAccountWithAddress(f.sdkCtx, sdk.AccAddress(v.PubKey().Address()))
f.accountKeeper.SetAccount(f.sdkCtx, acc)
simtestutil.AddTestAddrsFromPubKeys(f.bankKeeper, f.stakingKeeper, f.sdkCtx, []cryptotypes.PubKey{v.PubKey()}, math.NewInt(100000000000))
vals = append(vals, testutil.NewValidator(t, valAddr, v.PubKey()))
}