multiversx_sc_scenario/scenario/model/
storage_details_check.rs

1use crate::scenario_format::{
2    interpret_trait::{InterpretableFrom, InterpreterContext, IntoRaw},
3    serde_raw::CheckStorageDetailsRaw,
4};
5
6use std::collections::BTreeMap;
7
8use super::{BytesKey, BytesValue, CheckValue};
9
10#[derive(Debug, Default, Clone)]
11pub struct CheckStorageDetails {
12    pub storages: BTreeMap<BytesKey, CheckValue<BytesValue>>,
13    pub other_storages_allowed: bool,
14}
15
16impl InterpretableFrom<CheckStorageDetailsRaw> for CheckStorageDetails {
17    fn interpret_from(from: CheckStorageDetailsRaw, context: &InterpreterContext) -> Self {
18        CheckStorageDetails {
19            storages: from
20                .storages
21                .into_iter()
22                .map(|(k, v)| {
23                    (
24                        BytesKey::interpret_from(k, context),
25                        CheckValue::<BytesValue>::interpret_from(v, context),
26                    )
27                })
28                .collect(),
29            other_storages_allowed: from.other_storages_allowed,
30        }
31    }
32}
33
34impl IntoRaw<CheckStorageDetailsRaw> for CheckStorageDetails {
35    fn into_raw(self) -> CheckStorageDetailsRaw {
36        CheckStorageDetailsRaw {
37            storages: self
38                .storages
39                .into_iter()
40                .map(|(k, v)| (k.into_raw(), v.into_raw_explicit()))
41                .collect(),
42            other_storages_allowed: self.other_storages_allowed,
43        }
44    }
45}