mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-27 00:35:18 +00:00
38a98ac4fc
* split up payout.go file * extract genesis builders to new testutil package * move claim integration tests out of keeper * convert claim integration tests to handler tests * combine claim usdx minting keeper methods * combine hard claim keeper methods * combine delegator claim keeper methods * add multiply coins helper method * rename file to better match contents * add basic claiming unit tests * add claiming subset of delegator reward denoms * refactor msg tests * add msg ValidateBasic tests * connect swap hooks into keeper methods * tidy up delegator handler tests * add swap claiming msgs and keeper method * add swap claiming to client * add subset claiming to other msg types * split up handler test file * connect up subset claiming for swap * make multiplier name validation more strict * fix: struct tag typo in swap incentives * connect up subset claiming for hard * connect up subset claiming for delegator * fix: register cli tx routes for swp claiming * fix claim amount in claim event * fix token name in cli help docs * remove unused field in msg tests * tidy up swap and delegator handler tests * refactor hard handler tests * refactor usdx handler tests * remove unused constant Co-authored-by: karzak <kjydavis3@gmail.com>
130 lines
3.4 KiB
Go
130 lines
3.4 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/kava-labs/kava/x/swap/testutil"
|
|
"github.com/kava-labs/kava/x/swap/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type keeperTestSuite struct {
|
|
testutil.Suite
|
|
}
|
|
|
|
func (suite *keeperTestSuite) SetupTest() {
|
|
suite.Suite.SetupTest()
|
|
suite.Keeper.SetParams(suite.Ctx, types.DefaultParams())
|
|
}
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(keeperTestSuite))
|
|
}
|
|
|
|
func (suite *keeperTestSuite) setupPool(reserves sdk.Coins, totalShares sdk.Int, depositor sdk.AccAddress) string {
|
|
poolID := types.PoolIDFromCoins(reserves)
|
|
suite.AddCoinsToModule(reserves)
|
|
|
|
poolRecord := types.PoolRecord{
|
|
PoolID: poolID,
|
|
ReservesA: reserves[0],
|
|
ReservesB: reserves[1],
|
|
TotalShares: totalShares,
|
|
}
|
|
suite.Keeper.SetPool(suite.Ctx, poolRecord)
|
|
|
|
shareRecord := types.ShareRecord{
|
|
Depositor: depositor,
|
|
PoolID: poolID,
|
|
SharesOwned: totalShares,
|
|
}
|
|
suite.Keeper.SetDepositorShares(suite.Ctx, shareRecord)
|
|
|
|
return poolID
|
|
}
|
|
|
|
func (suite keeperTestSuite) TestParams_Persistance() {
|
|
keeper := suite.Keeper
|
|
|
|
params := types.Params{
|
|
AllowedPools: types.AllowedPools{
|
|
types.NewAllowedPool("ukava", "usdx"),
|
|
},
|
|
SwapFee: sdk.MustNewDecFromStr("0.03"),
|
|
}
|
|
keeper.SetParams(suite.Ctx, params)
|
|
suite.Equal(keeper.GetParams(suite.Ctx), params)
|
|
|
|
oldParams := params
|
|
params = types.Params{
|
|
AllowedPools: types.AllowedPools{
|
|
types.NewAllowedPool("hard", "ukava"),
|
|
},
|
|
SwapFee: sdk.MustNewDecFromStr("0.01"),
|
|
}
|
|
keeper.SetParams(suite.Ctx, params)
|
|
suite.NotEqual(keeper.GetParams(suite.Ctx), oldParams)
|
|
suite.Equal(keeper.GetParams(suite.Ctx), params)
|
|
}
|
|
|
|
func (suite keeperTestSuite) TestParams_GetSwapFee() {
|
|
keeper := suite.Keeper
|
|
|
|
params := types.Params{
|
|
SwapFee: sdk.MustNewDecFromStr("0.00333"),
|
|
}
|
|
keeper.SetParams(suite.Ctx, params)
|
|
|
|
suite.Equal(keeper.GetSwapFee(suite.Ctx), params.SwapFee)
|
|
}
|
|
|
|
func (suite *keeperTestSuite) TestPool_Persistance() {
|
|
reserves := sdk.NewCoins(
|
|
sdk.NewCoin("ukava", sdk.NewInt(10e6)),
|
|
sdk.NewCoin("usdx", sdk.NewInt(50e6)),
|
|
)
|
|
|
|
pool, err := types.NewDenominatedPool(reserves)
|
|
suite.Nil(err)
|
|
record := types.NewPoolRecord(pool)
|
|
|
|
suite.Keeper.SetPool(suite.Ctx, record)
|
|
|
|
savedRecord, ok := suite.Keeper.GetPool(suite.Ctx, record.PoolID)
|
|
suite.True(ok)
|
|
suite.Equal(record, savedRecord)
|
|
|
|
savedShares, ok := suite.Keeper.GetPoolShares(suite.Ctx, record.PoolID)
|
|
suite.True(ok)
|
|
suite.Equal(record.TotalShares, savedShares)
|
|
|
|
suite.Keeper.DeletePool(suite.Ctx, record.PoolID)
|
|
deletedPool, ok := suite.Keeper.GetPool(suite.Ctx, record.PoolID)
|
|
suite.False(ok)
|
|
suite.Equal(deletedPool, types.PoolRecord{})
|
|
}
|
|
|
|
func (suite *keeperTestSuite) TestShare_Persistance() {
|
|
poolID := "ukava/usdx"
|
|
depositor := sdk.AccAddress("testAddress1")
|
|
shares := sdk.NewInt(3126432331)
|
|
|
|
record := types.NewShareRecord(depositor, poolID, shares)
|
|
suite.Keeper.SetDepositorShares(suite.Ctx, record)
|
|
|
|
savedRecord, ok := suite.Keeper.GetDepositorShares(suite.Ctx, depositor, poolID)
|
|
suite.True(ok)
|
|
suite.Equal(record, savedRecord)
|
|
|
|
savedShares, ok := suite.Keeper.GetDepositorSharesAmount(suite.Ctx, depositor, poolID)
|
|
suite.True(ok)
|
|
suite.Equal(record.SharesOwned, savedShares)
|
|
|
|
suite.Keeper.DeleteDepositorShares(suite.Ctx, depositor, poolID)
|
|
deletedShares, ok := suite.Keeper.GetDepositorShares(suite.Ctx, depositor, poolID)
|
|
suite.False(ok)
|
|
suite.Equal(deletedShares, types.ShareRecord{})
|
|
}
|