mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
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
|
|
keeper := NewKeeper(mApp.Cdc, keyPricefeed, pk.Subspace(DefaultParamspace).WithKeyTable(ParamKeyTable()), DefaultCodespace)
|
|
|
|
// 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{}
|
|
}
|
|
}
|