diff --git a/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw b/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw index 5755298265c..44593f43781 100644 --- a/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw +++ b/test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw @@ -16,23 +16,23 @@ use std::{ abi TxContractTest { fn get_tx_type() -> Transaction; - fn get_tx_tip() -> u64; + fn get_tx_tip() -> Option; fn get_script_gas_limit() -> u64; - fn get_tx_maturity() -> u64; - fn get_tx_witness_limit() -> u64; - fn get_tx_max_fee() -> u64; - fn get_tx_script_length() -> u64; - fn get_tx_script_data_length() -> u64; + fn get_tx_maturity() -> Option; + fn get_tx_witness_limit() -> Option; + fn get_tx_max_fee() -> Option; + fn get_tx_script_length() -> Option; + fn get_tx_script_data_length() -> Option; fn get_tx_inputs_count() -> u64; fn get_tx_outputs_count() -> u64; fn get_tx_witnesses_count() -> u64; - fn get_tx_witness_pointer(index: u64) -> u64; - fn get_tx_witness_data_length(index: u64) -> u64; - fn get_tx_witness_data(index: u64) -> B512; - fn get_tx_script_start_pointer() -> u64; - fn get_tx_script_data_start_pointer() -> u64; + fn get_tx_witness_pointer(index: u64) -> Option; + fn get_tx_witness_data_length(index: u64) -> Option; + fn get_tx_witness_data(index: u64) -> Option; + fn get_tx_script_start_pointer() -> Option; + fn get_tx_script_data_start_pointer() -> Option; fn get_tx_id() -> b256; - fn get_tx_script_bytecode_hash() -> b256; + fn get_tx_script_bytecode_hash() -> Option; fn get_input_type(index: u64) -> Input; fn get_tx_input_pointer(index: u64) -> u64; @@ -58,25 +58,25 @@ impl TxContractTest for Contract { fn get_tx_type() -> Transaction { tx_type() } - fn get_tx_tip() -> u64 { - tx_tip().unwrap() + fn get_tx_tip() -> Option { + tx_tip() } fn get_script_gas_limit() -> u64 { script_gas_limit() } - fn get_tx_maturity() -> u64 { - tx_maturity().unwrap() + fn get_tx_maturity() -> Option { + tx_maturity() } - fn get_tx_witness_limit() -> u64 { - tx_witness_limit().unwrap() + fn get_tx_witness_limit() -> Option { + tx_witness_limit() } - fn get_tx_max_fee() -> u64 { - tx_max_fee().unwrap() + fn get_tx_max_fee() -> Option { + tx_max_fee() } - fn get_tx_script_length() -> u64 { + fn get_tx_script_length() -> Option { tx_script_length() } - fn get_tx_script_data_length() -> u64 { + fn get_tx_script_data_length() -> Option { tx_script_data_length() } fn get_tx_inputs_count() -> u64 { @@ -88,29 +88,40 @@ impl TxContractTest for Contract { fn get_tx_witnesses_count() -> u64 { tx_witnesses_count() } - fn get_tx_witness_pointer(index: u64) -> u64 { - tx_witness_pointer(index) + fn get_tx_witness_pointer(index: u64) -> Option { + let ptr = tx_witness_pointer(index); + if ptr.is_none() { + return None + } + + Some(asm(r1: ptr.unwrap()) { r1: u64 }) } - fn get_tx_witness_data_length(index: u64) -> u64 { + fn get_tx_witness_data_length(index: u64) -> Option { tx_witness_data_length(index) } - fn get_tx_witness_data(index: u64) -> B512 { + fn get_tx_witness_data(index: u64) -> Option { tx_witness_data(index) } - fn get_tx_script_start_pointer() -> u64 { - asm(ptr: tx_script_start_pointer()) { - ptr: u64 + fn get_tx_script_start_pointer() -> Option { + let ptr = tx_script_start_pointer(); + if ptr.is_none() { + return None } + + Some(asm(r1: ptr.unwrap()) { r1: u64 }) } - fn get_tx_script_data_start_pointer() -> u64 { - asm(r1: tx_script_data_start_pointer()) { - r1: u64 + fn get_tx_script_data_start_pointer() -> Option { + let ptr = tx_script_data_start_pointer(); + if ptr.is_none() { + return None } + + Some(asm(r1: ptr.unwrap()) { r1: u64 }) } fn get_tx_id() -> b256 { tx_id() } - fn get_tx_script_bytecode_hash() -> b256 { + fn get_tx_script_bytecode_hash() -> Option { tx_script_bytecode_hash() } fn get_tx_input_pointer(index: u64) -> u64 { diff --git a/test/src/sdk-harness/test_projects/script_bytecode/src/main.sw b/test/src/sdk-harness/test_projects/script_bytecode/src/main.sw index 68a45321117..2d9b577e1e9 100644 --- a/test/src/sdk-harness/test_projects/script_bytecode/src/main.sw +++ b/test/src/sdk-harness/test_projects/script_bytecode/src/main.sw @@ -15,7 +15,7 @@ impl Hash for [u64; 35] { fn main() -> b256 { // length of return array is script length padded to nearest full word - let script_bytecode: [u64; 35] = tx_script_bytecode(); + let script_bytecode: [u64; 35] = tx_script_bytecode().unwrap(); // Return the hash of the bytecode to compare sha256(script_bytecode) diff --git a/test/src/sdk-harness/test_projects/script_data/src/main.sw b/test/src/sdk-harness/test_projects/script_data/src/main.sw index e61c4f7a205..b31962c175c 100644 --- a/test/src/sdk-harness/test_projects/script_data/src/main.sw +++ b/test/src/sdk-harness/test_projects/script_data/src/main.sw @@ -4,13 +4,13 @@ use std::tx::tx_script_data; fn main() { // Reference type - let received: b256 = tx_script_data(); + let received: b256 = tx_script_data().unwrap(); let expected: b256 = 0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a; log(received); assert(received == expected); // Copy type - let received: u64 = tx_script_data(); + let received: u64 = tx_script_data().unwrap(); let expected: u64 = 17259675764097085660; log(received); assert(received == expected); diff --git a/test/src/sdk-harness/test_projects/tx_fields/mod.rs b/test/src/sdk-harness/test_projects/tx_fields/mod.rs index 1eb4dda1a61..19f98a9965b 100644 --- a/test/src/sdk-harness/test_projects/tx_fields/mod.rs +++ b/test/src/sdk-harness/test_projects/tx_fields/mod.rs @@ -1,5 +1,5 @@ use fuel_vm::fuel_crypto::Hasher; -use fuel_vm::fuel_tx::{Bytes32, ConsensusParameters, ContractId, Input as TxInput}; +use fuel_vm::fuel_tx::{ConsensusParameters, ContractId, Input as TxInput}; use fuels::types::transaction_builders::TransactionBuilder; use fuels::{ accounts::{predicate::Predicate, wallet::WalletUnlocked, Account}, @@ -220,7 +220,16 @@ mod tx { .await .unwrap(); - assert_eq!(result.value, tip); + assert_eq!(result.value, Some(tip)); + + let no_tip = contract_instance + .methods() + .get_tx_tip() + .call() + .await + .unwrap(); + + assert_eq!(no_tip.value, None); } #[tokio::test] @@ -251,7 +260,16 @@ mod tx { .call() .await .unwrap(); - assert_eq!(result.value, maturity); + assert_eq!(result.value, Some(maturity as u32)); + + // Assert none is returned with no maturity + let no_maturity = contract_instance + .methods() + .get_tx_maturity() + .call() + .await + .unwrap(); + assert_eq!(no_maturity.value, None); } #[tokio::test] @@ -266,7 +284,7 @@ mod tx { .call() .await .unwrap(); - assert_eq!(result.value, script_length); + assert_eq!(result.value, Some(script_length)); } #[tokio::test] @@ -281,7 +299,7 @@ mod tx { .call() .await .unwrap(); - assert_eq!(result.value, script_data_length); + assert_eq!(result.value, Some(script_data_length)); } #[tokio::test] @@ -368,7 +386,7 @@ mod tx { .await .unwrap(); - assert_eq!(response.value, 11024); + assert_eq!(response.value, Some(11024)); } #[tokio::test] @@ -382,7 +400,7 @@ mod tx { .await .unwrap(); - assert_eq!(result.value, 64); + assert_eq!(result.value, Some(64)); } #[tokio::test] @@ -402,7 +420,7 @@ mod tx { .take_receipts_checked(None) .unwrap(); - assert_eq!(receipts[1].data().unwrap(), witnesses[0].as_vec()); + assert_eq!(receipts[1].data().unwrap()[8..72], *witnesses[0].as_vec()); } #[tokio::test] @@ -418,7 +436,7 @@ mod tx { .call() .await .unwrap(); - assert_eq!(result.value, script_start_offset as u64); + assert_eq!(result.value, Some(script_start_offset as u64)); } #[tokio::test] @@ -445,7 +463,7 @@ mod tx { .call() .await .unwrap(); - assert_eq!(Bytes32::from(result.value.0), hash); + assert_eq!(result.value.unwrap(), Bits256(*hash)); } #[tokio::test] @@ -478,7 +496,7 @@ mod tx { .call() .await .unwrap(); - assert_eq!(result.value, 10392) + assert_eq!(result.value, Some(10392)) } }