2020-01-17 12:29:19 +00:00
|
|
|
package pricefeed_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-02-06 22:54:10 +00:00
|
|
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
|
|
tmtime "github.com/cometbft/cometbft/types/time"
|
2022-01-08 00:39:27 +00:00
|
|
|
|
2020-01-17 12:29:19 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
2020-01-17 12:29:19 +00:00
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/pricefeed"
|
2022-01-08 00:39:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/pricefeed/keeper"
|
2020-01-17 12:29:19 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GenesisTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
tApp app.TestApp
|
2020-01-17 12:29:19 +00:00
|
|
|
ctx sdk.Context
|
2022-01-08 00:39:27 +00:00
|
|
|
keeper keeper.Keeper
|
2020-01-17 12:29:19 +00:00
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *GenesisTestSuite) SetupTest() {
|
|
|
|
suite.tApp = app.NewTestApp()
|
|
|
|
suite.ctx = suite.tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
suite.keeper = suite.tApp.GetPriceFeedKeeper()
|
|
|
|
}
|
2020-01-17 12:29:19 +00:00
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *GenesisTestSuite) TestValidGenState() {
|
2020-01-17 12:29:19 +00:00
|
|
|
suite.NotPanics(func() {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.tApp.InitializeFromGenesisStates(
|
2020-01-17 12:29:19 +00:00
|
|
|
NewPricefeedGenStateMulti(),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(10)
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
// Must create a new TestApp or InitChain will panic with index already set
|
|
|
|
suite.tApp = app.NewTestApp()
|
2020-01-17 12:29:19 +00:00
|
|
|
suite.NotPanics(func() {
|
2022-01-08 00:39:27 +00:00
|
|
|
suite.tApp.InitializeFromGenesisStates(
|
2020-01-17 12:29:19 +00:00
|
|
|
NewPricefeedGenStateWithOracles(addrs),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-08 00:39:27 +00:00
|
|
|
func (suite *GenesisTestSuite) TestInitExportGenState() {
|
|
|
|
gs := NewPricefeedGen()
|
|
|
|
|
|
|
|
suite.NotPanics(func() {
|
|
|
|
pricefeed.InitGenesis(suite.ctx, suite.keeper, gs)
|
|
|
|
})
|
|
|
|
|
|
|
|
exportedGs := pricefeed.ExportGenesis(suite.ctx, suite.keeper)
|
|
|
|
suite.NoError(gs.VerboseEqual(exportedGs), "exported genesis should match init genesis")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *GenesisTestSuite) TestParamPricesGenState() {
|
|
|
|
gs := NewPricefeedGen()
|
|
|
|
|
|
|
|
suite.NotPanics(func() {
|
|
|
|
pricefeed.InitGenesis(suite.ctx, suite.keeper, gs)
|
|
|
|
})
|
|
|
|
|
|
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
|
|
suite.NoError(gs.Params.VerboseEqual(params), "params should equal init params")
|
|
|
|
|
|
|
|
pps := suite.keeper.GetRawPrices(suite.ctx, "btc:usd")
|
|
|
|
suite.NoError(gs.PostedPrices[0].VerboseEqual(pps[0]), "posted prices should equal init posted prices")
|
|
|
|
}
|
|
|
|
|
2020-01-17 12:29:19 +00:00
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(GenesisTestSuite))
|
|
|
|
}
|