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
#![allow(dead_code)]
mod ext_mock;
mod big_int_mock;
mod big_uint_mock;
mod test_util;
pub use ext_mock::*;
pub use big_int_mock::*;
pub use big_uint_mock::*;
pub use test_util::*;
#[macro_use]
extern crate alloc;
pub use alloc::boxed::Box;
pub use alloc::vec::Vec;
pub use std::collections::HashMap;
#[cfg(test)]
mod serialization_tests {
use super::*;
use core::fmt::Debug;
use elrond_wasm::serializer::{to_bytes, from_bytes};
use elrond_wasm::serde as serde;
pub fn ser_deser_ok<V>(element: V, expected_bytes: &[u8])
where
V: serde::Serialize + serde::de::DeserializeOwned + PartialEq + Debug + 'static,
{
let serialized_bytes = to_bytes(&element).unwrap();
assert_eq!(serialized_bytes.as_slice(), expected_bytes);
let deserialized: V = from_bytes(serialized_bytes.as_slice()).unwrap();
assert_eq!(deserialized, element);
}
#[test]
fn test_big_int_serialization() {
ser_deser_ok(RustBigInt::from(5), &[5u8]);
ser_deser_ok(RustBigInt::from(-5), &[251u8]);
}
#[test]
fn test_big_uint_serialization() {
ser_deser_ok(RustBigUint::from(5u32), &[5u8]);
}
}