Test monero amount serialisation

This commit is contained in:
rishflab 2020-10-26 11:14:03 +11:00
parent 28ffe063b7
commit fea6b29da9
2 changed files with 12 additions and 0 deletions

View File

@ -82,6 +82,7 @@ mod tests {
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use xmr_btc::serde::monero_private_key;
use xmr_btc::{CrossCurveScalar, Curve25519Scalar};
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct TestState {

View File

@ -77,6 +77,9 @@ mod tests {
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct MoneroPrivateKey(#[serde(with = "monero_private_key")] crate::monero::PrivateKey);
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct MoneroAmount(#[serde(with = "monero_amount")] crate::monero::Amount);
#[test]
fn serde_monero_private_key() {
let key = MoneroPrivateKey(monero::PrivateKey::from_scalar(Scalar::random(&mut OsRng)));
@ -84,4 +87,12 @@ mod tests {
let decoded: MoneroPrivateKey = serde_cbor::from_slice(&encoded).unwrap();
assert_eq!(key, decoded);
}
#[test]
fn serde_monero_amount() {
let amount = MoneroAmount(crate::monero::Amount::from_piconero(1000));
let encoded = serde_cbor::to_vec(&amount).unwrap();
let decoded: MoneroAmount = serde_cbor::from_slice(&encoded).unwrap();
assert_eq!(amount, decoded);
}
}