refactor(x/staking)!: KVStoreService, return errors and use context.Context (#16324)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
Facundo Medica
2023-06-16 18:40:44 +00:00
committed by GitHub
co-authored by Aleksandr Bezobchuk
parent c44957890a
commit 1be7d9805e
111 changed files with 3579 additions and 2215 deletions
@@ -19,16 +19,17 @@ func TestCancelUnbondingDelegation(t *testing.T) {
ctx := f.sdkCtx
msgServer := keeper.NewMsgServerImpl(f.stakingKeeper)
bondDenom := f.stakingKeeper.BondDenom(ctx)
bondDenom, err := f.stakingKeeper.BondDenom(ctx)
assert.NilError(t, err)
// set the not bonded pool module account
notBondedPool := f.stakingKeeper.GetNotBondedPool(ctx)
startTokens := f.stakingKeeper.TokensFromConsensusPower(ctx, 5)
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), startTokens))))
assert.NilError(t, testutil.FundModuleAccount(ctx, f.bankKeeper, notBondedPool.GetName(), sdk.NewCoins(sdk.NewCoin(bondDenom, startTokens))))
f.accountKeeper.SetModuleAccount(ctx, notBondedPool)
moduleBalance := f.bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), f.stakingKeeper.BondDenom(ctx))
moduleBalance := f.bankKeeper.GetBalance(ctx, notBondedPool.GetAddress(), bondDenom)
assert.DeepEqual(t, sdk.NewInt64Coin(bondDenom, startTokens.Int64()), moduleBalance)
// accounts
@@ -40,13 +41,13 @@ func TestCancelUnbondingDelegation(t *testing.T) {
validator, err := types.NewValidator(valAddr, PKs[0], types.NewDescription("Validator", "", "", "", ""))
validator.Status = types.Bonded
assert.NilError(t, err)
f.stakingKeeper.SetValidator(ctx, validator)
assert.NilError(t, f.stakingKeeper.SetValidator(ctx, validator))
validatorAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress)
assert.NilError(t, err)
// setting the ubd entry
unbondingAmount := sdk.NewInt64Coin(f.stakingKeeper.BondDenom(ctx), 5)
unbondingAmount := sdk.NewInt64Coin(bondDenom, 5)
ubd := types.NewUnbondingDelegation(
delegatorAddr, validatorAddr, 10,
ctx.BlockTime().Add(time.Minute*10),
@@ -55,7 +56,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
)
// set and retrieve a record
f.stakingKeeper.SetUnbondingDelegation(ctx, ubd)
assert.NilError(t, f.stakingKeeper.SetUnbondingDelegation(ctx, ubd))
resUnbond, found := f.stakingKeeper.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
assert.Assert(t, found)
assert.DeepEqual(t, ubd, resUnbond)
@@ -72,7 +73,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
req: types.MsgCancelUnbondingDelegation{
DelegatorAddress: resUnbond.DelegatorAddress,
ValidatorAddress: resUnbond.ValidatorAddress,
Amount: sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
Amount: sdk.NewCoin(bondDenom, sdk.NewInt(4)),
CreationHeight: 11,
},
expErrMsg: "unbonding delegation entry is not found at block height",
@@ -83,7 +84,7 @@ func TestCancelUnbondingDelegation(t *testing.T) {
req: types.MsgCancelUnbondingDelegation{
DelegatorAddress: resUnbond.DelegatorAddress,
ValidatorAddress: resUnbond.ValidatorAddress,
Amount: sdk.NewCoin(f.stakingKeeper.BondDenom(ctx), sdk.NewInt(4)),
Amount: sdk.NewCoin(bondDenom, sdk.NewInt(4)),
CreationHeight: 0,
},
expErrMsg: "invalid height",