diff --git a/CHANGELOG.md b/CHANGELOG.md index 36bcc5e74..6a6b15dc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * Add check for empty pay to id notes (#714). * [BREAKING] Refactored authentication out of the `Client` and added new separate authenticators (#718). +* Move error handling to the `TransactionRequestBuilder::build()` (#750). ## 0.7.0 (2025-01-28) diff --git a/bin/miden-cli/src/commands/new_transactions.rs b/bin/miden-cli/src/commands/new_transactions.rs index 2f1b90e69..d367ab826 100644 --- a/bin/miden-cli/src/commands/new_transactions.rs +++ b/bin/miden-cli/src/commands/new_transactions.rs @@ -77,10 +77,10 @@ impl MintCmd { (&self.note_type).into(), client.rng(), ) + .and_then(TransactionRequestBuilder::build) .map_err(|err| { CliError::Transaction(err.into(), "Failed to build mint transaction".to_string()) - })? - .build(); + })?; execute_transaction( &mut client, @@ -150,10 +150,10 @@ impl SendCmd { (&self.note_type).into(), client.rng(), ) + .and_then(TransactionRequestBuilder::build) .map_err(|err| { CliError::Transaction(err.into(), "Failed to build payment transaction".to_string()) - })? - .build(); + })?; execute_transaction( &mut client, @@ -219,10 +219,10 @@ impl SwapCmd { (&self.note_type).into(), client.rng(), ) + .and_then(TransactionRequestBuilder::build) .map_err(|err| { CliError::Transaction(err.into(), "Failed to build swap transaction".to_string()) - })? - .build(); + })?; execute_transaction( &mut client, @@ -312,9 +312,16 @@ impl ConsumeNotesCmd { )); } - let transaction_request = TransactionRequestBuilder::consume_notes(authenticated_notes) + let transaction_request = TransactionRequestBuilder::new() + .with_authenticated_input_notes(authenticated_notes.into_iter().map(|id| (id, None))) .with_unauthenticated_input_notes(unauthenticated_notes) - .build(); + .build() + .map_err(|err| { + CliError::Transaction( + err.into(), + "Failed to build consume notes transaction".to_string(), + ) + })?; execute_transaction( &mut client, diff --git a/bin/miden-cli/src/tests.rs b/bin/miden-cli/src/tests.rs index 25dc9ea99..8aaa944f0 100644 --- a/bin/miden-cli/src/tests.rs +++ b/bin/miden-cli/src/tests.rs @@ -805,8 +805,8 @@ async fn debug_mode_outputs_logs() { // Send transaction and wait for it to be committed let transaction_request = TransactionRequestBuilder::new() .with_own_output_notes(vec![OutputNote::Full(note.clone())]) - .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client, account.id(), transaction_request).await; // Export the note diff --git a/crates/rust-client/src/tests.rs b/crates/rust-client/src/tests.rs index bb77e5d28..c2493ce96 100644 --- a/crates/rust-client/src/tests.rs +++ b/crates/rust-client/src/tests.rs @@ -438,7 +438,8 @@ async fn test_mint_transaction() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let transaction = client.new_transaction(faucet.id(), transaction_request).await.unwrap(); @@ -465,7 +466,8 @@ async fn test_get_output_notes() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); //Before executing transaction, there are no output notes assert!(client.get_output_notes(NoteFilter::All).await.unwrap().is_empty()); @@ -528,8 +530,8 @@ async fn test_transaction_request_expiration() { ) .unwrap() .with_expiration_delta(5) - .unwrap() - .build(); + .build() + .unwrap(); let transaction = client.new_transaction(faucet.id(), transaction_request).await.unwrap(); @@ -562,7 +564,8 @@ async fn test_import_processing_note_returns_error() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let transaction = client.new_transaction(faucet.id(), transaction_request.clone()).await.unwrap(); @@ -572,8 +575,10 @@ async fn test_import_processing_note_returns_error() { let note = client.get_input_note(note_id).await.unwrap().unwrap(); let input = [(note.try_into().unwrap(), None)]; - let consume_note_request = - TransactionRequestBuilder::new().with_unauthenticated_input_notes(input).build(); + let consume_note_request = TransactionRequestBuilder::new() + .with_unauthenticated_input_notes(input) + .build() + .unwrap(); let transaction = client .new_transaction(account.id(), consume_note_request.clone()) .await @@ -618,7 +623,7 @@ async fn test_no_nonce_change_transaction_request() { let tx_script = client.compile_tx_script(vec![], code).unwrap(); let transaction_request = - TransactionRequestBuilder::new().with_custom_script(tx_script).unwrap().build(); + TransactionRequestBuilder::new().with_custom_script(tx_script).build().unwrap(); let transaction_execution_result = client.new_transaction(regular_account.id(), transaction_request).await.unwrap(); @@ -660,8 +665,8 @@ async fn test_note_without_asset() { // Create and execute transaction let transaction_request = TransactionRequestBuilder::new() .with_own_output_notes(vec![OutputNote::Full(note)]) - .unwrap() - .build(); + .build() + .unwrap(); let transaction = client.new_transaction(wallet.id(), transaction_request.clone()).await; @@ -675,8 +680,8 @@ async fn test_note_without_asset() { let transaction_request = TransactionRequestBuilder::new() .with_own_output_notes(vec![OutputNote::Full(note)]) - .unwrap() - .build(); + .build() + .unwrap(); let error = client.new_transaction(faucet.id(), transaction_request).await.unwrap_err(); diff --git a/crates/rust-client/src/transaction/mod.rs b/crates/rust-client/src/transaction/mod.rs index bb707597a..f3d083675 100644 --- a/crates/rust-client/src/transaction/mod.rs +++ b/crates/rust-client/src/transaction/mod.rs @@ -48,7 +48,7 @@ //! NoteType::Private, //! client.rng(), //! )? -//! .build(); +//! .build()?; //! //! // Execute the transaction. This returns a TransactionResult. //! let tx_result: TransactionResult = client.new_transaction(sender_id, tx_request).await?; @@ -1094,7 +1094,8 @@ mod test { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let tx_result = client.new_transaction(account.id(), tx_request).await.unwrap(); assert!(tx_result diff --git a/crates/rust-client/src/transaction/request/builder.rs b/crates/rust-client/src/transaction/request/builder.rs index 23f2cb722..056682bfb 100644 --- a/crates/rust-client/src/transaction/request/builder.rs +++ b/crates/rust-client/src/transaction/request/builder.rs @@ -10,7 +10,7 @@ use miden_objects::{ merkle::{InnerNodeInfo, MerkleStore}, rand::FeltRng, }, - note::{Note, NoteDetails, NoteExecutionMode, NoteId, NoteTag, NoteType}, + note::{Note, NoteDetails, NoteExecutionMode, NoteId, NoteTag, NoteType, PartialNote}, transaction::{OutputNote, TransactionScript}, vm::AdviceMap, Digest, Felt, FieldElement, @@ -36,15 +36,18 @@ pub struct TransactionRequestBuilder { /// Notes to be consumed by the transaction together with their (optional) arguments. This /// includes both authenticated and unauthenticated notes. input_notes: BTreeMap>, - /// Template for the creation of the transaction script. - script_template: Option, - /// A map of notes expected to be generated by the transactions. + /// Notes to be created by the transaction. This includes both full and partial output notes. + /// The transaction script will be generated based on these notes. + own_output_notes: Vec, + /// A map of expected full output notes to be generated by the transaction. expected_output_notes: BTreeMap, /// A map of details and tags of notes we expect to be created as part of future transactions /// with their respective tags. /// /// For example, after a swap note is consumed, a payback note is expected to be created. expected_future_notes: BTreeMap, + /// Custom transaction script to be used. + custom_script: Option, /// Initial state of the `AdviceMap` that provides data during runtime. advice_map: AdviceMap, /// Initial state of the `MerkleStore` that provides data during runtime. @@ -67,9 +70,10 @@ impl TransactionRequestBuilder { Self { unauthenticated_input_notes: vec![], input_notes: BTreeMap::new(), - script_template: None, + own_output_notes: Vec::new(), expected_output_notes: BTreeMap::new(), expected_future_notes: BTreeMap::new(), + custom_script: None, advice_map: AdviceMap::default(), merkle_store: MerkleStore::default(), expiration_delta: None, @@ -106,54 +110,29 @@ impl TransactionRequestBuilder { /// be used as a transaction script template. These notes will also be added to the expected /// output notes of the transaction. /// - /// If a transaction script template is already set (e.g. by calling `with_custom_script`), this - /// method will return an error. - pub fn with_own_output_notes( - mut self, - notes: impl IntoIterator, - ) -> Result { - if self.script_template.is_some() { - return Err(TransactionRequestError::ScriptTemplateError( - "Cannot set own notes when a script template is already set".to_string(), - )); - } - - let mut own_notes = Vec::new(); - + /// If a transaction script template is already set (e.g. by calling `with_custom_script`), the + /// [`TransactionRequestBuilder::build`] method will return an error. + #[must_use] + pub fn with_own_output_notes(mut self, notes: impl IntoIterator) -> Self { for note in notes { - match note { - OutputNote::Full(note) => { - self.expected_output_notes.insert(note.id(), note.clone()); - own_notes.push(note.into()); - }, - OutputNote::Partial(note) => own_notes.push(note), - OutputNote::Header(_) => return Err(TransactionRequestError::InvalidNoteVariant), - } + if let OutputNote::Full(note) = ¬e { + self.expected_output_notes.insert(note.id(), note.clone()); + }; + + self.own_output_notes.push(note); } - self.script_template = Some(TransactionScriptTemplate::SendNotes(own_notes)); - Ok(self) + self } /// Specifies a custom transaction script to be used. /// - /// If a script template is already set (e.g. by calling `with_own_output_notes`), this method - /// will return an error. - pub fn with_custom_script( - mut self, - script: TransactionScript, - ) -> Result { - if self.script_template.is_some() { - return Err(TransactionRequestError::ScriptTemplateError( - "Cannot set custom script when a script template is already set".to_string(), - )); - } else if self.expiration_delta.is_some() { - return Err(TransactionRequestError::ScriptTemplateError( - "Cannot set custom script when an expiration delta is already set".to_string(), - )); - } - self.script_template = Some(TransactionScriptTemplate::CustomScript(script)); - Ok(self) + /// If a script template is already set (e.g. by calling `with_own_output_notes`), the + /// [`TransactionRequestBuilder::build`] method will return an error. + #[must_use] + pub fn with_custom_script(mut self, script: TransactionScript) -> Self { + self.custom_script = Some(script); + self } /// Specifies one or more foreign accounts (public or private) that contain data @@ -226,18 +205,10 @@ impl TransactionRequestBuilder { /// Setting transaction expiration delta defines an upper bound for transaction expiration, /// but other code executed during the transaction may impose an even smaller transaction /// expiration delta. - pub fn with_expiration_delta( - mut self, - expiration_delta: u16, - ) -> Result { - if let Some(TransactionScriptTemplate::CustomScript(_)) = self.script_template { - return Err(TransactionRequestError::ScriptTemplateError( - "Cannot set expiration delta when a custom script is set".to_string(), - )); - } - + #[must_use] + pub fn with_expiration_delta(mut self, expiration_delta: u16) -> Self { self.expiration_delta = Some(expiration_delta); - Ok(self) + self } // STANDARDIZED REQUESTS @@ -275,7 +246,7 @@ impl TransactionRequestBuilder { rng, )?; - Self::new().with_own_output_notes(vec![OutputNote::Full(created_note)]) + Ok(Self::new().with_own_output_notes(vec![OutputNote::Full(created_note)])) } /// Returns a new [`TransactionRequestBuilder`] for a transaction to send a P2ID or P2IDR note. @@ -330,7 +301,7 @@ impl TransactionRequestBuilder { )? }; - Self::new().with_own_output_notes(vec![OutputNote::Full(created_note)]) + Ok(Self::new().with_own_output_notes(vec![OutputNote::Full(created_note)])) } /// Returns a new [`TransactionRequestBuilder`] for a transaction to send a SWAP note. This @@ -360,27 +331,63 @@ impl TransactionRequestBuilder { let payback_tag = NoteTag::from_account_id(swap_data.account_id(), NoteExecutionMode::Local)?; - Self::new() + Ok(Self::new() .with_expected_future_notes(vec![(payback_note_details, payback_tag)]) - .with_own_output_notes(vec![OutputNote::Full(created_note)]) + .with_own_output_notes(vec![OutputNote::Full(created_note)])) } // FINALIZE BUILDER // -------------------------------------------------------------------------------------------- /// Consumes the builder and returns a [`TransactionRequest`]. - pub fn build(self) -> TransactionRequest { - TransactionRequest { + /// + /// # Errors + /// - If both a custom script and own output notes are set. + /// - If an expiration delta is set when a custom script is set. + /// - If an invalid note variant is encountered in the own output notes. + pub fn build(self) -> Result { + let script_template = match (self.custom_script, self.own_output_notes.is_empty()) { + (Some(_), false) => { + return Err(TransactionRequestError::ScriptTemplateError( + "Cannot set both a custom script and own output notes".to_string(), + )); + }, + (Some(script), true) => { + if self.expiration_delta.is_some() { + return Err(TransactionRequestError::ScriptTemplateError( + "Cannot set expiration delta when a custom script is set".to_string(), + )); + } + + Some(TransactionScriptTemplate::CustomScript(script)) + }, + (None, false) => { + let partial_notes = self + .own_output_notes + .into_iter() + .map(|note| match note { + OutputNote::Header(_) => Err(TransactionRequestError::InvalidNoteVariant), + OutputNote::Partial(note) => Ok(note), + OutputNote::Full(note) => Ok(note.into()), + }) + .collect::, _>>()?; + + Some(TransactionScriptTemplate::SendNotes(partial_notes)) + }, + (None, true) => None, + }; + + Ok(TransactionRequest { unauthenticated_input_notes: self.unauthenticated_input_notes, input_notes: self.input_notes, - script_template: self.script_template, + script_template, expected_output_notes: self.expected_output_notes, expected_future_notes: self.expected_future_notes, advice_map: self.advice_map, merkle_store: self.merkle_store, foreign_accounts: self.foreign_accounts.into_values().collect(), expiration_delta: self.expiration_delta, - } + }) } } diff --git a/crates/rust-client/src/transaction/request/mod.rs b/crates/rust-client/src/transaction/request/mod.rs index 777587a88..27e7425e9 100644 --- a/crates/rust-client/src/transaction/request/mod.rs +++ b/crates/rust-client/src/transaction/request/mod.rs @@ -426,8 +426,8 @@ mod tests { OutputNote::Full(notes.pop().unwrap()), OutputNote::Partial(notes.pop().unwrap().into()), ]) - .unwrap() - .build(); + .build() + .unwrap(); let mut buffer = Vec::new(); tx_request.write_into(&mut buffer); diff --git a/crates/web-client/src/models/transaction_request.rs b/crates/web-client/src/models/transaction_request.rs index e27a0ec96..38acbb6e6 100644 --- a/crates/web-client/src/models/transaction_request.rs +++ b/crates/web-client/src/models/transaction_request.rs @@ -248,13 +248,13 @@ impl TransactionRequestBuilder { pub fn with_own_output_notes(mut self, notes: &OutputNotesArray) -> Self { let native_output_notes: Vec = notes.into(); - self.0 = self.0.clone().with_own_output_notes(native_output_notes).unwrap(); + self.0 = self.0.clone().with_own_output_notes(native_output_notes); self } pub fn with_custom_script(mut self, script: &TransactionScript) -> Self { let native_script: NativeTransactionScript = script.into(); - self.0 = self.0.clone().with_custom_script(native_script).unwrap(); + self.0 = self.0.clone().with_custom_script(native_script); self } @@ -281,7 +281,7 @@ impl TransactionRequestBuilder { } pub fn build(self) -> TransactionRequest { - TransactionRequest(self.0.build()) + TransactionRequest(self.0.build().unwrap()) } } diff --git a/crates/web-client/src/new_transactions.rs b/crates/web-client/src/new_transactions.rs index 66ec2d56b..2da845f9d 100644 --- a/crates/web-client/src/new_transactions.rs +++ b/crates/web-client/src/new_transactions.rs @@ -110,10 +110,10 @@ impl WebClient { note_type.into(), client.rng(), ) + .and_then(NativeTransactionRequestBuilder::build) .map_err(|err| { JsValue::from_str(&format!("Failed to create Mint Transaction Request: {err}")) - })? - .build(); + })?; let mint_transaction_execution_result = client .new_transaction(faucet_id.into(), mint_transaction_request) @@ -164,12 +164,12 @@ impl WebClient { note_type.into(), client.rng(), ) + .and_then(NativeTransactionRequestBuilder::build) .map_err(|err| { JsValue::from_str(&format!( "Failed to create Send Transaction Request with Recall Height: {err}" )) })? - .build() } else { NativeTransactionRequestBuilder::pay_to_id( payment_transaction, @@ -177,10 +177,10 @@ impl WebClient { note_type.into(), client.rng(), ) + .and_then(NativeTransactionRequestBuilder::build) .map_err(|err| { JsValue::from_str(&format!("Failed to create Send Transaction Request: {err}")) })? - .build() }; let send_transaction_execution_result = client @@ -221,7 +221,11 @@ impl WebClient { } let consume_transaction_request = - NativeTransactionRequestBuilder::consume_notes(result).build(); + NativeTransactionRequestBuilder::consume_notes(result).build().map_err(|err| { + JsValue::from_str(&format!( + "Failed to create Consume Transaction Request: {err}" + )) + })?; let consume_transaction_execution_result = client .new_transaction(account_id.into(), consume_transaction_request) @@ -284,7 +288,8 @@ impl WebClient { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let swap_transaction_execution_result = client .new_transaction(sender_account_id, swap_transaction_request.clone()) .await diff --git a/tests/integration/common.rs b/tests/integration/common.rs index de2245c7b..14f827292 100644 --- a/tests/integration/common.rs +++ b/tests/integration/common.rs @@ -332,7 +332,8 @@ pub async fn mint_note( client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(client, fungible_asset.faucet_id(), tx_request.clone()).await; // Check that note is committed and return it @@ -352,7 +353,8 @@ pub async fn consume_notes( println!("Consuming Note..."); let tx_request = TransactionRequestBuilder::consume_notes(input_notes.iter().map(|n| n.id()).collect()) - .build(); + .build() + .unwrap(); execute_tx_and_sync(client, account_id, tx_request).await; } @@ -384,7 +386,9 @@ pub async fn assert_note_cannot_be_consumed_twice( println!("Consuming Note..."); // Double-spend error expected to be received since we are consuming the same note - let tx_request = TransactionRequestBuilder::consume_notes(vec![note_to_consume_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note_to_consume_id]) + .build() + .unwrap(); match client.new_transaction(consuming_account_id, tx_request).await { Err(ClientError::TransactionExecutorError( TransactionExecutorError::FetchTransactionInputsFailed( @@ -419,5 +423,5 @@ pub fn mint_multiple_fungible_asset( }) .collect::>(); - TransactionRequestBuilder::new().with_own_output_notes(notes).unwrap().build() + TransactionRequestBuilder::new().with_own_output_notes(notes).build().unwrap() } diff --git a/tests/integration/custom_transactions_tests.rs b/tests/integration/custom_transactions_tests.rs index 256f75eec..002c8b4d0 100644 --- a/tests/integration/custom_transactions_tests.rs +++ b/tests/integration/custom_transactions_tests.rs @@ -101,9 +101,9 @@ async fn test_transaction_request() { let transaction_request = TransactionRequestBuilder::new() .with_authenticated_input_notes(note_args_map.clone()) .with_custom_script(tx_script) - .unwrap() .extend_advice_map(advice_map.clone()) - .build(); + .build() + .unwrap(); // This fails becuase of {asserted_value} having the incorrect number passed in assert!(client.new_transaction(regular_account.id(), transaction_request).await.is_err()); @@ -117,9 +117,9 @@ async fn test_transaction_request() { let transaction_request = TransactionRequestBuilder::new() .with_authenticated_input_notes(note_args_map) .with_custom_script(tx_script) - .unwrap() .extend_advice_map(advice_map) - .build(); + .build() + .unwrap(); // TEST CUSTOM SCRIPT SERIALIZATION let mut buffer = Vec::new(); @@ -214,10 +214,10 @@ async fn test_merkle_store() { let transaction_request = TransactionRequestBuilder::new() .with_authenticated_input_notes(note_args_map) .with_custom_script(tx_script) - .unwrap() .extend_advice_map(advice_map) .extend_merkle_store(merkle_store.inner_nodes()) - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client, regular_account.id(), transaction_request).await; @@ -235,8 +235,8 @@ async fn mint_custom_note( let transaction_request = TransactionRequestBuilder::new() .with_own_output_notes(vec![OutputNote::Full(note.clone())]) - .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(client, faucet_account_id, transaction_request).await; note diff --git a/tests/integration/fpi_tests.rs b/tests/integration/fpi_tests.rs index 3f5036067..1a789f234 100644 --- a/tests/integration/fpi_tests.rs +++ b/tests/integration/fpi_tests.rs @@ -70,8 +70,8 @@ async fn test_standard_fpi(storage_mode: AccountStorageMode) { foreign_account_id, TransactionRequestBuilder::new() .with_custom_script(deployment_tx_script) - .unwrap() - .build(), + .build() + .unwrap(), ) .await .unwrap(); @@ -125,7 +125,7 @@ async fn test_standard_fpi(storage_mode: AccountStorageMode) { assert!(foreign_accounts.is_empty()); // Create transaction request with FPI - let builder = TransactionRequestBuilder::new().with_custom_script(tx_script).unwrap(); + let builder = TransactionRequestBuilder::new().with_custom_script(tx_script); // We will require slot 0, key `MAP_KEY` as well as account proof let storage_requirements = @@ -142,7 +142,7 @@ async fn test_standard_fpi(storage_mode: AccountStorageMode) { ) }; - let tx_request = builder.with_foreign_accounts([foreign_account.unwrap()]).build(); + let tx_request = builder.with_foreign_accounts([foreign_account.unwrap()]).build().unwrap(); let tx_result = client.new_transaction(native_account.id(), tx_request).await.unwrap(); client.submit_transaction(tx_result).await.unwrap(); diff --git a/tests/integration/main.rs b/tests/integration/main.rs index 277d455fb..1dbc623e3 100644 --- a/tests/integration/main.rs +++ b/tests/integration/main.rs @@ -49,7 +49,8 @@ async fn test_added_notes() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); println!("Running Mint tx..."); execute_tx_and_sync(&mut client, faucet_account_header.id(), tx_request).await; @@ -85,7 +86,8 @@ async fn test_multiple_tx_on_same_block() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let tx_request_2 = TransactionRequestBuilder::pay_to_id( PaymentTransactionData::new(vec![Asset::Fungible(asset)], from_account_id, to_account_id), None, @@ -93,7 +95,8 @@ async fn test_multiple_tx_on_same_block() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); println!("Running P2ID tx..."); @@ -177,7 +180,8 @@ async fn test_p2id_transfer() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note = tx_request.expected_output_notes().next().unwrap().clone(); let transaction_id = execute_tx(&mut client, from_account_id, tx_request).await; @@ -207,7 +211,7 @@ async fn test_p2id_transfer() { // Consume P2ID note println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build().unwrap(); execute_tx_and_sync(&mut client, to_account_id, tx_request).await; // Ensure we have nothing else to consume @@ -270,7 +274,8 @@ async fn test_p2id_transfer_failing_not_enough_balance() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_failing_tx( &mut client, from_account_id, @@ -352,7 +357,8 @@ async fn test_p2idr_transfer_consumed_by_target() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client, from_account_id, tx_request.clone()).await; // Check that note is committed for the second account to consume @@ -363,7 +369,7 @@ async fn test_p2idr_transfer_consumed_by_target() { // Make the `to_account_id` consume P2IDR note let note_id = tx_request.expected_output_notes().next().unwrap().id(); println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note_id]).build().unwrap(); execute_tx_and_sync(&mut client, to_account_id, tx_request).await; let regular_account = client.get_account(from_account_id).await.unwrap().unwrap(); @@ -430,7 +436,8 @@ async fn test_p2idr_transfer_consumed_by_sender() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client, from_account_id, tx_request).await; // Check that note is committed @@ -440,7 +447,7 @@ async fn test_p2idr_transfer_consumed_by_sender() { // Check that it's still too early to consume println!("Consuming Note (too early)..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build().unwrap(); let transaction_execution_result = client.new_transaction(from_account_id, tx_request).await; assert!(transaction_execution_result.is_err_and(|err| { matches!( @@ -461,7 +468,7 @@ async fn test_p2idr_transfer_consumed_by_sender() { // Consume the note with the sender account println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build().unwrap(); execute_tx_and_sync(&mut client, from_account_id, tx_request).await; let regular_account = client.get_account(from_account_id).await.unwrap().unwrap(); @@ -521,7 +528,8 @@ async fn test_get_consumable_notes() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client, from_account_id, tx_request).await; // Check that note is consumable by both accounts @@ -589,7 +597,8 @@ async fn test_get_output_notes() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let output_note_id = tx_request.expected_output_notes().next().unwrap().id(); @@ -624,7 +633,8 @@ async fn test_import_expected_notes() { client_2.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note: InputNoteRecord = tx_request.expected_output_notes().next().unwrap().clone().into(); client_2.sync_state().await.unwrap(); @@ -658,7 +668,8 @@ async fn test_import_expected_notes() { client_2.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note: InputNoteRecord = tx_request.expected_output_notes().next().unwrap().clone().into(); // Import an uncommited note without verification @@ -709,7 +720,8 @@ async fn test_import_expected_note_uncommitted() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note: InputNoteRecord = tx_request.expected_output_notes().next().unwrap().clone().into(); client_2.sync_state().await.unwrap(); @@ -750,7 +762,8 @@ async fn test_import_expected_notes_from_the_past_as_committed() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note: InputNoteRecord = tx_request.expected_output_notes().next().unwrap().clone().into(); let block_height_before = client_1.get_sync_height().await.unwrap(); @@ -856,7 +869,8 @@ async fn test_sync_detail_values() { client1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note_id = tx_request.expected_output_notes().next().unwrap().id(); execute_tx_and_sync(&mut client1, from_account_id, tx_request).await; @@ -868,7 +882,7 @@ async fn test_sync_detail_values() { assert_eq!(new_details.updated_accounts.len(), 0); // Consume the note with the second account - let tx_request = TransactionRequestBuilder::consume_notes(vec![note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note_id]).build().unwrap(); execute_tx_and_sync(&mut client2, to_account_id, tx_request).await; // First client sync should have a new nullifier as the note was consumed @@ -903,7 +917,8 @@ async fn test_multiple_transactions_can_be_committed_in_different_blocks_without client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); println!("Executing transaction..."); let transaction_execution_result = @@ -930,7 +945,8 @@ async fn test_multiple_transactions_can_be_committed_in_different_blocks_without client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); println!("Executing transaction..."); let transaction_execution_result = @@ -967,7 +983,8 @@ async fn test_multiple_transactions_can_be_committed_in_different_blocks_without client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); println!("Executing transaction..."); let transaction_execution_result = @@ -1076,13 +1093,15 @@ async fn test_consume_multiple_expected_notes() { client_owned_notes.iter().map(|note| note.id()).collect(), ) .with_authenticated_input_notes(client_owned_notes.iter().map(|note| (note.id(), None))) - .build(); + .build() + .unwrap(); let tx_request_2 = TransactionRequestBuilder::consume_notes( unauth_owned_notes.iter().map(|note| note.id()).collect(), ) .with_unauthenticated_input_notes(unauth_owned_notes.iter().map(|note| ((*note).clone(), None))) - .build(); + .build() + .unwrap(); let tx_id_1 = execute_tx(&mut client, to_account_ids[0], tx_request_1).await; let tx_id_2 = execute_tx(&mut unauth_client, to_account_ids[1], tx_request_2).await; @@ -1155,7 +1174,8 @@ async fn test_import_consumed_note_with_proof() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; let note = client_1 .get_input_notes(NoteFilter::Committed) @@ -1168,7 +1188,7 @@ async fn test_import_consumed_note_with_proof() { // Consume the note with the sender account println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build().unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; // Import the consumed note @@ -1214,7 +1234,8 @@ async fn test_import_consumed_note_with_id() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; let note = client_1 .get_input_notes(NoteFilter::Committed) @@ -1227,7 +1248,7 @@ async fn test_import_consumed_note_with_id() { // Consume the note with the sender account println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build().unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; client_2.sync_state().await.unwrap(); @@ -1272,7 +1293,8 @@ async fn test_discarded_transaction() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; client_2.sync_state().await.unwrap(); @@ -1285,7 +1307,7 @@ async fn test_discarded_transaction() { .clone(); println!("Consuming Note..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![note.id()]).build().unwrap(); // Consume the note in client 1 but dont submit it to the node let tx_result = client_1.new_transaction(from_account_id, tx_request.clone()).await.unwrap(); @@ -1353,7 +1375,8 @@ async fn test_custom_transaction_prover() { client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let transaction_execution_result = client.new_transaction(faucet_account_id, tx_request.clone()).await.unwrap(); @@ -1464,8 +1487,8 @@ async fn test_expired_transaction_fails() { ) .unwrap() .with_expiration_delta(expiration_delta) - .unwrap() - .build(); + .build() + .unwrap(); println!("Executing transaction..."); let transaction_execution_result = diff --git a/tests/integration/onchain_tests.rs b/tests/integration/onchain_tests.rs index 13e03d762..073ae6e8a 100644 --- a/tests/integration/onchain_tests.rs +++ b/tests/integration/onchain_tests.rs @@ -52,7 +52,8 @@ async fn test_onchain_notes_flow() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note = tx_request.expected_output_notes().next().unwrap().clone(); execute_tx_and_sync(&mut client_1, faucet_account.id(), tx_request).await; @@ -87,7 +88,8 @@ async fn test_onchain_notes_flow() { client_2.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client_2, basic_wallet_1.id(), tx_request).await; // sync client 3 (basic account 2) @@ -240,7 +242,8 @@ async fn test_onchain_accounts() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client_1, from_account_id, tx_request).await; // sync on second client until we receive the note @@ -253,7 +256,7 @@ async fn test_onchain_accounts() { // Consume the note println!("Consuming note on second client..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![notes[0].id()]).build().unwrap(); execute_tx_and_sync(&mut client_2, to_account_id, tx_request).await; // sync on first client @@ -318,7 +321,8 @@ async fn test_onchain_notes_sync_with_tag() { client_1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let note = tx_request.expected_output_notes().next().unwrap().clone(); execute_tx_and_sync(&mut client_1, faucet_account.id(), tx_request).await; diff --git a/tests/integration/swap_transactions_tests.rs b/tests/integration/swap_transactions_tests.rs index 8410f879a..bc1eb3893 100644 --- a/tests/integration/swap_transactions_tests.rs +++ b/tests/integration/swap_transactions_tests.rs @@ -90,7 +90,9 @@ async fn test_swap_fully_onchain() { println!("Consuming mint note on first client..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![account_a_mint_note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![account_a_mint_note_id]) + .build() + .unwrap(); execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await; // Sync and consume note for accountB @@ -103,7 +105,9 @@ async fn test_swap_fully_onchain() { println!("Consuming mint note on second client..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![account_b_mint_note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![account_b_mint_note_id]) + .build() + .unwrap(); execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await; // Create ONCHAIN swap note (clientA offers 1 BTC in exchange of 25 ETH) @@ -124,7 +128,8 @@ async fn test_swap_fully_onchain() { client1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let expected_output_notes: Vec = tx_request.expected_output_notes().cloned().collect(); let expected_payback_note_details: Vec = @@ -152,8 +157,9 @@ async fn test_swap_fully_onchain() { client2.sync_state().await.unwrap(); println!("Consuming swap note on second client..."); - let tx_request = - TransactionRequestBuilder::consume_notes(vec![expected_output_notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![expected_output_notes[0].id()]) + .build() + .unwrap(); execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await; // sync on client 1, we should get the missing payback note details. @@ -163,7 +169,8 @@ async fn test_swap_fully_onchain() { let tx_request = TransactionRequestBuilder::consume_notes(vec![expected_payback_note_details[0].id()]) - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await; // At the end we should end up with @@ -300,7 +307,9 @@ async fn test_swap_private() { println!("Consuming mint note on first client..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![account_a_mint_note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![account_a_mint_note_id]) + .build() + .unwrap(); execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await; // Sync and consume note for accountB @@ -313,7 +322,9 @@ async fn test_swap_private() { println!("Consuming mint note on second client..."); - let tx_request = TransactionRequestBuilder::consume_notes(vec![account_b_mint_note_id]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![account_b_mint_note_id]) + .build() + .unwrap(); execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await; // Create ONCHAIN swap note (clientA offers 1 BTC in exchange of 25 ETH) @@ -334,7 +345,8 @@ async fn test_swap_private() { client1.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let expected_output_notes: Vec = tx_request.expected_output_notes().cloned().collect(); let expected_payback_note_details = @@ -370,8 +382,9 @@ async fn test_swap_private() { // consume swap note with accountB, and check that the vault changed appropiately println!("Consuming swap note on second client..."); - let tx_request = - TransactionRequestBuilder::consume_notes(vec![expected_output_notes[0].id()]).build(); + let tx_request = TransactionRequestBuilder::consume_notes(vec![expected_output_notes[0].id()]) + .build() + .unwrap(); execute_tx_and_sync(&mut client2, account_b.id(), tx_request).await; // sync on client 1, we should get the missing payback note details. @@ -381,7 +394,8 @@ async fn test_swap_private() { let tx_request = TransactionRequestBuilder::consume_notes(vec![expected_payback_note_details[0].id()]) - .build(); + .build() + .unwrap(); execute_tx_and_sync(&mut client1, account_a.id(), tx_request).await; // At the end we should end up with @@ -465,7 +479,8 @@ async fn mint( client.rng(), ) .unwrap() - .build(); + .build() + .unwrap(); let id = tx_request.expected_output_notes().next().unwrap().id(); execute_tx_and_sync(client, faucet_account_id, tx_request.clone()).await;