mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
ffef832d45
- Upgrade cosmos-sdk to v0.44.5 from v0.39.2 - Add Legacy Tx Endpoint for backwards compatibility - Add IBC v1.2.3 Support Co-authored-by: DracoLi <draco@dracoli.com> Co-authored-by: drklee3 <derrick@dlee.dev> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: Draco Li <draco@kava.io> Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: Denali Marsh <denali@kava.io>
72 lines
2.0 KiB
Go
72 lines
2.0 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
tmprototypes "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/pricefeed/keeper"
|
|
"github.com/kava-labs/kava/x/pricefeed/types"
|
|
)
|
|
|
|
type KeeperTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
addrs []sdk.AccAddress
|
|
ctx sdk.Context
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, tmprototypes.Header{Height: 1, Time: tmtime.Now()})
|
|
tApp.InitializeFromGenesisStates(
|
|
NewPricefeedGenStateMulti(),
|
|
)
|
|
suite.keeper = tApp.GetPriceFeedKeeper()
|
|
suite.ctx = ctx
|
|
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(10)
|
|
suite.addrs = addrs
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestGetSetOracles() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
suite.Equal([]sdk.AccAddress(nil), params.Markets[0].Oracles)
|
|
|
|
params.Markets[0].Oracles = suite.addrs
|
|
suite.NotPanics(func() { suite.keeper.SetParams(suite.ctx, params) })
|
|
params = suite.keeper.GetParams(suite.ctx)
|
|
suite.Equal(suite.addrs, params.Markets[0].Oracles)
|
|
|
|
addr, err := suite.keeper.GetOracle(suite.ctx, params.Markets[0].MarketID, suite.addrs[0])
|
|
suite.NoError(err)
|
|
suite.Equal(suite.addrs[0], addr)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestGetAuthorizedAddresses() {
|
|
_, oracles := app.GeneratePrivKeyAddressPairs(5)
|
|
|
|
params := types.Params{
|
|
Markets: []types.Market{
|
|
{MarketID: "btc:usd", BaseAsset: "btc", QuoteAsset: "usd", Oracles: oracles[:3], Active: true},
|
|
{MarketID: "xrp:usd", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: oracles[2:], Active: true},
|
|
{MarketID: "xrp:usd:30", BaseAsset: "xrp", QuoteAsset: "usd", Oracles: nil, Active: true},
|
|
},
|
|
}
|
|
suite.keeper.SetParams(suite.ctx, params)
|
|
|
|
actualOracles := suite.keeper.GetAuthorizedAddresses(suite.ctx)
|
|
|
|
suite.Require().ElementsMatch(oracles, actualOracles)
|
|
}
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
}
|