Skip to content

Commit

Permalink
Merge pull request #228 from dongsam/222-add-testcase-for-ratio-plan
Browse files Browse the repository at this point in the history
test: add test cases for reward allocation of ratio plan
  • Loading branch information
dongsam authored Nov 12, 2021
2 parents 1c2029c + f51bb36 commit fd562de
Showing 1 changed file with 88 additions and 11 deletions.
99 changes: 88 additions & 11 deletions x/farming/keeper/reward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
)

func (suite *KeeperTestSuite) TestAllocationInfos() {
normalPlans := []types.PlanI{
fixedAmountPlans := []types.PlanI{
types.NewFixedAmountPlan(
types.NewBasePlan(
1,
"",
types.PlanTypePrivate,
types.PlanTypePublic,
suite.addrs[0].String(),
suite.addrs[0].String(),
sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))),
Expand All @@ -29,7 +29,7 @@ func (suite *KeeperTestSuite) TestAllocationInfos() {
types.NewBasePlan(
2,
"",
types.PlanTypePrivate,
types.PlanTypePublic,
suite.addrs[0].String(),
suite.addrs[0].String(),
sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))),
Expand All @@ -39,6 +39,46 @@ func (suite *KeeperTestSuite) TestAllocationInfos() {
sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))),
}

ratioPlans := []types.PlanI{
types.NewRatioPlan(
types.NewBasePlan(
3,
"",
types.PlanTypePublic,
suite.addrs[0].String(),
suite.addrs[0].String(),
sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))),
types.ParseTime("2021-07-27T00:00:00Z"),
types.ParseTime("2021-07-28T00:00:00Z"),
),
sdk.MustNewDecFromStr("0.5")),
types.NewRatioPlan(
types.NewBasePlan(
4,
"",
types.PlanTypePublic,
suite.addrs[0].String(),
suite.addrs[0].String(),
sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))),
types.ParseTime("2021-07-27T12:00:00Z"),
types.ParseTime("2021-07-28T12:00:00Z"),
),
sdk.MustNewDecFromStr("0.6")),
}

hugeRatioPlan := types.NewRatioPlan(
types.NewBasePlan(
5,
"",
types.PlanTypePrivate,
suite.addrs[0].String(),
suite.addrs[0].String(),
sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))),
types.ParseTime("2021-07-27T12:00:00Z"),
types.ParseTime("2021-07-28T12:00:00Z"),
),
sdk.MustNewDecFromStr("0.999999"))

for _, tc := range []struct {
name string
plans []types.PlanI
Expand Down Expand Up @@ -66,58 +106,95 @@ func (suite *KeeperTestSuite) TestAllocationInfos() {
},
{
"start time & end time edgecase #1",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-26T23:59:59Z"),
nil,
},
{
"start time & end time edgecase #2",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-27T00:00:00Z"),
map[uint64]sdk.Coins{1: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #3",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-27T11:59:59Z"),
map[uint64]sdk.Coins{1: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #4",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-27T12:00:00Z"),
map[uint64]sdk.Coins{
1: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000)),
2: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #5",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-27T23:59:59Z"),
map[uint64]sdk.Coins{
1: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000)),
2: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #6",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-28T00:00:00Z"),
map[uint64]sdk.Coins{2: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #7",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-28T11:59:59Z"),
map[uint64]sdk.Coins{2: sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))},
},
{
"start time & end time edgecase #8",
normalPlans,
fixedAmountPlans,
types.ParseTime("2021-07-28T12:00:00Z"),
nil,
},
{
"test case for ratio plans #1",
ratioPlans,
types.ParseTime("2021-07-27T00:00:00Z"),
map[uint64]sdk.Coins{
3: sdk.NewCoins(sdk.NewInt64Coin(denom1, 500000000), sdk.NewInt64Coin(denom2, 500000000),
sdk.NewInt64Coin(denom3, 500000000), sdk.NewInt64Coin(sdk.DefaultBondDenom, 500000000))},
},
{
"test case for ratio plans #2",
ratioPlans,
types.ParseTime("2021-07-27T12:00:00Z"),
nil,
},
{
"test case for ratio plans #3",
ratioPlans,
types.ParseTime("2021-07-28T11:00:00Z"),
map[uint64]sdk.Coins{
4: sdk.NewCoins(sdk.NewInt64Coin(denom1, 600000000), sdk.NewInt64Coin(denom2, 600000000),
sdk.NewInt64Coin(denom3, 600000000), sdk.NewInt64Coin(sdk.DefaultBondDenom, 600000000))},
},
{
"test case for fixed plans with a ratio plan over balance #1",
append(fixedAmountPlans, hugeRatioPlan),
types.ParseTime("2021-07-27T12:00:00Z"),
nil,
},
{
"test case for fixed plans with a ratio plan over balance #2",
append([]types.PlanI{hugeRatioPlan}, fixedAmountPlans...),
types.ParseTime("2021-07-27T12:00:00Z"),
nil,
},
} {
suite.Run(tc.name, func() {
for _, plan := range suite.keeper.GetPlans(suite.ctx) {
suite.keeper.RemovePlan(suite.ctx, plan)
}
for _, plan := range tc.plans {
suite.keeper.SetPlan(suite.ctx, plan)
}
Expand Down

0 comments on commit fd562de

Please sign in to comment.