0g-chain/x/pricefeed/keeper/test_common.go

47 lines
1.3 KiB
Go
Raw Normal View History

2019-11-27 14:45:59 +00:00
package keeper
2019-11-25 19:46:02 +00:00
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
authexported "github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/mock"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
2019-11-27 14:45:59 +00:00
"github.com/kava-labs/kava/x/pricefeed/types"
2019-11-25 19:46:02 +00:00
)
type testHelper struct {
mApp *mock.App
keeper Keeper
addrs []sdk.AccAddress
pubKeys []crypto.PubKey
privKeys []crypto.PrivKey
}
2019-11-27 14:45:59 +00:00
func getMockApp(t *testing.T, numGenAccs int, genState types.GenesisState, genAccs []authexported.Account) testHelper {
2019-11-25 19:46:02 +00:00
mApp := mock.NewApp()
2019-11-27 14:45:59 +00:00
types.RegisterCodec(mApp.Cdc)
keyPricefeed := sdk.NewKVStoreKey(types.StoreKey)
2019-11-25 19:46:02 +00:00
pk := mApp.ParamsKeeper
keeper := NewKeeper(mApp.Cdc, keyPricefeed, pk.Subspace(types.DefaultParamspace), types.DefaultCodespace)
2019-11-25 19:46:02 +00:00
require.NoError(t, mApp.CompleteSetup(keyPricefeed))
valTokens := sdk.TokensFromConsensusPower(42)
var (
addrs []sdk.AccAddress
pubKeys []crypto.PubKey
privKeys []crypto.PrivKey
)
if genAccs == nil || len(genAccs) == 0 {
genAccs, addrs, pubKeys, privKeys = mock.CreateGenAccounts(numGenAccs,
sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens)))
}
mock.SetGenesis(mApp, genAccs)
return testHelper{mApp, keeper, addrs, pubKeys, privKeys}
}