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>
174 lines
5.7 KiB
Go
174 lines
5.7 KiB
Go
package keeper_test
|
|
|
|
// import (
|
|
// "strings"
|
|
// "testing"
|
|
|
|
// sdk "github.com/cosmos/cosmos-sdk/types"
|
|
// "github.com/stretchr/testify/suite"
|
|
// abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
// "github.com/kava-labs/kava/app"
|
|
// "github.com/kava-labs/kava/x/swap/keeper"
|
|
// "github.com/kava-labs/kava/x/swap/testutil"
|
|
// "github.com/kava-labs/kava/x/swap/types"
|
|
// )
|
|
|
|
// type querierTestSuite struct {
|
|
// testutil.Suite
|
|
// querier sdk.Querier
|
|
// addresses []sdk.AccAddress
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) SetupTest() {
|
|
// suite.Suite.SetupTest()
|
|
|
|
// // Set up auth GenesisState
|
|
// _, addrs := app.GeneratePrivKeyAddressPairs(5)
|
|
// coins := []sdk.Coins{}
|
|
// for j := 0; j < 5; j++ {
|
|
// coins = append(coins, cs(c("ukava", 10000000000), c("bnb", 10000000000), c("usdx", 10000000000)))
|
|
// }
|
|
// suite.addresses = addrs
|
|
// authGS := app.NewAuthGenState(addrs, coins)
|
|
|
|
// suite.App.InitializeFromGenesisStates(
|
|
// authGS,
|
|
// NewSwapGenStateMulti(),
|
|
// )
|
|
// suite.querier = keeper.NewQuerier(suite.Keeper)
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) TestUnkownRequest() {
|
|
// ctx := suite.Ctx.WithIsCheckTx(false)
|
|
// bz, err := suite.querier(ctx, []string{"invalid-path"}, abci.RequestQuery{})
|
|
// suite.Nil(bz)
|
|
// suite.EqualError(err, "unknown request: unknown swap query endpoint")
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) TestQueryParams() {
|
|
// ctx := suite.Ctx.WithIsCheckTx(false)
|
|
// bz, err := suite.querier(ctx, []string{types.QueryGetParams}, abci.RequestQuery{})
|
|
// suite.Nil(err)
|
|
// suite.NotNil(bz)
|
|
|
|
// var p types.Params
|
|
// suite.Nil(types.ModuleCdc.UnmarshalJSON(bz, &p))
|
|
|
|
// swapGenesisState := NewSwapGenStateMulti()
|
|
// gs := types.GenesisState{}
|
|
// err = types.ModuleCdc.UnmarshalJSON(swapGenesisState["swap"], &gs)
|
|
// suite.Require().NoError(err)
|
|
|
|
// suite.Equal(gs.Params, p)
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) TestQueryPool() {
|
|
// // Set up pool in store
|
|
// coinA := sdk.NewCoin("ukava", sdk.NewInt(10))
|
|
// coinB := sdk.NewCoin("usdx", sdk.NewInt(200))
|
|
|
|
// pool, err := types.NewDenominatedPool(sdk.NewCoins(coinA, coinB))
|
|
// suite.Nil(err)
|
|
// poolRecord := types.NewPoolRecordFromPool(pool)
|
|
// suite.Keeper.SetPool(suite.Ctx, poolRecord)
|
|
|
|
// ctx := suite.Ctx.WithIsCheckTx(false)
|
|
// // Set up request query
|
|
// query := abci.RequestQuery{
|
|
// Path: strings.Join([]string{"custom", types.QuerierRoute, types.QueryGetPool}, "/"),
|
|
// Data: types.ModuleCdc.MustMarshalJSON(types.NewQueryPoolParams(poolRecord.PoolID)),
|
|
// }
|
|
|
|
// bz, err := suite.querier(ctx, []string{types.QueryGetPool}, query)
|
|
// suite.Nil(err)
|
|
// suite.NotNil(bz)
|
|
|
|
// var res types.PoolStatsQueryResult
|
|
// suite.Nil(types.ModuleCdc.UnmarshalJSON(bz, &res))
|
|
|
|
// // Check that result matches expected result
|
|
// totalCoins := pool.ShareValue(pool.TotalShares())
|
|
// expectedResult := types.NewPoolStatsQueryResult(poolRecord.PoolID, totalCoins, pool.TotalShares())
|
|
// suite.Equal(expectedResult, res)
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) TestQueryPools() {
|
|
// // Set up pools in store
|
|
// coinA := sdk.NewCoin("ukava", sdk.NewInt(10))
|
|
// coinB := sdk.NewCoin("usdx", sdk.NewInt(200))
|
|
// coinC := sdk.NewCoin("usdx", sdk.NewInt(200))
|
|
|
|
// poolAB, err := types.NewDenominatedPool(sdk.NewCoins(coinA, coinB))
|
|
// suite.Nil(err)
|
|
// poolRecordAB := types.NewPoolRecordFromPool(poolAB)
|
|
// suite.Keeper.SetPool(suite.Ctx, poolRecordAB)
|
|
|
|
// poolAC, err := types.NewDenominatedPool(sdk.NewCoins(coinA, coinC))
|
|
// suite.Nil(err)
|
|
// poolRecordAC := types.NewPoolRecordFromPool(poolAC)
|
|
// suite.Keeper.SetPool(suite.Ctx, poolRecordAC)
|
|
|
|
// // Build a map of pools to compare to query results
|
|
// pools := types.PoolRecords{poolRecordAB, poolRecordAC}
|
|
// poolsMap := make(map[string]types.PoolRecord)
|
|
// for _, pool := range pools {
|
|
// poolsMap[pool.PoolID] = pool
|
|
// }
|
|
|
|
// ctx := suite.Ctx.WithIsCheckTx(false)
|
|
// bz, err := suite.querier(ctx, []string{types.QueryGetPools}, abci.RequestQuery{})
|
|
// suite.Nil(err)
|
|
// suite.NotNil(bz)
|
|
|
|
// var res types.PoolStatsQueryResults
|
|
// suite.Nil(types.ModuleCdc.UnmarshalJSON(bz, &res))
|
|
|
|
// // Check that all pools are accounted for
|
|
// suite.Equal(len(poolsMap), len(res))
|
|
// // Check that each individual result matches the expected result
|
|
// for _, pool := range res {
|
|
// expectedPool, ok := poolsMap[pool.Name]
|
|
// suite.True(ok)
|
|
// suite.Equal(expectedPool.PoolID, pool.Name)
|
|
// suite.Equal(sdk.NewCoins(expectedPool.ReservesA, expectedPool.ReservesB), pool.Coins)
|
|
// suite.Equal(expectedPool.TotalShares, pool.TotalShares)
|
|
// }
|
|
// }
|
|
|
|
// func (suite *querierTestSuite) TestQueryDeposit() {
|
|
// // Set up pool in store
|
|
// coinA := sdk.NewCoin("ukava", sdk.NewInt(10))
|
|
// coinB := sdk.NewCoin("usdx", sdk.NewInt(200))
|
|
// pool, err := types.NewDenominatedPool(sdk.NewCoins(coinA, coinB))
|
|
// suite.Nil(err)
|
|
// poolRecord := types.NewPoolRecordFromPool(pool)
|
|
// suite.Keeper.SetPool(suite.Ctx, poolRecord)
|
|
|
|
// // Deposit into pool
|
|
// owner := suite.addresses[0]
|
|
// err = suite.Keeper.Deposit(suite.Ctx, owner, coinA, coinB, sdk.MustNewDecFromStr("0.20"))
|
|
// suite.Nil(err)
|
|
|
|
// ctx := suite.Ctx.WithIsCheckTx(false)
|
|
// // Set up request query
|
|
// query := abci.RequestQuery{
|
|
// Path: strings.Join([]string{"custom", types.QuerierRoute, types.QueryGetDeposits}, "/"),
|
|
// Data: types.ModuleCdc.MustMarshalJSON(types.NewQueryDepositsParams(1, 100, owner, poolRecord.PoolID)),
|
|
// }
|
|
|
|
// bz, err := suite.querier(ctx, []string{types.QueryGetDeposits}, query)
|
|
// suite.Nil(err)
|
|
// suite.NotNil(bz)
|
|
|
|
// var res types.DepositsQueryResults
|
|
// suite.Nil(types.ModuleCdc.UnmarshalJSON(bz, &res))
|
|
|
|
// // As the only depositor all pool shares should belong to the owner
|
|
// suite.Equal(poolRecord.TotalShares, res[0].SharesOwned)
|
|
// }
|
|
|
|
// func TestQuerierTestSuite(t *testing.T) {
|
|
// suite.Run(t, new(querierTestSuite))
|
|
// }
|