2020-04-24 15:44:44 +00:00
|
|
|
package keeper_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-06-10 13:35:44 +00:00
|
|
|
"time"
|
2020-04-24 15:44:44 +00:00
|
|
|
|
2020-04-30 14:23:41 +00:00
|
|
|
"github.com/stretchr/testify/suite"
|
2021-06-10 13:35:44 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2020-04-24 15:44:44 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-04-30 14:13:31 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
|
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
2020-04-24 15:44:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test suite used for all keeper tests
|
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
keeper keeper.Keeper
|
|
|
|
|
|
|
|
app app.TestApp
|
|
|
|
ctx sdk.Context
|
|
|
|
|
|
|
|
genesisTime time.Time
|
|
|
|
addrs []sdk.AccAddress
|
2020-04-24 15:44:44 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
// SetupTest is run automatically before each suite test
|
2020-04-24 15:44:44 +00:00
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
2021-03-25 06:10:13 +00:00
|
|
|
config := sdk.GetConfig()
|
|
|
|
app.SetBech32AddressPrefixes(config)
|
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
_, suite.addrs = app.GeneratePrivKeyAddressPairs(5)
|
2021-01-25 12:58:12 +00:00
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
suite.genesisTime = time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC)
|
2021-03-25 06:10:13 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
func (suite *KeeperTestSuite) SetupApp() {
|
|
|
|
suite.app = app.NewTestApp()
|
2020-04-24 15:44:44 +00:00
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
suite.keeper = suite.app.GetIncentiveKeeper()
|
2020-04-24 15:44:44 +00:00
|
|
|
|
2021-06-10 13:35:44 +00:00
|
|
|
suite.ctx = suite.app.NewContext(true, abci.Header{Height: 1, Time: suite.genesisTime})
|
2020-04-24 15:44:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
func (suite *KeeperTestSuite) TestGetSetDeleteUSDXMintingClaim() {
|
2021-06-10 13:35:44 +00:00
|
|
|
suite.SetupApp()
|
2021-01-18 19:12:37 +00:00
|
|
|
c := types.NewUSDXMintingClaim(suite.addrs[0], c("ukava", 1000000), types.RewardIndexes{types.NewRewardIndex("bnb-a", sdk.ZeroDec())})
|
2021-01-21 13:52:09 +00:00
|
|
|
_, found := suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
2021-01-18 19:12:37 +00:00
|
|
|
suite.Require().False(found)
|
|
|
|
suite.Require().NotPanics(func() {
|
2021-01-21 13:52:09 +00:00
|
|
|
suite.keeper.SetUSDXMintingClaim(suite.ctx, c)
|
2020-04-24 15:44:44 +00:00
|
|
|
})
|
2021-01-21 13:52:09 +00:00
|
|
|
testC, found := suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
2021-01-18 19:12:37 +00:00
|
|
|
suite.Require().True(found)
|
|
|
|
suite.Require().Equal(c, testC)
|
|
|
|
suite.Require().NotPanics(func() {
|
2021-01-21 13:52:09 +00:00
|
|
|
suite.keeper.DeleteUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
2020-04-24 15:44:44 +00:00
|
|
|
})
|
2021-01-21 13:52:09 +00:00
|
|
|
_, found = suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
2021-01-18 19:12:37 +00:00
|
|
|
suite.Require().False(found)
|
2020-04-24 15:44:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
func (suite *KeeperTestSuite) TestIterateUSDXMintingClaims() {
|
2021-06-10 13:35:44 +00:00
|
|
|
suite.SetupApp()
|
2021-01-18 19:12:37 +00:00
|
|
|
for i := 0; i < len(suite.addrs); i++ {
|
|
|
|
c := types.NewUSDXMintingClaim(suite.addrs[i], c("ukava", 100000), types.RewardIndexes{types.NewRewardIndex("bnb-a", sdk.ZeroDec())})
|
|
|
|
suite.Require().NotPanics(func() {
|
2021-01-21 13:52:09 +00:00
|
|
|
suite.keeper.SetUSDXMintingClaim(suite.ctx, c)
|
2021-01-18 19:12:37 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
claims := types.USDXMintingClaims{}
|
2021-01-21 13:52:09 +00:00
|
|
|
suite.keeper.IterateUSDXMintingClaims(suite.ctx, func(c types.USDXMintingClaim) bool {
|
2020-04-24 15:44:44 +00:00
|
|
|
claims = append(claims, c)
|
|
|
|
return false
|
|
|
|
})
|
2021-01-18 19:12:37 +00:00
|
|
|
suite.Require().Equal(len(suite.addrs), len(claims))
|
2020-04-24 15:44:44 +00:00
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
claims = suite.keeper.GetAllUSDXMintingClaims(suite.ctx)
|
2021-01-18 19:12:37 +00:00
|
|
|
suite.Require().Equal(len(suite.addrs), len(claims))
|
2020-04-24 15:44:44 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 13:52:09 +00:00
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|