|
1 | 1 | use super::*; |
2 | | -use candid::{Int, Nat}; |
| 2 | + |
3 | 3 | use ic_base_types::PrincipalId; |
4 | 4 | use icp_ledger::protobuf::AccountIdentifier; |
5 | | -use maplit::hashmap; |
6 | 5 |
|
7 | 6 | #[test] |
8 | 7 | fn test_node_provider_conversions_always_create_32_byte_account_identifier() { |
@@ -130,144 +129,3 @@ fn test_reward_to_account_invalid_account_identifier_just_return_what_is_stored( |
130 | 129 | icp_ledger::AccountIdentifier::try_from(&converted_reward_to_account.to_account.unwrap()) |
131 | 130 | .expect_err("Should fail!"); |
132 | 131 | } |
133 | | - |
134 | | -#[test] |
135 | | -fn test_value_conversions() { |
136 | | - // Prepare test data for all value types |
137 | | - let nat_value = Nat::from(12345u64); |
138 | | - let int_value = Int::from(-9876i64); |
139 | | - |
140 | | - // Encode Nat and Int to bytes |
141 | | - let mut nat_bytes = Vec::new(); |
142 | | - nat_value.encode(&mut nat_bytes).unwrap(); |
143 | | - |
144 | | - let mut int_bytes = Vec::new(); |
145 | | - int_value.encode(&mut int_bytes).unwrap(); |
146 | | - |
147 | | - // Create a comprehensive map with all possible SelfDescribingValue types |
148 | | - let value_pb = pb::SelfDescribingValue { |
149 | | - value: Some(pb::self_describing_value::Value::Map( |
150 | | - pb::SelfDescribingValueMap { |
151 | | - values: hashmap! { |
152 | | - // Test Text type |
153 | | - "text_field".to_string() => pb::SelfDescribingValue { |
154 | | - value: Some(pb::self_describing_value::Value::Text("some text".to_string())), |
155 | | - }, |
156 | | - // Test Blob type |
157 | | - "blob_field".to_string() => pb::SelfDescribingValue { |
158 | | - value: Some(pb::self_describing_value::Value::Blob(vec![1, 2, 3, 4, 5])), |
159 | | - }, |
160 | | - // Test Nat type |
161 | | - "nat_field".to_string() => pb::SelfDescribingValue { |
162 | | - value: Some(pb::self_describing_value::Value::Nat(nat_bytes.clone())), |
163 | | - }, |
164 | | - // Test Int type |
165 | | - "int_field".to_string() => pb::SelfDescribingValue { |
166 | | - value: Some(pb::self_describing_value::Value::Int(int_bytes.clone())), |
167 | | - }, |
168 | | - // Test Array type with various elements |
169 | | - "array_field".to_string() => pb::SelfDescribingValue { |
170 | | - value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray { |
171 | | - values: vec![ |
172 | | - pb::SelfDescribingValue { |
173 | | - value: Some(pb::self_describing_value::Value::Text("first".to_string())), |
174 | | - }, |
175 | | - pb::SelfDescribingValue { |
176 | | - value: Some(pb::self_describing_value::Value::Text("second".to_string())), |
177 | | - }, |
178 | | - pb::SelfDescribingValue { |
179 | | - value: Some(pb::self_describing_value::Value::Blob(vec![10, 20, 30])), |
180 | | - }, |
181 | | - ], |
182 | | - })), |
183 | | - }, |
184 | | - // Test nested Map type |
185 | | - "nested_map_field".to_string() => pb::SelfDescribingValue { |
186 | | - value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap { |
187 | | - values: hashmap! { |
188 | | - "nested_text".to_string() => pb::SelfDescribingValue { |
189 | | - value: Some(pb::self_describing_value::Value::Text("nested value".to_string())), |
190 | | - }, |
191 | | - "nested_blob".to_string() => pb::SelfDescribingValue { |
192 | | - value: Some(pb::self_describing_value::Value::Blob(vec![255, 254, 253])), |
193 | | - }, |
194 | | - "nested_nat".to_string() => pb::SelfDescribingValue { |
195 | | - value: Some(pb::self_describing_value::Value::Nat(nat_bytes.clone())), |
196 | | - }, |
197 | | - }, |
198 | | - })), |
199 | | - }, |
200 | | - // Test empty Array |
201 | | - "empty_array_field".to_string() => pb::SelfDescribingValue { |
202 | | - value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray { |
203 | | - values: vec![], |
204 | | - })), |
205 | | - }, |
206 | | - // Test empty Map |
207 | | - "empty_map_field".to_string() => pb::SelfDescribingValue { |
208 | | - value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap { |
209 | | - values: hashmap! {}, |
210 | | - })), |
211 | | - }, |
212 | | - // Test Array containing Maps |
213 | | - "array_of_maps_field".to_string() => pb::SelfDescribingValue { |
214 | | - value: Some(pb::self_describing_value::Value::Array(pb::SelfDescribingValueArray { |
215 | | - values: vec![ |
216 | | - pb::SelfDescribingValue { |
217 | | - value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap { |
218 | | - values: hashmap! { |
219 | | - "key1".to_string() => pb::SelfDescribingValue { |
220 | | - value: Some(pb::self_describing_value::Value::Text("value1".to_string())), |
221 | | - }, |
222 | | - }, |
223 | | - })), |
224 | | - }, |
225 | | - pb::SelfDescribingValue { |
226 | | - value: Some(pb::self_describing_value::Value::Map(pb::SelfDescribingValueMap { |
227 | | - values: hashmap! { |
228 | | - "key2".to_string() => pb::SelfDescribingValue { |
229 | | - value: Some(pb::self_describing_value::Value::Text("value2".to_string())), |
230 | | - }, |
231 | | - }, |
232 | | - })), |
233 | | - }, |
234 | | - ], |
235 | | - })), |
236 | | - }, |
237 | | - }, |
238 | | - }, |
239 | | - )), |
240 | | - }; |
241 | | - |
242 | | - let value_pb_api = pb_api::SelfDescribingValue::from(value_pb); |
243 | | - |
244 | | - assert_eq!( |
245 | | - value_pb_api, |
246 | | - pb_api::SelfDescribingValue::Map(hashmap! { |
247 | | - "text_field".to_string() => pb_api::SelfDescribingValue::Text("some text".to_string()), |
248 | | - "blob_field".to_string() => pb_api::SelfDescribingValue::Blob(vec![1, 2, 3, 4, 5]), |
249 | | - "nat_field".to_string() => pb_api::SelfDescribingValue::Nat(nat_value.clone()), |
250 | | - "int_field".to_string() => pb_api::SelfDescribingValue::Int(int_value.clone()), |
251 | | - "array_field".to_string() => pb_api::SelfDescribingValue::Array(vec![ |
252 | | - pb_api::SelfDescribingValue::Text("first".to_string()), |
253 | | - pb_api::SelfDescribingValue::Text("second".to_string()), |
254 | | - pb_api::SelfDescribingValue::Blob(vec![10, 20, 30]), |
255 | | - ]), |
256 | | - "nested_map_field".to_string() => pb_api::SelfDescribingValue::Map(hashmap! { |
257 | | - "nested_text".to_string() => pb_api::SelfDescribingValue::Text("nested value".to_string()), |
258 | | - "nested_blob".to_string() => pb_api::SelfDescribingValue::Blob(vec![255, 254, 253]), |
259 | | - "nested_nat".to_string() => pb_api::SelfDescribingValue::Nat(nat_value.clone()), |
260 | | - }), |
261 | | - "empty_array_field".to_string() => pb_api::SelfDescribingValue::Array(vec![]), |
262 | | - "empty_map_field".to_string() => pb_api::SelfDescribingValue::Map(hashmap! {}), |
263 | | - "array_of_maps_field".to_string() => pb_api::SelfDescribingValue::Array(vec![ |
264 | | - pb_api::SelfDescribingValue::Map(hashmap! { |
265 | | - "key1".to_string() => pb_api::SelfDescribingValue::Text("value1".to_string()), |
266 | | - }), |
267 | | - pb_api::SelfDescribingValue::Map(hashmap! { |
268 | | - "key2".to_string() => pb_api::SelfDescribingValue::Text("value2".to_string()), |
269 | | - }), |
270 | | - ]), |
271 | | - }) |
272 | | - ); |
273 | | -} |
0 commit comments