Merge PR #4918: refactor crisis tests
This commit is contained in:
committed by
Alexander Bezobchuk
parent
e7b378d81d
commit
5aacf454e1
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/genaccounts"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
)
|
||||
|
||||
// Setup initializes a new SimApp. A Nop logger is set in SimApp.
|
||||
@@ -69,6 +71,30 @@ func SetupWithGenesisAccounts(genAccs genaccounts.GenesisAccounts) *SimApp {
|
||||
return app
|
||||
}
|
||||
|
||||
// AddTestAddrs constructs and returns accNum amount of accounts with an
|
||||
// initial balance of accAmt
|
||||
func AddTestAddrs(app *SimApp, ctx sdk.Context, accNum int, accAmt sdk.Int) []sdk.AccAddress {
|
||||
testAddrs := make([]sdk.AccAddress, accNum)
|
||||
for i := 0; i < accNum; i++ {
|
||||
pk := ed25519.GenPrivKey().PubKey()
|
||||
testAddrs[i] = sdk.AccAddress(pk.Address())
|
||||
}
|
||||
|
||||
initCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt))
|
||||
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(len(testAddrs)))))
|
||||
prevSupply := app.SupplyKeeper.GetSupply(ctx)
|
||||
app.SupplyKeeper.SetSupply(ctx, supply.NewSupply(prevSupply.GetTotal().Add(totalSupply)))
|
||||
|
||||
// fill all the addresses with some coins, set the loose pool tokens simultaneously
|
||||
for _, addr := range testAddrs {
|
||||
_, err := app.BankKeeper.AddCoins(ctx, addr, initCoins)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return testAddrs
|
||||
}
|
||||
|
||||
// CheckBalance checks the balance of an account.
|
||||
func CheckBalance(t *testing.T, app *SimApp, addr sdk.AccAddress, exp sdk.Coins) {
|
||||
ctxCheck := app.BaseApp.NewContext(true, abci.Header{})
|
||||
|
||||
Reference in New Issue
Block a user