use std::collections::HashMap; use log::debug; use sdk_client::api::{ create_confirmation_transaction, create_notification_transaction, dump_device, dump_message_cache, get_outputs, reset_device, restore_device, set_message_cache, setup }; use sdk_common::network::{ CachedMessage, CachedMessageStatus, Pcd }; use sdk_common::sp_client::bitcoin::OutPoint; use sdk_common::sp_client::spclient::OwnedOutput; use tsify::JsValueSerdeExt; use wasm_bindgen_test::*; wasm_bindgen_test_configure!(run_in_browser); mod utils; use utils::*; #[wasm_bindgen_test] fn test_alice_sends_prd_message_to_bob() { reset_device().unwrap(); setup(); debug!("==============================================\nStarting test_alice_sends_prd_message_to_bob\n=============================================="); // ============================ Alice restore_device(ALICE_LOGGED_DEVICE.to_owned()).unwrap(); // Alice first puts her message in a pcd let pcd = Pcd::new("TEST".to_owned()); debug!("Alice notified Bob about a message it sent"); let notification_tx = create_notification_transaction(helper_get_bob_address(), pcd, 1).unwrap(); let get_outputs_result = get_outputs().unwrap(); let alice_outputs: HashMap = get_outputs_result.into_serde().unwrap(); let notification_tweak_data = helper_get_tweak_data( ¬ification_tx.transaction, alice_outputs ); debug!("Alice parses her own notification transaction"); // Alice parse her own transaction to update her utxos helper_parse_transaction( ¬ification_tx.transaction, ¬ification_tweak_data, ); reset_device().unwrap(); restore_device(BOB_LOGGED_DEVICE.to_owned()).unwrap(); debug!("bob parses the transaction and the message"); helper_parse_transaction(¬ification_tx.transaction, ¬ification_tweak_data); helper_parse_cipher(notification_tx.new_network_msg.prd_cipher.unwrap()); let bob_notification_msg = helper_parse_cipher(notification_tx.new_network_msg.pcd_cipher.unwrap()); let msg_dump = dump_message_cache().unwrap(); debug!("bob_wallet: {:?}", dump_device()); debug!("bob_notification_msg: {:?}", msg_dump); debug!("commited_in: {:?}", msg_dump.get(0).unwrap().find("0x71b37cede4655932a5ce97bb8c4a7845adce96d4f85b64bc699bf74942c19f89")); assert!(bob_notification_msg.status == CachedMessageStatus::ReceivedMustConfirm); }