Skip to content

Commit 470bdb4

Browse files
authored
add roles/groups to the vitup mock (#280)
* add roles/groups to the vitup mock * update migration scripts * fix voteplan index (skip one because of the other role) * update migration scripts * derive Copy for Role since it's just an enum without fields, this should be fine * add role name to voteplan alias and use it as a filter in test * make tokens_list a Vec in order to have a fixed order * fix alias in private_vote_e2e_flow * votes_history_reflects_casted_votes: use correct role/group * fix role in test * fix voteplan alias in persistent log test * hardcode group correctly in batch * use default (direct) group wherever possible * iapyx: parametrize voting group * add missing argument in integration tests * Cargo.lock: update chain-wallet-libs and jormungandr-lib * update up.sql to vitss master * add internal_id in challenges.json
1 parent a589837 commit 470bdb4

File tree

41 files changed

+403
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+403
-223
lines changed

Cargo.lock

+14-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iapyx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ eccoxide = { git = "https://github.com/eugene-babichenko/eccoxide.git", branch =
5353
rayon = "1"
5454
bincode = "1.3.3"
5555
cocoon = { git = "https://github.com/dkijania/cocoon.git" }
56+
vit-servicing-station-lib = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }
5657

5758
[dependencies.reqwest]
5859
version = "0.10.6"

iapyx/src/bin/interactive/command.rs

+32-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::str::FromStr;
1515
use structopt::StructOpt;
1616
use thiserror::Error;
1717
use thor::cli::{Alias, Connection};
18-
use valgrind::{Proposal, ProposalExtension};
18+
use valgrind::ProposalExtension;
19+
use vit_servicing_station_lib::db::models::proposals::FullProposalInfo;
1920
use wallet_core::Choice;
2021

2122
///
@@ -136,6 +137,8 @@ pub struct Votes {
136137
/// Print title, otherwise only id would be print out
137138
#[structopt(long = "print-title")]
138139
pub print_proposal_title: bool,
140+
#[structopt(default_value = "direct", long)]
141+
pub voting_group: String,
139142
}
140143

141144
impl Votes {
@@ -157,7 +160,7 @@ impl Votes {
157160
let vote_plan_id_hash = Hash::from_str(&vote_plan_id)?;
158161
if self.print_proposal_title {
159162
let history = model.vote_plan_history(vote_plan_id_hash)?;
160-
let proposals = model.proposals()?;
163+
let proposals = model.proposals(&self.voting_group)?;
161164

162165
if let Some(history) = history {
163166
let history: Vec<String> = history
@@ -166,12 +169,12 @@ impl Votes {
166169
proposals
167170
.iter()
168171
.find(|y| {
169-
y.chain_proposal_index as u8 == *x
170-
&& y.chain_voteplan_id == vote_plan_id
172+
y.voteplan.chain_proposal_index as u8 == *x
173+
&& y.voteplan.chain_voteplan_id == vote_plan_id
171174
})
172175
.unwrap()
173176
})
174-
.map(|p| p.proposal_title.clone())
177+
.map(|p| p.proposal.proposal_title.clone())
175178
.collect();
176179
println!("{:#?}", history);
177180
} else {
@@ -184,7 +187,7 @@ impl Votes {
184187
None => {
185188
if self.print_proposal_title {
186189
let history = model.votes_history()?;
187-
let proposals = model.proposals()?;
190+
let proposals = model.proposals(&self.voting_group)?;
188191

189192
if let Some(history) = history {
190193
let history: Vec<String> = history
@@ -193,12 +196,13 @@ impl Votes {
193196
proposals
194197
.iter()
195198
.find(|y| {
196-
x.votes.contains(&(y.chain_proposal_index as u8))
197-
&& y.chain_voteplan_id == x.vote_plan_id.to_string()
199+
x.votes.contains(&(y.voteplan.chain_proposal_index as u8))
200+
&& y.voteplan.chain_voteplan_id
201+
== x.vote_plan_id.to_string()
198202
})
199203
.unwrap()
200204
})
201-
.map(|p| p.proposal_title.clone())
205+
.map(|p| p.proposal.proposal_title.clone())
202206
.collect();
203207
println!("{:#?}", history)
204208
} else {
@@ -248,11 +252,13 @@ pub struct SingleVote {
248252
/// Pin
249253
#[structopt(long, short)]
250254
pub pin: String,
255+
#[structopt(default_value = "direct", long)]
256+
pub voting_group: String,
251257
}
252258

253259
impl SingleVote {
254260
pub fn exec(self, mut model: CliController) -> Result<(), IapyxCommandError> {
255-
let proposals = model.proposals()?;
261+
let proposals = model.proposals(&self.voting_group)?;
256262
/* let block_date_generator = expiry::from_block_or_shift(
257263
self.valid_until_fixed,
258264
self.valid_until_shift,
@@ -264,6 +270,7 @@ impl SingleVote {
264270
.find(|x| x.chain_proposal_id_as_str() == self.proposal_id)
265271
.ok_or_else(|| IapyxCommandError::CannotFindProposal(self.proposal_id.clone()))?;
266272
let choice = proposal
273+
.proposal
267274
.chain_vote_options
268275
.0
269276
.get(&self.choice)
@@ -288,12 +295,16 @@ pub struct BatchOfVotes {
288295
/// Pin
289296
#[structopt(long, short)]
290297
pub pin: String,
298+
#[structopt(default_value = "direct", long)]
299+
pub voting_group: String,
291300
}
292301

293302
impl BatchOfVotes {
294303
pub fn exec(self, mut model: CliController) -> Result<(), IapyxCommandError> {
295-
let choices = self
296-
.zip_into_batch_input_data(serde_json::from_str(&self.choices)?, model.proposals()?)?;
304+
let choices = self.zip_into_batch_input_data(
305+
serde_json::from_str(&self.choices)?,
306+
model.proposals(&self.voting_group)?,
307+
)?;
297308
model.votes_batch(choices.iter().map(|(p, c)| (p, *c)).collect(), &self.pin)?;
298309
model.save_config()?;
299310
Ok(())
@@ -302,8 +313,8 @@ impl BatchOfVotes {
302313
fn zip_into_batch_input_data(
303314
&self,
304315
choices: HashMap<String, String>,
305-
proposals: Vec<Proposal>,
306-
) -> Result<Vec<(Proposal, Choice)>, IapyxCommandError> {
316+
proposals: Vec<FullProposalInfo>,
317+
) -> Result<Vec<(FullProposalInfo, Choice)>, IapyxCommandError> {
307318
let mut result = Vec::new();
308319

309320
for (proposal_id, choice) in choices {
@@ -313,6 +324,7 @@ impl BatchOfVotes {
313324
.ok_or_else(|| IapyxCommandError::CannotFindProposal(proposal_id.clone()))?;
314325

315326
let choice = proposal
327+
.proposal
316328
.chain_vote_options
317329
.0
318330
.get(&choice)
@@ -396,11 +408,13 @@ pub struct Proposals {
396408
/// Limit output entries
397409
#[structopt(short, long)]
398410
pub limit: Option<usize>,
411+
#[structopt(default_value = "direct", long)]
412+
pub voting_group: String,
399413
}
400414
impl Proposals {
401415
pub fn exec(self, model: CliController) -> Result<(), IapyxCommandError> {
402416
print_delim();
403-
for (id, proposal) in model.proposals()?.iter().enumerate() {
417+
for (id, proposal) in model.proposals(&self.voting_group)?.iter().enumerate() {
404418
if let Some(limit) = self.limit {
405419
if id >= limit {
406420
break;
@@ -414,10 +428,10 @@ impl Proposals {
414428
"{}. {} [{}] {}",
415429
(id + 1),
416430
proposal.chain_proposal_id_as_str(),
417-
proposal.proposal_title,
418-
proposal.proposal_summary
431+
proposal.proposal.proposal_title,
432+
proposal.proposal.proposal_summary
419433
);
420-
println!("{:#?}", proposal.chain_vote_options.0);
434+
println!("{:#?}", proposal.proposal.chain_vote_options.0);
421435
}
422436
}
423437
print_delim();

iapyx/src/bin/interactive/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use thor::cli::Connection;
2222
use thor::cli::WalletController;
2323
use thor::BlockDateGenerator;
2424
use valgrind::Fund;
25-
use valgrind::Proposal;
2625
use valgrind::SettingsExtensions;
2726
use valgrind::ValgrindClient;
27+
use vit_servicing_station_lib::db::models::proposals::FullProposalInfo;
2828
use wallet_core::Choice;
2929
use wallet_core::Value;
3030

@@ -115,8 +115,8 @@ impl CliController {
115115
})
116116
}
117117

118-
pub fn proposals(&self) -> Result<Vec<Proposal>, Error> {
119-
self.backend_client.proposals().map_err(Into::into)
118+
pub fn proposals(&self, group: &str) -> Result<Vec<FullProposalInfo>, Error> {
119+
self.backend_client.proposals(group).map_err(Into::into)
120120
}
121121

122122
pub fn funds(&self) -> Result<Fund, Error> {
@@ -143,7 +143,7 @@ impl CliController {
143143

144144
pub fn vote(
145145
&mut self,
146-
proposal: &Proposal,
146+
proposal: &FullProposalInfo,
147147
choice: Choice,
148148
password: &str,
149149
) -> Result<FragmentId, Error> {
@@ -155,7 +155,7 @@ impl CliController {
155155

156156
pub fn votes_batch(
157157
&mut self,
158-
votes_data: Vec<(&Proposal, Choice)>,
158+
votes_data: Vec<(&FullProposalInfo, Choice)>,
159159
password: &str,
160160
) -> Result<Vec<FragmentId>, Error> {
161161
let ids = self.controller(password)?.votes_batch(votes_data)?;

iapyx/src/bin/load/burst/count.rs

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ pub struct BurstCountIapyxLoadCommand {
7979
parse(from_str = parse_progress_bar_mode_from_str)
8080
)]
8181
progress_bar_mode: ProgressBarMode,
82+
83+
#[structopt(default_value = "direct", long)]
84+
pub voting_group: String,
8285
}
8386

8487
impl BurstCountIapyxLoadCommand {
@@ -114,6 +117,7 @@ impl BurstCountIapyxLoadCommand {
114117
read_pin_from_filename: self.read_pin_from_filename,
115118
use_https: self.use_https,
116119
debug: self.debug,
120+
voting_group: self.voting_group.clone(),
117121
}
118122
}
119123
}

iapyx/src/bin/load/burst/duration.rs

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub struct BurstDurationIapyxLoadCommand {
8181
parse(from_str = parse_progress_bar_mode_from_str)
8282
)]
8383
progress_bar_mode: ProgressBarMode,
84+
85+
#[structopt(default_value = "direct", long)]
86+
pub voting_group: String,
8487
}
8588

8689
impl BurstDurationIapyxLoadCommand {
@@ -116,6 +119,7 @@ impl BurstDurationIapyxLoadCommand {
116119
read_pin_from_filename: self.read_pin_from_filename,
117120
use_https: self.use_https,
118121
debug: self.debug,
122+
voting_group: self.voting_group.clone(),
119123
}
120124
}
121125
}

iapyx/src/bin/load/constant/count.rs

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ pub struct ConstantCountIapyxLoadCommand {
7575
parse(from_str = parse_progress_bar_mode_from_str)
7676
)]
7777
progress_bar_mode: ProgressBarMode,
78+
79+
#[structopt(default_value = "direct", long)]
80+
pub voting_group: String,
7881
}
7982

8083
impl ConstantCountIapyxLoadCommand {
@@ -110,6 +113,7 @@ impl ConstantCountIapyxLoadCommand {
110113
read_pin_from_filename: self.read_pin_from_filename,
111114
use_https: self.use_https,
112115
debug: self.debug,
116+
voting_group: self.voting_group.clone(),
113117
}
114118
}
115119
}

0 commit comments

Comments
 (0)