mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 12:05:18 +00:00
a573625df8
* bump SDK version to v0.38.3 Co-authored-by: Denali Marsh <denali@kava.io> Co-authored-by: Kevin Davis <kjydavis3@gmail.com> Co-authored-by: Kevin Davis <karzak@users.noreply.github.com> Co-authored-by: denalimarsh <denalimarsh@gmail.com> Co-authored-by: rhuairahrighairigh <ruaridh.odonnell@gmail.com>
143 lines
3.2 KiB
Go
143 lines
3.2 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/bep3/keeper"
|
|
"github.com/kava-labs/kava/x/bep3/types"
|
|
"github.com/stretchr/testify/suite"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
)
|
|
|
|
type ParamsTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
addrs []sdk.AccAddress
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) SetupTest() {
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, abci.Header{Height: 1, Time: tmtime.Now()})
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(10)
|
|
tApp.InitializeFromGenesisStates(NewBep3GenStateMulti(addrs[0]))
|
|
suite.keeper = tApp.GetBep3Keeper()
|
|
suite.ctx = ctx
|
|
suite.addrs = addrs
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetSetBnbDeputyAddress() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
params.BnbDeputyAddress = suite.addrs[1]
|
|
suite.NotPanics(func() { suite.keeper.SetParams(suite.ctx, params) })
|
|
|
|
params = suite.keeper.GetParams(suite.ctx)
|
|
suite.Equal(suite.addrs[1], params.BnbDeputyAddress)
|
|
addr := suite.keeper.GetBnbDeputyAddress(suite.ctx)
|
|
suite.Equal(suite.addrs[1], addr)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetMaxBlockLock() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
maxBlockLock := params.MaxBlockLock
|
|
|
|
res := suite.keeper.GetMaxBlockLock(suite.ctx)
|
|
suite.Equal(maxBlockLock, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetMinBlockLock() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
minBlockLock := params.MinBlockLock
|
|
|
|
res := suite.keeper.GetMinBlockLock(suite.ctx)
|
|
suite.Equal(minBlockLock, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAssets() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
assets := params.SupportedAssets
|
|
|
|
res, found := suite.keeper.GetAssets(suite.ctx)
|
|
suite.True(found)
|
|
suite.Equal(assets, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAssetByDenom() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
asset := params.SupportedAssets[0]
|
|
|
|
res, found := suite.keeper.GetAssetByDenom(suite.ctx, asset.Denom)
|
|
suite.True(found)
|
|
suite.Equal(asset, res)
|
|
}
|
|
|
|
func (suite *ParamsTestSuite) TestGetAssetByCoinID() {
|
|
params := suite.keeper.GetParams(suite.ctx)
|
|
asset := params.SupportedAssets[0]
|
|
|
|
res, found := suite.keeper.GetAssetByCoinID(suite.ctx, asset.CoinID)
|
|
suite.True(found)
|
|
suite.Equal(asset, res)
|
|
}
|
|
|
|
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))
|
|
}
|