Skip to content

Commit

Permalink
thelper
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Dec 24, 2023
1 parent 8dd7366 commit 07c421f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func genesisStateWithValSet(t *testing.T,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) GenesisState {
t.Helper()
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)
Expand Down Expand Up @@ -399,6 +400,7 @@ func TestAddr(addr string, bech string) (sdk.AccAddress, error) {

// CheckBalance checks the balance of an account.
func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, balances sdk.Coins) {
t.Helper()
ctxCheck := app.BaseApp.NewContext(true, tmproto.Header{})
require.True(t, balances.IsEqual(app.BankKeeper.GetAllBalances(ctxCheck, addr)))
}
Expand All @@ -411,6 +413,7 @@ func SignCheckDeliver(
t *testing.T, txCfg client.TxConfig, app *bam.BaseApp, header tmproto.Header, msgs []sdk.Msg,
chainID string, accNums, accSeqs []uint64, expSimPass, expPass bool, priv ...cryptotypes.PrivKey,
) (sdk.GasInfo, *sdk.Result, error) {
t.Helper()
tx, err := helpers.GenSignedMockTx(
rand.New(rand.NewSource(time.Now().UnixNano())),
txCfg,
Expand Down
2 changes: 2 additions & 0 deletions x/staking/keeper/liquid_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestAccountIsLiquidStakingProvider(t *testing.T) {

// Helper function to clear the Bonded pool balances before a unit test
func clearPoolBalance(t *testing.T, app *simapp.SimApp, ctx sdk.Context) {
t.Helper()
bondDenom := app.StakingKeeper.BondDenom(ctx)
initialBondedBalance := app.BankKeeper.GetBalance(ctx, app.AccountKeeper.GetModuleAddress(types.BondedPoolName), bondDenom)

Expand All @@ -102,6 +103,7 @@ func clearPoolBalance(t *testing.T, app *simapp.SimApp, ctx sdk.Context) {

// Helper function to fund the Bonded pool balances before a unit test
func fundPoolBalance(t *testing.T, app *simapp.SimApp, ctx sdk.Context, amount sdk.Int) {
t.Helper()
bondDenom := app.StakingKeeper.BondDenom(ctx)
bondedPoolCoin := sdk.NewCoin(bondDenom, amount)

Expand Down
1 change: 1 addition & 0 deletions x/staking/keeper/slash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

// bootstrapSlashTest creates 3 validators and bootstrap the app.
func bootstrapSlashTest(t *testing.T, power int64) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
t.Helper()
_, app, ctx := createTestInput(t)

addrDels, addrVals := generateAddresses(app, ctx, 100)
Expand Down
19 changes: 11 additions & 8 deletions x/staking/keeper/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ import (
"github.com/iqlusioninc/liquidity-staking-module/x/staking/types"
)

func newMonikerValidator(t testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
func newMonikerValidator(tb testing.TB, operator sdk.ValAddress, pubKey cryptotypes.PubKey, moniker string) types.Validator {
tb.Helper()
v, err := types.NewValidator(operator, pubKey, types.Description{Moniker: moniker})
require.NoError(t, err)
require.NoError(tb, err)
return v
}

func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
func bootstrapValidatorTest(tb testing.TB, power int64, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
tb.Helper()
_, app, ctx := createTestInput(&testing.T{})

addrDels, addrVals := generateAddresses(app, ctx, numAddrs)
Expand All @@ -44,25 +46,26 @@ func bootstrapValidatorTest(t testing.TB, power int64, numAddrs int) (*simapp.Si

// unbond genesis validator delegations
delegations := app.StakingKeeper.GetAllDelegations(ctx)
require.Len(t, delegations, 1)
require.Len(tb, delegations, 1)
delegation := delegations[0]

_, err := app.StakingKeeper.Undelegate(ctx, delegation.GetDelegatorAddr(), delegation.GetValidatorAddr(), delegation.Shares)
require.NoError(t, err)
require.NoError(tb, err)

// end block to unbond genesis validator
staking.EndBlocker(ctx, app.StakingKeeper)

return app, ctx, addrDels, addrVals
}

func initValidators(t testing.TB, power int64, numAddrs int, powers []int64) (*simapp.SimApp, sdk.Context, []sdk.ValAddress, []types.Validator) {
app, ctx, addrs, valAddrs := bootstrapValidatorTest(t, power, numAddrs)
func initValidators(tb testing.TB, power int64, numAddrs int, powers []int64) (*simapp.SimApp, sdk.Context, []sdk.ValAddress, []types.Validator) {
tb.Helper()
app, ctx, addrs, valAddrs := bootstrapValidatorTest(tb, power, numAddrs)
pks := simapp.CreateTestPubKeys(numAddrs)

vs := make([]types.Validator, len(powers))
for i, power := range powers {
vs[i] = teststaking.NewValidator(t, sdk.ValAddress(addrs[i]), pks[i])
vs[i] = teststaking.NewValidator(tb, sdk.ValAddress(addrs[i]), pks[i])
tokens := app.StakingKeeper.TokensFromConsensusPower(ctx, power)
vs[i], _ = vs[i].AddTokensFromDel(tokens)
}
Expand Down
4 changes: 2 additions & 2 deletions x/staking/types/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ func mkValidator(tokens int64, shares sdk.Dec) types.Validator {
}

// Creates a new validators and asserts the error check.
func newValidator(t *testing.T, operator sdk.ValAddress, pubKey cryptotypes.PubKey) types.Validator {
func newValidator(tb *testing.T, operator sdk.ValAddress, pubKey cryptotypes.PubKey) types.Validator {
v, err := types.NewValidator(operator, pubKey, types.Description{})
require.NoError(t, err)
require.NoError(tb, err)
return v
}

0 comments on commit 07c421f

Please sign in to comment.