2019-11-25 19:46:02 +00:00
|
|
|
package pricefeed
|
|
|
|
|
|
|
|
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"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testHelper struct {
|
|
|
|
mApp *mock.App
|
|
|
|
keeper Keeper
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
pubKeys []crypto.PubKey
|
|
|
|
privKeys []crypto.PrivKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func getMockApp(t *testing.T, numGenAccs int, genState GenesisState, genAccs []authexported.Account) testHelper {
|
|
|
|
mApp := mock.NewApp()
|
|
|
|
RegisterCodec(mApp.Cdc)
|
|
|
|
keyPricefeed := sdk.NewKVStoreKey(StoreKey)
|
|
|
|
pk := mApp.ParamsKeeper
|
2019-12-03 14:32:01 +00:00
|
|
|
keeper := NewKeeper(mApp.Cdc, keyPricefeed, pk.Subspace(DefaultParamspace).WithKeyTable(ParamKeyTable()), DefaultCodespace)
|
2019-11-25 19:46:02 +00:00
|
|
|
|
|
|
|
// Register routes
|
|
|
|
mApp.Router().AddRoute(RouterKey, NewHandler(keeper))
|
|
|
|
mApp.SetEndBlocker(getEndBlocker(keeper))
|
|
|
|
|
|
|
|
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}
|
|
|
|
}
|
|
|
|
|
|
|
|
// gov and staking endblocker
|
|
|
|
func getEndBlocker(keeper Keeper) sdk.EndBlocker {
|
|
|
|
return func(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock {
|
|
|
|
EndBlocker(ctx, keeper)
|
|
|
|
return abci.ResponseEndBlock{}
|
|
|
|
}
|
|
|
|
}
|