2022-04-05 07:09:27 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
2022-10-10 10:38:33 +00:00
|
|
|
"math/rand"
|
2022-04-05 07:09:27 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/app"
|
|
|
|
bondtypes "github.com/cerc-io/laconicd/x/bond/types"
|
2022-12-09 04:17:14 +00:00
|
|
|
registrykeeper "github.com/cerc-io/laconicd/x/registry/keeper"
|
|
|
|
"github.com/cerc-io/laconicd/x/registry/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2022-04-26 10:39:18 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank/testutil"
|
2022-04-05 07:09:27 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
)
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
var seed = int64(233)
|
2022-10-10 10:38:33 +00:00
|
|
|
|
2022-04-05 07:09:27 +00:00
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
app *app.EthermintApp
|
|
|
|
ctx sdk.Context
|
|
|
|
queryClient types.QueryClient
|
|
|
|
accounts []sdk.AccAddress
|
|
|
|
bond bondtypes.Bond
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
2022-10-10 10:38:33 +00:00
|
|
|
testApp := app.Setup(false, func(ea *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState {
|
2022-04-05 07:09:27 +00:00
|
|
|
return genesis
|
|
|
|
})
|
|
|
|
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
querier := registrykeeper.Querier{Keeper: testApp.RegistryKeeper}
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, testApp.InterfaceRegistry())
|
|
|
|
types.RegisterQueryServer(queryHelper, querier)
|
|
|
|
queryClient := types.NewQueryClient(queryHelper)
|
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
r := rand.New(rand.NewSource(seed))
|
|
|
|
accs := app.RandomAccounts(r, 1)
|
|
|
|
suite.accounts = []sdk.AccAddress{accs[0].Address}
|
2022-04-05 07:09:27 +00:00
|
|
|
account := suite.accounts[0]
|
2022-04-26 10:39:18 +00:00
|
|
|
_ = testutil.FundAccount(testApp.BankKeeper, ctx, account, sdk.NewCoins(sdk.Coin{
|
2022-04-05 07:09:27 +00:00
|
|
|
Denom: sdk.DefaultBondDenom,
|
|
|
|
Amount: sdk.NewInt(100000000000),
|
|
|
|
}))
|
|
|
|
|
|
|
|
bond, err := testApp.BondKeeper.CreateBond(ctx, account, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000000))))
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
suite.bond = *bond
|
|
|
|
suite.app, suite.ctx, suite.queryClient = testApp, ctx, queryClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParams(t *testing.T) {
|
2022-10-10 10:38:33 +00:00
|
|
|
testApp := app.Setup(false, func(ea *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState {
|
2022-04-05 07:09:27 +00:00
|
|
|
return genesis
|
|
|
|
})
|
|
|
|
ctx := testApp.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
|
|
|
|
expParams := types.DefaultParams()
|
2022-12-09 04:17:14 +00:00
|
|
|
params := testApp.RegistryKeeper.GetParams(ctx)
|
2022-04-05 07:09:27 +00:00
|
|
|
require.True(t, params.Equal(expParams))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|