@@ -12,16 +12,6 @@ import (
1212 "github.com/tendermint/farming/x/farming/types"
1313)
1414
15- /*
16- [TODO]:
17- We need to come up with better ways to simulate public plan proposals.
18- Currently, the details are ignored and only basic logics are written to simulate.
19-
20- These are some of the following considerations that i think need to be discussed and addressed:
21- 1. Randomize staking coin weights (single or multiple denoms)
22- 2. Simulate multiple proposals (add new weighted proposal content for multiple plans?)
23- */
24-
2515// Simulation operation weights constants.
2616const (
2717 OpWeightSimulateAddPublicPlanProposal = "op_weight_add_public_plan_proposal"
@@ -50,7 +40,7 @@ func ProposalContents(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keep
5040 }
5141}
5242
53- // SimulateAddPublicPlanProposal generates random public plan proposal content
43+ // SimulateAddPublicPlanProposal generates random public add plan proposal content.
5444func SimulateAddPublicPlanProposal (ak types.AccountKeeper , bk types.BankKeeper , k keeper.Keeper ) simtypes.ContentSimulatorFn {
5545 return func (r * rand.Rand , ctx sdk.Context , accs []simtypes.Account ) simtypes.Content {
5646 simAccount , _ := simtypes .RandomAcc (r , accs )
@@ -69,29 +59,19 @@ func SimulateAddPublicPlanProposal(ak types.AccountKeeper, bk types.BankKeeper,
6959 return nil
7060 }
7161
72- // add request proposal
73- req := & types.AddPlanRequest {
74- Name : "simulation-test-" + simtypes .RandStringOfLength (r , 5 ),
75- FarmingPoolAddress : simAccount .Address .String (),
76- TerminationAddress : simAccount .Address .String (),
77- StakingCoinWeights : sdk .NewDecCoins (sdk .NewInt64DecCoin (sdk .DefaultBondDenom , 1 )),
78- StartTime : ctx .BlockTime (),
79- EndTime : ctx .BlockTime ().AddDate (0 , 1 , 0 ),
80- EpochAmount : sdk .NewCoins (sdk .NewInt64Coin (poolCoins [r .Intn (3 )].Denom , int64 (simtypes .RandIntBetween (r , 10_000_000 , 1_000_000_000 )))),
81- }
82- addRequests := []* types.AddPlanRequest {req }
62+ addPlanReqs := ranAddPlanRequests (r , ctx , simAccount , poolCoins )
8363
8464 return types .NewPublicPlanProposal (
8565 simtypes .RandStringOfLength (r , 10 ),
8666 simtypes .RandStringOfLength (r , 100 ),
87- addRequests ,
67+ addPlanReqs ,
8868 []* types.ModifyPlanRequest {},
8969 []* types.DeletePlanRequest {},
9070 )
9171 }
9272}
9373
94- // SimulateModifyPublicPlanProposal generates random public plan proposal content
74+ // SimulateModifyPublicPlanProposal generates random public modify plan proposal content.
9575func SimulateModifyPublicPlanProposal (ak types.AccountKeeper , bk types.BankKeeper , k keeper.Keeper ) simtypes.ContentSimulatorFn {
9676 return func (r * rand.Rand , ctx sdk.Context , accs []simtypes.Account ) simtypes.Content {
9777 simAccount , _ := simtypes .RandomAcc (r , accs )
@@ -112,32 +92,33 @@ func SimulateModifyPublicPlanProposal(ak types.AccountKeeper, bk types.BankKeepe
11292
11393 req := & types.ModifyPlanRequest {}
11494
115- // TODO: decide which values of fields to randomize
11695 plans := k .GetPlans (ctx )
11796 for _ , p := range plans {
11897 if p .GetType () == types .PlanTypePublic {
11998 startTime := ctx .BlockTime ()
120- endTime := startTime .AddDate (0 , 1 , 0 )
99+ endTime := startTime .AddDate (0 , simtypes . RandIntBetween ( r , 1 , 28 ) , 0 )
121100
122101 switch plan := p .(type ) {
123102 case * types.FixedAmountPlan :
124103 req .PlanId = plan .GetId ()
125- req .Name = plan . GetName ( )
104+ req .Name = "simulation-test-" + simtypes . RandStringOfLength ( r , 5 )
126105 req .FarmingPoolAddress = plan .GetFarmingPoolAddress ().String ()
127106 req .TerminationAddress = plan .GetTerminationAddress ().String ()
128107 req .StakingCoinWeights = plan .GetStakingCoinWeights ()
129108 req .StartTime = & startTime
130109 req .EndTime = & endTime
131- req .EpochAmount = sdk .NewCoins (sdk .NewInt64Coin (poolCoins [r .Intn (3 )].Denom , int64 (simtypes .RandIntBetween (r , 10_000_000 , 1_000_000_000 ))))
110+ req .EpochAmount = sdk .NewCoins (
111+ sdk .NewInt64Coin (poolCoins [r .Intn (3 )].Denom , int64 (simtypes .RandIntBetween (r , 10_000_000 , 1_000_000_000 ))),
112+ )
132113 case * types.RatioPlan :
133114 req .PlanId = plan .GetId ()
134- req .Name = plan . GetName ( )
115+ req .Name = "simulation-test-" + simtypes . RandStringOfLength ( r , 5 )
135116 req .FarmingPoolAddress = plan .GetFarmingPoolAddress ().String ()
136117 req .TerminationAddress = plan .GetTerminationAddress ().String ()
137118 req .StakingCoinWeights = plan .GetStakingCoinWeights ()
138119 req .StartTime = & startTime
139120 req .EndTime = & endTime
140- req .EpochRatio = sdk .NewDecWithPrec (int64 (simtypes .RandIntBetween (r , 1 , 10 )), 1 )
121+ req .EpochRatio = sdk .NewDecWithPrec (int64 (simtypes .RandIntBetween (r , 1 , 5 )), 1 )
141122 }
142123 break
143124 }
@@ -147,19 +128,19 @@ func SimulateModifyPublicPlanProposal(ak types.AccountKeeper, bk types.BankKeepe
147128 return nil
148129 }
149130
150- updateRequests := []* types.ModifyPlanRequest {req }
131+ modifyPlanReqs := []* types.ModifyPlanRequest {req }
151132
152133 return types .NewPublicPlanProposal (
153134 simtypes .RandStringOfLength (r , 10 ),
154135 simtypes .RandStringOfLength (r , 100 ),
155136 []* types.AddPlanRequest {},
156- updateRequests ,
137+ modifyPlanReqs ,
157138 []* types.DeletePlanRequest {},
158139 )
159140 }
160141}
161142
162- // SimulateDeletePublicPlanProposal generates random public plan proposal content
143+ // SimulateDeletePublicPlanProposal generates random public delete plan proposal content.
163144func SimulateDeletePublicPlanProposal (ak types.AccountKeeper , bk types.BankKeeper , k keeper.Keeper ) simtypes.ContentSimulatorFn {
164145 return func (r * rand.Rand , ctx sdk.Context , accs []simtypes.Account ) simtypes.Content {
165146 simAccount , _ := simtypes .RandomAcc (r , accs )
@@ -187,14 +168,42 @@ func SimulateDeletePublicPlanProposal(ak types.AccountKeeper, bk types.BankKeepe
187168 return nil
188169 }
189170
190- deleteRequest := []* types.DeletePlanRequest {req }
171+ deletePlanReqs := []* types.DeletePlanRequest {req }
191172
192173 return types .NewPublicPlanProposal (
193174 simtypes .RandStringOfLength (r , 10 ),
194175 simtypes .RandStringOfLength (r , 100 ),
195176 []* types.AddPlanRequest {},
196177 []* types.ModifyPlanRequest {},
197- deleteRequest ,
178+ deletePlanReqs ,
198179 )
199180 }
200181}
182+
183+ // ranAddPlanRequests returns randomized add request proposals.
184+ func ranAddPlanRequests (r * rand.Rand , ctx sdk.Context , simAccount simtypes.Account , poolCoins sdk.Coins ) []* types.AddPlanRequest {
185+ ranProposals := make ([]* types.AddPlanRequest , 0 )
186+
187+ // Generate a random number of proposals with random values of each parameter
188+ for i := 0 ; i < simtypes .RandIntBetween (r , 1 , 3 ); i ++ {
189+ req := & types.AddPlanRequest {}
190+ req .Name = "simulation-test-" + simtypes .RandStringOfLength (r , 5 )
191+ req .FarmingPoolAddress = simAccount .Address .String ()
192+ req .TerminationAddress = simAccount .Address .String ()
193+ req .StakingCoinWeights = sdk .NewDecCoins (sdk .NewInt64DecCoin (sdk .DefaultBondDenom , 1 ))
194+ req .StartTime = ctx .BlockTime ()
195+ req .EndTime = ctx .BlockTime ().AddDate (0 , simtypes .RandIntBetween (r , 1 , 28 ), 0 )
196+
197+ // Generate a fixed amount plan if pseudo-random integer is an even number and
198+ // generate a ratio plan if it is an odd number
199+ if r .Int ()% 2 == 0 {
200+ req .EpochAmount = sdk .NewCoins (
201+ sdk .NewInt64Coin (poolCoins [r .Intn (3 )].Denom , int64 (simtypes .RandIntBetween (r , 10_000_000 , 100_000_000 ))),
202+ )
203+ } else {
204+ req .EpochRatio = sdk .NewDecWithPrec (int64 (simtypes .RandIntBetween (r , 1 , 10 )), 2 ) // 1% ~ 10%
205+ }
206+ ranProposals = append (ranProposals , req )
207+ }
208+ return ranProposals
209+ }
0 commit comments