-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1572 from multiversx/set-check-refactor
Scenario set/check refactor
- Loading branch information
Showing
11 changed files
with
221 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#![allow(unused)] // TEMP | ||
|
||
mod scenario_env; | ||
mod scenario_env_deploy; | ||
mod scenario_env_exec; | ||
mod scenario_env_query; | ||
mod scenario_check_state; | ||
mod scenario_exec_call; | ||
mod scenario_exec_deploy; | ||
mod scenario_query_call; | ||
mod scenario_rh_impl; | ||
mod scenario_set_state; | ||
mod scenario_tx_env; | ||
|
||
pub use scenario_env::{ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun}; | ||
pub use scenario_env_exec::ScenarioEnvExec; | ||
pub use scenario_env_query::ScenarioEnvQuery; | ||
pub use scenario_exec_call::ScenarioEnvExec; | ||
pub use scenario_query_call::ScenarioEnvQuery; | ||
pub use scenario_tx_env::{ScenarioTxEnv, ScenarioTxEnvData, ScenarioTxRun}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
framework/scenario/src/facade/world_tx/scenario_exec_call.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use multiversx_sc::{ | ||
tuple_util::NestedTupleFlatten, | ||
types::{ | ||
FunctionCall, ManagedAddress, ManagedBuffer, RHListExec, Tx, TxBaseWithEnv, TxEnv, | ||
TxFromSpecified, TxGas, TxPayment, TxToSpecified, | ||
}, | ||
}; | ||
|
||
use crate::{ | ||
api::StaticApi, | ||
scenario::tx_to_step::TxToStep, | ||
scenario_model::{TxExpect, TxResponse}, | ||
ScenarioTxEnv, ScenarioTxRun, ScenarioWorld, | ||
}; | ||
|
||
use super::ScenarioTxEnvData; | ||
|
||
/// Environment for executing transactions. | ||
pub struct ScenarioEnvExec<'w> { | ||
pub world: &'w mut ScenarioWorld, | ||
pub data: ScenarioTxEnvData, | ||
} | ||
|
||
impl<'w> TxEnv for ScenarioEnvExec<'w> { | ||
type Api = StaticApi; | ||
|
||
type RHExpect = TxExpect; | ||
|
||
fn resolve_sender_address(&self) -> ManagedAddress<Self::Api> { | ||
panic!("Explicit sender address expected") | ||
} | ||
|
||
fn default_gas_annotation(&self) -> ManagedBuffer<Self::Api> { | ||
self.data.default_gas_annotation() | ||
} | ||
|
||
fn default_gas_value(&self) -> u64 { | ||
self.data.default_gas_value() | ||
} | ||
} | ||
|
||
impl<'w> ScenarioTxEnv for ScenarioEnvExec<'w> { | ||
fn env_data(&self) -> &ScenarioTxEnvData { | ||
&self.data | ||
} | ||
} | ||
|
||
impl<'w, From, To, Payment, Gas, RH> ScenarioTxRun | ||
for Tx<ScenarioEnvExec<'w>, From, To, Payment, Gas, FunctionCall<StaticApi>, RH> | ||
where | ||
From: TxFromSpecified<ScenarioEnvExec<'w>>, | ||
To: TxToSpecified<ScenarioEnvExec<'w>>, | ||
Payment: TxPayment<ScenarioEnvExec<'w>>, | ||
Gas: TxGas<ScenarioEnvExec<'w>>, | ||
RH: RHListExec<TxResponse, ScenarioEnvExec<'w>>, | ||
RH::ListReturns: NestedTupleFlatten, | ||
{ | ||
type Returns = <RH::ListReturns as NestedTupleFlatten>::Unpacked; | ||
|
||
fn run(self) -> Self::Returns { | ||
let mut step_wrapper = self.tx_to_step(); | ||
step_wrapper.env.world.sc_call(&mut step_wrapper.step); | ||
step_wrapper.process_result() | ||
} | ||
} | ||
|
||
impl ScenarioWorld { | ||
pub fn tx(&mut self) -> TxBaseWithEnv<ScenarioEnvExec<'_>> { | ||
let data = self.new_env_data(); | ||
let env = ScenarioEnvExec { world: self, data }; | ||
Tx::new_with_env(env) | ||
} | ||
|
||
pub fn chain_call<From, To, Payment, Gas, RH, F>(&mut self, f: F) -> &mut Self | ||
where | ||
From: TxFromSpecified<ScenarioTxEnvData>, | ||
To: TxToSpecified<ScenarioTxEnvData>, | ||
Payment: TxPayment<ScenarioTxEnvData>, | ||
Gas: TxGas<ScenarioTxEnvData>, | ||
RH: RHListExec<TxResponse, ScenarioTxEnvData, ListReturns = ()>, | ||
F: FnOnce( | ||
TxBaseWithEnv<ScenarioTxEnvData>, | ||
) | ||
-> Tx<ScenarioTxEnvData, From, To, Payment, Gas, FunctionCall<StaticApi>, RH>, | ||
{ | ||
let env = self.new_env_data(); | ||
let tx_base = TxBaseWithEnv::new_with_env(env); | ||
let tx = f(tx_base); | ||
let mut step_wrapper = tx.tx_to_step(); | ||
self.sc_call(&mut step_wrapper.step); | ||
step_wrapper.process_result(); | ||
self | ||
} | ||
} |
14 changes: 4 additions & 10 deletions
14
...rc/facade/world_tx/scenario_env_deploy.rs → ...c/facade/world_tx/scenario_exec_deploy.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.