2022-03-22 21:13:27 +00:00
|
|
|
package savings_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
2022-03-29 09:45:04 +00:00
|
|
|
"github.com/kava-labs/kava/x/savings"
|
2022-03-22 21:13:27 +00:00
|
|
|
"github.com/kava-labs/kava/x/savings/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/savings/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GenesisTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
app app.TestApp
|
|
|
|
genTime time.Time
|
|
|
|
ctx sdk.Context
|
|
|
|
keeper keeper.Keeper
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *GenesisTestSuite) SetupTest() {
|
|
|
|
tApp := app.NewTestApp()
|
|
|
|
suite.genTime = tmtime.Canonical(time.Date(2022, 1, 1, 1, 1, 1, 1, time.UTC))
|
|
|
|
suite.ctx = tApp.NewContext(true, tmproto.Header{Height: 1, Time: suite.genTime})
|
|
|
|
suite.keeper = tApp.GetSavingsKeeper()
|
|
|
|
suite.app = tApp
|
|
|
|
|
|
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
|
|
|
suite.addrs = addrs
|
|
|
|
}
|
|
|
|
|
2022-03-29 09:45:04 +00:00
|
|
|
func (suite *GenesisTestSuite) TestInitExportGenesis() {
|
2022-03-23 13:27:54 +00:00
|
|
|
params := types.NewParams(
|
|
|
|
[]string{"btc", "ukava", "bnb"},
|
|
|
|
)
|
2022-03-29 09:45:04 +00:00
|
|
|
|
|
|
|
deposits := types.Deposits{
|
|
|
|
types.NewDeposit(
|
|
|
|
suite.addrs[0],
|
|
|
|
sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1e8))), // 100 ukava
|
|
|
|
),
|
|
|
|
}
|
|
|
|
|
|
|
|
savingsGenesis := types.NewGenesisState(params, deposits)
|
2022-03-22 21:13:27 +00:00
|
|
|
|
|
|
|
suite.NotPanics(
|
|
|
|
func() {
|
|
|
|
suite.app.InitializeFromGenesisStatesWithTime(
|
|
|
|
suite.genTime,
|
|
|
|
app.GenesisState{types.ModuleName: suite.app.AppCodec().MustMarshalJSON(&savingsGenesis)},
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2022-03-29 09:45:04 +00:00
|
|
|
|
|
|
|
expectedDeposits := suite.keeper.GetAllDeposits(suite.ctx)
|
|
|
|
expectedGenesis := savingsGenesis
|
|
|
|
expectedGenesis.Deposits = expectedDeposits
|
|
|
|
exportedGenesis := savings.ExportGenesis(suite.ctx, suite.keeper)
|
|
|
|
suite.Equal(expectedGenesis, exportedGenesis)
|
2022-03-22 21:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGenesisTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(GenesisTestSuite))
|
|
|
|
}
|