mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
614d4e40fe
* Update cometbft, cosmos, ethermint, and ibc-go * Replace github.com/tendermint/tendermint by github.com/cometbft/cometbft * Replace github.com/tendermint/tm-db by github.com/cometbft/cometbft-db * Replace gogo/protobuf with cosmos/gogoproto & simapp replacement * Replace cosmos-sdk/simapp/helpers with cosmos-sdk/testutil/sims * Remove no longer used simulations * Replace ibchost with ibcexported See https://github.com/cosmos/ibc-go/blob/v7.2.2/docs/migrations/v6-to-v7.md#ibc-module-constants * Add new consensus params keeper * Add consensus keeper to blockers * Fix keeper and module issues in app.go * Add IsSendEnabledCoins and update SetParams interface changes * Fix protobuf build for cosmos 47 (#1800) * fix cp errors by using -f; fix lint by only linting our proto dir; and use proofs.proto directly from ics23 for ibc-go v7 * run proto-all; commit updated third party deps and swagger changes * regenerate proto files * use correct gocosmos build plugin for buf * re-gen all protobuf files to update paths for new gocosmos plugin * update protoc and buf to latest versions * fix staking keeper issues in app.go * update tally handler for gov changes * chain id fix and flag fixes * update deps for cometbft 47.7 upgrade * remove all module legacy queriers * update stakingKeeper to pointer * Replace ModuleCdc from govv1beta1 to govcodec * remove simulations * abci.LastCommitInfo → abci.CommitInfo * Remove unused code in keys.go * simapp.MakeTestEncodingConfig -> moduletestutil.MakeTestEncodingConfi * Fix chain id issues in tests * Fix remaining unit test issues * Update changelog for upgrade * Fix e2e tests using updated kvtool * Update protonet to v47 compatible genesis * Bump cometbft-db to v0.9.1-kava.1 * Update kvtool * Remove extra changelog * Fix merged rocksdb issues * go mod cleanup * Bump cometbft-db to v9 and go to 1.21 * Bump rocksdb version to v8.10.0 * Update kvtool to latest version * Update gin to v1.9.0 * Use ibctm.ModuleName in app_test * Fallback to genesis chain id instead of client toml * Remove all simulations * Fix cdp migrations issue with v47 * Update dependencies to correct tags --------- Co-authored-by: Nick DeLuca <nickdeluca08@gmail.com>
179 lines
4.5 KiB
Go
179 lines
4.5 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
|
tmtime "github.com/cometbft/cometbft/types/time"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/bep3/keeper"
|
|
"github.com/kava-labs/kava/x/bep3/types"
|
|
)
|
|
|
|
type ParamsTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
addrs []sdk.AccAddress
|
|
ctx sdk.Context
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) SetupTest() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(10)
|
|
tApp.InitializeFromGenesisStates(NewBep3GenStateMulti(tApp.AppCodec(), addrs[0]))
|
|
suite.keeper = tApp.GetBep3Keeper()
|
|
suite.ctx = ctx
|
|
suite.addrs = addrs
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetSetAsset() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
suite.NotPanics(func() { suite.keeper.SetAsset(suite.ctx, asset) })
|
|
_, err = suite.keeper.GetAsset(suite.ctx, "dne")
|
|
suite.Require().Error(err)
|
|
|
|
_, err = suite.keeper.GetAsset(suite.ctx, "inc")
|
|
suite.Require().NoError(err)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAssets() {
|
|
assets, found := suite.keeper.GetAssets(suite.ctx)
|
|
suite.Require().True(found)
|
|
suite.Require().Equal(2, len(assets))
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetSetDeputyAddress() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
asset.DeputyAddress = suite.addrs[1]
|
|
suite.NotPanics(func() { suite.keeper.SetAsset(suite.ctx, asset) })
|
|
|
|
asset, err = suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
suite.Equal(suite.addrs[1], asset.DeputyAddress)
|
|
addr, err := suite.keeper.GetDeputyAddress(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
suite.Equal(suite.addrs[1], addr)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetDeputyFixedFee() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
bnbDeputyFixedFee := asset.FixedFee
|
|
|
|
res, err := suite.keeper.GetFixedFee(suite.ctx, asset.Denom)
|
|
suite.Require().NoError(err)
|
|
suite.Equal(bnbDeputyFixedFee, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetMinMaxSwapAmount() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
minAmount := asset.MinSwapAmount
|
|
|
|
res, err := suite.keeper.GetMinSwapAmount(suite.ctx, asset.Denom)
|
|
suite.Require().NoError(err)
|
|
suite.Equal(minAmount, res)
|
|
|
|
maxAmount := asset.MaxSwapAmount
|
|
res, err = suite.keeper.GetMaxSwapAmount(suite.ctx, asset.Denom)
|
|
suite.Require().NoError(err)
|
|
suite.Equal(maxAmount, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetMinMaxBlockLock() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
minLock := asset.MinBlockLock
|
|
|
|
res, err := suite.keeper.GetMinBlockLock(suite.ctx, asset.Denom)
|
|
suite.Require().NoError(err)
|
|
suite.Equal(minLock, res)
|
|
|
|
maxLock := asset.MaxBlockLock
|
|
res, err = suite.keeper.GetMaxBlockLock(suite.ctx, asset.Denom)
|
|
suite.Require().NoError(err)
|
|
suite.Equal(maxLock, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAssetByCoinID() {
|
|
asset, err := suite.keeper.GetAsset(suite.ctx, "bnb")
|
|
suite.Require().NoError(err)
|
|
|
|
res, found := suite.keeper.GetAssetByCoinID(suite.ctx, asset.CoinID)
|
|
suite.True(found)
|
|
suite.Equal(asset, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAuthorizedAddresses() {
|
|
deputyAddresses := suite.keeper.GetAuthorizedAddresses(suite.ctx)
|
|
// the test params use the same deputy address for two assets
|
|
expectedAddresses := []sdk.AccAddress{suite.addrs[0]}
|
|
|
|
suite.Require().ElementsMatch(expectedAddresses, deputyAddresses)
|
|
}
|
|
|
|
func (suite *AssetTestSuite) TestValidateLiveAsset() {
|
|
type args struct {
|
|
coin sdk.Coin
|
|
}
|
|
testCases := []struct {
|
|
name string
|
|
args args
|
|
expectedError error
|
|
expectPass bool
|
|
}{
|
|
{
|
|
"normal",
|
|
args{
|
|
coin: c("bnb", 1),
|
|
},
|
|
nil,
|
|
true,
|
|
},
|
|
{
|
|
"asset not supported",
|
|
args{
|
|
coin: c("bad", 1),
|
|
},
|
|
types.ErrAssetNotSupported,
|
|
false,
|
|
},
|
|
{
|
|
"asset not active",
|
|
args{
|
|
coin: c("inc", 1),
|
|
},
|
|
types.ErrAssetNotActive,
|
|
false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
suite.SetupTest()
|
|
suite.Run(tc.name, func() {
|
|
err := suite.keeper.ValidateLiveAsset(suite.ctx, tc.args.coin)
|
|
|
|
if tc.expectPass {
|
|
suite.Require().NoError(err)
|
|
} else {
|
|
suite.Require().Error(err)
|
|
suite.Require().True(errors.Is(err, tc.expectedError))
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestParamsTestSuite(t *testing.T) {
|
|
suite.Run(t, new(ParamsTestSuite))
|
|
}
|