Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli authored and Gianmarco Fraccaroli committed Apr 12, 2024
1 parent 14f3011 commit f82bcde
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 65 deletions.
68 changes: 25 additions & 43 deletions src/gen/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl TaskType {
}
TaskType::Bond => {
!state
.any_non_validator_address_with_at_least_native_token(MIN_FEE + 1)
.any_non_validator_address_with_at_least_native_token(MIN_FEE * 2)
.is_empty()
&& !state
.implicit_addresses_with_at_least_native_token_balance(MIN_FEE)
Expand All @@ -86,35 +86,27 @@ impl TaskType {
TaskType::Unbond => {
!state.any_bond().is_empty()
&& !state
.implicit_addresses_with_at_least_native_token_balance(
PROPOSAL_FUNDS + MIN_FEE,
)
.implicit_addresses_with_at_least_native_token_balance(MIN_FEE)
.is_empty()
}
TaskType::Withdraw => {
!state.any_unbond().is_empty()
&& !state
.implicit_addresses_with_at_least_native_token_balance(
PROPOSAL_FUNDS + MIN_FEE,
)
.implicit_addresses_with_at_least_native_token_balance(MIN_FEE)
.is_empty()
}
TaskType::VoteProposal => {
!state.any_bond().is_empty()
&& state.last_proposal_id > 0
&& !state
.implicit_addresses_with_at_least_native_token_balance(
PROPOSAL_FUNDS + MIN_FEE,
)
.implicit_addresses_with_at_least_native_token_balance(MIN_FEE)
.is_empty()
}
TaskType::Redelegate => {
!state.any_bond().is_empty()
&& !state.any_validator_address().len() > 1
&& !state.any_active_validator_address().is_empty()
&& !state
.implicit_addresses_with_at_least_native_token_balance(
PROPOSAL_FUNDS + MIN_FEE,
)
.implicit_addresses_with_at_least_native_token_balance(MIN_FEE)
.is_empty()
}
TaskType::BecomeValidator => {
Expand Down Expand Up @@ -395,7 +387,7 @@ impl TaskType {
}
TaskType::Unbond => {
let bond = state.random_bond();
let amount = utils::random_between(0, bond.amount);
let amount = utils::random_between(1, bond.amount);

let tx_settings = if bond.source.clone().is_implicit() {
let gas_payer = bond.source.clone();
Expand All @@ -420,7 +412,7 @@ impl TaskType {
}
TaskType::Withdraw => {
let unbond = state.random_unbond();
let amount = utils::random_between(0, unbond.amount);
let amount = utils::random_between(1, unbond.amount);

let tx_settings = if unbond.source.clone().is_implicit() {
let gas_payer = unbond.source.clone();
Expand Down Expand Up @@ -485,7 +477,7 @@ impl TaskType {
TxSettings::default_from_enstablished(account.implicit_addresses, gas_payer)
};

let amount = utils::random_between(0, bond.amount);
let amount = utils::random_between(1, bond.amount);
let step = RedelegateBuilder::default()
.amount(amount)
.source(bond.source)
Expand Down Expand Up @@ -516,23 +508,18 @@ impl TaskType {
Box::new(step)
}
TaskType::ChangeMetadata => {
let non_validator_account = state.random_validator_address();
let validator_account = state.random_validator_address();

let tx_settings = if non_validator_account.clone().address_type.is_implicit() {
let gas_payer = non_validator_account.alias.clone();
TxSettings::default_from_implicit(gas_payer)
} else {
let gas_payer = state
.random_implicit_account_with_at_least_native_token_balance(MIN_FEE)
.alias;
TxSettings::default_from_enstablished(
non_validator_account.implicit_addresses,
gas_payer,
)
};
let gas_payer = state
.random_implicit_account_with_at_least_native_token_balance(MIN_FEE)
.alias;
let tx_settings = TxSettings::default_from_enstablished(
validator_account.implicit_addresses,
gas_payer,
);

let step = ChangeMetadataBuilder::default()
.source(non_validator_account.alias)
.source(validator_account.alias)
.tx_settings(tx_settings)
.build()
.unwrap();
Expand All @@ -542,18 +529,13 @@ impl TaskType {
TaskType::DeactivateValidator => {
let validator_account = state.random_active_validator_address();

let tx_settings = if validator_account.clone().address_type.is_implicit() {
let gas_payer = validator_account.alias.clone();
TxSettings::default_from_implicit(gas_payer)
} else {
let gas_payer = state
.random_implicit_account_with_at_least_native_token_balance(MIN_FEE)
.alias;
TxSettings::default_from_enstablished(
validator_account.implicit_addresses,
gas_payer,
)
};
let gas_payer = state
.random_implicit_account_with_at_least_native_token_balance(MIN_FEE)
.alias;
let tx_settings = TxSettings::default_from_enstablished(
validator_account.implicit_addresses,
gas_payer,
);

let step = DeactivateValidatorBuilder::default()
.source(validator_account.alias)
Expand Down
6 changes: 1 addition & 5 deletions src/gen/steps/bonds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ impl Step for Bond {
}

fn total_post_hooks(&self) -> u64 {
if self.source.eq(&self.tx_settings.gas_payer) {
1
} else {
1
}
1
}

fn total_pre_hooks(&self) -> u64 {
Expand Down
4 changes: 2 additions & 2 deletions src/gen/steps/init_default_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl Step for InitDefaultProposal {

fn total_post_hooks(&self) -> u64 {
if self.author.eq(&self.tx_settings.gas_payer) {
1 // 2
1
} else {
1 // 3
1
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/gen/steps/new_wallet_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Step for NewWalletStep {
}

fn update_state(&self, state: &mut crate::state::State) {
state.insert_new_key(self.alias.clone())
state.insert_new_key(self.alias.clone());
}

fn post_hooks(&self, _step_index: u64, _state: &State) -> Vec<Box<dyn crate::step::Hook>> {
Expand All @@ -42,7 +42,7 @@ impl Step for NewWalletStep {
}

fn total_post_hooks(&self) -> u64 {
1
2
}

fn total_pre_hooks(&self) -> u64 {
Expand Down
3 changes: 0 additions & 3 deletions src/gen/steps/redelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ impl Step for Redelegate {
}

fn post_hooks(&self, step_index: u64, state: &State) -> Vec<Box<dyn crate::step::Hook>> {
let _gas_payer_balance =
state.get_alias_token_balance(&self.tx_settings.gas_payer, &Alias::native_token());

vec![Box::new(CheckStep::new(step_index))]
}

Expand Down
6 changes: 1 addition & 5 deletions src/gen/steps/transparent_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl Step for TransparentTransfer {
}

fn total_post_hooks(&self) -> u64 {
if self.source.eq(&self.tx_settings.gas_payer) {
1
} else {
1
}
1
}

fn total_pre_hooks(&self) -> u64 {
Expand Down
17 changes: 15 additions & 2 deletions src/tasks/redelegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
scenario::StepResult,
sdk::namada::Sdk,
state::state::{StepStorage, Storage},
utils::{settings::TxSettings, value::Value},
utils::{misc::ValidatorState, settings::TxSettings, value::Value},
};

pub enum TxRevealPkStorageKeys {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Task for TxRedelegate {
validator_src.clone(),
validator_target.clone(),
bond_amount,
);
).force(true);

let redelegate_tx_builder = self
.add_settings(sdk, redelegate_tx_builder, settings)
Expand Down Expand Up @@ -226,12 +226,25 @@ impl TaskParam for TxRedelegateParameters {
.to_string()
.as_str(),
);
// let validator_state = state.get_step_item(
// &step_id,
// ValidatorsQueryStorageKeys::State(validator_idx)
// .to_string()
// .as_str(),
// );

let dest_validator = AccountIndentifier::Address(validator_address);

if dest_validator != src_validator {
break Some(dest_validator);
}

// if dest_validator != src_validator
// && validator_state != ValidatorState::Inactive.to_string()
// && validator_state != ValidatorState::Jailed.to_string()
// {
// break Some(dest_validator);
// }
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/misc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};

use namada_sdk::proof_of_stake::types::ValidatorState as NamadaValidatorState;

Expand All @@ -19,8 +19,8 @@ impl Display for ValidatorState {
ValidatorState::BelowCapacity => write!(f, "below-capacity"),
ValidatorState::BelowThreshold => write!(f, "below-threshold"),
ValidatorState::Inactive => write!(f, "inactive"),
ValidatorState::Jailed => write!(f, "wallet-new-key"),
ValidatorState::Unknown => write!(f, "wallet-new-key"),
ValidatorState::Jailed => write!(f, "jailed"),
ValidatorState::Unknown => write!(f, "unknown"),
}
}
}
Expand Down

0 comments on commit f82bcde

Please sign in to comment.