mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
63c8421a81
* move multipliers to their own file * add multipliers per denom to MsgClaimHardReward * claim with multipliers per denom for hard claims * remove unused error * add multipliers per denom to params connect to to hard claiming * temporary fix migration * update usdx claiming for new multiplier params * claim with multipliers per denom for delegator * claim with multipliers per denom for swap rewards * tidy up multiplier name validation * rename new multipliers field in params * remove old multpliers from params * clear up various TODOs * add tags to new structs * remove dead code
87 lines
2.1 KiB
Go
87 lines
2.1 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.MultipliersPerDenom{
|
|
{
|
|
Denom: "hard",
|
|
Multipliers: 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, "hard", "large")
|
|
suite.ErrorIs(err, types.ErrInvalidMultiplier)
|
|
|
|
// invalid multiplier name
|
|
err = suite.keeper.ClaimDelegatorReward(suite.ctx, claim.Owner, claim.Owner, "hard", "")
|
|
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.MultipliersPerDenom{
|
|
{
|
|
Denom: "hard",
|
|
Multipliers: 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, "hard", "small")
|
|
suite.ErrorIs(err, types.ErrClaimExpired)
|
|
}
|