Skip to content

Commit

Permalink
Tx -> Step conversion refactor - part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Apr 2, 2024
1 parent 5390e22 commit 3506d25
Show file tree
Hide file tree
Showing 18 changed files with 448 additions and 284 deletions.
1 change: 0 additions & 1 deletion framework/scenario/src/facade/world_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod scenario_env;
mod scenario_env_deploy;
mod scenario_env_exec;
mod scenario_env_query;
pub mod scenario_env_util;
mod scenario_rh_impl;

pub use expr::*;
Expand Down
20 changes: 10 additions & 10 deletions framework/scenario/src/facade/world_tx/scenario_env_deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use multiversx_sc::{

use crate::{
api::StaticApi,
scenario::tx_to_step::TxToStep,
scenario_model::{AddressValue, BytesValue, ScCallStep, ScDeployStep, TxResponse},
ScenarioEnvExec, ScenarioTxEnv, ScenarioTxRun, ScenarioWorld,
};

use super::{scenario_env_util::*, ScenarioTxEnvData};
use super::ScenarioTxEnvData;

impl<'w, From, Payment, Gas, CodeValue, RH> ScenarioTxRun
for Tx<
Expand All @@ -39,11 +40,9 @@ where
type Returns = <RH::ListReturns as NestedTupleFlatten>::Unpacked;

fn run(self) -> Self::Returns {
let mut step =
tx_to_sc_deploy_step(&self.env, self.from, self.payment, self.gas, self.data);
step.expect = Some(self.result_handler.list_tx_expect());
self.env.world.sc_deploy(&mut step);
process_result(step.response, self.result_handler)
let mut step_wrapper = self.tx_to_step();
step_wrapper.env.world.sc_deploy(&mut step_wrapper.step);
step_wrapper.process_result()
}
}

Expand All @@ -70,10 +69,11 @@ impl ScenarioWorld {
let env = self.new_env_data();
let tx_base = TxBaseWithEnv::new_with_env(env);
let tx = f(tx_base);
let mut step = tx_to_sc_deploy_step(&tx.env, tx.from, tx.payment, tx.gas, tx.data);
self.sc_deploy(&mut step);
step.expect = Some(tx.result_handler.list_tx_expect());
process_result(step.response, tx.result_handler);

let mut step_wrapper = tx.tx_to_step();
self.sc_deploy(&mut step_wrapper.step);
step_wrapper.process_result();

self
}
}
24 changes: 8 additions & 16 deletions framework/scenario/src/facade/world_tx/scenario_env_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ use multiversx_sc::{

use crate::{
api::StaticApi,
scenario::tx_to_step::TxToStep,
scenario_model::{AddressValue, BytesValue, ScCallStep, ScDeployStep, TxExpect, TxResponse},
ScenarioTxEnv, ScenarioTxRun, ScenarioWorld,
};

use super::{scenario_env_util::*, ScenarioTxEnvData};
use super::ScenarioTxEnvData;

/// Environment for executing transactions.
pub struct ScenarioEnvExec<'w> {
Expand Down Expand Up @@ -61,17 +62,9 @@ where
type Returns = <RH::ListReturns as NestedTupleFlatten>::Unpacked;

fn run(self) -> Self::Returns {
let mut step = tx_to_sc_call_step(
&self.env,
self.from,
self.to,
self.payment,
self.gas,
self.data,
);
step.expect = Some(self.result_handler.list_tx_expect());
self.env.world.sc_call(&mut step);
process_result(step.response, self.result_handler)
let mut step_wrapper = self.tx_to_step();
step_wrapper.env.world.sc_call(&mut step_wrapper.step);
step_wrapper.process_result()
}
}

Expand All @@ -97,10 +90,9 @@ impl ScenarioWorld {
let env = self.new_env_data();
let tx_base = TxBaseWithEnv::new_with_env(env);
let tx = f(tx_base);
let mut step = tx_to_sc_call_step(&tx.env, tx.from, tx.to, tx.payment, tx.gas, tx.data);
step.expect = Some(tx.result_handler.list_tx_expect());
self.sc_call(&mut step);
process_result(step.response, tx.result_handler);
let mut step_wrapper = tx.tx_to_step();
self.sc_call(&mut step_wrapper.step);
step_wrapper.process_result();
self
}
}
17 changes: 7 additions & 10 deletions framework/scenario/src/facade/world_tx/scenario_env_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ use multiversx_sc::{

use crate::{
api::StaticApi,
scenario::tx_to_step::TxToQueryStep,
scenario_model::{TxExpect, TxResponse},
ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun, ScenarioWorld,
};

use super::scenario_env_util::*;

pub struct ScenarioEnvQuery<'w> {
pub world: &'w mut ScenarioWorld,
pub data: ScenarioTxEnvData,
Expand Down Expand Up @@ -55,10 +54,9 @@ where
type Returns = <RH::ListReturns as NestedTupleFlatten>::Unpacked;

fn run(self) -> Self::Returns {
let mut step = tx_to_sc_query_step(&self.env, self.to, self.data);
step.expect = Some(self.result_handler.list_tx_expect());
self.env.world.sc_query(&mut step);
process_result(step.response, self.result_handler)
let mut step_wrapper = self.tx_to_query_step();
step_wrapper.env.world.sc_query(&mut step_wrapper.step);
step_wrapper.process_result()
}
}

Expand All @@ -80,10 +78,9 @@ impl ScenarioWorld {
let env = self.new_env_data();
let tx_base = TxBaseWithEnv::new_with_env(env);
let tx = f(tx_base);
let mut step = tx_to_sc_query_step(&tx.env, tx.to, tx.data);
self.sc_query(&mut step);
step.expect = Some(tx.result_handler.list_tx_expect());
process_result(step.response, tx.result_handler);
let mut step_wrapper = tx.tx_to_query_step();
self.sc_query(&mut step_wrapper.step);
step_wrapper.process_result();
self
}
}
175 changes: 0 additions & 175 deletions framework/scenario/src/facade/world_tx/scenario_env_util.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod run_list;
pub mod run_trace;
pub mod run_vm;
mod scenario_runner;
pub mod tx_to_step;

pub use parse_util::{parse_scenario, parse_scenario_raw};
pub use scenario_runner::ScenarioRunner;
11 changes: 11 additions & 0 deletions framework/scenario/src/scenario/tx_to_step.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod step_annotation;
mod step_wrapper;
mod tx_to_step_call;
mod tx_to_step_deploy;
mod tx_to_step_query;
mod tx_to_step_trait;
mod tx_to_step_transfer;

pub use step_annotation::*;
pub use step_wrapper::StepWrapper;
pub use tx_to_step_trait::*;
40 changes: 40 additions & 0 deletions framework/scenario/src/scenario/tx_to_step/step_annotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use multiversx_chain_scenario_format::serde_raw::ValueSubTree;
use multiversx_sc::types::{AnnotatedValue, Code, ManagedAddress, TxCodeValue, TxEnv, TxGas};

use crate::scenario_model::{AddressValue, BytesValue, U64Value};

pub fn address_annotated<Env, Addr>(env: &Env, from: Addr) -> AddressValue
where
Env: TxEnv,
Addr: AnnotatedValue<Env, ManagedAddress<Env::Api>>,
{
let annotation = from.annotation(env).to_string();
AddressValue {
value: from.into_value(env).to_address(),
original: ValueSubTree::Str(annotation),
}
}

pub fn code_annotated<Env, CodeValue>(env: &Env, code: Code<CodeValue>) -> BytesValue
where
Env: TxEnv,
CodeValue: TxCodeValue<Env>,
{
let annotation = code.0.annotation(env).to_string();
BytesValue {
value: code.0.into_value(env).to_vec(),
original: ValueSubTree::Str(annotation),
}
}

pub fn gas_annotated<Env, Gas>(env: &Env, gas: Gas) -> U64Value
where
Env: TxEnv,
Gas: TxGas<Env>,
{
let annotation = gas.gas_annotation(env).to_string();
U64Value {
value: gas.gas_value(env),
original: ValueSubTree::Str(annotation),
}
}
Loading

0 comments on commit 3506d25

Please sign in to comment.