From 357a9f2512c2902229ce06ceaf2498c7dedb37aa Mon Sep 17 00:00:00 2001 From: Taeyoung Park Date: Tue, 9 Nov 2021 17:42:01 +0900 Subject: [PATCH 1/2] test: add test code for ratio plan (cherry picked from commit 5913d559899baf8b66cc93c9fd5740a7abcf0bfb) --- x/farming/keeper/reward_test.go | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 74374fbf..089525fe 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -39,6 +39,33 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { sdk.NewCoins(sdk.NewInt64Coin(denom3, 1000))), } + ratioPlans := []types.PlanI{ + types.NewRatioPlan( + types.NewBasePlan( + 3, + "", + types.PlanTypePrivate, + 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.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.6")), + } + for _, tc := range []struct { name string plans []types.PlanI @@ -116,6 +143,28 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { 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))}, + }, } { suite.Run(tc.name, func() { for _, plan := range tc.plans { From f51bb3689078d9174d0f62296e6ab05bc9d938ce Mon Sep 17 00:00:00 2001 From: dongsam Date: Fri, 12 Nov 2021 14:33:32 +0900 Subject: [PATCH 2/2] test: add cases for fixed plan with ratio plan --- x/farming/keeper/reward_test.go | 54 +++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/x/farming/keeper/reward_test.go b/x/farming/keeper/reward_test.go index 089525fe..0e55fac0 100644 --- a/x/farming/keeper/reward_test.go +++ b/x/farming/keeper/reward_test.go @@ -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))), @@ -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))), @@ -44,7 +44,7 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { types.NewBasePlan( 3, "", - types.PlanTypePrivate, + types.PlanTypePublic, suite.addrs[0].String(), suite.addrs[0].String(), sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))), @@ -56,7 +56,7 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { types.NewBasePlan( 4, "", - types.PlanTypePrivate, + types.PlanTypePublic, suite.addrs[0].String(), suite.addrs[0].String(), sdk.NewDecCoins(sdk.NewDecCoinFromDec(denom1, sdk.NewDec(1))), @@ -66,6 +66,19 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { 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 @@ -93,25 +106,25 @@ 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)), @@ -119,7 +132,7 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { }, { "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)), @@ -127,19 +140,19 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { }, { "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, }, @@ -165,8 +178,23 @@ func (suite *KeeperTestSuite) TestAllocationInfos() { 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) }