Skip to content

Commit

Permalink
added bond + check bond
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli authored and Gianmarco Fraccaroli committed Mar 19, 2024
1 parent 5767333 commit 3658f0c
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/checks/bonds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl Check for BondsCheck {

#[derive(Clone, Debug, Deserialize)]
pub struct BondsCheckParametersDto {
amount: Value,
delegate: Value,
delegator: Value,
pub amount: Value,
pub delegate: Value,
pub delegator: Value,
}

#[derive(Clone, Debug)]
Expand Down
1 change: 1 addition & 0 deletions src/gen/hooks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod check_balance;
pub mod check_bond;
pub mod check_step;
pub mod query_validators;
pub mod storage_check;
6 changes: 4 additions & 2 deletions src/gen/hooks/query_validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Display;

use derive_builder::Builder;
use namada_scenario_tester::{
scenario::StepType,
queries::validators::ValidatorsQueryParametersDto, scenario::StepType,
};

use crate::step::Hook;
Expand All @@ -24,7 +24,9 @@ impl QueryValidatorSet {

impl Hook for QueryValidatorSet {
fn to_json(&self) -> StepType {
todo!()
StepType::QueryValidators {
parameters: ValidatorsQueryParametersDto { epoch: None },
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/gen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@ fn main() {
TaskType::NewWalletKey,
TaskType::FaucetTransafer,
TaskType::TransparentTransfer,
// TaskType::Bond,
// TaskType::InitAccount,
TaskType::Bond,
TaskType::InitAccount,
];

let mut scenario_builder = ScenarioBuilder::new(tasks, vec![1.into(), 1.into(), 2.into()]);
let mut scenario_builder = ScenarioBuilder::new(
tasks,
vec![1.into(), 1.into(), 2.into(), 2.into(), 1.into()],
);

for _step_index in 0..=10 {
for _step_index in 0..=20 {
let next_task = loop {
let task_type = scenario_builder.choose_next_task();
if scenario_builder.is_valid_task(task_type) {
break task_type;
}
};
let step = scenario_builder.build_step(next_task); // bond
let step = scenario_builder.build_step(next_task);

scenario_builder.update_state(step.clone());
scenario_builder.update_scenario(step.clone());
}

for step in scenario_builder.scenario {
println!("{:?}", step);
for (index, step) in scenario_builder.scenario.iter().enumerate() {
println!("{}: {:?}", index, step);
}
}
2 changes: 1 addition & 1 deletion src/gen/scenario_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ScenarioBuilder {
.into_iter()
.map(|step| step.to_json())
.collect::<Vec<StepType>>();
let step_json = step.to_json();
let step_json = step.to_json(step_index);

self.scenario.extend(pre_hooks_json);
self.scenario.push(step_json);
Expand Down
2 changes: 1 addition & 1 deletion src/gen/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl TaskType {
}

pub trait Step: DynClone + Debug + Display {
fn to_json(&self) -> StepType;
fn to_json(&self, step_index: u64) -> StepType;
fn update_state(&self, state: &mut State);
fn post_hooks(&self, step_index: u64, state: &State) -> Vec<Box<dyn Hook>>;
fn pre_hooks(&self, state: &State) -> Vec<Box<dyn Hook>>;
Expand Down
25 changes: 20 additions & 5 deletions src/gen/steps/bonds.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::fmt::Display;

use derive_builder::Builder;
use namada_scenario_tester::scenario::StepType;
use namada_scenario_tester::{
scenario::StepType, tasks::bond::TxBondParametersDto, utils::value::Value,
};

use crate::{
entity::Alias,
hooks::{check_step::CheckStep, query_validators::QueryValidatorSet},
hooks::{check_bond::CheckBond, check_step::CheckStep, query_validators::QueryValidatorSet},
state::State,
step::Step,
};
Expand All @@ -17,8 +19,14 @@ pub struct Bond {
}

impl Step for Bond {
fn to_json(&self) -> StepType {
todo!()
fn to_json(&self, step_index: u64) -> StepType {
StepType::Bond {
parameters: TxBondParametersDto {
source: Value::v(self.source.to_string()),
validator: Value::r(step_index - 1, "validator-1-address".to_string()),
amount: Value::v(self.amount.to_string()),
},
}
}

fn update_state(&self, state: &mut crate::state::State) {
Expand All @@ -27,7 +35,14 @@ impl Step for Bond {
}

fn post_hooks(&self, step_index: u64, _state: &State) -> Vec<Box<dyn crate::step::Hook>> {
vec![Box::new(CheckStep::new(step_index))]
vec![
Box::new(CheckStep::new(step_index)),
Box::new(CheckBond::new(
self.source.clone(),
step_index - 1,
self.amount,
)),
]
}

fn pre_hooks(&self, _state: &State) -> Vec<Box<dyn crate::step::Hook>> {
Expand Down
2 changes: 1 addition & 1 deletion src/gen/steps/faucet_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct FaucetTransfer {
}

impl Step for FaucetTransfer {
fn to_json(&self) -> StepType {
fn to_json(&self, _step_index: u64) -> StepType {
StepType::TransparentTransfer {
parameters: TxTransparentTransferParametersDto {
source: Value::v("faucet".to_string()),
Expand Down
17 changes: 14 additions & 3 deletions src/gen/steps/init_account.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::fmt::Display;

use derive_builder::Builder;
use namada_scenario_tester::scenario::StepType;
use namada_scenario_tester::{
scenario::StepType, tasks::init_account::TxInitAccountParametersDto, utils::value::Value,
};

use crate::{entity::Alias, hooks::check_step::CheckStep, state::State, step::Step};

Expand All @@ -13,8 +15,17 @@ pub struct InitAccount {
}

impl Step for InitAccount {
fn to_json(&self) -> StepType {
todo!()
fn to_json(&self, _step_index: u64) -> StepType {
StepType::InitAccount {
parameters: TxInitAccountParametersDto {
sources: self
.pks
.iter()
.map(|alias| Value::v(alias.to_string()))
.collect(),
threshold: Some(Value::v(self.threshold.to_string())),
},
}
}

fn update_state(&self, state: &mut crate::state::State) {
Expand Down
2 changes: 1 addition & 1 deletion src/gen/steps/new_wallet_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct NewWalletStep {
}

impl Step for NewWalletStep {
fn to_json(&self) -> StepType {
fn to_json(&self, _step_index: u64) -> StepType {
StepType::WalletNewKey {
parameters: WalletNewKeyParametersDto {},
}
Expand Down
2 changes: 1 addition & 1 deletion src/gen/steps/transparent_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct TransparentTransfer {
}

impl Step for TransparentTransfer {
fn to_json(&self) -> StepType {
fn to_json(&self, _step_index: u64) -> StepType {
StepType::TransparentTransfer {
parameters: TxTransparentTransferParametersDto {
source: Value::v(self.source.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion src/queries/validators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Query for ValidatorsQuery {

#[derive(Clone, Debug, Deserialize)]
pub struct ValidatorsQueryParametersDto {
epoch: Option<Value>,
pub epoch: Option<Value>,
}

#[derive(Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/tasks/bond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl Task for TxBond {

#[derive(Clone, Debug, Deserialize)]
pub struct TxBondParametersDto {
source: Value,
validator: Value,
amount: Value,
pub source: Value,
pub validator: Value,
pub amount: Value,
}

#[derive(Clone, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/tasks/init_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl Task for TxInitAccount {

#[derive(Clone, Debug, Deserialize)]
pub struct TxInitAccountParametersDto {
sources: Vec<Value>,
threshold: Option<Value>,
pub sources: Vec<Value>,
pub threshold: Option<Value>,
}

impl TxInitAccountParametersDto {
Expand Down

0 comments on commit 3658f0c

Please sign in to comment.