From a371c140ceab11ef7d284548b60b65ac6cf0426f Mon Sep 17 00:00:00 2001 From: Brian Corbin Date: Fri, 14 Apr 2023 14:18:07 -0700 Subject: [PATCH] fixing tests and lint issues --- Cargo.lock | 1 + full-service/Cargo.toml | 3 +- full-service/src/db/transaction_log.rs | 74 +++++++----- full-service/src/db/txo.rs | 29 ++--- .../src/json_rpc/v1/api/test_utils.rs | 2 +- full-service/src/service/account.rs | 9 +- full-service/src/service/gift_code.rs | 12 +- full-service/src/service/hardware_wallet.rs | 5 +- full-service/src/service/receipt.rs | 22 ++-- full-service/src/service/transaction.rs | 109 ++++++++++-------- .../src/service/transaction_builder.rs | 65 +++++++---- full-service/src/service/transaction_log.rs | 7 +- full-service/src/service/txo.rs | 7 +- full-service/src/test_utils.rs | 7 +- 14 files changed, 206 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7940503b6d..fd628385ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3222,6 +3222,7 @@ dependencies = [ "strum_macros", "tempdir", "tiny-bip39", + "tokio", "url", "uuid", "vergen", diff --git a/full-service/Cargo.toml b/full-service/Cargo.toml index 9937a76681..d2efc51139 100644 --- a/full-service/Cargo.toml +++ b/full-service/Cargo.toml @@ -90,7 +90,8 @@ mc-fog-report-validation-test-utils = { path = "../mobilecoin/fog/report/validat bs58 = "0.5.0" tempdir = "0.3" -url = "2.4" +tokio = "1.27" +url = "2.3" [build-dependencies] anyhow = "1.0" diff --git a/full-service/src/db/transaction_log.rs b/full-service/src/db/transaction_log.rs index d98f004ceb..0774b4946a 100644 --- a/full-service/src/db/transaction_log.rs +++ b/full-service/src/db/transaction_log.rs @@ -856,7 +856,7 @@ mod tests { use std::ops::DerefMut; use mc_account_keys::{PublicAddress, CHANGE_SUBADDRESS_INDEX}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_ledger_db::Ledger; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Token}; use rand::{rngs::StdRng, SeedableRng}; @@ -877,7 +877,7 @@ mod tests { use super::*; - #[test_with_logger] + #[async_test_with_logger] // Test the happy path for log_submitted. When a transaction is submitted to the // MobileCoin network, several things must happen for Full-Service to // maintain accurate transaction history. @@ -887,7 +887,7 @@ mod tests { // 3. The change TXO(s) are marked as minted, secreted // 4. The transaction_log is created and added to the transaction_log table // 5. Once the change is received, it is marked as minted, unspent - fn test_log_submitted(logger: Logger) { + async fn test_log_submitted(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -909,6 +909,9 @@ mod tests { // Build a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); builder @@ -919,10 +922,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal - .clone() - .sign(&account_key, None) - .unwrap(); + let tx_proposal = unsigned_tx_proposal.clone().sign(&account).await.unwrap(); assert_eq!( TransactionId::from(&tx_proposal), @@ -1064,8 +1064,8 @@ mod tests { ); } - #[test_with_logger] - fn test_log_submitted_zero_change(logger: Logger) { + #[async_test_with_logger] + async fn test_log_submitted_zero_change(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1087,6 +1087,9 @@ mod tests { // Build a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); // Add outlays all to the same recipient, so that we exceed u64::MAX in this tx @@ -1100,7 +1103,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); let tx_log = TransactionLog::log_submitted( &tx_proposal, @@ -1142,8 +1145,8 @@ mod tests { assert_eq!(associated.change.len(), 1); } - #[test_with_logger] - fn test_delete_transaction_logs_for_account(logger: Logger) { + #[async_test_with_logger] + async fn test_delete_transaction_logs_for_account(logger: Logger) { use crate::db::schema::{ transaction_input_txos, transaction_logs, transaction_output_txos, }; @@ -1172,6 +1175,9 @@ mod tests { // Build a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); builder.add_recipient(recipient, 50 * MOB, Mob::ID).unwrap(); @@ -1180,7 +1186,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); // Log submitted transaction from tx_proposal TransactionLog::log_submitted( @@ -1248,8 +1254,8 @@ mod tests { // // This test confirms that submitting a transaction_log for < u64::Max, but > // i64::Max succeeds - #[test_with_logger] - fn test_log_submitted_big_int(logger: Logger) { + #[async_test_with_logger] + async fn test_log_submitted_big_int(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1271,6 +1277,9 @@ mod tests { // Build a transaction for > i64::Max let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); builder @@ -1281,7 +1290,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!( tx_proposal.payload_txos[0].amount.value, @@ -1315,8 +1324,8 @@ mod tests { // // Note: This is also testing 2 inputs, as opposed to the happy path test // above, which tests only 1 input. - #[test_with_logger] - fn test_log_submitted_to_self(logger: Logger) { + #[async_test_with_logger] + async fn test_log_submitted_to_self(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1337,6 +1346,9 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let mut builder = WalletTransactionBuilder::new( AccountID::from(&account_key).to_string(), ledger_db.clone(), @@ -1351,7 +1363,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); // Log submitted transaction from tx_proposal let tx_log = TransactionLog::log_submitted( @@ -1539,8 +1551,8 @@ mod tests { ); } - #[test_with_logger] - fn test_log_built_signed_and_submitted(logger: Logger) { + #[async_test_with_logger] + async fn test_log_built_signed_and_submitted(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1562,6 +1574,9 @@ mod tests { // Build a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); builder @@ -1592,10 +1607,7 @@ mod tests { assert_eq!(tx_log, expected_tx_log); - let tx_proposal = unsigned_tx_proposal - .clone() - .sign(&account_key, None) - .unwrap(); + let tx_proposal = unsigned_tx_proposal.clone().sign(&account).await.unwrap(); let tx_bytes = mc_util_serial::encode(&tx_proposal.tx); assert_eq!( @@ -1760,8 +1772,8 @@ mod tests { ); } - #[test_with_logger] - fn test_log_submitted_with_comment_change(logger: Logger) { + #[async_test_with_logger] + async fn test_log_submitted_with_comment_change(logger: Logger) { // Test setup // log_submitted @@ -1788,6 +1800,9 @@ mod tests { // Build a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); builder.add_recipient(recipient, 50 * MOB, Mob::ID).unwrap(); @@ -1816,10 +1831,7 @@ mod tests { assert_eq!(tx_log, expected_tx_log); - let tx_proposal = unsigned_tx_proposal - .clone() - .sign(&account_key, None) - .unwrap(); + let tx_proposal = unsigned_tx_proposal.clone().sign(&account).await.unwrap(); let tx_bytes = mc_util_serial::encode(&tx_proposal.tx); assert_eq!( diff --git a/full-service/src/db/txo.rs b/full-service/src/db/txo.rs index 9bc0524bd1..eb1687e7d2 100644 --- a/full-service/src/db/txo.rs +++ b/full-service/src/db/txo.rs @@ -1986,7 +1986,7 @@ impl TxoModel for Txo { mod tests { use mc_account_keys::{AccountKey, PublicAddress, RootIdentity, CHANGE_SUBADDRESS_INDEX}; use mc_common::{ - logger::{log, test_with_logger, Logger}, + logger::{async_test_with_logger, log, test_with_logger, Logger}, HashSet, }; use mc_fog_report_validation::MockFogPubkeyResolver; @@ -2020,8 +2020,8 @@ mod tests { // each step of the lifecycle. // Note: This is not a replacement for a service-level test, but instead tests // basic assumptions after common DB operations with the Txo. - #[test_with_logger] - fn test_received_txo_lifecycle(logger: Logger) { + #[async_test_with_logger] + async fn test_received_txo_lifecycle(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -2064,6 +2064,7 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + let txos = Txo::list_for_account( &alice_account_id.to_string(), None, @@ -2133,7 +2134,7 @@ mod tests { TxoStatus::Created, ); - let tx_proposal = unsigned_tx_proposal.sign(&alice_account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&alice_account).await.unwrap(); // There should be 2 outputs, one to dest and one change assert_eq!(tx_proposal.tx.prefix.outputs.len(), 2); transaction_log = TransactionLog::log_signed( @@ -2389,7 +2390,8 @@ mod tests { 72 * MOB, wallet_db.clone(), ledger_db.clone(), - ); + ) + .await; let associated_txos = transaction_log .get_associated_txos(&mut wallet_db.get_pooled_conn().unwrap()) @@ -2769,8 +2771,8 @@ mod tests { } } - #[test_with_logger] - fn test_create_minted(logger: Logger) { + #[async_test_with_logger] + async fn test_create_minted(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let root_id = RootIdentity::from_random(&mut rng); @@ -2826,7 +2828,8 @@ mod tests { MOB, wallet_db.clone(), ledger_db, - ); + ) + .await; let associated_txos = transaction_log .get_associated_txos(&mut wallet_db.get_pooled_conn().unwrap()) @@ -2843,8 +2846,8 @@ mod tests { } // Test that the confirmation number validates correctly. - #[test_with_logger] - fn test_validate_confirmation(logger: Logger) { + #[async_test_with_logger] + async fn test_validate_confirmation(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -2888,6 +2891,8 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + let sender_account = Account::get(&AccountID::from(&sender_account_key), conn).unwrap(); + let mut builder: WalletTransactionBuilder = WalletTransactionBuilder::new( AccountID::from(&sender_account_key).to_string(), @@ -2906,9 +2911,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal - .sign(&sender_account_key, None) - .unwrap(); + let proposal = unsigned_tx_proposal.sign(&sender_account).await.unwrap(); // Sleep to make sure that the foreign keys exist std::thread::sleep(Duration::from_secs(3)); diff --git a/full-service/src/json_rpc/v1/api/test_utils.rs b/full-service/src/json_rpc/v1/api/test_utils.rs index 2c7c6d5e6e..e8ca3e8c53 100644 --- a/full-service/src/json_rpc/v1/api/test_utils.rs +++ b/full-service/src/json_rpc/v1/api/test_utils.rs @@ -69,7 +69,7 @@ async fn test_wallet_api( id: command.0.id, }; - match wallet_api_inner(&state.service, JsonCommandRequest::try_from(&req)?) { + match wallet_api_inner(&state.service, JsonCommandRequest::try_from(&req)?).await { Ok(command_response) => { response.result = Some(command_response); } diff --git a/full-service/src/service/account.rs b/full-service/src/service/account.rs index eb844bed41..e6c61d99a7 100644 --- a/full-service/src/service/account.rs +++ b/full-service/src/service/account.rs @@ -647,7 +647,7 @@ mod tests { }, }; use mc_account_keys::{AccountKey, PublicAddress, RootIdentity, ViewAccountKey}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, test_with_logger, Logger}; use mc_crypto_keys::RistrettoPrivate; use mc_rand::RngCore; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Amount, Token}; @@ -746,8 +746,8 @@ mod tests { ); } - #[test_with_logger] - fn test_resync_account_badly_stored_txo(logger: Logger) { + #[async_test_with_logger] + async fn test_resync_account_badly_stored_txo(logger: Logger) { use crate::{ db::{ account::AccountID, @@ -830,7 +830,8 @@ mod tests { 72 * MOB, wallet_db.clone(), ledger_db.clone(), - ); + ) + .await; // Store the real values for the txo's amount and target_key (arbitrary fields // we want to corrupt and sync back) diff --git a/full-service/src/service/gift_code.rs b/full-service/src/service/gift_code.rs index b2098a013e..60e3a6aaa8 100644 --- a/full-service/src/service/gift_code.rs +++ b/full-service/src/service/gift_code.rs @@ -866,13 +866,13 @@ mod tests { }, }; use mc_account_keys::PublicAddress; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_rand::rand_core::RngCore; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Token}; use rand::{rngs::StdRng, SeedableRng}; - #[test_with_logger] - fn test_gift_code_lifecycle(logger: Logger) { + #[async_test_with_logger] + async fn test_gift_code_lifecycle(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -926,6 +926,7 @@ mod tests { None, None, ) + .await .unwrap(); log::info!(logger, "Built gift code transaction"); @@ -1051,8 +1052,8 @@ mod tests { ) } - #[test_with_logger] - fn test_remove_gift_code(logger: Logger) { + #[async_test_with_logger] + async fn test_remove_gift_code(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -1106,6 +1107,7 @@ mod tests { None, None, ) + .await .unwrap(); log::info!(logger, "Built gift code transaction"); diff --git a/full-service/src/service/hardware_wallet.rs b/full-service/src/service/hardware_wallet.rs index 8f098b0076..3757ab5624 100644 --- a/full-service/src/service/hardware_wallet.rs +++ b/full-service/src/service/hardware_wallet.rs @@ -7,7 +7,6 @@ use std::convert::TryFrom; use ledger_mob::{transport::GenericTransport, Connect, DeviceHandle, LedgerProvider}; use mc_common::logger::global_log; -use mc_core::keys::TxOutPublic; use mc_crypto_keys::RistrettoPublic; use strum::Display; @@ -47,7 +46,7 @@ async fn get_device_handle() -> Result, HardwareW let ledger_provider = LedgerProvider::new().unwrap(); let devices = ledger_provider.list_devices(ledger_mob::Filter::Hid).await; - if devices.len() == 0 { + if devices.is_empty() { return Err(HardwareWalletServiceError::NoHardwareWalletsFound); } @@ -76,7 +75,7 @@ pub async fn sign_tx_proposal( let tx_out_public_key = RistrettoPublic::try_from(&txo.tx_out.public_key)?; let key_image = txos_synced .iter() - .find(|txo| txo.tx_out_public_key == TxOutPublic::from(tx_out_public_key)) + .find(|txo| txo.tx_out_public_key == tx_out_public_key) .ok_or(HardwareWalletServiceError::KeyImageNotFoundForSignedInput)? .key_image; diff --git a/full-service/src/service/receipt.rs b/full-service/src/service/receipt.rs index 5aa446997a..bdaf713e49 100644 --- a/full-service/src/service/receipt.rs +++ b/full-service/src/service/receipt.rs @@ -318,7 +318,7 @@ mod tests { util::b58::b58_encode_public_address, }; use mc_account_keys::{AccountKey, PublicAddress}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_crypto_keys::{ReprBytes, RistrettoPrivate, RistrettoPublic}; use mc_rand::RngCore; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, tx::TxOut, Amount, Token}; @@ -375,8 +375,8 @@ mod tests { assert_eq!(txo.get_masked_amount().unwrap(), &tx_receipt.amount); } - #[test_with_logger] - fn test_create_receipt(logger: Logger) { + #[async_test_with_logger] + async fn test_create_receipt(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -433,6 +433,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .expect("Could not build transaction"); let receipts = service @@ -504,8 +505,8 @@ mod tests { // All txos received should return TransactionSuccess, and TransactionPending // until they are received. - #[test_with_logger] - fn test_check_receiver_receipt_status_success(logger: Logger) { + #[async_test_with_logger] + async fn test_check_receiver_receipt_status_success(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -562,6 +563,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .expect("Could not build transaction"); let receipts = service @@ -625,8 +627,8 @@ mod tests { assert_eq!(status, ReceiptTransactionStatus::FailedAmountDecryption); } - #[test_with_logger] - fn test_check_receiver_receipt_status_wrong_value(logger: Logger) { + #[async_test_with_logger] + async fn test_check_receiver_receipt_status_wrong_value(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -684,6 +686,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .expect("Could not build transaction"); let receipts = service @@ -767,8 +770,8 @@ mod tests { assert_eq!(status, ReceiptTransactionStatus::FailedAmountDecryption); } - #[test_with_logger] - fn test_check_receiver_receipt_status_invalid_confirmation(logger: Logger) { + #[async_test_with_logger] + async fn test_check_receiver_receipt_status_invalid_confirmation(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -826,6 +829,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .expect("Could not build transaction"); let receipts = service diff --git a/full-service/src/service/transaction.rs b/full-service/src/service/transaction.rs index b2898ef4cc..8be6baf68e 100644 --- a/full-service/src/service/transaction.rs +++ b/full-service/src/service/transaction.rs @@ -260,6 +260,7 @@ impl TransactionMemo { Ok(account_key) => account_key, Err(_) => { global_log::warn!("Could not get account key, using empty memo"); + #[allow(clippy::box_default)] return Ok(Box::new(EmptyMemoBuilder::default())); } }; @@ -673,7 +674,7 @@ mod tests { util::b58::b58_encode_public_address, }; use mc_account_keys::{AccountKey, PublicAddress}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_crypto_keys::RistrettoPublic; use mc_rand::rand_core::RngCore; use mc_transaction_core::{ @@ -685,8 +686,8 @@ mod tests { use rand::{rngs::StdRng, SeedableRng}; use std::convert::TryFrom; - #[test_with_logger] - fn test_build_transaction_and_log(logger: Logger) { + #[async_test_with_logger] + async fn test_build_transaction_and_log(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -774,6 +775,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); log::info!(logger, "Built transaction from Alice"); @@ -803,6 +805,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); log::info!(logger, "Built transaction from Alice"); @@ -832,6 +835,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); log::info!(logger, "Built transaction from Alice"); @@ -843,8 +847,8 @@ mod tests { } // Test sending a transaction from Alice -> Bob, and then from Bob -> Alice - #[test_with_logger] - fn test_send_transaction(logger: Logger) { + #[async_test_with_logger] + async fn test_send_transaction(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -921,6 +925,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); log::info!(logger, "Built and submitted transaction from Alice"); @@ -1023,6 +1028,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); // NOTE: Submitting to the test ledger via propose_tx doesn't actually add the @@ -1081,8 +1087,8 @@ mod tests { } // Building a transaction for an invalid public address should fail. - #[test_with_logger] - fn test_invalid_public_address_fails(logger: Logger) { + #[async_test_with_logger] + async fn test_invalid_public_address_fails(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -1118,17 +1124,20 @@ mod tests { &logger, ); - match service.build_and_sign_transaction( - &alice.id, - &[("NOTB58".to_string(), AmountJSON::new(42 * MOB, Mob::ID))], - None, - None, - None, - None, - None, - TransactionMemo::RTH(None, None), - None, - ) { + match service + .build_and_sign_transaction( + &alice.id, + &[("NOTB58".to_string(), AmountJSON::new(42 * MOB, Mob::ID))], + None, + None, + None, + None, + None, + TransactionMemo::RTH(None, None), + None, + ) + .await + { Ok(_) => { panic!("Should not be able to build transaction to invalid b58 public address") } @@ -1137,8 +1146,8 @@ mod tests { }; } - #[test_with_logger] - fn test_maximum_inputs_and_outputs(logger: Logger) { + #[async_test_with_logger] + async fn test_maximum_inputs_and_outputs(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -1182,17 +1191,20 @@ mod tests { AmountJSON::new(42 * MOB, Mob::ID), )); } - match service.build_and_sign_transaction( - &alice.id, - &outputs, - None, - None, - None, - None, - None, - TransactionMemo::RTH(None, None), - None, - ) { + match service + .build_and_sign_transaction( + &alice.id, + &outputs, + None, + None, + None, + None, + None, + TransactionMemo::RTH(None, None), + None, + ) + .await + { Ok(_) => { panic!("Should not be able to build transaction with too many ouputs") } @@ -1214,17 +1226,20 @@ mod tests { for _ in 0..17 { inputs.push("fake txo id".to_string()); } - match service.build_and_sign_transaction( - &alice.id, - &outputs, - Some(&inputs), - None, - None, - None, - None, - TransactionMemo::RTH(None, None), - None, - ) { + match service + .build_and_sign_transaction( + &alice.id, + &outputs, + Some(&inputs), + None, + None, + None, + None, + TransactionMemo::RTH(None, None), + None, + ) + .await + { Ok(_) => { panic!("Should not be able to build transaction with too many inputs") } @@ -1236,8 +1251,8 @@ mod tests { } // Test sending a transaction from Alice -> Bob, and then from Bob -> Alice - #[test_with_logger] - fn test_send_transaction_with_sender_memo_cred_subaddress_index(logger: Logger) { + #[async_test_with_logger] + async fn test_send_transaction_with_sender_memo_cred_subaddress_index(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -1320,6 +1335,7 @@ mod tests { TransactionMemo::RTH(Some(alice_address_from_bob.subaddress_index as u64), None), None, ) + .await .unwrap(); log::info!(logger, "Built and submitted transaction from Alice"); @@ -1424,8 +1440,8 @@ mod tests { } // Test sending a transaction from Alice -> Bob, and then from Bob -> Alice - #[test_with_logger] - fn test_send_transaction_with_payment_request_id(logger: Logger) { + #[async_test_with_logger] + async fn test_send_transaction_with_payment_request_id(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -1513,6 +1529,7 @@ mod tests { ), None, ) + .await .unwrap(); log::info!(logger, "Built and submitted transaction from Alice"); diff --git a/full-service/src/service/transaction_builder.rs b/full-service/src/service/transaction_builder.rs index b1e8facee8..b2dcf0ef4e 100644 --- a/full-service/src/service/transaction_builder.rs +++ b/full-service/src/service/transaction_builder.rs @@ -537,11 +537,11 @@ mod tests { }, }; use mc_account_keys::AccountKey; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, test_with_logger, Logger}; use rand::{rngs::StdRng, SeedableRng}; - #[test_with_logger] - fn test_build_with_utxos(logger: Logger) { + #[async_test_with_logger] + async fn test_build_with_utxos(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -563,6 +563,9 @@ mod tests { // Construct a transaction let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); @@ -580,7 +583,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.payload_txos.len(), 1); assert_eq!(proposal.payload_txos[0].recipient_public_address, recipient); assert_eq!(proposal.payload_txos[0].amount.value, value); @@ -698,8 +701,8 @@ mod tests { } // Users should be able to set the txos specifically that they want to send - #[test_with_logger] - fn test_setting_txos(logger: Logger) { + #[async_test_with_logger] + async fn test_setting_txos(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -733,6 +736,9 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); @@ -767,7 +773,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.payload_txos.len(), 1); assert_eq!(proposal.payload_txos[0].recipient_public_address, recipient); assert_eq!( @@ -953,8 +959,8 @@ mod tests { } // Test max_spendable correctly filters out txos above max_spendable - #[test_with_logger] - fn test_max_spendable(logger: Logger) { + #[async_test_with_logger] + async fn test_max_spendable(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -975,6 +981,9 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); @@ -1011,7 +1020,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.payload_txos.len(), 1); assert_eq!(proposal.payload_txos[0].recipient_public_address, recipient); assert_eq!(proposal.payload_txos[0].amount.value, 80 * MOB); @@ -1021,8 +1030,8 @@ mod tests { } // Test setting and not setting tombstone block - #[test_with_logger] - fn test_tombstone(logger: Logger) { + #[async_test_with_logger] + async fn test_tombstone(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1042,6 +1051,7 @@ mod tests { &mut rng, &logger, ); + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); @@ -1073,7 +1083,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.tombstone_block, 23); // Build a transaction and explicitly set tombstone @@ -1091,13 +1101,13 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.tombstone_block, 20); } // Test setting and not setting the fee - #[test_with_logger] - fn test_fee(logger: Logger) { + #[async_test_with_logger] + async fn test_fee(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1118,6 +1128,9 @@ mod tests { let mut pooled_conn = wallet_db.get_pooled_conn().unwrap(); let conn = pooled_conn.deref_mut(); + + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let (recipient, mut builder) = builder_for_random_recipient(&account_key, &ledger_db, &mut rng); @@ -1129,7 +1142,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.fee, Mob::MINIMUM_FEE); // You cannot set fee to 0 @@ -1149,7 +1162,7 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.fee, Mob::MINIMUM_FEE); // Setting fee less than minimum fee should fail @@ -1176,13 +1189,13 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.fee, Mob::MINIMUM_FEE * 10); } // Even if change is zero, we should still have a change output - #[test_with_logger] - fn test_change_zero_mob(logger: Logger) { + #[async_test_with_logger] + async fn test_change_zero_mob(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1218,7 +1231,8 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.fee, Mob::MINIMUM_FEE); assert_eq!(proposal.payload_txos.len(), 1); @@ -1231,8 +1245,8 @@ mod tests { // We should be able to add multiple TxOuts to the same recipient, not to // multiple - #[test_with_logger] - fn test_add_multiple_outputs_to_same_recipient(logger: Logger) { + #[async_test_with_logger] + async fn test_add_multiple_outputs_to_same_recipient(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let db_test_context = WalletDbTestContext::default(); @@ -1275,7 +1289,8 @@ mod tests { let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let proposal = unsigned_tx_proposal.sign(&account_key, None).unwrap(); + let account = Account::get(&AccountID::from(&account_key), conn).unwrap(); + let proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); assert_eq!(proposal.tx.prefix.fee, Mob::MINIMUM_FEE); assert_eq!(proposal.payload_txos.len(), 4); diff --git a/full-service/src/service/transaction_log.rs b/full-service/src/service/transaction_log.rs index 45b60a2d27..3582efa052 100644 --- a/full-service/src/service/transaction_log.rs +++ b/full-service/src/service/transaction_log.rs @@ -137,13 +137,13 @@ mod tests { }, }; use mc_account_keys::{AccountKey, PublicAddress}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_rand::rand_core::RngCore; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Token}; use rand::{rngs::StdRng, SeedableRng}; - #[test_with_logger] - fn test_list_transaction_logs_for_account_with_min_and_max_block_index(logger: Logger) { + #[async_test_with_logger] + async fn test_list_transaction_logs_for_account_with_min_and_max_block_index(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -209,6 +209,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); { diff --git a/full-service/src/service/txo.rs b/full-service/src/service/txo.rs index 40fc8f9c08..2e81d7378c 100644 --- a/full-service/src/service/txo.rs +++ b/full-service/src/service/txo.rs @@ -358,13 +358,13 @@ mod tests { util::b58::b58_encode_public_address, }; use mc_account_keys::{AccountKey, PublicAddress}; - use mc_common::logger::{test_with_logger, Logger}; + use mc_common::logger::{async_test_with_logger, Logger}; use mc_rand::RngCore; use mc_transaction_core::{ring_signature::KeyImage, tokens::Mob, Token}; use rand::{rngs::StdRng, SeedableRng}; - #[test_with_logger] - fn test_txo_lifecycle(logger: Logger) { + #[async_test_with_logger] + async fn test_txo_lifecycle(logger: Logger) { let mut rng: StdRng = SeedableRng::from_seed([20u8; 32]); let known_recipients: Vec = Vec::new(); @@ -446,6 +446,7 @@ mod tests { TransactionMemo::RTH(None, None), None, ) + .await .unwrap(); let _submitted = service .submit_transaction(&tx_proposal, None, Some(alice.id.clone())) diff --git a/full-service/src/test_utils.rs b/full-service/src/test_utils.rs index 4a36b2c5be..0f7f15bfe4 100644 --- a/full-service/src/test_utils.rs +++ b/full-service/src/test_utils.rs @@ -428,7 +428,7 @@ pub fn create_test_received_txo( /// Creates a test minted and change txo. /// /// Returns (txproposal, ((output_txo_id, value), (change_txo_id, value))) -pub fn create_test_minted_and_change_txos( +pub async fn create_test_minted_and_change_txos( src_account_key: AccountKey, recipient: PublicAddress, value: u64, @@ -449,10 +449,13 @@ pub fn create_test_minted_and_change_txos( builder.add_recipient(recipient, value, Mob::ID).unwrap(); builder.select_txos(conn, None).unwrap(); builder.set_tombstone(0).unwrap(); + + let account = Account::get(&AccountID::from(&src_account_key), conn).unwrap(); + let unsigned_tx_proposal = builder .build(TransactionMemo::RTH(None, None), conn) .unwrap(); - let tx_proposal = unsigned_tx_proposal.sign(&src_account_key, None).unwrap(); + let tx_proposal = unsigned_tx_proposal.sign(&account).await.unwrap(); // There should be 2 outputs, one to dest and one change assert_eq!(tx_proposal.tx.prefix.outputs.len(), 2);