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
use crate::data::Value;
use super::TxTester;
impl TxTester {
/// ## Filtering methods for testing inputs
///
/// Not apply filter to inputs
pub fn all_inputs(&mut self) -> &mut Self {
self.inputs_evaluating = self.tx_body.inputs.clone();
self
}
/// ## Filtering methods for testing inputs
///
/// Filter inputs by address
pub fn inputs_at(&mut self, address: &str) -> &mut Self {
self.inputs_evaluating = self
.tx_body
.inputs
.iter()
.filter(|input| input.to_utxo().output.address == address)
.cloned()
.collect();
self
}
/// ## Filtering methods for testing inputs
///
/// Filter inputs by unit
pub fn inputs_with(&mut self, unit: &str) -> &mut Self {
self.inputs_evaluating = self
.tx_body
.inputs
.iter()
.filter(|input| {
let input_value = Value::from_asset_vec(&input.to_utxo().output.amount.clone());
let quantity = input_value.get(unit);
quantity > 0
})
.cloned()
.collect();
self
}
/// ## Filtering methods for testing inputs
///
/// Filter inputs by policy ID
pub fn inputs_with_policy(&mut self, policy_id: &str) -> &mut Self {
self.inputs_evaluating = self
.tx_body
.inputs
.iter()
.filter(|input| {
let input_value = Value::from_asset_vec(&input.to_utxo().output.amount.clone());
let assets = input_value.get_policy_assets(policy_id);
assets.len() > 0
})
.cloned()
.collect();
self
}
/// ## Filtering methods for testing inputs
///
/// Filter inputs by address and policy ID
pub fn inputs_at_with_policy(&mut self, address: &str, policy_id: &str) -> &mut Self {
self.inputs_evaluating = self
.tx_body
.inputs
.iter()
.filter(|input| {
let utxo = input.to_utxo();
let input_value = Value::from_asset_vec(&utxo.output.amount.clone());
let assets = input_value.get_policy_assets(policy_id);
utxo.output.address == address && assets.len() > 0
})
.cloned()
.collect();
self
}
/// ## Filtering methods for testing inputs
///
/// Filter inputs by address and unit
pub fn inputs_at_with(&mut self, address: &str, unit: &str) -> &mut Self {
self.inputs_evaluating = self
.tx_body
.inputs
.iter()
.filter(|input| {
let utxo = input.to_utxo();
let input_value = Value::from_asset_vec(&utxo.output.amount.clone());
let quantity = input_value.get(unit);
utxo.output.address == address && quantity > 0
})
.cloned()
.collect();
self
}
/// ## Testing methods for inputs
///
/// *Reminder - It must be called after filtering methods for inputs*
///
/// Check if inputs contain the expected value.
pub fn inputs_value(&mut self, expected_value: Value) -> &mut Self {
let mut value = Value::new();
self.inputs_evaluating.iter().for_each(|input| {
let utxo = input.to_utxo();
value.add_assets(&utxo.output.amount);
});
let is_value_correct = value.eq(&expected_value);
if !is_value_correct {
self.add_trace(
"inputs_value",
&format!(
"inputs {:?} have value {:?}, expect {:?}",
self.inputs_evaluating, value, expected_value
),
);
}
self
}
/// ## Testing methods for inputs
///
/// *Reminder - It must be called after filtering methods for inputs*
///
/// Check if inputs contain a specific inline datum.
pub fn inputs_inline_datum_exist(&mut self, datum_cbor: &str) -> &mut Self {
let inputs_with_inline_datum: Vec<_> = self
.inputs_evaluating
.iter()
.filter(|input| {
let utxo = input.to_utxo();
if let Some(datum) = utxo.output.plutus_data {
datum == *datum_cbor
} else {
false
}
})
.cloned()
.collect();
if inputs_with_inline_datum.is_empty() {
self.add_trace(
"inputs_inline_datum_exist",
&format!("No inputs with inline datum matching: {}", datum_cbor),
);
}
self
}
}