mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
d56bb77231
* organise testing committee gen state * remove repeated test app initialization * minor fixes from linter in tests * move more setup to SetupApp * split up KeeperTestSuite for each reward type * simplify KeeperTestSuite * simplify PayoutKeeperSuite * simplify DelegatorRewardSuite * simplify SupplyRewardsSuite * simplify BorrowRewardsSuite * simplify USDXRewardsSuite * add auth genesis builder for easier test setup * migrate all incentive tests to auth builder * add incentive genesis builder for easier setup migrate hard incentive tests * migrate all tests to incentive builder * add hard genesis builder * small tidy ups * deduplicate initialTime from borrow tests * deduplicate initialtTime from supply tests * deduplicate initialTime from usdx and keeper tests * deduplicate initialTime in delgator tests * deduplicate genesis time in payout test * deduplicate test app initialization * make authGenesisBuilder available for all modules * remove unused pricefeed setup * export incentive genesis builder * remove commented out test cases * migrate cdp test to new test state builders * migrate vv payout tests to use new builders
88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/incentive/keeper"
|
|
"github.com/kava-labs/kava/x/incentive/types"
|
|
)
|
|
|
|
// Test suite used for all keeper tests
|
|
type KeeperTestSuite struct {
|
|
suite.Suite
|
|
|
|
keeper keeper.Keeper
|
|
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
|
|
genesisTime time.Time
|
|
addrs []sdk.AccAddress
|
|
}
|
|
|
|
// SetupTest is run automatically before each suite test
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
config := sdk.GetConfig()
|
|
app.SetBech32AddressPrefixes(config)
|
|
|
|
_, suite.addrs = app.GeneratePrivKeyAddressPairs(5)
|
|
|
|
suite.genesisTime = time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) SetupApp() {
|
|
suite.app = app.NewTestApp()
|
|
|
|
suite.keeper = suite.app.GetIncentiveKeeper()
|
|
|
|
suite.ctx = suite.app.NewContext(true, abci.Header{Height: 1, Time: suite.genesisTime})
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestGetSetDeleteUSDXMintingClaim() {
|
|
suite.SetupApp()
|
|
c := types.NewUSDXMintingClaim(suite.addrs[0], c("ukava", 1000000), types.RewardIndexes{types.NewRewardIndex("bnb-a", sdk.ZeroDec())})
|
|
_, found := suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
|
suite.Require().False(found)
|
|
suite.Require().NotPanics(func() {
|
|
suite.keeper.SetUSDXMintingClaim(suite.ctx, c)
|
|
})
|
|
testC, found := suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
|
suite.Require().True(found)
|
|
suite.Require().Equal(c, testC)
|
|
suite.Require().NotPanics(func() {
|
|
suite.keeper.DeleteUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
|
})
|
|
_, found = suite.keeper.GetUSDXMintingClaim(suite.ctx, suite.addrs[0])
|
|
suite.Require().False(found)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestIterateUSDXMintingClaims() {
|
|
suite.SetupApp()
|
|
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() {
|
|
suite.keeper.SetUSDXMintingClaim(suite.ctx, c)
|
|
})
|
|
}
|
|
claims := types.USDXMintingClaims{}
|
|
suite.keeper.IterateUSDXMintingClaims(suite.ctx, func(c types.USDXMintingClaim) bool {
|
|
claims = append(claims, c)
|
|
return false
|
|
})
|
|
suite.Require().Equal(len(suite.addrs), len(claims))
|
|
|
|
claims = suite.keeper.GetAllUSDXMintingClaims(suite.ctx)
|
|
suite.Require().Equal(len(suite.addrs), len(claims))
|
|
}
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
}
|