Add serialization tests

Also update monero-epee-bin-serde to actually make them pass :)
This commit is contained in:
Thomas Eizinger 2021-05-27 12:02:43 +10:00
parent 60de1846c9
commit 0c501ba2cc
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
2 changed files with 101 additions and 1 deletions

2
Cargo.lock generated
View File

@ -2341,7 +2341,7 @@ dependencies = [
[[package]]
name = "monero-epee-bin-serde"
version = "1.0.0"
source = "git+https://github.com/comit-network/monero-epee-bin-serde#f2c8baa39f04ac4e7a71c76a16c2c6f9a5ee3e3b"
source = "git+https://github.com/comit-network/monero-epee-bin-serde#174912f04e6c594507da8248025b84ca1838da69"
dependencies = [
"byteorder",
"serde",

View File

@ -308,3 +308,103 @@ mod monero_serde_hex_transaction {
Ok(block)
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::convert::TryInto;
#[test]
fn serialize_get_o_indexes_payload() {
let payload = GetOIndexesPayload {
txid: "0bdd2418548da386d9594d2c7245fcdbb5212d3136a3e2170fe25d1c663af9ae"
.parse()
.unwrap(),
};
let serialized = monero_epee_bin_serde::to_bytes(&payload).unwrap();
assert_eq!(serialized, vec![
1, 17, 1, 1, 1, 1, 2, 1, 1, 4, 4, 116, 120, 105, 100, 10, 128, 11, 221, 36, 24, 84,
141, 163, 134, 217, 89, 77, 44, 114, 69, 252, 219, 181, 33, 45, 49, 54, 163, 226, 23,
15, 226, 93, 28, 102, 58, 249, 174
]);
}
#[test]
fn serialize_get_outs_response() {
let serialized = vec![
1, 17, 1, 1, 1, 1, 2, 1, 1, 20, 7, 99, 114, 101, 100, 105, 116, 115, 5, 0, 0, 0, 0, 0,
0, 0, 0, 4, 111, 117, 116, 115, 140, 8, 20, 6, 104, 101, 105, 103, 104, 116, 5, 160,
137, 0, 0, 0, 0, 0, 0, 3, 107, 101, 121, 10, 128, 196, 230, 228, 99, 110, 92, 135, 48,
214, 48, 163, 38, 67, 223, 131, 119, 178, 119, 204, 39, 248, 228, 128, 191, 235, 9,
141, 208, 244, 146, 77, 183, 4, 109, 97, 115, 107, 10, 128, 125, 48, 19, 21, 95, 237,
13, 240, 131, 129, 119, 85, 86, 182, 134, 102, 143, 33, 246, 173, 92, 233, 51, 45, 226,
192, 29, 195, 100, 251, 247, 62, 4, 116, 120, 105, 100, 10, 128, 60, 124, 111, 251,
212, 227, 37, 68, 131, 236, 210, 49, 243, 39, 129, 186, 167, 99, 109, 134, 146, 252,
16, 126, 143, 104, 113, 31, 209, 240, 138, 10, 8, 117, 110, 108, 111, 99, 107, 101,
100, 11, 1, 20, 6, 104, 101, 105, 103, 104, 116, 5, 234, 154, 0, 0, 0, 0, 0, 0, 3, 107,
101, 121, 10, 128, 137, 17, 157, 123, 99, 63, 39, 21, 109, 248, 127, 124, 106, 167,
225, 212, 162, 87, 103, 140, 12, 181, 82, 53, 237, 227, 208, 140, 19, 195, 32, 214, 4,
109, 97, 115, 107, 10, 128, 155, 99, 238, 164, 35, 235, 70, 138, 156, 90, 209, 116,
130, 59, 5, 222, 246, 103, 68, 201, 138, 108, 159, 27, 164, 175, 159, 113, 216, 170,
94, 185, 4, 116, 120, 105, 100, 10, 128, 74, 167, 203, 241, 95, 83, 105, 214, 153, 8,
60, 211, 169, 90, 84, 254, 129, 90, 198, 167, 177, 191, 19, 228, 43, 101, 147, 38, 231,
196, 222, 63, 8, 117, 110, 108, 111, 99, 107, 101, 100, 11, 1, 6, 115, 116, 97, 116,
117, 115, 10, 8, 79, 75, 8, 116, 111, 112, 95, 104, 97, 115, 104, 10, 0, 9, 117, 110,
116, 114, 117, 115, 116, 101, 100, 11, 0,
];
let out = monero_epee_bin_serde::from_bytes::<GetOutsResponse, _>(serialized).unwrap();
assert_eq!(out, GetOutsResponse {
base: BaseResponse {
credits: 0,
status: Status::Ok,
top_hash: "".to_string(),
untrusted: false
},
outs: vec![
OutKey {
height: 35232,
key: [
196, 230, 228, 99, 110, 92, 135, 48, 214, 48, 163, 38, 67, 223, 131, 119,
178, 119, 204, 39, 248, 228, 128, 191, 235, 9, 141, 208, 244, 146, 77, 183
]
.try_into()
.unwrap(),
mask: [
125, 48, 19, 21, 95, 237, 13, 240, 131, 129, 119, 85, 86, 182, 134, 102,
143, 33, 246, 173, 92, 233, 51, 45, 226, 192, 29, 195, 100, 251, 247, 62
]
.try_into()
.unwrap(),
txid: "3c7c6ffbd4e3254483ecd231f32781baa7636d8692fc107e8f68711fd1f08a0a"
.parse()
.unwrap(),
unlocked: true
},
OutKey {
height: 39658,
key: [
137, 17, 157, 123, 99, 63, 39, 21, 109, 248, 127, 124, 106, 167, 225, 212,
162, 87, 103, 140, 12, 181, 82, 53, 237, 227, 208, 140, 19, 195, 32, 214
]
.try_into()
.unwrap(),
mask: [
155, 99, 238, 164, 35, 235, 70, 138, 156, 90, 209, 116, 130, 59, 5, 222,
246, 103, 68, 201, 138, 108, 159, 27, 164, 175, 159, 113, 216, 170, 94,
185
]
.try_into()
.unwrap(),
txid: "4aa7cbf15f5369d699083cd3a95a54fe815ac6a7b1bf13e42b659326e7c4de3f"
.parse()
.unwrap(),
unlocked: true
},
]
});
}
}