multiversx_sc_scenario/scenario/
run_list.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use crate::scenario_model::*;

use super::ScenarioRunner;

/// Aggregates several scenario runners into one, and calls them in order.
///
/// The empty object can act as a placeholder, in case we want to provide a `ScenarioRunner` that does nothing.
#[derive(Default)]
pub struct ScenarioRunnerList {
    list: Vec<Box<dyn ScenarioRunner>>,
}

impl ScenarioRunnerList {
    pub const fn empty() -> Self {
        ScenarioRunnerList { list: Vec::new() }
    }

    pub fn push<R>(&mut self, runner: R)
    where
        R: ScenarioRunner + 'static,
    {
        self.list.push(Box::new(runner));
    }

    pub fn is_empty(&self) -> bool {
        self.list.is_empty()
    }
}

impl ScenarioRunner for ScenarioRunnerList {
    fn run_external_steps(&mut self, step: &ExternalStepsStep) {
        for runner in self.list.iter_mut() {
            runner.run_external_steps(step);
        }
    }

    fn run_set_state_step(&mut self, step: &SetStateStep) {
        for runner in self.list.iter_mut() {
            runner.run_set_state_step(step);
        }
    }

    fn run_sc_call_step(&mut self, step: &mut ScCallStep) {
        for runner in self.list.iter_mut() {
            runner.run_sc_call_step(step);
        }
    }

    fn run_multi_sc_call_step(&mut self, steps: &mut [ScCallStep]) {
        for runner in self.list.iter_mut() {
            for step in steps.iter_mut() {
                runner.run_sc_call_step(step);
            }
        }
    }

    fn run_multi_sc_deploy_step(&mut self, steps: &mut [ScDeployStep]) {
        for runner in self.list.iter_mut() {
            for step in steps.iter_mut() {
                runner.run_sc_deploy_step(step);
            }
        }
    }

    fn run_sc_query_step(&mut self, step: &mut ScQueryStep) {
        for runner in self.list.iter_mut() {
            runner.run_sc_query_step(step);
        }
    }

    fn run_sc_deploy_step(&mut self, step: &mut ScDeployStep) {
        for runner in self.list.iter_mut() {
            runner.run_sc_deploy_step(step);
        }
    }

    fn run_transfer_step(&mut self, step: &TransferStep) {
        for runner in self.list.iter_mut() {
            runner.run_transfer_step(step);
        }
    }

    fn run_validator_reward_step(&mut self, step: &ValidatorRewardStep) {
        for runner in self.list.iter_mut() {
            runner.run_validator_reward_step(step);
        }
    }

    fn run_check_state_step(&mut self, step: &CheckStateStep) {
        for runner in self.list.iter_mut() {
            runner.run_check_state_step(step);
        }
    }

    fn run_dump_state_step(&mut self) {
        for runner in self.list.iter_mut() {
            runner.run_dump_state_step();
        }
    }
}