Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bitzoic committed Aug 15, 2024
1 parent 41435a2 commit a1c264a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 47 deletions.
77 changes: 44 additions & 33 deletions test/src/sdk-harness/test_artifacts/tx_contract/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ use std::{

abi TxContractTest {
fn get_tx_type() -> Transaction;
fn get_tx_tip() -> u64;
fn get_tx_tip() -> Option<u64>;
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<u32>;
fn get_tx_witness_limit() -> Option<u64>;
fn get_tx_max_fee() -> Option<u64>;
fn get_tx_script_length() -> Option<u64>;
fn get_tx_script_data_length() -> Option<u64>;
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<u64>;
fn get_tx_witness_data_length(index: u64) -> Option<u64>;
fn get_tx_witness_data(index: u64) -> Option<B512>;
fn get_tx_script_start_pointer() -> Option<u64>;
fn get_tx_script_data_start_pointer() -> Option<u64>;
fn get_tx_id() -> b256;
fn get_tx_script_bytecode_hash() -> b256;
fn get_tx_script_bytecode_hash() -> Option<b256>;

fn get_input_type(index: u64) -> Input;
fn get_tx_input_pointer(index: u64) -> u64;
Expand All @@ -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<u64> {
tx_tip()
}
fn get_script_gas_limit() -> u64 {
script_gas_limit()
}
fn get_tx_maturity() -> u64 {
tx_maturity().unwrap()
fn get_tx_maturity() -> Option<u32> {
tx_maturity()
}
fn get_tx_witness_limit() -> u64 {
tx_witness_limit().unwrap()
fn get_tx_witness_limit() -> Option<u64> {
tx_witness_limit()
}
fn get_tx_max_fee() -> u64 {
tx_max_fee().unwrap()
fn get_tx_max_fee() -> Option<u64> {
tx_max_fee()
}
fn get_tx_script_length() -> u64 {
fn get_tx_script_length() -> Option<u64> {
tx_script_length()
}
fn get_tx_script_data_length() -> u64 {
fn get_tx_script_data_length() -> Option<u64> {
tx_script_data_length()
}
fn get_tx_inputs_count() -> u64 {
Expand All @@ -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<u64> {
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<u64> {
tx_witness_data_length(index)
}
fn get_tx_witness_data(index: u64) -> B512 {
fn get_tx_witness_data(index: u64) -> Option<B512> {
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<u64> {
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<u64> {
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<b256> {
tx_script_bytecode_hash()
}
fn get_tx_input_pointer(index: u64) -> u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/src/sdk-harness/test_projects/script_data/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 29 additions & 11 deletions test/src/sdk-harness/test_projects/tx_fields/mod.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -266,7 +284,7 @@ mod tx {
.call()
.await
.unwrap();
assert_eq!(result.value, script_length);
assert_eq!(result.value, Some(script_length));
}

#[tokio::test]
Expand All @@ -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]
Expand Down Expand Up @@ -368,7 +386,7 @@ mod tx {
.await
.unwrap();

assert_eq!(response.value, 11024);
assert_eq!(response.value, Some(11024));
}

#[tokio::test]
Expand All @@ -382,7 +400,7 @@ mod tx {
.await
.unwrap();

assert_eq!(result.value, 64);
assert_eq!(result.value, Some(64));
}

#[tokio::test]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -478,7 +496,7 @@ mod tx {
.call()
.await
.unwrap();
assert_eq!(result.value, 10392)
assert_eq!(result.value, Some(10392))
}
}

Expand Down

0 comments on commit a1c264a

Please sign in to comment.