mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
9d9b169e6a
* swap module scaffolding * global swap fee * can't think of a reason for begin blocker; removing for abci.go for now; * test pair types; refactor pair name logic; simplify pairs validation and fix stack overflow error * check comparison * use test package * init swap module genesis * add basic marshall tests * remove reward apy from pairs * fix integration helpers * use max swap fee constant; fix validation of swap fee; add tests to cover param validation and param set setup * use noerror over nil * start genesis tests * test param set validation mirrors param validation * add genesis tests * remove print statement * add subtests for genesis test cases; add extra querier test for unknown route; add keeper params testing * add spec * update swagger * find replace hard -> swap in comments * remove unused method * rename pairs to allowed pools; pool is more commonly used, and allowedPool makes it more clear what swap parameter is for. In addition, we won't conflict with Pool data structure for storing a created pool in the store. * remove generated link * missed spec rename * validate token order for allowed pools * fix swagger * json should be snakecase; change allowedPools to allowed_pools Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/swap/keeper"
|
|
"github.com/kava-labs/kava/x/swap/types"
|
|
)
|
|
|
|
type QuerierTestSuite struct {
|
|
suite.Suite
|
|
keeper keeper.Keeper
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
querier sdk.Querier
|
|
}
|
|
|
|
func (suite *QuerierTestSuite) SetupTest() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
|
|
tApp.InitializeFromGenesisStates(
|
|
NewSwapGenStateMulti(),
|
|
)
|
|
|
|
suite.ctx = ctx
|
|
suite.app = tApp
|
|
suite.keeper = tApp.GetSwapKeeper()
|
|
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{}
|
|
types.ModuleCdc.UnmarshalJSON(swapGenesisState["swap"], &gs)
|
|
|
|
suite.Equal(gs.Params, p)
|
|
}
|
|
|
|
func TestQuerierTestSuite(t *testing.T) {
|
|
suite.Run(t, new(QuerierTestSuite))
|
|
}
|