refactor creation of the simapp
This commit is contained in:
parent
594e0a6bfa
commit
e155b1083d
|
@ -8,18 +8,15 @@ import (
|
|||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
func TestNewQuerier(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000))
|
||||
_, addrAcc2 := addrs[0], addrs[1]
|
||||
addrVal1, _ := sdk.ValAddress(addrs[0]), sdk.ValAddress(addrs[1])
|
||||
|
@ -109,9 +106,7 @@ func TestNewQuerier(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryParametersPool(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
bondDenom := sdk.DefaultBondDenom
|
||||
|
@ -136,21 +131,10 @@ func TestQueryParametersPool(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryValidators(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
params := app.StakingKeeper.GetParams(ctx)
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
codec := simapp.NewAppCodec()
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
codec.Staking,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000))
|
||||
|
||||
// Create Validators
|
||||
|
@ -214,21 +198,10 @@ func TestQueryValidators(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryDelegation(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
params := app.StakingKeeper.GetParams(ctx)
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
codec := simapp.NewAppCodec()
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
codec.Staking,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
||||
|
@ -452,20 +425,9 @@ func TestQueryDelegation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryRedelegations(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
codec := simapp.NewAppCodec()
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
codec.Staking,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
||||
|
@ -532,20 +494,9 @@ func TestQueryRedelegations(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryUnbondingDelegation(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
codec := simapp.NewAppCodec()
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
codec.Staking,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||
addrVal1 := sdk.ValAddress(addrAcc1)
|
||||
|
@ -638,9 +589,7 @@ func TestQueryUnbondingDelegation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestQueryHistoricalInfo(t *testing.T) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||
querier := staking.NewQuerier(app.StakingKeeper)
|
||||
|
||||
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||
|
|
|
@ -5,6 +5,12 @@ import (
|
|||
"encoding/hex"
|
||||
"strconv"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
|
||||
|
@ -96,3 +102,21 @@ func CreateTestAddr(addr string, bech string) sdk.AccAddress {
|
|||
|
||||
return res
|
||||
}
|
||||
|
||||
// getBaseSimappWithCustomKeeper Returns a simapp with custom StakingKeeper
|
||||
// to avoid messing with the hooks.
|
||||
func getBaseSimappWithCustomKeeper() (*codec.Codec, *simapp.SimApp, sdk.Context) {
|
||||
cdc := codec.New()
|
||||
app := simapp.Setup(false)
|
||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
||||
|
||||
app.StakingKeeper = keeper.NewKeeper(
|
||||
simapp.NewAppCodec().Staking,
|
||||
app.GetKey(staking.StoreKey),
|
||||
app.BankKeeper,
|
||||
app.SupplyKeeper,
|
||||
app.GetSubspace(staking.ModuleName),
|
||||
)
|
||||
|
||||
return cdc, app, ctx
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue