[tests/pairing] Replace create_update_transaction with *message

This commit is contained in:
Sosthene 2024-10-30 15:10:33 +01:00
parent 7ba532cebe
commit 0a81ce12df

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
use sdk_client::api::{ use sdk_client::api::{
add_validation_token_to_prd, create_commit_message, create_device_from_sp_wallet, create_update_transaction, dump_device, dump_process_cache, get_address, get_outputs, get_update_proposals, pair_device, parse_cipher, reset_device, response_prd, restore_device, set_process_cache, setup, ApiReturn add_validation_token_to_prd, create_commit_message, create_connect_transaction, create_device_from_sp_wallet, create_update_message, dump_device, dump_process_cache, get_address, get_outputs, get_update_proposals, pair_device, parse_cipher, reset_device, response_prd, restore_device, set_process_cache, setup, ApiReturn
}; };
use sdk_common::log::{debug, info}; use sdk_common::log::{debug, info};
use sdk_common::pcd::{Member, RoleDefinition}; use sdk_common::pcd::{Member, RoleDefinition};
@ -91,27 +91,14 @@ fn test_pairing() {
// we can update our local device now, first with an empty txid // we can update our local device now, first with an empty txid
pair_device(OutPoint::null().to_string(), vec![helper_get_bob_address()]).unwrap(); pair_device(OutPoint::null().to_string(), vec![helper_get_bob_address()]).unwrap();
debug!("Alice sends a transaction commiting to an update prd to Bob"); debug!("Alice sends an update prd to Bob");
let alice_pairing_return = let alice_pairing_return =
create_update_transaction(None, pairing_init_state.to_string(), 1).unwrap(); create_update_message(None, pairing_init_state.to_string()).unwrap();
let (root_outpoint, alice_init_process) = alice_pairing_return.updated_process.unwrap(); let (root_outpoint, alice_init_process) = alice_pairing_return.updated_process.unwrap();
alice_process_cache.insert(root_outpoint.clone(), alice_init_process.clone()); alice_process_cache.insert(root_outpoint.clone(), alice_init_process.clone());
let pairing_tx_msg = alice_pairing_return.new_tx_to_send.unwrap(); let alice_to_bob_cipher = alice_pairing_return.ciphers_to_send[0];
// This is only for testing, the relay takes care of that in prod
let get_outputs_result = get_outputs().unwrap();
let alice_outputs: HashMap<OutPoint, OwnedOutput> = get_outputs_result.into_serde().unwrap();
let alice_pairing_tweak_data =
helper_get_tweak_data(&pairing_tx_msg.transaction, alice_outputs);
// End of the test only part
// Alice parses her own transaction
helper_parse_transaction(&pairing_tx_msg.transaction, &alice_pairing_tweak_data);
// this is only for testing, as we're playing both parts // this is only for testing, as we're playing both parts
let alice_device = dump_device().unwrap(); let alice_device = dump_device().unwrap();
@ -121,25 +108,8 @@ fn test_pairing() {
reset_device().unwrap(); reset_device().unwrap();
create_device_from_sp_wallet(BOB_LOGIN_WALLET.to_owned()).unwrap(); create_device_from_sp_wallet(BOB_LOGIN_WALLET.to_owned()).unwrap();
// Bob receives Alice pairing transaction debug!("Bob receives the update prd");
debug!("Bob parses Alice pairing transaction"); let bob_parsed_return = parse_cipher(alice_to_bob_cipher).unwrap();
helper_parse_transaction(&pairing_tx_msg.transaction, &alice_pairing_tweak_data);
debug!("Bob receives the prd");
let mut bob_retrieved_prd: ApiReturn = ApiReturn::default();
for cipher in alice_pairing_return.ciphers_to_send.iter() {
// debug!("Parsing cipher: {:#?}", cipher);
match parse_cipher(cipher.clone()) {
Ok(res) => bob_retrieved_prd = res,
Err(e) => {
debug!("Error parsing cipher: {:#?}", e);
continue;
}
}
}
assert!(bob_retrieved_prd.ciphers_to_send.len() == 1);
assert!(bob_retrieved_prd.updated_process.is_some());
debug!("Bob retrieved prd: {:#?}", bob_retrieved_prd); debug!("Bob retrieved prd: {:#?}", bob_retrieved_prd);