@@ -42,7 +42,7 @@ pub struct ScenarioBuilder {
42
42
config : ConfigBuilder ,
43
43
initials : Option < Vec < WalletTemplateBuilder > > ,
44
44
stake_pools : Option < Vec < StakePoolDefBuilder > > ,
45
- vote_plans : Vec < VotePlanDefBuilder > ,
45
+ vote_plans : Option < Vec < VotePlanDefBuilder > > ,
46
46
}
47
47
48
48
pub fn prepare_scenario ( ) -> ScenarioBuilder {
@@ -54,32 +54,32 @@ pub fn prepare_scenario() -> ScenarioBuilder {
54
54
config : default_config_builder,
55
55
initials : None ,
56
56
stake_pools : None ,
57
- vote_plans : Vec :: new ( ) ,
57
+ vote_plans : None ,
58
58
}
59
59
}
60
60
61
61
impl ScenarioBuilder {
62
- pub fn with_config ( & mut self , config : ConfigBuilder ) -> & mut Self {
62
+ pub fn with_config ( mut self , config : ConfigBuilder ) -> Self {
63
63
self . config = config;
64
64
self
65
65
}
66
66
67
- pub fn with_initials ( & mut self , initials : Vec < & mut WalletTemplateBuilder > ) -> & mut Self {
68
- self . initials = Some ( initials. iter ( ) . map ( |x| ( * * x ) . clone ( ) ) . collect ( ) ) ;
67
+ pub fn with_initials ( mut self , initials : Vec < WalletTemplateBuilder > ) -> Self {
68
+ self . initials = Some ( initials) ;
69
69
self
70
70
}
71
71
72
- pub fn with_vote_plans ( & mut self , vote_plans : Vec < & mut VotePlanDefBuilder > ) -> & mut Self {
73
- self . vote_plans = vote_plans . iter ( ) . map ( |x| ( * * x ) . clone ( ) ) . collect ( ) ;
72
+ pub fn with_vote_plans ( mut self , vote_plans : Vec < VotePlanDefBuilder > ) -> Self {
73
+ self . vote_plans = Some ( vote_plans ) ;
74
74
self
75
75
}
76
76
77
- pub fn with_stake_pools ( & mut self , stake_pools : Vec < & mut StakePoolDefBuilder > ) -> & mut Self {
78
- self . stake_pools = Some ( stake_pools. iter ( ) . map ( |x| ( * * x ) . clone ( ) ) . collect ( ) ) ;
77
+ pub fn with_stake_pools ( mut self , stake_pools : Vec < StakePoolDefBuilder > ) -> Self {
78
+ self . stake_pools = Some ( stake_pools) ;
79
79
self
80
80
}
81
81
82
- pub fn build ( & self ) -> Result < ( TestLedger , Controller ) , ScenarioBuilderError > {
82
+ pub fn build ( self ) -> Result < ( TestLedger , Controller ) , ScenarioBuilderError > {
83
83
if self . initials . is_none ( ) {
84
84
return Err ( ScenarioBuilderError :: UndefinedInitials ) ;
85
85
}
@@ -107,14 +107,17 @@ impl ScenarioBuilder {
107
107
let faucets: Vec < AddressDataValue > =
108
108
wallets. iter ( ) . cloned ( ) . map ( |x| x. as_account ( ) ) . collect ( ) ;
109
109
110
- let vote_plan_defs: Vec < VotePlanDef > =
111
- self . vote_plans . iter ( ) . map ( |x| x. clone ( ) . build ( ) ) . collect ( ) ;
112
- let vote_plan_fragments: Vec < Fragment > = self
110
+ let vote_plan_defs: Vec < VotePlanDef > = self
113
111
. vote_plans
112
+ . iter ( )
113
+ . map ( |builders| builders. into_iter ( ) )
114
+ . flatten ( )
115
+ . map ( |x| x. clone ( ) . build ( ) )
116
+ . collect ( ) ;
117
+ let vote_plan_fragments: Vec < Fragment > = vote_plan_defs
114
118
. iter ( )
115
119
. cloned ( )
116
- . map ( |x| {
117
- let vote_plan_def = x. build ( ) ;
120
+ . map ( |vote_plan_def| {
118
121
let owner = wallets
119
122
. iter ( )
120
123
. cloned ( )
@@ -211,9 +214,9 @@ impl ScenarioBuilder {
211
214
}
212
215
213
216
fn build_stake_pool ( & self , template : StakePoolTemplate ) -> StakePool {
214
- let mut builder = StakePoolBuilder :: new ( ) ;
215
- builder . with_owners ( template. owners ( ) ) ;
216
- builder . with_alias ( & template. alias ( ) ) ;
217
+ let mut builder = StakePoolBuilder :: new ( )
218
+ . with_owners ( template. owners ( ) )
219
+ . with_alias ( & template. alias ( ) ) ;
217
220
218
221
if let Some ( stake_pools) = & self . stake_pools {
219
222
let stake_pool_def_opt = stake_pools
@@ -224,12 +227,12 @@ impl ScenarioBuilder {
224
227
225
228
if let Some ( stake_pool_def) = stake_pool_def_opt {
226
229
if let Some ( pool_permission) = stake_pool_def. pool_permission ( ) {
227
- builder. with_pool_permissions ( pool_permission) ;
230
+ builder = builder . with_pool_permissions ( pool_permission) ;
228
231
}
229
232
if let Some ( tax_type) = stake_pool_def. tax_type {
230
- builder. with_tax_type ( tax_type) ;
233
+ builder = builder . with_tax_type ( tax_type) ;
231
234
}
232
- builder. with_reward_account ( stake_pool_def. has_reward_account ) ;
235
+ builder = builder . with_reward_account ( stake_pool_def. has_reward_account ) ;
233
236
}
234
237
}
235
238
builder. build ( )
0 commit comments