-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ddb39dc
commit 62f2036
Showing
9 changed files
with
326 additions
and
163 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
"strconv" | ||
) | ||
|
||
func (suite *IntegrationTestSuite) TestPendingUnlockParticipant() { | ||
list := suite.k.GetAllPendingUnlockParticipant(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
staticEpoch := 500 | ||
max := 10 | ||
for i := 1; i <= max; i++ { | ||
pup := types.PendingUnlockParticipant{Index: types.CreatePendingUnlockParticipantKey(int64(i), "something")} | ||
suite.k.SetPendingUnlockParticipant(suite.ctx, pup) | ||
|
||
pup = types.PendingUnlockParticipant{Index: types.CreatePendingUnlockParticipantKey(int64(staticEpoch), strconv.Itoa(i))} | ||
suite.k.SetPendingUnlockParticipant(suite.ctx, pup) | ||
|
||
list = suite.k.GetAllPendingUnlockParticipant(suite.ctx) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), 2*i) | ||
|
||
list = suite.k.GetAllEpochPendingUnlockParticipant(suite.ctx, int64(i)) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), 1) | ||
} | ||
|
||
list = suite.k.GetAllEpochPendingUnlockParticipant(suite.ctx, int64(staticEpoch)) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max) | ||
|
||
pup := types.PendingUnlockParticipant{Index: types.CreatePendingUnlockParticipantKey(int64(staticEpoch), "5")} | ||
suite.k.RemovePendingUnlockParticipant(suite.ctx, pup) | ||
|
||
list = suite.k.GetAllEpochPendingUnlockParticipant(suite.ctx, int64(staticEpoch)) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (suite *IntegrationTestSuite) TestDistributeAllStakingRewards() { | ||
initial := types.StakingReward{ | ||
RewardId: "01", | ||
PrizeAmount: "100", | ||
PrizeDenom: denomBze, | ||
StakingDenom: denomStake, | ||
Duration: 10, | ||
Payouts: 0, | ||
MinStake: 0, | ||
Lock: 10, | ||
StakedAmount: "10", | ||
DistributedStake: "0", | ||
} | ||
suite.k.SetStakingReward(suite.ctx, initial) | ||
|
||
rewardAmt, ok := sdk.NewIntFromString(initial.PrizeAmount) | ||
suite.Require().True(ok) | ||
|
||
for i := uint32(0); i < initial.Duration; i++ { | ||
suite.k.DistributeAllStakingRewards(suite.ctx) | ||
storage, f := suite.k.GetStakingReward(suite.ctx, initial.RewardId) | ||
suite.Require().True(f) | ||
suite.Require().EqualValues(storage.Payouts, i+1) | ||
|
||
staked, ok := sdk.NewIntFromString(storage.StakedAmount) | ||
suite.Require().True(ok) | ||
|
||
newDistribution := rewardAmt.ToDec().Quo(staked.ToDec()) | ||
distributed, err := sdk.NewDecFromStr(initial.DistributedStake) | ||
suite.Require().NoError(err) | ||
|
||
distributed = distributed.Add(newDistribution) | ||
suite.Require().EqualValuesf(distributed.String(), storage.DistributedStake, fmt.Sprintf("values not equal on %d iteration", i)) | ||
|
||
initial.DistributedStake = distributed.String() | ||
staked = staked.AddRaw(int64(i)) | ||
initial.StakedAmount = staked.String() | ||
storage.StakedAmount = initial.StakedAmount | ||
|
||
suite.k.SetStakingReward(suite.ctx, storage) | ||
} | ||
|
||
suite.k.DistributeAllStakingRewards(suite.ctx) | ||
suite.k.DistributeAllStakingRewards(suite.ctx) | ||
suite.k.DistributeAllStakingRewards(suite.ctx) | ||
storage, f := suite.k.GetStakingReward(suite.ctx, initial.RewardId) | ||
suite.Require().True(f) | ||
suite.Require().EqualValues(storage.Payouts, initial.Duration) | ||
suite.Require().EqualValues(storage.DistributedStake, initial.DistributedStake) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,37 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
"strconv" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
|
||
// | ||
//func createNStakingRewardParticipant(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.StakingRewardParticipant { | ||
// items := make([]types.StakingRewardParticipant, n) | ||
// for i := range items { | ||
// items[i].Index = strconv.Itoa(i) | ||
// | ||
// keeper.SetStakingRewardParticipant(ctx, items[i]) | ||
// } | ||
// return items | ||
//} | ||
// | ||
//func TestStakingRewardParticipantGet(t *testing.T) { | ||
// keeper, ctx := keepertest.RewardsKeeper(t) | ||
// items := createNStakingRewardParticipant(keeper, ctx, 10) | ||
// for _, item := range items { | ||
// rst, found := keeper.GetStakingRewardParticipant(ctx, | ||
// item.Index, | ||
// ) | ||
// require.True(t, found) | ||
// require.Equal(t, | ||
// nullify.Fill(&item), | ||
// nullify.Fill(&rst), | ||
// ) | ||
// } | ||
//} | ||
//func TestStakingRewardParticipantRemove(t *testing.T) { | ||
// keeper, ctx := keepertest.RewardsKeeper(t) | ||
// items := createNStakingRewardParticipant(keeper, ctx, 10) | ||
// for _, item := range items { | ||
// keeper.RemoveStakingRewardParticipant(ctx, | ||
// item.Index, | ||
// ) | ||
// _, found := keeper.GetStakingRewardParticipant(ctx, | ||
// item.Index, | ||
// ) | ||
// require.False(t, found) | ||
// } | ||
//} | ||
// | ||
//func TestStakingRewardParticipantGetAll(t *testing.T) { | ||
// keeper, ctx := keepertest.RewardsKeeper(t) | ||
// items := createNStakingRewardParticipant(keeper, ctx, 10) | ||
// require.ElementsMatch(t, | ||
// nullify.Fill(items), | ||
// nullify.Fill(keeper.GetAllStakingRewardParticipant(ctx)), | ||
// ) | ||
//} | ||
func (suite *IntegrationTestSuite) TestStakingRewardParticipant() { | ||
list := suite.k.GetAllStakingRewardParticipant(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
_, f := suite.k.GetStakingRewardParticipant(suite.ctx, "fake", "fake2") | ||
suite.Require().False(f) | ||
|
||
max := 10 | ||
for i := 0; i < max; i++ { | ||
convI := strconv.Itoa(i) | ||
srp := types.StakingRewardParticipant{Address: convI, RewardId: convI} | ||
suite.k.SetStakingRewardParticipant(suite.ctx, srp) | ||
|
||
newSrp, f := suite.k.GetStakingRewardParticipant(suite.ctx, convI, convI) | ||
suite.Require().True(f) | ||
suite.Require().EqualValues(newSrp, srp) | ||
} | ||
|
||
list = suite.k.GetAllStakingRewardParticipant(suite.ctx) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max) | ||
|
||
suite.k.RemoveStakingRewardParticipant(suite.ctx, "0", "0") | ||
_, f = suite.k.GetStakingRewardParticipant(suite.ctx, "0", "0") | ||
suite.Require().False(f) | ||
|
||
list = suite.k.GetAllStakingRewardParticipant(suite.ctx) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,49 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
keepertest "github.com/bze-alphateam/bze/testutil/keeper" | ||
"github.com/bze-alphateam/bze/testutil/nullify" | ||
"github.com/bze-alphateam/bze/x/rewards/keeper" | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/stretchr/testify/require" | ||
"strconv" | ||
) | ||
|
||
// Prevent strconv unused error | ||
var _ = strconv.IntSize | ||
func (suite *IntegrationTestSuite) TestStakingReward() { | ||
list := suite.k.GetAllStakingReward(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
func createNStakingReward(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.StakingReward { | ||
items := make([]types.StakingReward, n) | ||
for i := range items { | ||
items[i].RewardId = strconv.Itoa(i) | ||
_, f := suite.k.GetStakingReward(suite.ctx, "fake") | ||
suite.Require().False(f) | ||
|
||
keeper.SetStakingReward(ctx, items[i]) | ||
} | ||
return items | ||
} | ||
counter := suite.k.GetStakingRewardsCounter(suite.ctx) | ||
suite.Require().EqualValues(counter, 0) | ||
|
||
func TestStakingRewardGet(t *testing.T) { | ||
keeper, ctx := keepertest.RewardsKeeper(t) | ||
items := createNStakingReward(keeper, ctx, 10) | ||
for _, item := range items { | ||
rst, found := keeper.GetStakingReward(ctx, | ||
item.RewardId, | ||
) | ||
require.True(t, found) | ||
require.Equal(t, | ||
nullify.Fill(&item), | ||
nullify.Fill(&rst), | ||
) | ||
} | ||
} | ||
func TestStakingRewardRemove(t *testing.T) { | ||
keeper, ctx := keepertest.RewardsKeeper(t) | ||
items := createNStakingReward(keeper, ctx, 10) | ||
for _, item := range items { | ||
keeper.RemoveStakingReward(ctx, | ||
item.RewardId, | ||
) | ||
_, found := keeper.GetStakingReward(ctx, | ||
item.RewardId, | ||
) | ||
require.False(t, found) | ||
max := 10 | ||
for i := 0; i < max; i++ { | ||
sr := types.StakingReward{RewardId: strconv.Itoa(i), Lock: uint32(i)} | ||
suite.k.SetStakingReward(suite.ctx, sr) | ||
|
||
newSr, f := suite.k.GetStakingReward(suite.ctx, sr.RewardId) | ||
suite.Require().True(f) | ||
suite.Require().EqualValues(newSr, sr) | ||
} | ||
} | ||
|
||
func TestStakingRewardGetAll(t *testing.T) { | ||
keeper, ctx := keepertest.RewardsKeeper(t) | ||
items := createNStakingReward(keeper, ctx, 10) | ||
require.ElementsMatch(t, | ||
nullify.Fill(items), | ||
nullify.Fill(keeper.GetAllStakingReward(ctx)), | ||
) | ||
list = suite.k.GetAllStakingReward(suite.ctx) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max) | ||
|
||
suite.k.IterateAllStakingRewards(suite.ctx, func(ctx sdk.Context, sr types.StakingReward) (stop bool) { | ||
suite.Require().LessOrEqual(sr.Lock, uint32(max)) | ||
|
||
return false | ||
}) | ||
|
||
counter = suite.k.GetStakingRewardsCounter(suite.ctx) | ||
suite.Require().EqualValues(counter, max) | ||
|
||
suite.k.RemoveStakingReward(suite.ctx, "0") | ||
_, f = suite.k.GetStakingReward(suite.ctx, "0") | ||
suite.Require().False(f) | ||
|
||
list = suite.k.GetAllStakingReward(suite.ctx) | ||
suite.Require().NotEmpty(list) | ||
suite.Require().EqualValues(len(list), max-1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package keeper_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/bze-alphateam/bze/x/rewards/types" | ||
"strconv" | ||
) | ||
|
||
func (suite *IntegrationTestSuite) TestPendingTradingRewardExpiration() { | ||
list := suite.k.GetAllPendingTradingRewardExpiration(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
max := 10 | ||
for i := 1; i <= max; i++ { | ||
ptre := types.TradingRewardExpiration{RewardId: "01", ExpireAt: uint32(i)} | ||
suite.k.SetPendingTradingRewardExpiration(suite.ctx, ptre) | ||
|
||
ptre = types.TradingRewardExpiration{RewardId: strconv.Itoa(i), ExpireAt: uint32(i)} | ||
suite.k.SetPendingTradingRewardExpiration(suite.ctx, ptre) | ||
|
||
list = suite.k.GetAllPendingTradingRewardExpiration(suite.ctx) | ||
suite.Require().EqualValues(len(list), i*2) | ||
|
||
//just check the other list is not altered | ||
list = suite.k.GetAllActiveTradingRewardExpiration(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
list = suite.k.GetAllPendingTradingRewardExpirationByExpireAt(suite.ctx, uint32(i)) | ||
suite.Require().EqualValues(len(list), 2) | ||
} | ||
|
||
suite.k.RemovePendingTradingRewardExpiration(suite.ctx, 1, "1") | ||
list = suite.k.GetAllPendingTradingRewardExpirationByExpireAt(suite.ctx, uint32(1)) | ||
suite.Require().EqualValues(len(list), 1) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestActiveTradingRewardExpiration() { | ||
list := suite.k.GetAllActiveTradingRewardExpiration(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
max := 10 | ||
for i := 1; i <= max; i++ { | ||
ptre := types.TradingRewardExpiration{RewardId: "01", ExpireAt: uint32(i)} | ||
suite.k.SetActiveTradingRewardExpiration(suite.ctx, ptre) | ||
|
||
ptre = types.TradingRewardExpiration{RewardId: strconv.Itoa(i), ExpireAt: uint32(i)} | ||
suite.k.SetActiveTradingRewardExpiration(suite.ctx, ptre) | ||
|
||
list = suite.k.GetAllActiveTradingRewardExpiration(suite.ctx) | ||
suite.Require().EqualValues(len(list), i*2) | ||
|
||
//just check the other list is not altered | ||
list = suite.k.GetAllPendingTradingRewardExpiration(suite.ctx) | ||
suite.Require().Empty(list) | ||
|
||
list = suite.k.GetAllActiveTradingRewardExpirationByExpireAt(suite.ctx, uint32(i)) | ||
suite.Require().EqualValues(len(list), 2) | ||
} | ||
|
||
suite.k.RemoveActiveTradingRewardExpiration(suite.ctx, 1, "1") | ||
list = suite.k.GetAllActiveTradingRewardExpirationByExpireAt(suite.ctx, uint32(1)) | ||
suite.Require().EqualValues(len(list), 1) | ||
} |
Oops, something went wrong.