multiversx_sc_scenario/whitebox_legacy/
tx_mandos.rs1use crate::multiversx_sc::{
2 codec::{top_encode_to_vec_u8_or_panic, TopEncode},
3 types::heap::Address,
4};
5use multiversx_chain_vm::host::context::TxTokenTransfer;
6use num_traits::Zero;
7
8pub struct ScCallMandos {
9 pub(crate) from: Address,
10 pub(crate) to: Address,
11 pub(crate) egld_value: num_bigint::BigUint,
12 pub(crate) esdt: Vec<TxTokenTransfer>,
13 pub(crate) function: String,
14 pub(crate) arguments: Vec<Vec<u8>>,
15 pub(crate) gas_limit: u64,
16 pub(crate) gas_price: u64,
17}
18
19impl ScCallMandos {
20 pub fn new(from: &Address, to: &Address, function: &str) -> Self {
21 ScCallMandos {
22 from: from.clone(),
23 to: to.clone(),
24 egld_value: num_bigint::BigUint::zero(),
25 esdt: Vec::new(),
26 function: function.to_owned(),
27 arguments: Vec::new(),
28 gas_limit: u64::MAX,
29 gas_price: 0,
30 }
31 }
32
33 pub fn add_egld_value(&mut self, egld_value: &num_bigint::BigUint) {
34 self.egld_value.clone_from(egld_value);
35 }
36
37 pub fn add_esdt_transfer(
38 &mut self,
39 token_id: &[u8],
40 nonce: u64,
41 esdt_value: &num_bigint::BigUint,
42 ) {
43 self.esdt.push(TxTokenTransfer {
44 token_identifier: token_id.to_vec(),
45 nonce,
46 value: esdt_value.clone(),
47 });
48 }
49
50 pub fn add_argument<T: TopEncode>(&mut self, arg: &T) {
51 self.arguments.push(top_encode_to_vec_u8_or_panic(arg));
52 }
53
54 pub fn set_gas_limit(&mut self, gas_limit: u64) {
55 self.gas_limit = gas_limit;
56 }
57
58 pub fn set_gas_price(&mut self, gas_price: u64) {
59 self.gas_price = gas_price;
60 }
61}
62
63pub struct ScQueryMandos {
64 pub(crate) to: Address,
65 pub(crate) function: String,
66 pub(crate) arguments: Vec<Vec<u8>>,
67}
68
69impl ScQueryMandos {
70 pub fn new(to: &Address, function: &str) -> Self {
71 ScQueryMandos {
72 to: to.clone(),
73 function: function.to_owned(),
74 arguments: Vec::new(),
75 }
76 }
77
78 pub fn add_argument<T: TopEncode>(&mut self, arg: &T) {
79 self.arguments.push(top_encode_to_vec_u8_or_panic(arg));
80 }
81}
82
83pub struct TxExpectMandos {
84 pub(crate) out: Vec<Vec<u8>>,
85 pub(crate) status: u64,
86 pub(crate) message: String,
87 }
89
90impl TxExpectMandos {
91 pub fn new(status: u64) -> Self {
92 TxExpectMandos {
93 out: Vec::new(),
94 status,
95 message: String::new(),
96 }
97 }
98
99 pub fn add_out_value<T: TopEncode>(&mut self, out_val: &T) {
100 self.out.push(top_encode_to_vec_u8_or_panic(out_val));
101 }
102
103 pub fn set_message(&mut self, msg: &str) {
104 self.message = msg.to_string();
105 }
106}