use serde::{Deserialize, Serialize};
use crate::asset::CryptoAsset;
use crate::chain::Chain;
use crate::number::Ex3Uint;
use crate::{AssetId, WalletRegisterId};
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize, Hash)]
pub struct AssetRegistration {
pub parent_id: Option<AssetId>,
pub asset: CryptoAsset,
}
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct UpdateChainConfirmationTimes {
pub chain: Chain,
pub confirmation_times: Ex3Uint,
}
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct UpdateGlobalWithdrawalFeeTo {
pub fee_to: WalletRegisterId,
}
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
pub struct UpdateAssetWithdrawalFeeTo {
pub asset_id: AssetId,
pub fee_to: Option<WalletRegisterId>,
}
#[cfg(test)]
mod tests {
use ex3_serde::{bincode, cbor};
use crate::asset::TokenType;
use crate::chain::ChainType;
use super::*;
#[test]
fn test_register_asset_bincode_serde() {
let register_asset = AssetRegistration {
parent_id: None,
asset: CryptoAsset {
chain: Chain {
r#type: ChainType::Ethereum,
network: 1u8.into(),
},
r#type: TokenType::ERC20,
address: "0x01283012830123".to_string(),
},
};
let encoded = bincode::serialize(®ister_asset).unwrap();
let decoded: AssetRegistration = bincode::deserialize(&encoded).unwrap();
assert_eq!(register_asset, decoded);
let encoded = cbor::serialize(®ister_asset).unwrap();
let decoded: AssetRegistration = cbor::deserialize(&encoded).unwrap();
assert_eq!(register_asset, decoded);
}
#[test]
fn test_update_token_type_confirmation_times_bincode_serde() {
let update_token_type_confirmation_times = UpdateChainConfirmationTimes {
chain: Chain {
r#type: ChainType::Ethereum,
network: 1u8.into(),
},
confirmation_times: Ex3Uint::from(100u32),
};
let encoded = bincode::serialize(&update_token_type_confirmation_times).unwrap();
let decoded: UpdateChainConfirmationTimes = bincode::deserialize(&encoded).unwrap();
assert_eq!(update_token_type_confirmation_times, decoded);
}
#[test]
fn test_update_token_type_confirmation_times_serde() {
let update_token_type_confirmation_times = UpdateChainConfirmationTimes {
chain: Chain {
r#type: ChainType::Ethereum,
network: 1u8.into(),
},
confirmation_times: Ex3Uint::from(100u32),
};
let encoded = cbor::serialize(&update_token_type_confirmation_times).unwrap();
let decoded: UpdateChainConfirmationTimes = cbor::deserialize(&encoded).unwrap();
assert_eq!(update_token_type_confirmation_times, decoded);
let encoded = cbor::serialize(&update_token_type_confirmation_times).unwrap();
let decoded: UpdateChainConfirmationTimes = cbor::deserialize(&encoded).unwrap();
assert_eq!(update_token_type_confirmation_times, decoded);
}
#[test]
fn test_update_global_fee_to_serde() {
let update_global_fee_to = UpdateGlobalWithdrawalFeeTo {
fee_to: WalletRegisterId::from(100u32),
};
let encoded = bincode::serialize(&update_global_fee_to).unwrap();
let decoded: UpdateGlobalWithdrawalFeeTo = bincode::deserialize(&encoded).unwrap();
assert_eq!(update_global_fee_to, decoded);
let encoded = cbor::serialize(&update_global_fee_to).unwrap();
let decoded: UpdateGlobalWithdrawalFeeTo = cbor::deserialize(&encoded).unwrap();
assert_eq!(update_global_fee_to, decoded);
}
#[test]
fn test_update_asset_fee_to_serde() {
let update_asset_fee_to = UpdateAssetWithdrawalFeeTo {
asset_id: AssetId::from(100u32),
fee_to: Some(WalletRegisterId::from(100u32)),
};
let encoded = bincode::serialize(&update_asset_fee_to).unwrap();
let decoded: UpdateAssetWithdrawalFeeTo = bincode::deserialize(&encoded).unwrap();
assert_eq!(update_asset_fee_to, decoded);
let encoded = cbor::serialize(&update_asset_fee_to).unwrap();
let decoded: UpdateAssetWithdrawalFeeTo = cbor::deserialize(&encoded).unwrap();
assert_eq!(update_asset_fee_to, decoded);
}
}