use serde::{
Deserialize,
};
use crate::{
date_time::UtcDateTime,
api::{
DeviceInfo, MessageProcessError, MessageAction, MessageProcessSuccess,
ForeignBlockchain, ForeignTokenInfo, AssetMigrationDirection, CatenisServiceInfo,
NFAssetIssuanceProcessError, NFTokenDataManipulationProgress, NFTokenRetrievalProcessError,
}
};
mod ws;
pub use ws::*;
use crate::api::NFAssetIssuanceResult;
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MessageProcessProgressDone {
pub bytes_processed: usize,
pub done: bool,
pub success: bool,
pub error: Option<MessageProcessError>,
pub finish_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ExecutedForeignTransactionInfo {
pub txid: String,
pub is_pending: bool,
pub success: bool,
pub error: Option<String>,
}
#[derive(Debug, Deserialize, Copy, Clone, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TerminalAssetExportStatus {
Success,
Error,
}
#[derive(Debug, Deserialize, Copy, Clone, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TerminalAssetMigrationStatus {
Interrupted,
Success,
Error,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NFAssetIssuanceProcessProgressDone {
pub percent_processed: u8,
pub done: bool,
pub success: bool,
pub error: Option<NFAssetIssuanceProcessError>,
pub finish_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NFTokenRetrievalProcessProgressDone {
pub bytes_retrieved: usize,
pub done: bool,
pub success: bool,
pub error: Option<NFTokenRetrievalProcessError>,
pub finish_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NFTokenTransferProcessProgressDone {
pub data_manipulation: NFTokenDataManipulationProgress,
pub done: bool,
pub success: bool,
pub error: Option<NFTokenRetrievalProcessError>,
pub finish_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NewMessageReceivedNotify {
pub message_id: String,
pub from: DeviceInfo,
pub received_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct SentMessageReadNotify {
pub message_id: String,
pub to: DeviceInfo,
pub read_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AssetReceivedNotify {
pub asset_id: String,
pub amount: f64,
pub issuer: DeviceInfo,
pub from: DeviceInfo,
pub received_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct AssetConfirmedNotify {
pub asset_id: String,
pub amount: f64,
pub issuer: DeviceInfo,
pub from: DeviceInfo,
pub confirmed_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalMessageProgressNotify {
pub ephemeral_message_id: String,
pub action: MessageAction,
pub progress: MessageProcessProgressDone,
pub result: Option<MessageProcessSuccess>,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalAssetExportOutcomeNotify {
pub asset_id: String,
pub foreign_blockchain: ForeignBlockchain,
pub foreign_transaction: ExecutedForeignTransactionInfo,
pub token: ForeignTokenInfo,
pub status: TerminalAssetExportStatus,
pub date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalAssetMigrationOutcomeNotify {
pub migration_id: String,
pub asset_id: String,
pub foreign_blockchain: ForeignBlockchain,
pub direction: AssetMigrationDirection,
pub amount: f64,
pub catenis_service: CatenisServiceInfo,
pub foreign_transaction: ExecutedForeignTransactionInfo,
pub status: TerminalAssetMigrationStatus,
pub date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalNFAssetIssuanceOutcomeNotify {
pub asset_issuance_id: String,
pub asset_id: Option<String>,
pub progress: NFAssetIssuanceProcessProgressDone,
pub result: Option<NFAssetIssuanceResult>,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NonFungibleTokenReceivedNotify {
pub nf_token_ids: Vec<String>,
pub issuer: DeviceInfo,
pub from: DeviceInfo,
pub received_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct NonFungibleTokenConfirmedNotify {
pub nf_token_ids: Vec<String>,
pub issuer: DeviceInfo,
pub from: DeviceInfo,
pub confirmed_date: UtcDateTime,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalNFTokenRetrievalOutcomeNotify {
pub nf_token_id: String,
pub token_retrieval_id: String,
pub progress: NFTokenRetrievalProcessProgressDone,
pub continuation_token: Option<String>,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct FinalNFTokenTransferOutcomeNotify {
pub nf_token_id: String,
pub token_transfer_id: String,
pub progress: NFTokenTransferProcessProgressDone,
}
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(untagged)]
pub enum NotificationMessage {
NewMessageReceived(NewMessageReceivedNotify),
SentMessageRead(SentMessageReadNotify),
AssetReceived(AssetReceivedNotify),
AssetConfirmed(AssetConfirmedNotify),
FinalMessageProgress(FinalMessageProgressNotify),
FinalAssetExportOutcome(FinalAssetExportOutcomeNotify),
FinalAssetMigrationOutcome(FinalAssetMigrationOutcomeNotify),
FinalNFAssetIssuanceOutcome(FinalNFAssetIssuanceOutcomeNotify),
NonFungibleTokenReceived(NonFungibleTokenReceivedNotify),
NonFungibleTokenConfirmed(NonFungibleTokenConfirmedNotify),
FinalNFTokenRetrievalOutcome(FinalNFTokenRetrievalOutcomeNotify),
FinalNFTokenTransferOutcome(FinalNFTokenTransferOutcomeNotify),
}
#[cfg(test)]
mod tests {
use super::*;
use crate::api::CatenisServiceStatus;
#[test]
fn it_deserialize_message_process_progress_done_no_opts() {
let json = r#"{"bytesProcessed":0,"done":true,"success":true,"finishDate":"2020-12-09T12:05:23.012Z"}"#;
let message_process_progress_done: MessageProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(message_process_progress_done, MessageProcessProgressDone {
bytes_processed: 0,
done: true,
success: true,
error: None,
finish_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_message_process_progress_done_all_opts() {
let json = r#"{"bytesProcessed":1024,"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2020-12-09T12:05:23.012Z"}"#;
let message_process_progress: MessageProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(message_process_progress, MessageProcessProgressDone {
bytes_processed: 1024,
done: true,
success: false,
error: Some(MessageProcessError {
code: 500,
message: String::from("Internal server error")
}),
finish_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_executed_foreign_transaction_info_no_opts() {
let json = r#"{"txid":"0x1f14474f441557056055a186ccf6839bd4dfce79e0b134d77084b6ef4274dc1a","isPending":false,"success":true}"#;
let executed_foreign_transaction_info: ExecutedForeignTransactionInfo = serde_json::from_str(json).unwrap();
assert_eq!(executed_foreign_transaction_info, ExecutedForeignTransactionInfo {
txid: String::from("0x1f14474f441557056055a186ccf6839bd4dfce79e0b134d77084b6ef4274dc1a"),
is_pending: false,
success: true,
error: None
});
}
#[test]
fn it_deserialize_executed_foreign_transaction_info_all_opts() {
let json = r#"{"txid":"0x1f14474f441557056055a186ccf6839bd4dfce79e0b134d77084b6ef4274dc1a","isPending":false,"success":false,"error":"Simulated error"}"#;
let executed_foreign_transaction_info: ExecutedForeignTransactionInfo = serde_json::from_str(json).unwrap();
assert_eq!(executed_foreign_transaction_info, ExecutedForeignTransactionInfo {
txid: String::from("0x1f14474f441557056055a186ccf6839bd4dfce79e0b134d77084b6ef4274dc1a"),
is_pending: false,
success: false,
error: Some(String::from("Simulated error")),
});
}
#[test]
fn it_deserialize_terminal_asset_export_status() {
let json = r#""success""#;
let terminal_asset_export_status: TerminalAssetExportStatus = serde_json::from_str(json).unwrap();
assert_eq!(terminal_asset_export_status, TerminalAssetExportStatus::Success);
}
#[test]
fn it_deserialize_terminal_asset_migration_status() {
let json = r#""interrupted""#;
let terminal_asset_migration_status: TerminalAssetMigrationStatus = serde_json::from_str(json).unwrap();
assert_eq!(terminal_asset_migration_status, TerminalAssetMigrationStatus::Interrupted);
}
#[test]
fn it_deserialize_new_message_received_notify() {
let json = r#"{"messageId":"mt7ZYbBYpM3zcgAf3H8X","from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"receivedDate":"2020-12-09T12:05:23.012Z"}"#;
let new_message_received_notify: NewMessageReceivedNotify = serde_json::from_str(json).unwrap();
assert_eq!(new_message_received_notify, NewMessageReceivedNotify {
message_id: String::from("mt7ZYbBYpM3zcgAf3H8X"),
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
received_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_sent_message_read_notify() {
let json = r#"{"messageId":"mt7ZYbBYpM3zcgAf3H8X","to":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"readDate":"2020-12-09T12:05:23.012Z"}"#;
let sent_message_read_notify: SentMessageReadNotify = serde_json::from_str(json).unwrap();
assert_eq!(sent_message_read_notify, SentMessageReadNotify {
message_id: String::from("mt7ZYbBYpM3zcgAf3H8X"),
to: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
read_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_asset_received_notify() {
let json = r#"{"assetId":"aQjlzShmrnEZeeYBZihc","amount":54,"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"receivedDate":"2020-12-09T12:05:23.012Z"}"#;
let asset_received_notify: AssetReceivedNotify = serde_json::from_str(json).unwrap();
assert_eq!(asset_received_notify, AssetReceivedNotify {
asset_id: String::from("aQjlzShmrnEZeeYBZihc"),
amount: 54.0,
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
received_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_asset_confirmed_notify() {
let json = r#"{"assetId":"aQjlzShmrnEZeeYBZihc","amount":54,"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"confirmedDate":"2020-12-09T12:05:23.012Z"}"#;
let asset_confirmed_notify: AssetConfirmedNotify = serde_json::from_str(json).unwrap();
assert_eq!(asset_confirmed_notify, AssetConfirmedNotify {
asset_id: String::from("aQjlzShmrnEZeeYBZihc"),
amount: 54.0,
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
confirmed_date: "2020-12-09T12:05:23.012Z".into(),
});
}
#[test]
fn it_deserialize_final_message_progress_notify_no_opts() {
let json = r#"{"ephemeralMessageId":"pJiMtfdB94YkvRvXp7dA","action":"log","progress":{"bytesProcessed":0,"done":true,"success":true,"finishDate":"2020-12-09T12:05:23.012Z"}}"#;
let final_message_progress_notify: FinalMessageProgressNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_message_progress_notify, FinalMessageProgressNotify {
ephemeral_message_id: String::from("pJiMtfdB94YkvRvXp7dA"),
action: MessageAction::Log,
progress: MessageProcessProgressDone {
bytes_processed: 0,
done: true,
success: true,
error: None,
finish_date: "2020-12-09T12:05:23.012Z".into(),
},
result: None,
});
}
#[test]
fn it_deserialize_final_message_progress_notify_all_opts() {
let json = r#"{"ephemeralMessageId":"pJiMtfdB94YkvRvXp7dA","action":"log","progress":{"bytesProcessed":0,"done":true,"success":true,"finishDate":"2020-12-09T12:05:23.012Z"},"result":{"messageId":"mt7ZYbBYpM3zcgAf3H8X"}}"#;
let final_message_progress_notify: FinalMessageProgressNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_message_progress_notify, FinalMessageProgressNotify {
ephemeral_message_id: String::from("pJiMtfdB94YkvRvXp7dA"),
action: MessageAction::Log,
progress: MessageProcessProgressDone {
bytes_processed: 0,
done: true,
success: true,
error: None,
finish_date: "2020-12-09T12:05:23.012Z".into(),
},
result: Some(MessageProcessSuccess {
message_id: String::from("mt7ZYbBYpM3zcgAf3H8X"),
continuation_token: None,
}),
});
}
#[test]
fn it_deserialize_final_asset_export_outcome_notify() {
let json = r#"{"assetId":"amNiawM69NjYM8QghoPD","foreignBlockchain":"ethereum","foreignTransaction":{"isPending":false,"success":true,"txid":"0x1738722379007192cac3b8e7ee3babfd1c8304133ea1a7957b93f6134ed62e48"},"token":{"name":"Catenis test token #5","symbol":"CTK5","id":"0xbAE69964D40900c6933A2CF8dD53f97c97Ab9BE7"},"status":"success","date":"2021-07-02T21:26:33.841Z"}"#;
let final_asset_export_outcome_notify: FinalAssetExportOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_asset_export_outcome_notify, FinalAssetExportOutcomeNotify {
asset_id: String::from("amNiawM69NjYM8QghoPD"),
foreign_blockchain: ForeignBlockchain::Ethereum,
foreign_transaction: ExecutedForeignTransactionInfo {
txid: String::from("0x1738722379007192cac3b8e7ee3babfd1c8304133ea1a7957b93f6134ed62e48"),
is_pending: false,
success: true,
error: None,
},
token: ForeignTokenInfo {
name: String::from("Catenis test token #5"),
symbol: String::from("CTK5"),
id: Some(String::from("0xbAE69964D40900c6933A2CF8dD53f97c97Ab9BE7")),
},
status: TerminalAssetExportStatus::Success,
date: "2021-07-02T21:26:33.841Z".into(),
});
}
#[test]
fn it_deserialize_final_asset_migration_outcome_notify() {
let json = r#"{"migrationId":"gbRQqs5z3ReCGfygorai","assetId":"amNiawM69NjYM8QghoPD","foreignBlockchain":"ethereum","direction":"outward","amount":50,"catenisService":{"status":"fulfilled","txid":"823941a1e02eab77d5ceecc943d7745bc49068f35d4109f7d60f9ca6fc669838"},"foreignTransaction":{"isPending":false,"success":true,"txid":"0x098d5588d03db577edfc8fc5b0094a62e22825bc9c7fc8e38430563350c75bfd"},"status":"success","date":"2021-07-03T12:51:04.771Z"}"#;
let final_asset_migration_outcome_notify: FinalAssetMigrationOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_asset_migration_outcome_notify, FinalAssetMigrationOutcomeNotify {
migration_id: String::from("gbRQqs5z3ReCGfygorai"),
asset_id: String::from("amNiawM69NjYM8QghoPD"),
foreign_blockchain: ForeignBlockchain::Ethereum,
direction: AssetMigrationDirection::Outward,
amount: 50.0,
catenis_service: CatenisServiceInfo {
status: CatenisServiceStatus::Fulfilled,
txid: Some(String::from("823941a1e02eab77d5ceecc943d7745bc49068f35d4109f7d60f9ca6fc669838")),
error: None,
},
foreign_transaction: ExecutedForeignTransactionInfo {
txid: String::from("0x098d5588d03db577edfc8fc5b0094a62e22825bc9c7fc8e38430563350c75bfd"),
is_pending: false,
success: true,
error: None,
},
status: TerminalAssetMigrationStatus::Success,
date: "2021-07-03T12:51:04.771Z".into(),
});
}
#[test]
fn it_deserialize_new_message_received_notification_message() {
let json = r#"{"messageId":"mt7ZYbBYpM3zcgAf3H8X","from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"receivedDate":"2020-12-09T12:05:23.012Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::NewMessageReceived(
NewMessageReceivedNotify {
message_id: String::from("mt7ZYbBYpM3zcgAf3H8X"),
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
received_date: "2020-12-09T12:05:23.012Z".into(),
}
)
);
}
#[test]
fn it_deserialize_sent_message_read_notification_message() {
let json = r#"{"messageId":"mt7ZYbBYpM3zcgAf3H8X","to":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"readDate":"2020-12-09T12:05:23.012Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::SentMessageRead(
SentMessageReadNotify {
message_id: String::from("mt7ZYbBYpM3zcgAf3H8X"),
to: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
read_date: "2020-12-09T12:05:23.012Z".into(),
}
)
);
}
#[test]
fn it_deserialize_asset_received_notification_message() {
let json = r#"{"assetId":"aQjlzShmrnEZeeYBZihc","amount":54,"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"receivedDate":"2020-12-09T12:05:23.012Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::AssetReceived(
AssetReceivedNotify {
asset_id: String::from("aQjlzShmrnEZeeYBZihc"),
amount: 54.0,
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
received_date: "2020-12-09T12:05:23.012Z".into(),
}
)
);
}
#[test]
fn it_deserialize_asset_confirmed_notification_message() {
let json = r#"{"assetId":"aQjlzShmrnEZeeYBZihc","amount":54,"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"confirmedDate":"2020-12-09T12:05:23.012Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::AssetConfirmed(
AssetConfirmedNotify {
asset_id: String::from("aQjlzShmrnEZeeYBZihc"),
amount: 54.0,
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
confirmed_date: "2020-12-09T12:05:23.012Z".into(),
}
)
);
}
#[test]
fn it_deserialize_final_message_progress_notification_message() {
let json = r#"{"ephemeralMessageId":"pJiMtfdB94YkvRvXp7dA","action":"log","progress":{"bytesProcessed":0,"done":true,"success":true,"finishDate":"2020-12-09T12:05:23.012Z"}}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalMessageProgress(
FinalMessageProgressNotify {
ephemeral_message_id: String::from("pJiMtfdB94YkvRvXp7dA"),
action: MessageAction::Log,
progress: MessageProcessProgressDone {
bytes_processed: 0,
done: true,
success: true,
error: None,
finish_date: "2020-12-09T12:05:23.012Z".into(),
},
result: None,
}
)
);
}
#[test]
fn it_deserialize_final_asset_export_outcome_notification_message() {
let json = r#"{"assetId":"amNiawM69NjYM8QghoPD","foreignBlockchain":"ethereum","foreignTransaction":{"isPending":false,"success":true,"txid":"0x1738722379007192cac3b8e7ee3babfd1c8304133ea1a7957b93f6134ed62e48"},"token":{"name":"Catenis test token #5","symbol":"CTK5","id":"0xbAE69964D40900c6933A2CF8dD53f97c97Ab9BE7"},"status":"success","date":"2021-07-02T21:26:33.841Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalAssetExportOutcome(
FinalAssetExportOutcomeNotify {
asset_id: String::from("amNiawM69NjYM8QghoPD"),
foreign_blockchain: ForeignBlockchain::Ethereum,
foreign_transaction: ExecutedForeignTransactionInfo {
txid: String::from("0x1738722379007192cac3b8e7ee3babfd1c8304133ea1a7957b93f6134ed62e48"),
is_pending: false,
success: true,
error: None,
},
token: ForeignTokenInfo {
name: String::from("Catenis test token #5"),
symbol: String::from("CTK5"),
id: Some(String::from("0xbAE69964D40900c6933A2CF8dD53f97c97Ab9BE7")),
},
status: TerminalAssetExportStatus::Success,
date: "2021-07-02T21:26:33.841Z".into(),
}
)
);
}
#[test]
fn it_deserialize_final_asset_migration_outcome_notification_message() {
let json = r#"{"migrationId":"gbRQqs5z3ReCGfygorai","assetId":"amNiawM69NjYM8QghoPD","foreignBlockchain":"ethereum","direction":"outward","amount":50,"catenisService":{"status":"fulfilled","txid":"823941a1e02eab77d5ceecc943d7745bc49068f35d4109f7d60f9ca6fc669838"},"foreignTransaction":{"isPending":false,"success":true,"txid":"0x098d5588d03db577edfc8fc5b0094a62e22825bc9c7fc8e38430563350c75bfd"},"status":"success","date":"2021-07-03T12:51:04.771Z"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalAssetMigrationOutcome(
FinalAssetMigrationOutcomeNotify {
migration_id: String::from("gbRQqs5z3ReCGfygorai"),
asset_id: String::from("amNiawM69NjYM8QghoPD"),
foreign_blockchain: ForeignBlockchain::Ethereum,
direction: AssetMigrationDirection::Outward,
amount: 50.0,
catenis_service: CatenisServiceInfo {
status: CatenisServiceStatus::Fulfilled,
txid: Some(String::from("823941a1e02eab77d5ceecc943d7745bc49068f35d4109f7d60f9ca6fc669838")),
error: None,
},
foreign_transaction: ExecutedForeignTransactionInfo {
txid: String::from("0x098d5588d03db577edfc8fc5b0094a62e22825bc9c7fc8e38430563350c75bfd"),
is_pending: false,
success: true,
error: None,
},
status: TerminalAssetMigrationStatus::Success,
date: "2021-07-03T12:51:04.771Z".into(),
}
)
);
}
mod nf_assets_tests {
use crate::api::NFAssetIssuanceResult;
use super::*;
#[test]
fn it_deserialize_nf_asset_issuance_process_progress_done_error() {
let json = r#"{"percentProcessed":25,"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2022-11-01T16:55:21.000"}"#;
let nf_asset_issuance_process_progress_done: NFAssetIssuanceProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_asset_issuance_process_progress_done, NFAssetIssuanceProcessProgressDone {
percent_processed: 25,
done: true,
success: false,
error: Some(NFAssetIssuanceProcessError {
code: 500,
message: String::from("Internal server error"),
}),
finish_date: "2022-11-01T16:55:21.000".into(),
});
}
#[test]
fn it_deserialize_nf_asset_issuance_process_progress_done_success() {
let json = r#"{"percentProcessed":100,"done":true,"success":true,"finishDate":"2022-11-01T16:57:46.123"}"#;
let nf_asset_issuance_process_progress_done: NFAssetIssuanceProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_asset_issuance_process_progress_done, NFAssetIssuanceProcessProgressDone {
percent_processed: 100,
done: true,
success: true,
error: None,
finish_date: "2022-11-01T16:57:46.123".into(),
});
}
#[test]
fn it_deserialize_final_nf_asset_issuance_outcome_notify_no_opts() {
let json = r#"{"assetIssuanceId":"iWWKqTx6svmErabyCZKM","progress":{"percentProcessed":25,"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2022-11-01T16:55:21.000"}}"#;
let final_nf_asset_issuance_outcome_notify: FinalNFAssetIssuanceOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_nf_asset_issuance_outcome_notify, FinalNFAssetIssuanceOutcomeNotify {
asset_issuance_id: String::from("iWWKqTx6svmErabyCZKM"),
asset_id: None,
progress: NFAssetIssuanceProcessProgressDone {
percent_processed: 25,
done: true,
success: false,
error: Some(NFAssetIssuanceProcessError {
code: 500,
message: String::from("Internal server error"),
}),
finish_date: "2022-11-01T16:55:21.000".into(),
},
result: None,
});
}
#[test]
fn it_deserialize_final_nf_asset_issuance_outcome_notify_all_opts() {
let json = r#"{"assetIssuanceId":"iWWKqTx6svmErabyCZKM","assetId":"ahfTzqgWAXnMR6Z57mcp","progress":{"percentProcessed":100,"done":true,"success":true,"finishDate":"2022-11-01T16:57:46.123"},"result":{"nfTokenIds":["tDGQpGy627J6uAw4grYq"]}}"#;
let final_nf_asset_issuance_outcome_notify: FinalNFAssetIssuanceOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_nf_asset_issuance_outcome_notify, FinalNFAssetIssuanceOutcomeNotify {
asset_issuance_id: String::from("iWWKqTx6svmErabyCZKM"),
asset_id: Some(String::from("ahfTzqgWAXnMR6Z57mcp")),
progress: NFAssetIssuanceProcessProgressDone {
percent_processed: 100,
done: true,
success: true,
error: None,
finish_date: "2022-11-01T16:57:46.123".into(),
},
result: Some(NFAssetIssuanceResult {
asset_id: None,
nf_token_ids: vec![
String::from("tDGQpGy627J6uAw4grYq"),
],
}),
});
}
#[test]
fn it_deserialize_final_nf_asset_issuance_outcome_notification_message() {
let json = r#"{"assetIssuanceId":"iWWKqTx6svmErabyCZKM","assetId":"ahfTzqgWAXnMR6Z57mcp","progress":{"percentProcessed":100,"done":true,"success":true,"finishDate":"2022-11-01T16:57:46.123"},"result":{"nfTokenIds":["tDGQpGy627J6uAw4grYq"]}}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalNFAssetIssuanceOutcome(
FinalNFAssetIssuanceOutcomeNotify {
asset_issuance_id: String::from("iWWKqTx6svmErabyCZKM"),
asset_id: Some(String::from("ahfTzqgWAXnMR6Z57mcp")),
progress: NFAssetIssuanceProcessProgressDone {
percent_processed: 100,
done: true,
success: true,
error: None,
finish_date: "2022-11-01T16:57:46.123".into(),
},
result: Some(NFAssetIssuanceResult {
asset_id: None,
nf_token_ids: vec![
String::from("tDGQpGy627J6uAw4grYq"),
],
}),
}
)
);
}
#[test]
fn it_deserialize_non_fungible_token_received_notify() {
let json = r#"{"nfTokenIds":["tQyJrga3ke65RR23iyr2","tf2rbknDoo9wPsKBkskj"],"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"d8YpQ7jgPBJEkBrnvp58"},"receivedDate":"2022-11-09T12:11:34.443"}"#;
let non_fungible_token_received_notify: NonFungibleTokenReceivedNotify = serde_json::from_str(json).unwrap();
assert_eq!(non_fungible_token_received_notify, NonFungibleTokenReceivedNotify {
nf_token_ids: vec![
String::from("tQyJrga3ke65RR23iyr2"),
String::from("tf2rbknDoo9wPsKBkskj"),
],
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("d8YpQ7jgPBJEkBrnvp58"),
name: None,
prod_unique_id: None,
},
received_date: "2022-11-09T12:11:34.443".into()
});
}
#[test]
fn it_deserialize_non_fungible_token_received_notification_message() {
let json = r#"{"nfTokenIds":["tQyJrga3ke65RR23iyr2","tf2rbknDoo9wPsKBkskj"],"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"d8YpQ7jgPBJEkBrnvp58"},"receivedDate":"2022-11-09T12:11:34.443"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::NonFungibleTokenReceived(
NonFungibleTokenReceivedNotify {
nf_token_ids: vec![
String::from("tQyJrga3ke65RR23iyr2"),
String::from("tf2rbknDoo9wPsKBkskj"),
],
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("d8YpQ7jgPBJEkBrnvp58"),
name: None,
prod_unique_id: None,
},
received_date: "2022-11-09T12:11:34.443".into()
}
)
);
}
#[test]
fn it_deserialize_non_fungible_token_confirmed_notify() {
let json = r#"{"nfTokenIds":["tQyJrga3ke65RR23iyr2","tf2rbknDoo9wPsKBkskj"],"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"d8YpQ7jgPBJEkBrnvp58"},"confirmedDate":"2022-11-09T12:20:45.120"}"#;
let non_fungible_token_confirmed_notify: NonFungibleTokenConfirmedNotify = serde_json::from_str(json).unwrap();
assert_eq!(non_fungible_token_confirmed_notify, NonFungibleTokenConfirmedNotify {
nf_token_ids: vec![
String::from("tQyJrga3ke65RR23iyr2"),
String::from("tf2rbknDoo9wPsKBkskj"),
],
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("d8YpQ7jgPBJEkBrnvp58"),
name: None,
prod_unique_id: None,
},
confirmed_date: "2022-11-09T12:20:45.120".into()
});
}
#[test]
fn it_deserialize_non_fungible_token_confirmed_notification_message() {
let json = r#"{"nfTokenIds":["tQyJrga3ke65RR23iyr2","tf2rbknDoo9wPsKBkskj"],"issuer":{"deviceId":"drc3XdxNtzoucpw9xiRp"},"from":{"deviceId":"d8YpQ7jgPBJEkBrnvp58"},"confirmedDate":"2022-11-09T12:20:45.120"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::NonFungibleTokenConfirmed(
NonFungibleTokenConfirmedNotify {
nf_token_ids: vec![
String::from("tQyJrga3ke65RR23iyr2"),
String::from("tf2rbknDoo9wPsKBkskj"),
],
issuer: DeviceInfo {
device_id: String::from("drc3XdxNtzoucpw9xiRp"),
name: None,
prod_unique_id: None,
},
from: DeviceInfo {
device_id: String::from("d8YpQ7jgPBJEkBrnvp58"),
name: None,
prod_unique_id: None,
},
confirmed_date: "2022-11-09T12:20:45.120".into()
}
)
);
}
#[test]
fn it_deserialize_nf_token_retrieval_process_progress_done_error() {
let json = r#"{"bytesRetrieved":512,"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2022-11-05T12:01:47.483"}"#;
let nf_token_retrieval_process_progress_done: NFTokenRetrievalProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_token_retrieval_process_progress_done, NFTokenRetrievalProcessProgressDone {
bytes_retrieved: 512,
done: true,
success: false,
error: Some(NFTokenRetrievalProcessError {
code: 500,
message: String::from("Internal server error"),
}),
finish_date: "2022-11-05T12:01:47.483".into(),
});
}
#[test]
fn it_deserialize_nf_token_retrieval_process_progress_done_success() {
let json = r#"{"bytesRetrieved":1024,"done":true,"success":true,"finishDate":"2022-11-05T12:06:32.405"}"#;
let nf_token_retrieval_process_progress_done: NFTokenRetrievalProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_token_retrieval_process_progress_done, NFTokenRetrievalProcessProgressDone {
bytes_retrieved: 1024,
done: true,
success: true,
error: None,
finish_date: "2022-11-05T12:06:32.405".into(),
});
}
#[test]
fn it_deserialize_final_nf_token_retrieval_outcome_notify_no_opts() {
let json = r#"{"nfTokenId":"tDGQpGy627J6uAw4grYq","tokenRetrievalId":"rGEcL2HhoarCupvbkrv9","progress":{"bytesRetrieved":512,"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2022-11-05T12:01:47.483"}}"#;
let final_nf_token_retrieval_outcome_notify: FinalNFTokenRetrievalOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_nf_token_retrieval_outcome_notify, FinalNFTokenRetrievalOutcomeNotify {
nf_token_id: String::from("tDGQpGy627J6uAw4grYq"),
token_retrieval_id: String::from("rGEcL2HhoarCupvbkrv9"),
progress: NFTokenRetrievalProcessProgressDone {
bytes_retrieved: 512,
done: true,
success: false,
error: Some(NFTokenRetrievalProcessError {
code: 500,
message: String::from("Internal server error"),
}),
finish_date: "2022-11-05T12:01:47.483".into(),
},
continuation_token: None,
});
}
#[test]
fn it_deserialize_final_nf_token_retrieval_outcome_notify_all_opts() {
let json = r#"{"nfTokenId":"tDGQpGy627J6uAw4grYq","tokenRetrievalId":"rGEcL2HhoarCupvbkrv9","progress":{"bytesRetrieved":1024,"done":true,"success":true,"finishDate":"2022-11-05T12:06:32.405"},"continuationToken":"eXxdwcoXm3dJBF7Ej759"}"#;
let final_nf_token_retrieval_outcome_notify: FinalNFTokenRetrievalOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_nf_token_retrieval_outcome_notify, FinalNFTokenRetrievalOutcomeNotify {
nf_token_id: String::from("tDGQpGy627J6uAw4grYq"),
token_retrieval_id: String::from("rGEcL2HhoarCupvbkrv9"),
progress: NFTokenRetrievalProcessProgressDone {
bytes_retrieved: 1024,
done: true,
success: true,
error: None,
finish_date: "2022-11-05T12:06:32.405".into(),
},
continuation_token: Some(String::from("eXxdwcoXm3dJBF7Ej759")),
});
}
#[test]
fn it_deserialize_final_nf_token_retrieval_outcome_notification_message() {
let json = r#"{"nfTokenId":"tDGQpGy627J6uAw4grYq","tokenRetrievalId":"rGEcL2HhoarCupvbkrv9","progress":{"bytesRetrieved":1024,"done":true,"success":true,"finishDate":"2022-11-05T12:06:32.405"},"continuationToken":"eXxdwcoXm3dJBF7Ej759"}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalNFTokenRetrievalOutcome(
FinalNFTokenRetrievalOutcomeNotify {
nf_token_id: String::from("tDGQpGy627J6uAw4grYq"),
token_retrieval_id: String::from("rGEcL2HhoarCupvbkrv9"),
progress: NFTokenRetrievalProcessProgressDone {
bytes_retrieved: 1024,
done: true,
success: true,
error: None,
finish_date: "2022-11-05T12:06:32.405".into(),
},
continuation_token: Some(String::from("eXxdwcoXm3dJBF7Ej759")),
}
)
);
}
#[test]
fn it_deserialize_nf_token_transfer_process_progress_done_error() {
let json = r#"{"dataManipulation":{"bytesRead":512},"done":true,"success":false,"error":{"code":500,"message":"Internal server error"},"finishDate":"2022-11-07T09:05:52.972"}"#;
let nf_token_transfer_process_progress_done: NFTokenTransferProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_token_transfer_process_progress_done, NFTokenTransferProcessProgressDone {
data_manipulation: NFTokenDataManipulationProgress {
bytes_read: 512,
bytes_written: None
},
done: true,
success: false,
error: Some(NFTokenRetrievalProcessError {
code: 500,
message: String::from("Internal server error"),
}),
finish_date: "2022-11-07T09:05:52.972".into(),
});
}
#[test]
fn it_deserialize_nf_token_transfer_process_progress_done_success() {
let json = r#"{"dataManipulation":{"bytesRead":1234,"bytesWritten":1024},"done":true,"success":true,"finishDate":"2022-11-07T10:09:57.384"}"#;
let nf_token_transfer_process_progress_done: NFTokenTransferProcessProgressDone = serde_json::from_str(json).unwrap();
assert_eq!(nf_token_transfer_process_progress_done, NFTokenTransferProcessProgressDone {
data_manipulation: NFTokenDataManipulationProgress {
bytes_read: 1234,
bytes_written: Some(1024),
},
done: true,
success: true,
error: None,
finish_date: "2022-11-07T10:09:57.384".into(),
});
}
#[test]
fn it_deserialize_final_nf_token_transfer_outcome_notify() {
let json = r#"{"nfTokenId":"tDGQpGy627J6uAw4grYq","tokenTransferId":"xuYnPMKQSBXi28wRaZpN","progress":{"dataManipulation":{"bytesRead":1234,"bytesWritten":1024},"done":true,"success":true,"finishDate":"2022-11-07T10:09:57.384"}}"#;
let final_nf_token_transfer_outcome_notify: FinalNFTokenTransferOutcomeNotify = serde_json::from_str(json).unwrap();
assert_eq!(final_nf_token_transfer_outcome_notify, FinalNFTokenTransferOutcomeNotify {
nf_token_id: String::from("tDGQpGy627J6uAw4grYq"),
token_transfer_id: String::from("xuYnPMKQSBXi28wRaZpN"),
progress: NFTokenTransferProcessProgressDone {
data_manipulation: NFTokenDataManipulationProgress {
bytes_read: 1234,
bytes_written: Some(1024),
},
done: true,
success: true,
error: None,
finish_date: "2022-11-07T10:09:57.384".into(),
},
});
}
#[test]
fn it_deserialize_final_nf_token_transfer_outcome_notification_message() {
let json = r#"{"nfTokenId":"tDGQpGy627J6uAw4grYq","tokenTransferId":"xuYnPMKQSBXi28wRaZpN","progress":{"dataManipulation":{"bytesRead":1234,"bytesWritten":1024},"done":true,"success":true,"finishDate":"2022-11-07T10:09:57.384"}}"#;
let notification_message: NotificationMessage = serde_json::from_str(json).unwrap();
assert_eq!(
notification_message,
NotificationMessage::FinalNFTokenTransferOutcome(
FinalNFTokenTransferOutcomeNotify {
nf_token_id: String::from("tDGQpGy627J6uAw4grYq"),
token_transfer_id: String::from("xuYnPMKQSBXi28wRaZpN"),
progress: NFTokenTransferProcessProgressDone {
data_manipulation: NFTokenDataManipulationProgress {
bytes_read: 1234,
bytes_written: Some(1024),
},
done: true,
success: true,
error: None,
finish_date: "2022-11-07T10:09:57.384".into(),
},
}
)
);
}
}
}