Skip to content

Commit

Permalink
interactor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 2, 2024
1 parent 8b905af commit 00b390f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
8 changes: 4 additions & 4 deletions framework/snippets/src/interactor_multi_sc_exec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
interactor_multi_sc_process::{update_nonces_and_sign_tx, SenderSet, Txs},
Interactor, StepBuffer, TransactionSpec,
Interactor, InteractorStep, StepBuffer,
};

use multiversx_sc_scenario::scenario_model::TxResponse;
Expand Down Expand Up @@ -32,7 +32,7 @@ impl Interactor {

for sc_call_step in &mut buffer.refs {
let mut transaction = sc_call_step.to_transaction(self);
let sender_address = &sc_call_step.to_address().value;
let sender_address = &sc_call_step.sender_address().value;
let sender = self
.sender_map
.get_mut(sender_address)
Expand All @@ -45,11 +45,11 @@ impl Interactor {
}
}

fn retrieve_senders(sc_call_steps: &[&mut dyn TransactionSpec]) -> SenderSet {
fn retrieve_senders(sc_call_steps: &[&mut dyn InteractorStep]) -> SenderSet {
let mut senders = SenderSet::new();

for sc_call_step in sc_call_steps {
let sender_address = &sc_call_step.to_address().value;
let sender_address = &sc_call_step.sender_address().value;
senders.insert(sender_address.clone());
}
senders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ use multiversx_sdk::data::transaction::Transaction;

use crate::Interactor;

pub trait TransactionSpec {
/// Describes a scenario step that can be executed in an interactor.
pub trait InteractorStep {
fn to_transaction(&self, interactor: &Interactor) -> Transaction;

fn to_address(&self) -> &AddressValue;
fn sender_address(&self) -> &AddressValue;

fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner);

fn set_response(&mut self, tx_response: TxResponse);
}

impl TransactionSpec for ScCallStep {
impl InteractorStep for ScCallStep {
fn to_transaction(&self, interactor: &Interactor) -> Transaction {
interactor.tx_call_to_blockchain_tx(&self.tx)
}

fn to_address(&self) -> &AddressValue {
fn sender_address(&self) -> &AddressValue {
&self.tx.from
}

Expand All @@ -35,12 +36,12 @@ impl TransactionSpec for ScCallStep {
}
}

impl TransactionSpec for ScDeployStep {
impl InteractorStep for ScDeployStep {
fn to_transaction(&self, interactor: &Interactor) -> Transaction {
interactor.sc_deploy_to_blockchain_tx(self)
}

fn to_address(&self) -> &AddressValue {
fn sender_address(&self) -> &AddressValue {
&self.tx.from
}

Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ mod interactor_sc_deploy;
mod interactor_sc_extra;
mod interactor_sc_transfer;
mod interactor_sender;
mod interactor_step;
mod interactor_tx;
mod interactor_tx_spec;
mod interactor_vm_query;
mod step_buffer;

Expand All @@ -18,8 +18,8 @@ pub use hex;
pub use interactor::*;
pub use interactor_dns::*;
pub use interactor_sender::*;
pub use interactor_step::InteractorStep;
pub use interactor_tx::*;
pub use interactor_tx_spec::*;
pub use log;
pub use multiversx_sc_scenario::{self, multiversx_sc};
pub use multiversx_sdk as erdrs; // TODO: remove
Expand Down
6 changes: 3 additions & 3 deletions framework/snippets/src/step_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use multiversx_sc_scenario::scenario_model::{ScCallStep, ScDeployStep};

use crate::TransactionSpec;
use crate::InteractorStep;

#[derive(Default)]
pub struct StepBuffer<'a> {
pub refs: Vec<&'a mut dyn TransactionSpec>,
pub refs: Vec<&'a mut dyn InteractorStep>,
}

impl<'a> StepBuffer<'a> {
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'a> StepBuffer<'a> {
buffer
}

pub fn to_refs_vec(&'a self) -> Vec<&'a dyn TransactionSpec> {
pub fn to_refs_vec(&'a self) -> Vec<&'a dyn InteractorStep> {
self.refs.iter().map(|r| &**r).collect()
}
}

0 comments on commit 00b390f

Please sign in to comment.