Skip to content

Commit

Permalink
add roles/groups to the vitup mock (#280)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ecioppettini authored Jun 16, 2022
1 parent a589837 commit 470bdb4
Show file tree
Hide file tree
Showing 41 changed files with 403 additions and 223 deletions.
27 changes: 14 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions iapyx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ eccoxide = { git = "https://github.com/eugene-babichenko/eccoxide.git", branch =
rayon = "1"
bincode = "1.3.3"
cocoon = { git = "https://github.com/dkijania/cocoon.git" }
vit-servicing-station-lib = { git = "https://github.com/input-output-hk/vit-servicing-station.git", branch = "master" }

[dependencies.reqwest]
version = "0.10.6"
Expand Down
50 changes: 32 additions & 18 deletions iapyx/src/bin/interactive/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use std::str::FromStr;
use structopt::StructOpt;
use thiserror::Error;
use thor::cli::{Alias, Connection};
use valgrind::{Proposal, ProposalExtension};
use valgrind::ProposalExtension;
use vit_servicing_station_lib::db::models::proposals::FullProposalInfo;
use wallet_core::Choice;

///
Expand Down Expand Up @@ -136,6 +137,8 @@ pub struct Votes {
/// Print title, otherwise only id would be print out
#[structopt(long = "print-title")]
pub print_proposal_title: bool,
#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl Votes {
Expand All @@ -157,7 +160,7 @@ impl Votes {
let vote_plan_id_hash = Hash::from_str(&vote_plan_id)?;
if self.print_proposal_title {
let history = model.vote_plan_history(vote_plan_id_hash)?;
let proposals = model.proposals()?;
let proposals = model.proposals(&self.voting_group)?;

if let Some(history) = history {
let history: Vec<String> = history
Expand All @@ -166,12 +169,12 @@ impl Votes {
proposals
.iter()
.find(|y| {
y.chain_proposal_index as u8 == *x
&& y.chain_voteplan_id == vote_plan_id
y.voteplan.chain_proposal_index as u8 == *x
&& y.voteplan.chain_voteplan_id == vote_plan_id
})
.unwrap()
})
.map(|p| p.proposal_title.clone())
.map(|p| p.proposal.proposal_title.clone())
.collect();
println!("{:#?}", history);
} else {
Expand All @@ -184,7 +187,7 @@ impl Votes {
None => {
if self.print_proposal_title {
let history = model.votes_history()?;
let proposals = model.proposals()?;
let proposals = model.proposals(&self.voting_group)?;

if let Some(history) = history {
let history: Vec<String> = history
Expand All @@ -193,12 +196,13 @@ impl Votes {
proposals
.iter()
.find(|y| {
x.votes.contains(&(y.chain_proposal_index as u8))
&& y.chain_voteplan_id == x.vote_plan_id.to_string()
x.votes.contains(&(y.voteplan.chain_proposal_index as u8))
&& y.voteplan.chain_voteplan_id
== x.vote_plan_id.to_string()
})
.unwrap()
})
.map(|p| p.proposal_title.clone())
.map(|p| p.proposal.proposal_title.clone())
.collect();
println!("{:#?}", history)
} else {
Expand Down Expand Up @@ -248,11 +252,13 @@ pub struct SingleVote {
/// Pin
#[structopt(long, short)]
pub pin: String,
#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl SingleVote {
pub fn exec(self, mut model: CliController) -> Result<(), IapyxCommandError> {
let proposals = model.proposals()?;
let proposals = model.proposals(&self.voting_group)?;
/* let block_date_generator = expiry::from_block_or_shift(
self.valid_until_fixed,
self.valid_until_shift,
Expand All @@ -264,6 +270,7 @@ impl SingleVote {
.find(|x| x.chain_proposal_id_as_str() == self.proposal_id)
.ok_or_else(|| IapyxCommandError::CannotFindProposal(self.proposal_id.clone()))?;
let choice = proposal
.proposal
.chain_vote_options
.0
.get(&self.choice)
Expand All @@ -288,12 +295,16 @@ pub struct BatchOfVotes {
/// Pin
#[structopt(long, short)]
pub pin: String,
#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl BatchOfVotes {
pub fn exec(self, mut model: CliController) -> Result<(), IapyxCommandError> {
let choices = self
.zip_into_batch_input_data(serde_json::from_str(&self.choices)?, model.proposals()?)?;
let choices = self.zip_into_batch_input_data(
serde_json::from_str(&self.choices)?,
model.proposals(&self.voting_group)?,
)?;
model.votes_batch(choices.iter().map(|(p, c)| (p, *c)).collect(), &self.pin)?;
model.save_config()?;
Ok(())
Expand All @@ -302,8 +313,8 @@ impl BatchOfVotes {
fn zip_into_batch_input_data(
&self,
choices: HashMap<String, String>,
proposals: Vec<Proposal>,
) -> Result<Vec<(Proposal, Choice)>, IapyxCommandError> {
proposals: Vec<FullProposalInfo>,
) -> Result<Vec<(FullProposalInfo, Choice)>, IapyxCommandError> {
let mut result = Vec::new();

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

let choice = proposal
.proposal
.chain_vote_options
.0
.get(&choice)
Expand Down Expand Up @@ -396,11 +408,13 @@ pub struct Proposals {
/// Limit output entries
#[structopt(short, long)]
pub limit: Option<usize>,
#[structopt(default_value = "direct", long)]
pub voting_group: String,
}
impl Proposals {
pub fn exec(self, model: CliController) -> Result<(), IapyxCommandError> {
print_delim();
for (id, proposal) in model.proposals()?.iter().enumerate() {
for (id, proposal) in model.proposals(&self.voting_group)?.iter().enumerate() {
if let Some(limit) = self.limit {
if id >= limit {
break;
Expand All @@ -414,10 +428,10 @@ impl Proposals {
"{}. {} [{}] {}",
(id + 1),
proposal.chain_proposal_id_as_str(),
proposal.proposal_title,
proposal.proposal_summary
proposal.proposal.proposal_title,
proposal.proposal.proposal_summary
);
println!("{:#?}", proposal.chain_vote_options.0);
println!("{:#?}", proposal.proposal.chain_vote_options.0);
}
}
print_delim();
Expand Down
10 changes: 5 additions & 5 deletions iapyx/src/bin/interactive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use thor::cli::Connection;
use thor::cli::WalletController;
use thor::BlockDateGenerator;
use valgrind::Fund;
use valgrind::Proposal;
use valgrind::SettingsExtensions;
use valgrind::ValgrindClient;
use vit_servicing_station_lib::db::models::proposals::FullProposalInfo;
use wallet_core::Choice;
use wallet_core::Value;

Expand Down Expand Up @@ -115,8 +115,8 @@ impl CliController {
})
}

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

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

pub fn vote(
&mut self,
proposal: &Proposal,
proposal: &FullProposalInfo,
choice: Choice,
password: &str,
) -> Result<FragmentId, Error> {
Expand All @@ -155,7 +155,7 @@ impl CliController {

pub fn votes_batch(
&mut self,
votes_data: Vec<(&Proposal, Choice)>,
votes_data: Vec<(&FullProposalInfo, Choice)>,
password: &str,
) -> Result<Vec<FragmentId>, Error> {
let ids = self.controller(password)?.votes_batch(votes_data)?;
Expand Down
4 changes: 4 additions & 0 deletions iapyx/src/bin/load/burst/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub struct BurstCountIapyxLoadCommand {
parse(from_str = parse_progress_bar_mode_from_str)
)]
progress_bar_mode: ProgressBarMode,

#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl BurstCountIapyxLoadCommand {
Expand Down Expand Up @@ -114,6 +117,7 @@ impl BurstCountIapyxLoadCommand {
read_pin_from_filename: self.read_pin_from_filename,
use_https: self.use_https,
debug: self.debug,
voting_group: self.voting_group.clone(),
}
}
}
4 changes: 4 additions & 0 deletions iapyx/src/bin/load/burst/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub struct BurstDurationIapyxLoadCommand {
parse(from_str = parse_progress_bar_mode_from_str)
)]
progress_bar_mode: ProgressBarMode,

#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl BurstDurationIapyxLoadCommand {
Expand Down Expand Up @@ -116,6 +119,7 @@ impl BurstDurationIapyxLoadCommand {
read_pin_from_filename: self.read_pin_from_filename,
use_https: self.use_https,
debug: self.debug,
voting_group: self.voting_group.clone(),
}
}
}
4 changes: 4 additions & 0 deletions iapyx/src/bin/load/constant/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct ConstantCountIapyxLoadCommand {
parse(from_str = parse_progress_bar_mode_from_str)
)]
progress_bar_mode: ProgressBarMode,

#[structopt(default_value = "direct", long)]
pub voting_group: String,
}

impl ConstantCountIapyxLoadCommand {
Expand Down Expand Up @@ -110,6 +113,7 @@ impl ConstantCountIapyxLoadCommand {
read_pin_from_filename: self.read_pin_from_filename,
use_https: self.use_https,
debug: self.debug,
voting_group: self.voting_group.clone(),
}
}
}
Loading

0 comments on commit 470bdb4

Please sign in to comment.