mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 08:15:19 +00:00
38a98ac4fc
* split up payout.go file * extract genesis builders to new testutil package * move claim integration tests out of keeper * convert claim integration tests to handler tests * combine claim usdx minting keeper methods * combine hard claim keeper methods * combine delegator claim keeper methods * add multiply coins helper method * rename file to better match contents * add basic claiming unit tests * add claiming subset of delegator reward denoms * refactor msg tests * add msg ValidateBasic tests * connect swap hooks into keeper methods * tidy up delegator handler tests * add swap claiming msgs and keeper method * add swap claiming to client * add subset claiming to other msg types * split up handler test file * connect up subset claiming for swap * make multiplier name validation more strict * fix: struct tag typo in swap incentives * connect up subset claiming for hard * connect up subset claiming for delegator * fix: register cli tx routes for swp claiming * fix claim amount in claim event * fix token name in cli help docs * remove unused field in msg tests * tidy up swap and delegator handler tests * refactor hard handler tests * refactor usdx handler tests * remove unused constant Co-authored-by: karzak <kjydavis3@gmail.com>
82 lines
2.2 KiB
Go
82 lines
2.2 KiB
Go
package keeper_test
|
||
|
||
import (
|
||
"errors"
|
||
"testing"
|
||
"time"
|
||
|
||
"github.com/stretchr/testify/suite"
|
||
|
||
"github.com/kava-labs/kava/x/incentive/types"
|
||
)
|
||
|
||
// ClaimTests runs unit tests for the keeper Claim methods
|
||
type ClaimTests struct {
|
||
unitTester
|
||
}
|
||
|
||
func TestClaim(t *testing.T) {
|
||
suite.Run(t, new(ClaimTests))
|
||
}
|
||
|
||
func (suite *ClaimTests) ErrorIs(err, target error) bool {
|
||
return suite.Truef(errors.Is(err, target), "err didn't match: %s, it was: %s", target, err)
|
||
}
|
||
|
||
func (suite *ClaimTests) TestCannotClaimWhenMultiplierNotRecognised() {
|
||
subspace := &fakeParamSubspace{
|
||
params: types.Params{
|
||
ClaimMultipliers: types.Multipliers{
|
||
types.NewMultiplier(types.Small, 1, d("0.2")),
|
||
},
|
||
},
|
||
}
|
||
suite.keeper = suite.NewKeeper(subspace, nil, nil, nil, nil, nil, nil)
|
||
|
||
claim := types.DelegatorClaim{
|
||
BaseMultiClaim: types.BaseMultiClaim{
|
||
Owner: arbitraryAddress(),
|
||
},
|
||
}
|
||
suite.storeDelegatorClaim(claim)
|
||
|
||
// multiplier not in params
|
||
err := suite.keeper.ClaimDelegatorReward(suite.ctx, claim.Owner, claim.Owner, types.Large, nil)
|
||
suite.ErrorIs(err, types.ErrInvalidMultiplier)
|
||
|
||
// invalid multiplier name
|
||
err = suite.keeper.ClaimDelegatorReward(suite.ctx, claim.Owner, claim.Owner, "", nil)
|
||
suite.ErrorIs(err, types.ErrInvalidMultiplier)
|
||
|
||
// invalid multiplier name
|
||
const zeroWidthSpace = ""
|
||
err = suite.keeper.ClaimDelegatorReward(suite.ctx, claim.Owner, claim.Owner, types.Small+zeroWidthSpace, nil)
|
||
suite.ErrorIs(err, types.ErrInvalidMultiplier)
|
||
}
|
||
|
||
func (suite *ClaimTests) TestCannotClaimAfterEndTime() {
|
||
endTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
|
||
|
||
subspace := &fakeParamSubspace{
|
||
params: types.Params{
|
||
ClaimMultipliers: types.Multipliers{
|
||
types.NewMultiplier(types.Small, 1, d("0.2")),
|
||
},
|
||
ClaimEnd: endTime,
|
||
},
|
||
}
|
||
suite.keeper = suite.NewKeeper(subspace, nil, nil, nil, nil, nil, nil)
|
||
|
||
suite.ctx = suite.ctx.WithBlockTime(endTime.Add(time.Nanosecond))
|
||
|
||
claim := types.DelegatorClaim{
|
||
BaseMultiClaim: types.BaseMultiClaim{
|
||
Owner: arbitraryAddress(),
|
||
},
|
||
}
|
||
suite.storeDelegatorClaim(claim)
|
||
|
||
err := suite.keeper.ClaimDelegatorReward(suite.ctx, claim.Owner, claim.Owner, types.Small, nil)
|
||
suite.ErrorIs(err, types.ErrClaimExpired)
|
||
}
|