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"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
"github.com/cosmos/cosmos-sdk/simapp"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewQuerier(t *testing.T) {
|
func TestNewQuerier(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000))
|
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.NewInt(10000))
|
||||||
_, addrAcc2 := addrs[0], addrs[1]
|
_, addrAcc2 := addrs[0], addrs[1]
|
||||||
addrVal1, _ := sdk.ValAddress(addrs[0]), sdk.ValAddress(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) {
|
func TestQueryParametersPool(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
querier := staking.NewQuerier(app.StakingKeeper)
|
||||||
|
|
||||||
bondDenom := sdk.DefaultBondDenom
|
bondDenom := sdk.DefaultBondDenom
|
||||||
|
@ -136,21 +131,10 @@ func TestQueryParametersPool(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryValidators(t *testing.T) {
|
func TestQueryValidators(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
params := app.StakingKeeper.GetParams(ctx)
|
params := app.StakingKeeper.GetParams(ctx)
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
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))
|
addrs := simapp.AddTestAddrs(app, ctx, 500, sdk.TokensFromConsensusPower(10000))
|
||||||
|
|
||||||
// Create Validators
|
// Create Validators
|
||||||
|
@ -214,21 +198,10 @@ func TestQueryValidators(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryDelegation(t *testing.T) {
|
func TestQueryDelegation(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
params := app.StakingKeeper.GetParams(ctx)
|
params := app.StakingKeeper.GetParams(ctx)
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
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))
|
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||||
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
||||||
|
@ -452,20 +425,9 @@ func TestQueryDelegation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryRedelegations(t *testing.T) {
|
func TestQueryRedelegations(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
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))
|
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||||
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)
|
||||||
|
@ -532,20 +494,9 @@ func TestQueryRedelegations(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryUnbondingDelegation(t *testing.T) {
|
func TestQueryUnbondingDelegation(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
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))
|
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||||
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
addrAcc1, addrAcc2 := addrs[0], addrs[1]
|
||||||
addrVal1 := sdk.ValAddress(addrAcc1)
|
addrVal1 := sdk.ValAddress(addrAcc1)
|
||||||
|
@ -638,9 +589,7 @@ func TestQueryUnbondingDelegation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryHistoricalInfo(t *testing.T) {
|
func TestQueryHistoricalInfo(t *testing.T) {
|
||||||
cdc := codec.New()
|
cdc, app, ctx := getBaseSimappWithCustomKeeper()
|
||||||
app := simapp.Setup(false)
|
|
||||||
ctx := app.BaseApp.NewContext(false, abci.Header{})
|
|
||||||
querier := staking.NewQuerier(app.StakingKeeper)
|
querier := staking.NewQuerier(app.StakingKeeper)
|
||||||
|
|
||||||
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.TokensFromConsensusPower(10000))
|
||||||
|
|
|
@ -5,6 +5,12 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"strconv"
|
"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"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
|
||||||
|
@ -96,3 +102,21 @@ func CreateTestAddr(addr string, bech string) sdk.AccAddress {
|
||||||
|
|
||||||
return res
|
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