drt_sc_snippets/multi/
interactor_step.rs

1use drt_sc_scenario::{
2    denali_system::ScenarioRunner,
3    scenario_model::{AddressValue, ScCallStep, ScDeployStep, TxResponse},
4};
5use drt_sdk::data::transaction::Transaction;
6
7use crate::Interactor;
8
9/// Describes a scenario step that can be executed in an interactor.
10pub trait InteractorStep {
11    fn to_transaction(&self, interactor: &Interactor) -> Transaction;
12
13    fn sender_address(&self) -> &AddressValue;
14
15    fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner);
16
17    fn set_response(&mut self, tx_response: TxResponse);
18}
19
20impl InteractorStep for ScCallStep {
21    fn to_transaction(&self, interactor: &Interactor) -> Transaction {
22        interactor.tx_call_to_blockchain_tx(&self.tx)
23    }
24
25    fn sender_address(&self) -> &AddressValue {
26        &self.tx.from
27    }
28
29    fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) {
30        let mut clone = self.clone();
31        step_runner.run_sc_call_step(&mut clone); // TODO: make mutability uniform
32    }
33
34    fn set_response(&mut self, response: TxResponse) {
35        self.save_response(response);
36    }
37}
38
39impl InteractorStep for ScDeployStep {
40    fn to_transaction(&self, interactor: &Interactor) -> Transaction {
41        interactor.sc_deploy_to_blockchain_tx(self)
42    }
43
44    fn sender_address(&self) -> &AddressValue {
45        &self.tx.from
46    }
47
48    fn run_step(&mut self, step_runner: &mut dyn ScenarioRunner) {
49        step_runner.run_sc_deploy_step(self);
50    }
51
52    fn set_response(&mut self, response: TxResponse) {
53        self.save_response(response);
54    }
55}