multiversx_sc_scenario/scenario/model/step/
step_enum.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use crate::scenario_format::{
    interpret_trait::{InterpretableFrom, InterpreterContext, IntoRaw},
    serde_raw::StepRaw,
};

use crate::scenario::model::{
    Account, AddressKey, BlockInfo, BytesValue, CheckAccounts, NewAddress, TxCall, TxDeploy,
    TxExpect, TxQuery, TxTransfer, TxValidatorReward,
};

use super::{
    CheckStateStep, DumpStateStep, ScCallStep, ScDeployStep, ScQueryStep, SetStateStep,
    TransferStep, ValidatorRewardStep,
};

#[derive(Debug, Clone)]
pub struct ExternalStepsStep {
    pub comment: Option<String>,
    pub path: String,
}

#[derive(Debug, Clone)]
pub enum Step {
    ExternalSteps(ExternalStepsStep),
    SetState(SetStateStep),
    ScCall(ScCallStep),
    ScQuery(ScQueryStep),
    ScDeploy(ScDeployStep),
    Transfer(TransferStep),
    ValidatorReward(ValidatorRewardStep),
    CheckState(CheckStateStep),
    DumpState(DumpStateStep),
}

impl InterpretableFrom<StepRaw> for Step {
    fn interpret_from(from: StepRaw, context: &InterpreterContext) -> Self {
        match from {
            StepRaw::ExternalSteps { comment, path } => {
                Step::ExternalSteps(ExternalStepsStep { comment, path })
            },
            StepRaw::SetState {
                comment,
                accounts,
                new_addresses,
                new_token_identifiers,
                block_hashes,
                previous_block_info,
                current_block_info,
            } => Step::SetState(SetStateStep {
                comment,
                accounts: accounts
                    .into_iter()
                    .map(|(k, v)| {
                        (
                            AddressKey::interpret_from(k, context),
                            Account::interpret_from(v, context),
                        )
                    })
                    .collect(),
                new_addresses: new_addresses
                    .into_iter()
                    .map(|t| NewAddress::interpret_from(t, context))
                    .collect(),
                new_token_identifiers,
                block_hashes: block_hashes
                    .into_iter()
                    .map(|t| BytesValue::interpret_from(t, context))
                    .collect(),
                previous_block_info: Box::new(
                    previous_block_info.map(|v| BlockInfo::interpret_from(v, context)),
                ),
                current_block_info: Box::new(
                    current_block_info.map(|v| BlockInfo::interpret_from(v, context)),
                ),
            }),
            StepRaw::ScCall {
                id,
                tx_id,
                comment,
                display_logs: _,
                tx,
                expect,
            } => Step::ScCall(ScCallStep {
                id,
                tx_id,
                comment,
                tx: Box::new(TxCall::interpret_from(tx, context)),
                expect: expect.map(|v| TxExpect::interpret_from(v, context)),
                ..Default::default()
            }),
            StepRaw::ScQuery {
                id,
                tx_id,
                comment,
                display_logs: _,
                tx,
                expect,
            } => Step::ScQuery(ScQueryStep {
                id,
                tx_id,
                comment,
                tx: Box::new(TxQuery::interpret_from(tx, context)),
                expect: expect.map(|v| TxExpect::interpret_from(v, context)),
                ..Default::default()
            }),
            StepRaw::ScDeploy {
                id,
                tx_id,
                comment,
                display_logs: _,
                tx,
                expect,
            } => Step::ScDeploy(ScDeployStep {
                id,
                tx_id,
                comment,
                tx: Box::new(TxDeploy::interpret_from(tx, context)),
                expect: expect.map(|v| TxExpect::interpret_from(v, context)),
                ..Default::default()
            }),
            StepRaw::Transfer {
                id,
                tx_id,
                comment,
                tx,
            } => Step::Transfer(TransferStep {
                id,
                tx_id,
                comment,
                tx: Box::new(TxTransfer::interpret_from(tx, context)),
            }),
            StepRaw::ValidatorReward {
                id,
                tx_id,
                comment,
                tx,
            } => Step::ValidatorReward(ValidatorRewardStep {
                id,
                tx_id,
                comment,
                tx: Box::new(TxValidatorReward::interpret_from(tx, context)),
            }),
            StepRaw::CheckState { comment, accounts } => Step::CheckState(CheckStateStep {
                comment,
                accounts: CheckAccounts::interpret_from(accounts, context),
            }),
            StepRaw::DumpState { comment } => Step::DumpState(DumpStateStep { comment }),
        }
    }
}

impl IntoRaw<StepRaw> for Step {
    fn into_raw(self) -> StepRaw {
        match self {
            Step::ExternalSteps(s) => StepRaw::ExternalSteps {
                comment: s.comment,
                path: s.path,
            },
            Step::SetState(s) => StepRaw::SetState {
                comment: s.comment,
                accounts: s
                    .accounts
                    .into_iter()
                    .map(|(address, account)| (address.into_raw(), account.into_raw()))
                    .collect(),
                new_addresses: s
                    .new_addresses
                    .into_iter()
                    .map(|na| na.into_raw())
                    .collect(),
                new_token_identifiers: s.new_token_identifiers,
                block_hashes: s.block_hashes.into_iter().map(|bh| bh.original).collect(),
                previous_block_info: s.previous_block_info.map(|bi| bi.into_raw()),
                current_block_info: s.current_block_info.map(|bi| bi.into_raw()),
            },
            Step::ScCall(s) => StepRaw::ScCall {
                id: s.id,
                tx_id: s.tx_id,
                comment: s.comment,
                display_logs: None,
                tx: s.tx.into_raw(),
                expect: s.expect.map(|expect| expect.into_raw()),
            },
            Step::ScQuery(s) => StepRaw::ScQuery {
                id: s.id,
                tx_id: s.tx_id,
                comment: s.comment,
                display_logs: None,
                tx: s.tx.into_raw(),
                expect: s.expect.map(|expect| expect.into_raw()),
            },
            Step::ScDeploy(s) => StepRaw::ScDeploy {
                id: s.id,
                tx_id: s.tx_id,
                comment: s.comment,
                display_logs: None,
                tx: s.tx.into_raw(),
                expect: s.expect.map(|expect| expect.into_raw()),
            },
            Step::Transfer(s) => StepRaw::Transfer {
                id: s.id,
                tx_id: s.tx_id,
                comment: s.comment,
                tx: s.tx.into_raw(),
            },
            Step::ValidatorReward(s) => StepRaw::ValidatorReward {
                id: s.id,
                tx_id: s.tx_id,
                comment: s.comment,
                tx: s.tx.into_raw(),
            },
            Step::CheckState(s) => StepRaw::CheckState {
                comment: s.comment,
                accounts: s.accounts.into_raw(),
            },
            Step::DumpState(s) => StepRaw::DumpState { comment: s.comment },
        }
    }
}