From 42e7b57ba7f5f66b3a18e917e4400ff84db20dc5 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 21 May 2026 20:40:15 +0300 Subject: [PATCH 01/23] added logical operations --- simf/logical_operations.simf | 17 ++++++++ simf/mock/logical_operations_mock.simf | 27 ++++++++++++ tests/logical_operations_test.rs | 59 ++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 simf/logical_operations.simf create mode 100644 simf/mock/logical_operations_mock.simf create mode 100644 tests/logical_operations_test.rs diff --git a/simf/logical_operations.simf b/simf/logical_operations.simf new file mode 100644 index 0000000..2d82f02 --- /dev/null +++ b/simf/logical_operations.simf @@ -0,0 +1,17 @@ +/// Returns the result of the NOT operation on the provided value +pub fn not(bit: bool) -> bool { + ::into(jet::complement_1(::into(bit))) +} + +/// Returns the result of the OR operation on the provided values +pub fn or(a: bool, b: bool) -> bool { + ::into(jet::or_1(::into(a), ::into(b))) +} + +/// Returns the result of the AND operation on the provided values +pub fn and(a: bool, b: bool) -> bool { + ::into(jet::and_1(::into(a), ::into(b))) +} + +// todo: remove after module functionality is implemented +fn main() {} diff --git a/simf/mock/logical_operations_mock.simf b/simf/mock/logical_operations_mock.simf new file mode 100644 index 0000000..355f582 --- /dev/null +++ b/simf/mock/logical_operations_mock.simf @@ -0,0 +1,27 @@ +// todo: switch to function import when available +pub fn not(bit: bool) -> bool { + ::into(jet::complement_1(::into(bit))) +} + +pub fn or(a: bool, b: bool) -> bool { + ::into(jet::or_1(::into(a), ::into(b))) +} + +pub fn and(a: bool, b: bool) -> bool { + ::into(jet::and_1(::into(a), ::into(b))) +} + +fn main() { + assert!(not(false)); + assert!(not((not(true)))); + + assert!(or(true, false)); + assert!(or(false, true)); + assert!(or(true, true)); + assert!(not(or(false, false))); + + assert!(and(true, true)); + assert!(not(and(true, false))); + assert!(not(and(false, true))); + assert!(not(and(false, false))); +} diff --git a/tests/logical_operations_test.rs b/tests/logical_operations_test.rs new file mode 100644 index 0000000..320d86c --- /dev/null +++ b/tests/logical_operations_test.rs @@ -0,0 +1,59 @@ +use simplex::simplicityhl::elements::{Script}; + +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +use simplicityhl_std::artifacts::mock::logical_operations_mock::LogicalOperationsMockProgram; +use simplicityhl_std::artifacts::mock::logical_operations_mock::derived_logical_operations_mock::{LogicalOperationsMockArguments, LogicalOperationsMockWitness}; + +fn get_script(context: &simplex::TestContext) -> (LogicalOperationsMockProgram, Script) { + let arguments = LogicalOperationsMockArguments {}; + + let logical_operations_program = LogicalOperationsMockProgram::new(arguments); + + let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + + (logical_operations_program, logical_operations_script) +} + +fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + + let (_, logical_operations_script) = get_script(context); + + let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + let provider = context.get_default_provider(); + + let (logical_operations_program, logical_operations_script) = get_script(context); + + let asserts_utxos = provider.fetch_scripthash_utxos(&logical_operations_script)?; + + let mut ft = FinalTransaction::new(); + + let witness = LogicalOperationsMockWitness {}; + + ft.add_program_input( + PartialInput::new(asserts_utxos[0].clone()), + ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + RequiredSignature::None, + ); + + let tx_receipt = signer.broadcast(&ft)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +#[simplex::test] +fn logical_operations_test(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script(&context)?; + + Ok(()) +} From 1bfbd07b18e3d4d653899b8d75abbab00e159770 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Mon, 25 May 2026 12:37:37 +0300 Subject: [PATCH 02/23] added functions for u16 --- simf/mock/u16_mock.simf | 71 +++++++++++++++++++++++++++++++++++++++++ simf/u16.simf | 48 ++++++++++++++++++++++++++++ tests/u16_test.rs | 59 ++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+) create mode 100644 simf/mock/u16_mock.simf create mode 100644 simf/u16.simf create mode 100644 tests/u16_test.rs diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf new file mode 100644 index 0000000..e54eb73 --- /dev/null +++ b/simf/mock/u16_mock.simf @@ -0,0 +1,71 @@ +// todo: switch to function import when available +pub fn checked_add_16(a: u16, b: u16) -> Option { + let (carry, sum): (bool, u16) = jet::add_16(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +pub fn safe_add_16(a: u16, b: u16) -> u16 { + unwrap(checked_add_16(a, b)) +} + +pub fn checked_subtract_16(a: u16, b: u16) -> Option { + let (borrow, diff): (bool, u16) = jet::subtract_16(a, b); + match borrow { + true => None, + false => Some(diff), + } +} + +pub fn safe_subtract_16(a: u16, b: u16) -> u16 { + unwrap(checked_subtract_16(a, b)) +} + +pub fn checked_multiply_16(a: u16, b: u16) -> Option { + let result: u32 = jet::multiply_16(a, b); + + let (high, low): (u16, u16) = ::into(result); + + match jet::is_zero_16(high) { + true => Some(low), + false => None, + } +} + +pub fn safe_multiply_16(a: u16, b: u16) -> u16 { + unwrap(checked_multiply_16(a, b)) +} + +fn main() { + let maxU16: u16 = 0xffff; + + let fittingU16: Option = checked_add_16(1, 2); + assert!(jet::eq_16(unwrap(fittingU16), 3)); + + let overflowingU16: Option = checked_add_16(maxU16, 1); + assert!(is_none::(overflowingU16)); + + let fittingU16: u16 = safe_add_16(1, 2); + assert!(jet::eq_16(fittingU16, 3)); + + let fittingU16: Option = checked_subtract_16(maxU16, 1); + assert!(jet::eq_16(unwrap(fittingU16), 0xfffe)); + + let overflowingU16: Option = checked_subtract_16(1, 2); + assert!(is_none::(overflowingU16)); + + let fittingU16: u16 = safe_subtract_16(10, 2); + assert!(jet::eq_16(fittingU16, 8)); + + let fittingU16: Option = checked_multiply_16(3, 2); + assert!(jet::eq_16(unwrap(fittingU16), 6)); + + let overflowingU16: Option = checked_multiply_16(maxU16, 2); + assert!(is_none::(overflowingU16)); + + let fittingU16: u16 = safe_multiply_16(1, 2); + assert!(jet::eq_16(fittingU16, 2)); +} diff --git a/simf/u16.simf b/simf/u16.simf new file mode 100644 index 0000000..f78eac1 --- /dev/null +++ b/simf/u16.simf @@ -0,0 +1,48 @@ +/// Returns the sum of two u16 values wrapped in Some, or None if the result overflows u16 +pub fn checked_add_16(a: u16, b: u16) -> Option { + let (carry, sum): (bool, u16) = jet::add_16(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +/// Returns the sum of two u16 values, panics if the result overflows u16 +pub fn safe_add_16(a: u16, b: u16) -> u16 { + unwrap(checked_add_16(a, b)) +} + +/// Returns the difference of two u16 values wrapped in Some, or None if the result overflows u16 +pub fn checked_subtract_16(a: u16, b: u16) -> Option { + let (borrow, diff): (bool, u16) = jet::subtract_16(a, b); + match borrow { + true => None, + false => Some(diff), + } +} + +/// Returns the difference of two u16 values, panics if the result overflows u16 +pub fn safe_subtract_16(a: u16, b: u16) -> u16 { + unwrap(checked_subtract_16(a, b)) +} + +/// Returns the product of two u16 values wrapped in Some, or None if the result overflows u16 +pub fn checked_multiply_16(a: u16, b: u16) -> Option { + let result: u32 = jet::multiply_16(a, b); + + let (high, low): (u16, u16) = ::into(result); + + match jet::is_zero_16(high) { + true => Some(low), + false => None, + } +} + +/// Returns the product of two u16 values, panics if the result overflows u16 +pub fn safe_multiply_16(a: u16, b: u16) -> u16 { + unwrap(checked_multiply_16(a, b)) +} + +// todo: remove after module functionality is implemented +fn main() {} \ No newline at end of file diff --git a/tests/u16_test.rs b/tests/u16_test.rs new file mode 100644 index 0000000..8ddcd18 --- /dev/null +++ b/tests/u16_test.rs @@ -0,0 +1,59 @@ +use simplex::simplicityhl::elements::{Script}; + +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +use simplicityhl_std::artifacts::mock::u16_mock::U16MockProgram; +use simplicityhl_std::artifacts::mock::u16_mock::derived_u16_mock::{U16MockArguments, U16MockWitness}; + +fn get_script(context: &simplex::TestContext) -> (U16MockProgram, Script) { + let arguments = U16MockArguments {}; + + let logical_operations_program = U16MockProgram::new(arguments); + + let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + + (logical_operations_program, logical_operations_script) +} + +fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + + let (_, logical_operations_script) = get_script(context); + + let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + let provider = context.get_default_provider(); + + let (logical_operations_program, logical_operations_script) = get_script(context); + + let asserts_utxos = provider.fetch_scripthash_utxos(&logical_operations_script)?; + + let mut ft = FinalTransaction::new(); + + let witness = U16MockWitness {}; + + ft.add_program_input( + PartialInput::new(asserts_utxos[0].clone()), + ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + RequiredSignature::None, + ); + + let tx_receipt = signer.broadcast(&ft)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +#[simplex::test] +fn u16_test(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script(&context)?; + + Ok(()) +} From 906ed04875da95580bab076f83003741b8c5e15b Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 27 May 2026 17:06:04 +0300 Subject: [PATCH 03/23] added functions for u32 --- simf/mock/u32_mock.simf | 72 +++++++++++++++++++++++++++++++++++++++++ simf/u32.simf | 49 ++++++++++++++++++++++++++++ tests/u32_test.rs | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 simf/mock/u32_mock.simf create mode 100644 simf/u32.simf create mode 100644 tests/u32_test.rs diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf new file mode 100644 index 0000000..53838da --- /dev/null +++ b/simf/mock/u32_mock.simf @@ -0,0 +1,72 @@ +// todo: switch to function import when available +pub fn checked_add_32(a: u32, b: u32) -> Option { + let (carry, sum): (bool, u32) = jet::add_32(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +pub fn safe_add_32(a: u32, b: u32) -> u32 { + unwrap(checked_add_32(a, b)) +} + +pub fn checked_subtract_32(a: u32, b: u32) -> Option { + let (borrow, diff): (bool, u32) = jet::subtract_32(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +pub fn safe_subtract_32(a: u32, b: u32) -> u32 { + unwrap(checked_subtract_32(a, b)) +} + +pub fn checked_multiply_32(a: u32, b: u32) -> Option { + let result: u64 = jet::multiply_32(a, b); + + let (high, low): (u32, u32) = ::into(result); + + match jet::is_zero_32(high) { + true => Some(low), + false => None, + } +} + +pub fn safe_multiply_32(a: u32, b: u32) -> u32 { + unwrap(checked_multiply_32(a, b)) +} + +fn main() { + let maxU32: u32 = 0xffffffff; + + let fittingU32: Option = checked_add_32(1, 2); + assert!(jet::eq_32(unwrap(fittingU32), 3)); + + let overflowingU32: Option = checked_add_32(maxU32, 1); + assert!(is_none::(overflowingU32)); + + let fittingU32: u32 = safe_add_32(1, 2); + assert!(jet::eq_32(fittingU32, 3)); + + let fittingU32: Option = checked_subtract_32(maxU32, 1); + assert!(jet::eq_32(unwrap(fittingU32), 0xfffffffe)); + + let overflowingU32: Option = checked_subtract_32(1, 2); + assert!(is_none::(overflowingU32)); + + let fittingU32: u32 = safe_subtract_32(10, 2); + assert!(jet::eq_32(fittingU32, 8)); + + let fittingU32: Option = checked_multiply_32(3, 2); + assert!(jet::eq_32(unwrap(fittingU32), 6)); + + let overflowingU32: Option = checked_multiply_32(maxU32, 2); + assert!(is_none::(overflowingU32)); + + let fittingU32: u32 = safe_multiply_32(1, 2); + assert!(jet::eq_32(fittingU32, 2)); +} diff --git a/simf/u32.simf b/simf/u32.simf new file mode 100644 index 0000000..a45d5a4 --- /dev/null +++ b/simf/u32.simf @@ -0,0 +1,49 @@ +/// Returns the sum of two u32 values wrapped in Some, or None if the result overflows u32 +pub fn checked_add_32(a: u32, b: u32) -> Option { + let (carry, sum): (bool, u32) = jet::add_32(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +/// Returns the sum of two u32 values, panics if the result overflows u32 +pub fn safe_add_32(a: u32, b: u32) -> u32 { + unwrap(checked_add_32(a, b)) +} + +/// Returns the sum of two u32 values, panics if the result overflows u32 +pub fn checked_subtract_32(a: u32, b: u32) -> Option { + let (borrow, diff): (bool, u32) = jet::subtract_32(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +/// Returns the difference of two u32 values, panics if the result overflows u32 +pub fn safe_subtract_32(a: u32, b: u32) -> u32 { + unwrap(checked_subtract_32(a, b)) +} + +/// Returns the product of two u32 values wrapped in Some, or None if the result overflows u32 +pub fn checked_multiply_32(a: u32, b: u32) -> Option { + let result: u64 = jet::multiply_32(a, b); + + let (high, low): (u32, u32) = ::into(result); + + match jet::is_zero_32(high) { + true => Some(low), + false => None, + } +} + +/// Returns the product of two u32 values, panics if the result overflows u32 +pub fn safe_multiply_32(a: u32, b: u32) -> u32 { + unwrap(checked_multiply_32(a, b)) +} + +// todo: remove after module functionality is implemented +fn main() {} diff --git a/tests/u32_test.rs b/tests/u32_test.rs new file mode 100644 index 0000000..280e5d6 --- /dev/null +++ b/tests/u32_test.rs @@ -0,0 +1,59 @@ +use simplex::simplicityhl::elements::{Script}; + +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +use simplicityhl_std::artifacts::mock::u32_mock::U32MockProgram; +use simplicityhl_std::artifacts::mock::u32_mock::derived_u32_mock::{U32MockArguments, U32MockWitness}; + +fn get_script(context: &simplex::TestContext) -> (U32MockProgram, Script) { + let arguments = U32MockArguments {}; + + let logical_operations_program = U32MockProgram::new(arguments); + + let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + + (logical_operations_program, logical_operations_script) +} + +fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + + let (_, logical_operations_script) = get_script(context); + + let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + let provider = context.get_default_provider(); + + let (logical_operations_program, logical_operations_script) = get_script(context); + + let asserts_utxos = provider.fetch_scripthash_utxos(&logical_operations_script)?; + + let mut ft = FinalTransaction::new(); + + let witness = U32MockWitness {}; + + ft.add_program_input( + PartialInput::new(asserts_utxos[0].clone()), + ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + RequiredSignature::None, + ); + + let tx_receipt = signer.broadcast(&ft)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +#[simplex::test] +fn u32_test(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script(&context)?; + + Ok(()) +} From 9ce71f0205991d819382e6f7b885a7bb43eab9fa Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 27 May 2026 17:12:08 +0300 Subject: [PATCH 04/23] added functions for u64 --- simf/mock/u64_mock.simf | 72 +++++++++++++++++++++++++++++++++++++++++ simf/u64.simf | 49 ++++++++++++++++++++++++++++ tests/u64_test.rs | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 simf/mock/u64_mock.simf create mode 100644 simf/u64.simf create mode 100644 tests/u64_test.rs diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf new file mode 100644 index 0000000..86e84ab --- /dev/null +++ b/simf/mock/u64_mock.simf @@ -0,0 +1,72 @@ +// todo: switch to function import when available +pub fn checked_add_64(a: u64, b: u64) -> Option { + let (carry, sum): (bool, u64) = jet::add_64(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +pub fn safe_add_64(a: u64, b: u64) -> u64 { + unwrap(checked_add_64(a, b)) +} + +pub fn checked_subtract_64(a: u64, b: u64) -> Option { + let (borrow, diff): (bool, u64) = jet::subtract_64(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +pub fn safe_subtract_64(a: u64, b: u64) -> u64 { + unwrap(checked_subtract_64(a, b)) +} + +pub fn checked_multiply_64(a: u64, b: u64) -> Option { + let result: u128 = jet::multiply_64(a, b); + + let (high, low): (u64, u64) = ::into(result); + + match jet::is_zero_64(high) { + true => Some(low), + false => None, + } +} + +pub fn safe_multiply_64(a: u64, b: u64) -> u64 { + unwrap(checked_multiply_64(a, b)) +} + +fn main() { + let maxU64: u64 = 0xffffffffffffffff; + + let fittingU64: Option = checked_add_64(1, 2); + assert!(jet::eq_64(unwrap(fittingU64), 3)); + + let overflowingU64: Option = checked_add_64(maxU64, 1); + assert!(is_none::(overflowingU64)); + + let fittingU64: u64 = safe_add_64(1, 2); + assert!(jet::eq_64(fittingU64, 3)); + + let fittingU64: Option = checked_subtract_64(maxU64, 1); + assert!(jet::eq_64(unwrap(fittingU64), 0xfffffffffffffffe)); + + let overflowingU64: Option = checked_subtract_64(1, 2); + assert!(is_none::(overflowingU64)); + + let fittingU64: u64 = safe_subtract_64(10, 2); + assert!(jet::eq_64(fittingU64, 8)); + + let fittingU64: Option = checked_multiply_64(3, 2); + assert!(jet::eq_64(unwrap(fittingU64), 6)); + + let overflowingU64: Option = checked_multiply_64(maxU64, 2); + assert!(is_none::(overflowingU64)); + + let fittingU64: u64 = safe_multiply_64(1, 2); + assert!(jet::eq_64(fittingU64, 2)); +} diff --git a/simf/u64.simf b/simf/u64.simf new file mode 100644 index 0000000..2577405 --- /dev/null +++ b/simf/u64.simf @@ -0,0 +1,49 @@ +/// Returns the sum of two u64 values wrapped in Some, or None if the result overflows u64 +pub fn checked_add_64(a: u64, b: u64) -> Option { + let (carry, sum): (bool, u64) = jet::add_64(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +/// Returns the sum of two u64 values, panics if the result overflows u64 +pub fn safe_add_64(a: u64, b: u64) -> u64 { + unwrap(checked_add_64(a, b)) +} + +/// Returns the sum of two u64 values, panics if the result overflows u64 +pub fn checked_subtract_64(a: u64, b: u64) -> Option { + let (borrow, diff): (bool, u64) = jet::subtract_64(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +/// Returns the difference of two u64 values, panics if the result overflows u64 +pub fn safe_subtract_64(a: u64, b: u64) -> u64 { + unwrap(checked_subtract_64(a, b)) +} + +/// Returns the product of two u64 values wrapped in Some, or None if the result overflows u64 +pub fn checked_multiply_64(a: u64, b: u64) -> Option { + let result: u128 = jet::multiply_64(a, b); + + let (high, low): (u64, u64) = ::into(result); + + match jet::is_zero_64(high) { + true => Some(low), + false => None, + } +} + +/// Returns the product of two u64 values, panics if the result overflows u64 +pub fn safe_multiply_64(a: u64, b: u64) -> u64 { + unwrap(checked_multiply_64(a, b)) +} + +// todo: remove after module functionality is implemented +fn main() {} diff --git a/tests/u64_test.rs b/tests/u64_test.rs new file mode 100644 index 0000000..9dce803 --- /dev/null +++ b/tests/u64_test.rs @@ -0,0 +1,59 @@ +use simplex::simplicityhl::elements::{Script}; + +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +use simplicityhl_std::artifacts::mock::u64_mock::U64MockProgram; +use simplicityhl_std::artifacts::mock::u64_mock::derived_u64_mock::{U64MockArguments, U64MockWitness}; + +fn get_script(context: &simplex::TestContext) -> (U64MockProgram, Script) { + let arguments = U64MockArguments {}; + + let logical_operations_program = U64MockProgram::new(arguments); + + let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + + (logical_operations_program, logical_operations_script) +} + +fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + + let (_, logical_operations_script) = get_script(context); + + let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + let provider = context.get_default_provider(); + + let (logical_operations_program, logical_operations_script) = get_script(context); + + let asserts_utxos = provider.fetch_scripthash_utxos(&logical_operations_script)?; + + let mut ft = FinalTransaction::new(); + + let witness = U64MockWitness {}; + + ft.add_program_input( + PartialInput::new(asserts_utxos[0].clone()), + ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + RequiredSignature::None, + ); + + let tx_receipt = signer.broadcast(&ft)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +#[simplex::test] +fn u64_test(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script(&context)?; + + Ok(()) +} From b24247c2f4a2eb18ceb3a45bf9225a6caeee7e2c Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 28 May 2026 11:59:43 +0300 Subject: [PATCH 05/23] added functions for u8 --- simf/mock/u8_mock.simf | 72 ++++++++++++++++++++++++++++++++++++++++++ simf/u8.simf | 49 ++++++++++++++++++++++++++++ tests/u8_test.rs | 59 ++++++++++++++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 simf/mock/u8_mock.simf create mode 100644 simf/u8.simf create mode 100644 tests/u8_test.rs diff --git a/simf/mock/u8_mock.simf b/simf/mock/u8_mock.simf new file mode 100644 index 0000000..f4670d5 --- /dev/null +++ b/simf/mock/u8_mock.simf @@ -0,0 +1,72 @@ +// todo: switch to function import when available +pub fn checked_add_8(a: u8, b: u8) -> Option { + let (carry, sum): (bool, u8) = jet::add_8(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +pub fn safe_add_8(a: u8, b: u8) -> u8 { + unwrap(checked_add_8(a, b)) +} + +pub fn checked_subtract_8(a: u8, b: u8) -> Option { + let (borrow, diff): (bool, u8) = jet::subtract_8(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +pub fn safe_subtract_8(a: u8, b: u8) -> u8 { + unwrap(checked_subtract_8(a, b)) +} + +pub fn checked_multiply_8(a: u8, b: u8) -> Option { + let result: u16 = jet::multiply_8(a, b); + + let (high, low): (u8, u8) = ::into(result); + + match jet::is_zero_8(high) { + true => Some(low), + false => None, + } +} + +pub fn safe_multiply_8(a: u8, b: u8) -> u8 { + unwrap(checked_multiply_8(a, b)) +} + +fn main() { + let maxU8: u8 = 0xff; + + let fittingU8: Option = checked_add_8(1, 2); + assert!(jet::eq_8(unwrap(fittingU8), 3)); + + let overflowingU8: Option = checked_add_8(maxU8, 1); + assert!(is_none::(overflowingU8)); + + let fittingU8: u8 = safe_add_8(1, 2); + assert!(jet::eq_8(fittingU8, 3)); + + let fittingU8: Option = checked_subtract_8(maxU8, 1); + assert!(jet::eq_8(unwrap(fittingU8), 0xfe)); + + let overflowingU8: Option = checked_subtract_8(1, 2); + assert!(is_none::(overflowingU8)); + + let fittingU8: u8 = safe_subtract_8(10, 2); + assert!(jet::eq_8(fittingU8, 8)); + + let fittingU8: Option = checked_multiply_8(3, 2); + assert!(jet::eq_8(unwrap(fittingU8), 6)); + + let overflowingU8: Option = checked_multiply_8(maxU8, 2); + assert!(is_none::(overflowingU8)); + + let fittingU8: u8 = safe_multiply_8(1, 2); + assert!(jet::eq_8(fittingU8, 2)); +} diff --git a/simf/u8.simf b/simf/u8.simf new file mode 100644 index 0000000..43fe792 --- /dev/null +++ b/simf/u8.simf @@ -0,0 +1,49 @@ +/// Returns the sum of two u8 values wrapped in Some, or None if the result overflows u8 +pub fn checked_add_8(a: u8, b: u8) -> Option { + let (carry, sum): (bool, u8) = jet::add_8(a, b); + + match carry { + true => None, + false => Some(sum), + } +} + +/// Returns the sum of two u8 values, panics if the result overflows u8 +pub fn safe_add_8(a: u8, b: u8) -> u8 { + unwrap(checked_add_8(a, b)) +} + +/// Returns the difference of two u8 values wrapped in Some, or None if the result overflows u8 +pub fn checked_subtract_8(a: u8, b: u8) -> Option { + let (borrow, diff): (bool, u8) = jet::subtract_8(a, b); + + match borrow { + true => None, + false => Some(diff), + } +} + +/// Returns the difference of two u8 values, panics if the result overflows u8 +pub fn safe_subtract_8(a: u8, b: u8) -> u8 { + unwrap(checked_subtract_8(a, b)) +} + +/// Returns the product of two u8 values wrapped in Some, or None if the result overflows u8 +pub fn checked_multiply_8(a: u8, b: u8) -> Option { + let result: u16 = jet::multiply_8(a, b); + + let (high, low): (u8, u8) = ::into(result); + + match jet::is_zero_8(high) { + true => Some(low), + false => None, + } +} + +/// Returns the product of two u8 values, panics if the result overflows u8 +pub fn safe_multiply_8(a: u8, b: u8) -> u8 { + unwrap(checked_multiply_8(a, b)) +} + +// todo: remove after module functionality is implemented +fn main() {} diff --git a/tests/u8_test.rs b/tests/u8_test.rs new file mode 100644 index 0000000..6ee5f9c --- /dev/null +++ b/tests/u8_test.rs @@ -0,0 +1,59 @@ +use simplex::simplicityhl::elements::{Script}; + +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +use simplicityhl_std::artifacts::mock::u8_mock::U8MockProgram; +use simplicityhl_std::artifacts::mock::u8_mock::derived_u8_mock::{U8MockArguments, U8MockWitness}; + +fn get_script(context: &simplex::TestContext) -> (U8MockProgram, Script) { + let arguments = U8MockArguments {}; + + let logical_operations_program = U8MockProgram::new(arguments); + + let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + + (logical_operations_program, logical_operations_script) +} + +fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + + let (_, logical_operations_script) = get_script(context); + + let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { + let signer = context.get_default_signer(); + let provider = context.get_default_provider(); + + let (logical_operations_program, logical_operations_script) = get_script(context); + + let asserts_utxos = provider.fetch_scripthash_utxos(&logical_operations_script)?; + + let mut ft = FinalTransaction::new(); + + let witness = U8MockWitness {}; + + ft.add_program_input( + PartialInput::new(asserts_utxos[0].clone()), + ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + RequiredSignature::None, + ); + + let tx_receipt = signer.broadcast(&ft)?; + println!("Broadcast: {}", tx_receipt); + + Ok(()) +} + +#[simplex::test] +fn u8_test(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script(&context)?; + + Ok(()) +} From 83dd81217845ef6c1fe9901d142b88f4caa8cde1 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Tue, 2 Jun 2026 19:16:20 +0300 Subject: [PATCH 06/23] added uint division --- simf/mock/u16_mock.simf | 24 ++++++++++++++++++++++++ simf/mock/u32_mock.simf | 24 ++++++++++++++++++++++++ simf/mock/u64_mock.simf | 24 ++++++++++++++++++++++++ simf/mock/u8_mock.simf | 24 ++++++++++++++++++++++++ simf/u16.simf | 15 ++++++++++++++- simf/u32.simf | 13 +++++++++++++ simf/u64.simf | 13 +++++++++++++ simf/u8.simf | 13 +++++++++++++ 8 files changed, 149 insertions(+), 1 deletion(-) diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf index e54eb73..f43b879 100644 --- a/simf/mock/u16_mock.simf +++ b/simf/mock/u16_mock.simf @@ -39,9 +39,21 @@ pub fn safe_multiply_16(a: u16, b: u16) -> u16 { unwrap(checked_multiply_16(a, b)) } +pub fn checked_divide_16(a: u16, b: u16) -> Option { + match jet::is_zero_16(b) { + true => None, + false => Some(jet::divide_16(a, b)), + } +} + +pub fn safe_divide_16(a: u16, b: u16) -> u16 { + unwrap(checked_divide_16(a, b)) +} + fn main() { let maxU16: u16 = 0xffff; + // add let fittingU16: Option = checked_add_16(1, 2); assert!(jet::eq_16(unwrap(fittingU16), 3)); @@ -51,6 +63,7 @@ fn main() { let fittingU16: u16 = safe_add_16(1, 2); assert!(jet::eq_16(fittingU16, 3)); + // substract let fittingU16: Option = checked_subtract_16(maxU16, 1); assert!(jet::eq_16(unwrap(fittingU16), 0xfffe)); @@ -60,6 +73,7 @@ fn main() { let fittingU16: u16 = safe_subtract_16(10, 2); assert!(jet::eq_16(fittingU16, 8)); + // multiply let fittingU16: Option = checked_multiply_16(3, 2); assert!(jet::eq_16(unwrap(fittingU16), 6)); @@ -68,4 +82,14 @@ fn main() { let fittingU16: u16 = safe_multiply_16(1, 2); assert!(jet::eq_16(fittingU16, 2)); + + // divide + let fittingU16: Option = checked_divide_16(4, 2); + assert!(jet::eq_16(unwrap(fittingU16), 2)); + + let overflowingU16: Option = checked_divide_16(maxU16, 0); + assert!(is_none::(overflowingU16)); + + let fittingU16: u16 = safe_divide_16(4, 2); + assert!(jet::eq_16(fittingU16, 2)); } diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf index 53838da..4ddad24 100644 --- a/simf/mock/u32_mock.simf +++ b/simf/mock/u32_mock.simf @@ -40,9 +40,21 @@ pub fn safe_multiply_32(a: u32, b: u32) -> u32 { unwrap(checked_multiply_32(a, b)) } +pub fn checked_divide_32(a: u32, b: u32) -> Option { + match jet::is_zero_32(b) { + true => None, + false => Some(jet::divide_32(a, b)), + } +} + +pub fn safe_divide_32(a: u32, b: u32) -> u32 { + unwrap(checked_divide_32(a, b)) +} + fn main() { let maxU32: u32 = 0xffffffff; + // add let fittingU32: Option = checked_add_32(1, 2); assert!(jet::eq_32(unwrap(fittingU32), 3)); @@ -52,6 +64,7 @@ fn main() { let fittingU32: u32 = safe_add_32(1, 2); assert!(jet::eq_32(fittingU32, 3)); + // substract let fittingU32: Option = checked_subtract_32(maxU32, 1); assert!(jet::eq_32(unwrap(fittingU32), 0xfffffffe)); @@ -61,6 +74,7 @@ fn main() { let fittingU32: u32 = safe_subtract_32(10, 2); assert!(jet::eq_32(fittingU32, 8)); + // multiply let fittingU32: Option = checked_multiply_32(3, 2); assert!(jet::eq_32(unwrap(fittingU32), 6)); @@ -69,4 +83,14 @@ fn main() { let fittingU32: u32 = safe_multiply_32(1, 2); assert!(jet::eq_32(fittingU32, 2)); + + // divide + let fittingU32: Option = checked_divide_32(4, 2); + assert!(jet::eq_32(unwrap(fittingU32), 2)); + + let overflowingU32: Option = checked_divide_32(5, 0); + assert!(is_none::(overflowingU32)); + + let fittingU32: u32 = safe_divide_32(5, 2); + assert!(jet::eq_32(fittingU32, 2)); } diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf index 86e84ab..626b17e 100644 --- a/simf/mock/u64_mock.simf +++ b/simf/mock/u64_mock.simf @@ -40,9 +40,21 @@ pub fn safe_multiply_64(a: u64, b: u64) -> u64 { unwrap(checked_multiply_64(a, b)) } +pub fn checked_divide_64(a: u64, b: u64) -> Option { + match jet::is_zero_64(b) { + true => None, + false => Some(jet::divide_64(a, b)), + } +} + +pub fn safe_divide_64(a: u64, b: u64) -> u64 { + unwrap(checked_divide_64(a, b)) +} + fn main() { let maxU64: u64 = 0xffffffffffffffff; + // add let fittingU64: Option = checked_add_64(1, 2); assert!(jet::eq_64(unwrap(fittingU64), 3)); @@ -52,6 +64,7 @@ fn main() { let fittingU64: u64 = safe_add_64(1, 2); assert!(jet::eq_64(fittingU64, 3)); + // substract let fittingU64: Option = checked_subtract_64(maxU64, 1); assert!(jet::eq_64(unwrap(fittingU64), 0xfffffffffffffffe)); @@ -61,6 +74,7 @@ fn main() { let fittingU64: u64 = safe_subtract_64(10, 2); assert!(jet::eq_64(fittingU64, 8)); + // multiply let fittingU64: Option = checked_multiply_64(3, 2); assert!(jet::eq_64(unwrap(fittingU64), 6)); @@ -69,4 +83,14 @@ fn main() { let fittingU64: u64 = safe_multiply_64(1, 2); assert!(jet::eq_64(fittingU64, 2)); + + // divide + let fittingU64: Option = checked_divide_64(4, 2); + assert!(jet::eq_64(unwrap(fittingU64), 2)); + + let overflowingU64: Option = checked_divide_64(5, 0); + assert!(is_none::(overflowingU64)); + + let fittingU64: u64 = safe_divide_64(5, 2); + assert!(jet::eq_64(fittingU64, 2)); } diff --git a/simf/mock/u8_mock.simf b/simf/mock/u8_mock.simf index f4670d5..dd93a4a 100644 --- a/simf/mock/u8_mock.simf +++ b/simf/mock/u8_mock.simf @@ -40,9 +40,21 @@ pub fn safe_multiply_8(a: u8, b: u8) -> u8 { unwrap(checked_multiply_8(a, b)) } +pub fn checked_divide_8(a: u8, b: u8) -> Option { + match jet::is_zero_8(b) { + true => None, + false => Some(jet::divide_8(a, b)), + } +} + +pub fn safe_divide_8(a: u8, b: u8) -> u8 { + unwrap(checked_divide_8(a, b)) +} + fn main() { let maxU8: u8 = 0xff; + // add let fittingU8: Option = checked_add_8(1, 2); assert!(jet::eq_8(unwrap(fittingU8), 3)); @@ -52,6 +64,7 @@ fn main() { let fittingU8: u8 = safe_add_8(1, 2); assert!(jet::eq_8(fittingU8, 3)); + // substract let fittingU8: Option = checked_subtract_8(maxU8, 1); assert!(jet::eq_8(unwrap(fittingU8), 0xfe)); @@ -61,6 +74,7 @@ fn main() { let fittingU8: u8 = safe_subtract_8(10, 2); assert!(jet::eq_8(fittingU8, 8)); + // multiply let fittingU8: Option = checked_multiply_8(3, 2); assert!(jet::eq_8(unwrap(fittingU8), 6)); @@ -69,4 +83,14 @@ fn main() { let fittingU8: u8 = safe_multiply_8(1, 2); assert!(jet::eq_8(fittingU8, 2)); + + // divide + let fittingU8: Option = checked_divide_8(4, 2); + assert!(jet::eq_8(unwrap(fittingU8), 2)); + + let overflowingU8: Option = checked_divide_8(5, 0); + assert!(is_none::(overflowingU8)); + + let fittingU8: u8 = safe_divide_8(5, 2); + assert!(jet::eq_8(fittingU8, 2)); } diff --git a/simf/u16.simf b/simf/u16.simf index f78eac1..82e75fa 100644 --- a/simf/u16.simf +++ b/simf/u16.simf @@ -44,5 +44,18 @@ pub fn safe_multiply_16(a: u16, b: u16) -> u16 { unwrap(checked_multiply_16(a, b)) } +/// Returns the quotient of two u16 values wrapped in Some, or None if the result overflows u16 +pub fn checked_divide_16(a: u16, b: u16) -> Option { + match jet::is_zero_16(b) { + true => None, + false => Some(jet::divide_16(a, b)), + } +} + +/// Returns the quotient of two u16 values, panics if the result overflows u16 +pub fn safe_divide_16(a: u16, b: u16) -> u16 { + unwrap(checked_divide_16(a, b)) +} + // todo: remove after module functionality is implemented -fn main() {} \ No newline at end of file +fn main() {} diff --git a/simf/u32.simf b/simf/u32.simf index a45d5a4..9c134fe 100644 --- a/simf/u32.simf +++ b/simf/u32.simf @@ -45,5 +45,18 @@ pub fn safe_multiply_32(a: u32, b: u32) -> u32 { unwrap(checked_multiply_32(a, b)) } +/// Returns the quotient of two u32 values wrapped in Some, or None if the result overflows u32 +pub fn checked_divide_32(a: u32, b: u32) -> Option { + match jet::is_zero_32(b) { + true => None, + false => Some(jet::divide_32(a, b)), + } +} + +/// Returns the quotient of two u32 values, panics if the result overflows u32 +pub fn safe_divide_32(a: u32, b: u32) -> u32 { + unwrap(checked_divide_32(a, b)) +} + // todo: remove after module functionality is implemented fn main() {} diff --git a/simf/u64.simf b/simf/u64.simf index 2577405..e583a51 100644 --- a/simf/u64.simf +++ b/simf/u64.simf @@ -45,5 +45,18 @@ pub fn safe_multiply_64(a: u64, b: u64) -> u64 { unwrap(checked_multiply_64(a, b)) } +/// Returns the quotient of two u64 values wrapped in Some, or None if the result overflows u64 +pub fn checked_divide_64(a: u64, b: u64) -> Option { + match jet::is_zero_64(b) { + true => None, + false => Some(jet::divide_64(a, b)), + } +} + +/// Returns the quotient of two u64 values, panics if the result overflows u64 +pub fn safe_divide_64(a: u64, b: u64) -> u64 { + unwrap(checked_divide_64(a, b)) +} + // todo: remove after module functionality is implemented fn main() {} diff --git a/simf/u8.simf b/simf/u8.simf index 43fe792..f857b01 100644 --- a/simf/u8.simf +++ b/simf/u8.simf @@ -45,5 +45,18 @@ pub fn safe_multiply_8(a: u8, b: u8) -> u8 { unwrap(checked_multiply_8(a, b)) } +/// Returns the quotient of two u8 values wrapped in Some, or None if the result overflows u8 +pub fn checked_divide_8(a: u8, b: u8) -> Option { + match jet::is_zero_8(b) { + true => None, + false => Some(jet::divide_8(a, b)), + } +} + +/// Returns the quotient of two u8 values, panics if the result overflows u8 +pub fn safe_divide_8(a: u8, b: u8) -> u8 { + unwrap(checked_divide_8(a, b)) +} + // todo: remove after module functionality is implemented fn main() {} From 651e652d6db5a443c742fd0915a197f75f51030e Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 12:36:43 +0300 Subject: [PATCH 07/23] removed unsuported "pub" modifier for now --- simf/asserts.simf | 22 +++++++++++----------- simf/logical_operations.simf | 6 +++--- simf/mock/asserts_mock.simf | 22 +++++++++++----------- simf/mock/logical_operations_mock.simf | 6 +++--- simf/mock/u16_mock.simf | 16 ++++++++-------- simf/mock/u32_mock.simf | 16 ++++++++-------- simf/mock/u64_mock.simf | 16 ++++++++-------- simf/mock/u8_mock.simf | 16 ++++++++-------- simf/u16.simf | 16 ++++++++-------- simf/u32.simf | 16 ++++++++-------- simf/u64.simf | 16 ++++++++-------- simf/u8.simf | 16 ++++++++-------- 12 files changed, 92 insertions(+), 92 deletions(-) diff --git a/simf/asserts.simf b/simf/asserts.simf index a95ba99..0085d2d 100644 --- a/simf/asserts.simf +++ b/simf/asserts.simf @@ -1,55 +1,55 @@ /// Asserts that two u8 are equal -pub fn assert_eq8(a: u8, b: u8) { +fn assert_eq8(a: u8, b: u8) { assert!(jet::eq_8(a, b)); } /// Asserts that two u16 are equal -pub fn assert_eq16(a: u16, b: u16) { +fn assert_eq16(a: u16, b: u16) { assert!(jet::eq_16(a, b)); } /// Asserts that two u32 are equal -pub fn assert_eq32(a: u32, b: u32) { +fn assert_eq32(a: u32, b: u32) { assert!(jet::eq_32(a, b)); } /// Asserts that two u64 are equal -pub fn assert_eq64(a: u64, b: u64) { +fn assert_eq64(a: u64, b: u64) { assert!(jet::eq_64(a, b)); } /// Asserts that two u256 are equal -pub fn assert_eq256(a: u256, b: u256) { +fn assert_eq256(a: u256, b: u256) { assert!(jet::eq_256(a, b)); } /// Asserts that provided u8 Option value is a None -pub fn assert_none8(val: Option) { +fn assert_none8(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u16 Option value is a None -pub fn assert_none16(val: Option) { +fn assert_none16(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u32 Option value is a None -pub fn assert_none32(val: Option) { +fn assert_none32(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u64 Option value is a None -pub fn assert_none64(val: Option) { +fn assert_none64(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u128 Option value is a None -pub fn assert_none128(val: Option) { +fn assert_none128(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u256 Option value is a None -pub fn assert_none256(val: Option) { +fn assert_none256(val: Option) { assert!(is_none::(val)); } diff --git a/simf/logical_operations.simf b/simf/logical_operations.simf index 2d82f02..a8b94de 100644 --- a/simf/logical_operations.simf +++ b/simf/logical_operations.simf @@ -1,15 +1,15 @@ /// Returns the result of the NOT operation on the provided value -pub fn not(bit: bool) -> bool { +fn not(bit: bool) -> bool { ::into(jet::complement_1(::into(bit))) } /// Returns the result of the OR operation on the provided values -pub fn or(a: bool, b: bool) -> bool { +fn or(a: bool, b: bool) -> bool { ::into(jet::or_1(::into(a), ::into(b))) } /// Returns the result of the AND operation on the provided values -pub fn and(a: bool, b: bool) -> bool { +fn and(a: bool, b: bool) -> bool { ::into(jet::and_1(::into(a), ::into(b))) } diff --git a/simf/mock/asserts_mock.simf b/simf/mock/asserts_mock.simf index f20b8c8..5004777 100644 --- a/simf/mock/asserts_mock.simf +++ b/simf/mock/asserts_mock.simf @@ -1,45 +1,45 @@ // todo: switch to function import when available -pub fn assert_eq8(a: u8, b: u8) { // 1 +fn assert_eq8(a: u8, b: u8) { // 1 assert!(jet::eq_8(a, b)); } -pub fn assert_eq16(a: u16, b: u16) { // 2 +fn assert_eq16(a: u16, b: u16) { // 2 assert!(jet::eq_16(a, b)); } -pub fn assert_eq32(a: u32, b: u32) { // 3 +fn assert_eq32(a: u32, b: u32) { // 3 assert!(jet::eq_32(a, b)); } -pub fn assert_eq64(a: u64, b: u64) { // 4 +fn assert_eq64(a: u64, b: u64) { // 4 assert!(jet::eq_64(a, b)); } -pub fn assert_eq256(a: u256, b: u256) { // 5 +fn assert_eq256(a: u256, b: u256) { // 5 assert!(jet::eq_256(a, b)); } -pub fn assert_none8(val: Option) { // 6 +fn assert_none8(val: Option) { // 6 assert!(is_none::(val)); } -pub fn assert_none16(val: Option) { // 7 +fn assert_none16(val: Option) { // 7 assert!(is_none::(val)); } -pub fn assert_none32(val: Option) { // 8 +fn assert_none32(val: Option) { // 8 assert!(is_none::(val)); } -pub fn assert_none64(val: Option) { // 9 +fn assert_none64(val: Option) { // 9 assert!(is_none::(val)); } -pub fn assert_none128(val: Option) { // 10 +fn assert_none128(val: Option) { // 10 assert!(is_none::(val)); } -pub fn assert_none256(val: Option) { // 11 +fn assert_none256(val: Option) { // 11 assert!(is_none::(val)); } diff --git a/simf/mock/logical_operations_mock.simf b/simf/mock/logical_operations_mock.simf index 355f582..4ab4e22 100644 --- a/simf/mock/logical_operations_mock.simf +++ b/simf/mock/logical_operations_mock.simf @@ -1,13 +1,13 @@ // todo: switch to function import when available -pub fn not(bit: bool) -> bool { +fn not(bit: bool) -> bool { ::into(jet::complement_1(::into(bit))) } -pub fn or(a: bool, b: bool) -> bool { +fn or(a: bool, b: bool) -> bool { ::into(jet::or_1(::into(a), ::into(b))) } -pub fn and(a: bool, b: bool) -> bool { +fn and(a: bool, b: bool) -> bool { ::into(jet::and_1(::into(a), ::into(b))) } diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf index f43b879..5484606 100644 --- a/simf/mock/u16_mock.simf +++ b/simf/mock/u16_mock.simf @@ -1,5 +1,5 @@ // todo: switch to function import when available -pub fn checked_add_16(a: u16, b: u16) -> Option { +fn checked_add_16(a: u16, b: u16) -> Option { let (carry, sum): (bool, u16) = jet::add_16(a, b); match carry { @@ -8,11 +8,11 @@ pub fn checked_add_16(a: u16, b: u16) -> Option { } } -pub fn safe_add_16(a: u16, b: u16) -> u16 { +fn safe_add_16(a: u16, b: u16) -> u16 { unwrap(checked_add_16(a, b)) } -pub fn checked_subtract_16(a: u16, b: u16) -> Option { +fn checked_subtract_16(a: u16, b: u16) -> Option { let (borrow, diff): (bool, u16) = jet::subtract_16(a, b); match borrow { true => None, @@ -20,11 +20,11 @@ pub fn checked_subtract_16(a: u16, b: u16) -> Option { } } -pub fn safe_subtract_16(a: u16, b: u16) -> u16 { +fn safe_subtract_16(a: u16, b: u16) -> u16 { unwrap(checked_subtract_16(a, b)) } -pub fn checked_multiply_16(a: u16, b: u16) -> Option { +fn checked_multiply_16(a: u16, b: u16) -> Option { let result: u32 = jet::multiply_16(a, b); let (high, low): (u16, u16) = ::into(result); @@ -35,18 +35,18 @@ pub fn checked_multiply_16(a: u16, b: u16) -> Option { } } -pub fn safe_multiply_16(a: u16, b: u16) -> u16 { +fn safe_multiply_16(a: u16, b: u16) -> u16 { unwrap(checked_multiply_16(a, b)) } -pub fn checked_divide_16(a: u16, b: u16) -> Option { +fn checked_divide_16(a: u16, b: u16) -> Option { match jet::is_zero_16(b) { true => None, false => Some(jet::divide_16(a, b)), } } -pub fn safe_divide_16(a: u16, b: u16) -> u16 { +fn safe_divide_16(a: u16, b: u16) -> u16 { unwrap(checked_divide_16(a, b)) } diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf index 4ddad24..10df2b7 100644 --- a/simf/mock/u32_mock.simf +++ b/simf/mock/u32_mock.simf @@ -1,5 +1,5 @@ // todo: switch to function import when available -pub fn checked_add_32(a: u32, b: u32) -> Option { +fn checked_add_32(a: u32, b: u32) -> Option { let (carry, sum): (bool, u32) = jet::add_32(a, b); match carry { @@ -8,11 +8,11 @@ pub fn checked_add_32(a: u32, b: u32) -> Option { } } -pub fn safe_add_32(a: u32, b: u32) -> u32 { +fn safe_add_32(a: u32, b: u32) -> u32 { unwrap(checked_add_32(a, b)) } -pub fn checked_subtract_32(a: u32, b: u32) -> Option { +fn checked_subtract_32(a: u32, b: u32) -> Option { let (borrow, diff): (bool, u32) = jet::subtract_32(a, b); match borrow { @@ -21,11 +21,11 @@ pub fn checked_subtract_32(a: u32, b: u32) -> Option { } } -pub fn safe_subtract_32(a: u32, b: u32) -> u32 { +fn safe_subtract_32(a: u32, b: u32) -> u32 { unwrap(checked_subtract_32(a, b)) } -pub fn checked_multiply_32(a: u32, b: u32) -> Option { +fn checked_multiply_32(a: u32, b: u32) -> Option { let result: u64 = jet::multiply_32(a, b); let (high, low): (u32, u32) = ::into(result); @@ -36,18 +36,18 @@ pub fn checked_multiply_32(a: u32, b: u32) -> Option { } } -pub fn safe_multiply_32(a: u32, b: u32) -> u32 { +fn safe_multiply_32(a: u32, b: u32) -> u32 { unwrap(checked_multiply_32(a, b)) } -pub fn checked_divide_32(a: u32, b: u32) -> Option { +fn checked_divide_32(a: u32, b: u32) -> Option { match jet::is_zero_32(b) { true => None, false => Some(jet::divide_32(a, b)), } } -pub fn safe_divide_32(a: u32, b: u32) -> u32 { +fn safe_divide_32(a: u32, b: u32) -> u32 { unwrap(checked_divide_32(a, b)) } diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf index 626b17e..5c2a7b3 100644 --- a/simf/mock/u64_mock.simf +++ b/simf/mock/u64_mock.simf @@ -1,5 +1,5 @@ // todo: switch to function import when available -pub fn checked_add_64(a: u64, b: u64) -> Option { +fn checked_add_64(a: u64, b: u64) -> Option { let (carry, sum): (bool, u64) = jet::add_64(a, b); match carry { @@ -8,11 +8,11 @@ pub fn checked_add_64(a: u64, b: u64) -> Option { } } -pub fn safe_add_64(a: u64, b: u64) -> u64 { +fn safe_add_64(a: u64, b: u64) -> u64 { unwrap(checked_add_64(a, b)) } -pub fn checked_subtract_64(a: u64, b: u64) -> Option { +fn checked_subtract_64(a: u64, b: u64) -> Option { let (borrow, diff): (bool, u64) = jet::subtract_64(a, b); match borrow { @@ -21,11 +21,11 @@ pub fn checked_subtract_64(a: u64, b: u64) -> Option { } } -pub fn safe_subtract_64(a: u64, b: u64) -> u64 { +fn safe_subtract_64(a: u64, b: u64) -> u64 { unwrap(checked_subtract_64(a, b)) } -pub fn checked_multiply_64(a: u64, b: u64) -> Option { +fn checked_multiply_64(a: u64, b: u64) -> Option { let result: u128 = jet::multiply_64(a, b); let (high, low): (u64, u64) = ::into(result); @@ -36,18 +36,18 @@ pub fn checked_multiply_64(a: u64, b: u64) -> Option { } } -pub fn safe_multiply_64(a: u64, b: u64) -> u64 { +fn safe_multiply_64(a: u64, b: u64) -> u64 { unwrap(checked_multiply_64(a, b)) } -pub fn checked_divide_64(a: u64, b: u64) -> Option { +fn checked_divide_64(a: u64, b: u64) -> Option { match jet::is_zero_64(b) { true => None, false => Some(jet::divide_64(a, b)), } } -pub fn safe_divide_64(a: u64, b: u64) -> u64 { +fn safe_divide_64(a: u64, b: u64) -> u64 { unwrap(checked_divide_64(a, b)) } diff --git a/simf/mock/u8_mock.simf b/simf/mock/u8_mock.simf index dd93a4a..3cd23bc 100644 --- a/simf/mock/u8_mock.simf +++ b/simf/mock/u8_mock.simf @@ -1,5 +1,5 @@ // todo: switch to function import when available -pub fn checked_add_8(a: u8, b: u8) -> Option { +fn checked_add_8(a: u8, b: u8) -> Option { let (carry, sum): (bool, u8) = jet::add_8(a, b); match carry { @@ -8,11 +8,11 @@ pub fn checked_add_8(a: u8, b: u8) -> Option { } } -pub fn safe_add_8(a: u8, b: u8) -> u8 { +fn safe_add_8(a: u8, b: u8) -> u8 { unwrap(checked_add_8(a, b)) } -pub fn checked_subtract_8(a: u8, b: u8) -> Option { +fn checked_subtract_8(a: u8, b: u8) -> Option { let (borrow, diff): (bool, u8) = jet::subtract_8(a, b); match borrow { @@ -21,11 +21,11 @@ pub fn checked_subtract_8(a: u8, b: u8) -> Option { } } -pub fn safe_subtract_8(a: u8, b: u8) -> u8 { +fn safe_subtract_8(a: u8, b: u8) -> u8 { unwrap(checked_subtract_8(a, b)) } -pub fn checked_multiply_8(a: u8, b: u8) -> Option { +fn checked_multiply_8(a: u8, b: u8) -> Option { let result: u16 = jet::multiply_8(a, b); let (high, low): (u8, u8) = ::into(result); @@ -36,18 +36,18 @@ pub fn checked_multiply_8(a: u8, b: u8) -> Option { } } -pub fn safe_multiply_8(a: u8, b: u8) -> u8 { +fn safe_multiply_8(a: u8, b: u8) -> u8 { unwrap(checked_multiply_8(a, b)) } -pub fn checked_divide_8(a: u8, b: u8) -> Option { +fn checked_divide_8(a: u8, b: u8) -> Option { match jet::is_zero_8(b) { true => None, false => Some(jet::divide_8(a, b)), } } -pub fn safe_divide_8(a: u8, b: u8) -> u8 { +fn safe_divide_8(a: u8, b: u8) -> u8 { unwrap(checked_divide_8(a, b)) } diff --git a/simf/u16.simf b/simf/u16.simf index 82e75fa..c44ef13 100644 --- a/simf/u16.simf +++ b/simf/u16.simf @@ -1,5 +1,5 @@ /// Returns the sum of two u16 values wrapped in Some, or None if the result overflows u16 -pub fn checked_add_16(a: u16, b: u16) -> Option { +fn checked_add_16(a: u16, b: u16) -> Option { let (carry, sum): (bool, u16) = jet::add_16(a, b); match carry { @@ -9,12 +9,12 @@ pub fn checked_add_16(a: u16, b: u16) -> Option { } /// Returns the sum of two u16 values, panics if the result overflows u16 -pub fn safe_add_16(a: u16, b: u16) -> u16 { +fn safe_add_16(a: u16, b: u16) -> u16 { unwrap(checked_add_16(a, b)) } /// Returns the difference of two u16 values wrapped in Some, or None if the result overflows u16 -pub fn checked_subtract_16(a: u16, b: u16) -> Option { +fn checked_subtract_16(a: u16, b: u16) -> Option { let (borrow, diff): (bool, u16) = jet::subtract_16(a, b); match borrow { true => None, @@ -23,12 +23,12 @@ pub fn checked_subtract_16(a: u16, b: u16) -> Option { } /// Returns the difference of two u16 values, panics if the result overflows u16 -pub fn safe_subtract_16(a: u16, b: u16) -> u16 { +fn safe_subtract_16(a: u16, b: u16) -> u16 { unwrap(checked_subtract_16(a, b)) } /// Returns the product of two u16 values wrapped in Some, or None if the result overflows u16 -pub fn checked_multiply_16(a: u16, b: u16) -> Option { +fn checked_multiply_16(a: u16, b: u16) -> Option { let result: u32 = jet::multiply_16(a, b); let (high, low): (u16, u16) = ::into(result); @@ -40,12 +40,12 @@ pub fn checked_multiply_16(a: u16, b: u16) -> Option { } /// Returns the product of two u16 values, panics if the result overflows u16 -pub fn safe_multiply_16(a: u16, b: u16) -> u16 { +fn safe_multiply_16(a: u16, b: u16) -> u16 { unwrap(checked_multiply_16(a, b)) } /// Returns the quotient of two u16 values wrapped in Some, or None if the result overflows u16 -pub fn checked_divide_16(a: u16, b: u16) -> Option { +fn checked_divide_16(a: u16, b: u16) -> Option { match jet::is_zero_16(b) { true => None, false => Some(jet::divide_16(a, b)), @@ -53,7 +53,7 @@ pub fn checked_divide_16(a: u16, b: u16) -> Option { } /// Returns the quotient of two u16 values, panics if the result overflows u16 -pub fn safe_divide_16(a: u16, b: u16) -> u16 { +fn safe_divide_16(a: u16, b: u16) -> u16 { unwrap(checked_divide_16(a, b)) } diff --git a/simf/u32.simf b/simf/u32.simf index 9c134fe..a7113ab 100644 --- a/simf/u32.simf +++ b/simf/u32.simf @@ -1,5 +1,5 @@ /// Returns the sum of two u32 values wrapped in Some, or None if the result overflows u32 -pub fn checked_add_32(a: u32, b: u32) -> Option { +fn checked_add_32(a: u32, b: u32) -> Option { let (carry, sum): (bool, u32) = jet::add_32(a, b); match carry { @@ -9,12 +9,12 @@ pub fn checked_add_32(a: u32, b: u32) -> Option { } /// Returns the sum of two u32 values, panics if the result overflows u32 -pub fn safe_add_32(a: u32, b: u32) -> u32 { +fn safe_add_32(a: u32, b: u32) -> u32 { unwrap(checked_add_32(a, b)) } /// Returns the sum of two u32 values, panics if the result overflows u32 -pub fn checked_subtract_32(a: u32, b: u32) -> Option { +fn checked_subtract_32(a: u32, b: u32) -> Option { let (borrow, diff): (bool, u32) = jet::subtract_32(a, b); match borrow { @@ -24,12 +24,12 @@ pub fn checked_subtract_32(a: u32, b: u32) -> Option { } /// Returns the difference of two u32 values, panics if the result overflows u32 -pub fn safe_subtract_32(a: u32, b: u32) -> u32 { +fn safe_subtract_32(a: u32, b: u32) -> u32 { unwrap(checked_subtract_32(a, b)) } /// Returns the product of two u32 values wrapped in Some, or None if the result overflows u32 -pub fn checked_multiply_32(a: u32, b: u32) -> Option { +fn checked_multiply_32(a: u32, b: u32) -> Option { let result: u64 = jet::multiply_32(a, b); let (high, low): (u32, u32) = ::into(result); @@ -41,12 +41,12 @@ pub fn checked_multiply_32(a: u32, b: u32) -> Option { } /// Returns the product of two u32 values, panics if the result overflows u32 -pub fn safe_multiply_32(a: u32, b: u32) -> u32 { +fn safe_multiply_32(a: u32, b: u32) -> u32 { unwrap(checked_multiply_32(a, b)) } /// Returns the quotient of two u32 values wrapped in Some, or None if the result overflows u32 -pub fn checked_divide_32(a: u32, b: u32) -> Option { +fn checked_divide_32(a: u32, b: u32) -> Option { match jet::is_zero_32(b) { true => None, false => Some(jet::divide_32(a, b)), @@ -54,7 +54,7 @@ pub fn checked_divide_32(a: u32, b: u32) -> Option { } /// Returns the quotient of two u32 values, panics if the result overflows u32 -pub fn safe_divide_32(a: u32, b: u32) -> u32 { +fn safe_divide_32(a: u32, b: u32) -> u32 { unwrap(checked_divide_32(a, b)) } diff --git a/simf/u64.simf b/simf/u64.simf index e583a51..4d4337d 100644 --- a/simf/u64.simf +++ b/simf/u64.simf @@ -1,5 +1,5 @@ /// Returns the sum of two u64 values wrapped in Some, or None if the result overflows u64 -pub fn checked_add_64(a: u64, b: u64) -> Option { +fn checked_add_64(a: u64, b: u64) -> Option { let (carry, sum): (bool, u64) = jet::add_64(a, b); match carry { @@ -9,12 +9,12 @@ pub fn checked_add_64(a: u64, b: u64) -> Option { } /// Returns the sum of two u64 values, panics if the result overflows u64 -pub fn safe_add_64(a: u64, b: u64) -> u64 { +fn safe_add_64(a: u64, b: u64) -> u64 { unwrap(checked_add_64(a, b)) } /// Returns the sum of two u64 values, panics if the result overflows u64 -pub fn checked_subtract_64(a: u64, b: u64) -> Option { +fn checked_subtract_64(a: u64, b: u64) -> Option { let (borrow, diff): (bool, u64) = jet::subtract_64(a, b); match borrow { @@ -24,12 +24,12 @@ pub fn checked_subtract_64(a: u64, b: u64) -> Option { } /// Returns the difference of two u64 values, panics if the result overflows u64 -pub fn safe_subtract_64(a: u64, b: u64) -> u64 { +fn safe_subtract_64(a: u64, b: u64) -> u64 { unwrap(checked_subtract_64(a, b)) } /// Returns the product of two u64 values wrapped in Some, or None if the result overflows u64 -pub fn checked_multiply_64(a: u64, b: u64) -> Option { +fn checked_multiply_64(a: u64, b: u64) -> Option { let result: u128 = jet::multiply_64(a, b); let (high, low): (u64, u64) = ::into(result); @@ -41,12 +41,12 @@ pub fn checked_multiply_64(a: u64, b: u64) -> Option { } /// Returns the product of two u64 values, panics if the result overflows u64 -pub fn safe_multiply_64(a: u64, b: u64) -> u64 { +fn safe_multiply_64(a: u64, b: u64) -> u64 { unwrap(checked_multiply_64(a, b)) } /// Returns the quotient of two u64 values wrapped in Some, or None if the result overflows u64 -pub fn checked_divide_64(a: u64, b: u64) -> Option { +fn checked_divide_64(a: u64, b: u64) -> Option { match jet::is_zero_64(b) { true => None, false => Some(jet::divide_64(a, b)), @@ -54,7 +54,7 @@ pub fn checked_divide_64(a: u64, b: u64) -> Option { } /// Returns the quotient of two u64 values, panics if the result overflows u64 -pub fn safe_divide_64(a: u64, b: u64) -> u64 { +fn safe_divide_64(a: u64, b: u64) -> u64 { unwrap(checked_divide_64(a, b)) } diff --git a/simf/u8.simf b/simf/u8.simf index f857b01..cb6aa07 100644 --- a/simf/u8.simf +++ b/simf/u8.simf @@ -1,5 +1,5 @@ /// Returns the sum of two u8 values wrapped in Some, or None if the result overflows u8 -pub fn checked_add_8(a: u8, b: u8) -> Option { +fn checked_add_8(a: u8, b: u8) -> Option { let (carry, sum): (bool, u8) = jet::add_8(a, b); match carry { @@ -9,12 +9,12 @@ pub fn checked_add_8(a: u8, b: u8) -> Option { } /// Returns the sum of two u8 values, panics if the result overflows u8 -pub fn safe_add_8(a: u8, b: u8) -> u8 { +fn safe_add_8(a: u8, b: u8) -> u8 { unwrap(checked_add_8(a, b)) } /// Returns the difference of two u8 values wrapped in Some, or None if the result overflows u8 -pub fn checked_subtract_8(a: u8, b: u8) -> Option { +fn checked_subtract_8(a: u8, b: u8) -> Option { let (borrow, diff): (bool, u8) = jet::subtract_8(a, b); match borrow { @@ -24,12 +24,12 @@ pub fn checked_subtract_8(a: u8, b: u8) -> Option { } /// Returns the difference of two u8 values, panics if the result overflows u8 -pub fn safe_subtract_8(a: u8, b: u8) -> u8 { +fn safe_subtract_8(a: u8, b: u8) -> u8 { unwrap(checked_subtract_8(a, b)) } /// Returns the product of two u8 values wrapped in Some, or None if the result overflows u8 -pub fn checked_multiply_8(a: u8, b: u8) -> Option { +fn checked_multiply_8(a: u8, b: u8) -> Option { let result: u16 = jet::multiply_8(a, b); let (high, low): (u8, u8) = ::into(result); @@ -41,12 +41,12 @@ pub fn checked_multiply_8(a: u8, b: u8) -> Option { } /// Returns the product of two u8 values, panics if the result overflows u8 -pub fn safe_multiply_8(a: u8, b: u8) -> u8 { +fn safe_multiply_8(a: u8, b: u8) -> u8 { unwrap(checked_multiply_8(a, b)) } /// Returns the quotient of two u8 values wrapped in Some, or None if the result overflows u8 -pub fn checked_divide_8(a: u8, b: u8) -> Option { +fn checked_divide_8(a: u8, b: u8) -> Option { match jet::is_zero_8(b) { true => None, false => Some(jet::divide_8(a, b)), @@ -54,7 +54,7 @@ pub fn checked_divide_8(a: u8, b: u8) -> Option { } /// Returns the quotient of two u8 values, panics if the result overflows u8 -pub fn safe_divide_8(a: u8, b: u8) -> u8 { +fn safe_divide_8(a: u8, b: u8) -> u8 { unwrap(checked_divide_8(a, b)) } From 8a610d1d564f8456486ce4d0383c84fb1f13be70 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 18:01:35 +0300 Subject: [PATCH 08/23] refactored tests for u8 --- Cargo.lock | 125 ++++++++---------- Cargo.toml | 1 + simf/mock/u8_mock.simf | 172 ++++++++++++++++++------ tests/u8_test.rs | 289 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 478 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 367e18e..9dd590b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -90,17 +90,16 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "base58ck" -version = "0.1.0" +version = "0.1.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +checksum = "ec5dc7e09f7bb15f0062da7c03086d6b71a2c84e0af4fccbbc7d8c6559847816" dependencies = [ - "bitcoin-internals", "bitcoin_hashes", ] @@ -137,14 +136,13 @@ dependencies = [ [[package]] name = "bitcoin" -version = "0.32.9" +version = "0.32.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf93e61f2dbc3e3c41234ca26a65e2c0b0975c52e0f069ab9893ebbede584d3" +checksum = "39581299241111285f3268ba75ddf372746fd041620918b145c1af9d75e91b6c" dependencies = [ "base58ck", "base64 0.21.7", "bech32", - "bitcoin-internals", "bitcoin-io", "bitcoin-units", "bitcoin_hashes", @@ -154,20 +152,11 @@ dependencies = [ "serde", ] -[[package]] -name = "bitcoin-internals" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" -dependencies = [ - "serde", -] - [[package]] name = "bitcoin-io" -version = "0.1.4" +version = "0.1.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dee39a0ee5b4095224a0cfc6bf4cc1baf0f9624b96b367e53b66d974e51d953" +checksum = "11301df0b06f22dea7bb1916403fdd88a371031e495c49b8f96931b28189e175" [[package]] name = "bitcoin-private" @@ -177,19 +166,18 @@ checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57" [[package]] name = "bitcoin-units" -version = "0.1.3" +version = "0.1.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "346568ebaab2918487cea76dd55dae13c27bb618cdb737c952e69eb2017c4118" +checksum = "57bad157b78d0d1b22c4cbb6a35a566211fc4d14866a37f2c780652b50f3b845" dependencies = [ - "bitcoin-internals", "serde", ] [[package]] name = "bitcoin_hashes" -version = "0.14.1" +version = "0.14.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26ec84b80c482df901772e931a9a681e26a1b9ee2302edeff23cb30328745c8b" +checksum = "0c9901a56e133a1fc86eeb1113e2591f45f4682451ca893bff494d2f88918e3f" dependencies = [ "bitcoin-io", "hex-conservative", @@ -241,9 +229,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.11.1" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" +checksum = "84d7ced0ae9557296835c32bf1b1e02b44c746701f898460fb000d7eaa84f00a" [[package]] name = "block-buffer" @@ -266,9 +254,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.20.2" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "byteorder" @@ -278,9 +266,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.2.62" +version = "1.2.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1dce859f0832a7d088c4f1119888ab94ef4b5d6795d1ce05afb7fe159d79f98" +checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" dependencies = [ "find-msvc-tools", "shlex", @@ -402,9 +390,9 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "either" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" dependencies = [ "serde", ] @@ -584,7 +572,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.12.1", "ignore", "walkdir", ] @@ -708,9 +696,9 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" -version = "0.3.98" +version = "0.3.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67df7112613f8bfd9150013a0314e196f4800d3201ae742489d999db2f979f08" +checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" dependencies = [ "cfg-if", "futures-util", @@ -756,15 +744,15 @@ checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "log" -version = "0.4.29" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "113b30b4cd05f7c06868fdb2854f66a7b9fece9a48425351cd532e810d74024f" [[package]] name = "memchr" -version = "2.8.0" +version = "2.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" +checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8" [[package]] name = "memoffset" @@ -777,9 +765,9 @@ dependencies = [ [[package]] name = "miniscript" -version = "12.3.6" +version = "12.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c14116d8342edd3626b0f8e84df16f4e6a76dc04799ba747493403236a1b8ac5" +checksum = "b8343cc1ef1408bd9bdbf69f7aef47017dfab7e6349ec26fddf62e0e9fb5a4cf" dependencies = [ "bech32", "bitcoin", @@ -1000,7 +988,7 @@ version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.12.1", "errno", "libc", "linux-raw-sys 0.4.15", @@ -1013,7 +1001,7 @@ version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.12.1", "errno", "libc", "linux-raw-sys 0.12.1", @@ -1158,9 +1146,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", @@ -1191,9 +1179,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.3.0" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" [[package]] name = "simplicity-lang" @@ -1246,6 +1234,7 @@ name = "simplicityhl_std" version = "0.1.0" dependencies = [ "anyhow", + "rand", "smplx-std", ] @@ -1467,7 +1456,7 @@ version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" dependencies = [ - "winnow 1.0.2", + "winnow 1.0.3", ] [[package]] @@ -1478,9 +1467,9 @@ checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" [[package]] name = "typenum" -version = "1.20.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40ce102ab67701b8526c123c1bab5cbe42d7040ccfd0f64af1a385808d2f43de" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" @@ -1499,9 +1488,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.13.2" +version = "1.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" [[package]] name = "unicode-xid" @@ -1563,9 +1552,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ace1d07c165b0864824eee619580c4689389afa9dc9ed3a4c75040d82e6790" +checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" dependencies = [ "cfg-if", "once_cell", @@ -1576,9 +1565,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e68e6f4afd367a562002c05637acb8578ff2dea1943df76afb9e83d177c8578" +checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1586,9 +1575,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a9ec35c64b2a7cb35d3fead40c4238d0940c86d107136999567a4703259f2" +checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" dependencies = [ "bumpalo", "proc-macro2", @@ -1599,9 +1588,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.121" +version = "0.2.122" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e0100b01e9f0d03189a92b96772a1fb998639d981193d7dbab487302513441" +checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" dependencies = [ "unicode-ident", ] @@ -1634,7 +1623,7 @@ version = "0.244.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" dependencies = [ - "bitflags 2.11.1", + "bitflags 2.12.1", "hashbrown 0.15.5", "indexmap", "semver", @@ -1772,9 +1761,9 @@ checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" [[package]] name = "winnow" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ee1708bef14716a11bae175f579062d4554d95be2c6829f518df847b7b3fdd0" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" [[package]] name = "wit-bindgen" @@ -1840,7 +1829,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" dependencies = [ "anyhow", - "bitflags 2.11.1", + "bitflags 2.12.1", "indexmap", "log", "serde", @@ -1872,18 +1861,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eed437bf9d6692032087e337407a86f04cd8d6a16a37199ed57949d415bd68e9" +checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.48" +version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" +checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 030390b..33ff4c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ version = "0.1.0" smplx-std = { version = ">=0.0.5, <0.1.0" } anyhow = { version = "1.0.101" } +rand = "0.8.6" diff --git a/simf/mock/u8_mock.simf b/simf/mock/u8_mock.simf index 3cd23bc..1bc71fd 100644 --- a/simf/mock/u8_mock.simf +++ b/simf/mock/u8_mock.simf @@ -51,46 +51,144 @@ fn safe_divide_8(a: u8, b: u8) -> u8 { unwrap(checked_divide_8(a, b)) } -fn main() { - let maxU8: u8 = 0xff; - - // add - let fittingU8: Option = checked_add_8(1, 2); - assert!(jet::eq_8(unwrap(fittingU8), 3)); - - let overflowingU8: Option = checked_add_8(maxU8, 1); - assert!(is_none::(overflowingU8)); - - let fittingU8: u8 = safe_add_8(1, 2); - assert!(jet::eq_8(fittingU8, 3)); +// helper +fn if_test_this_function(index: u8, flag: u8) -> bool { + jet::eq_8(index, flag) +} - // substract - let fittingU8: Option = checked_subtract_8(maxU8, 1); - assert!(jet::eq_8(unwrap(fittingU8), 0xfe)); +fn main() { + let function_index: u8 = witness::FUNCTION_INDEX; + let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - let overflowingU8: Option = checked_subtract_8(1, 2); - assert!(is_none::(overflowingU8)); + let first_arg: u8 = witness::FIRST_ARG; + let second_arg: u8 = witness::SECOND_ARG; + let result: u8 = witness::RESULT; - let fittingU8: u8 = safe_subtract_8(10, 2); - assert!(jet::eq_8(fittingU8, 8)); + // add + match if_test_this_function(0, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: Option = checked_add_8(first_arg, second_arg); + assert!(is_none::(overflowingU8)); + }, + false => { + let fittingU8: Option = checked_add_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fittingU8), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(1, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: u8 = safe_add_8(first_arg, second_arg); + }, + false => { + let fittingU8: u8 = safe_add_8(first_arg, second_arg); + assert!(jet::eq_8(fittingU8, result)); + } + } + }, + false => (), + }; + + // subtract + match if_test_this_function(2, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: Option = checked_subtract_8(first_arg, second_arg); + assert!(is_none::(overflowingU8)); + }, + false => { + let fittingU8: Option = checked_subtract_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fittingU8), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(3, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: u8 = safe_subtract_8(first_arg, second_arg); + }, + false => { + let fittingU8: u8 = safe_subtract_8(first_arg, second_arg); + assert!(jet::eq_8(fittingU8, result)); + } + } + }, + false => (), + }; // multiply - let fittingU8: Option = checked_multiply_8(3, 2); - assert!(jet::eq_8(unwrap(fittingU8), 6)); - - let overflowingU8: Option = checked_multiply_8(maxU8, 2); - assert!(is_none::(overflowingU8)); - - let fittingU8: u8 = safe_multiply_8(1, 2); - assert!(jet::eq_8(fittingU8, 2)); - - // divide - let fittingU8: Option = checked_divide_8(4, 2); - assert!(jet::eq_8(unwrap(fittingU8), 2)); - - let overflowingU8: Option = checked_divide_8(5, 0); - assert!(is_none::(overflowingU8)); - - let fittingU8: u8 = safe_divide_8(5, 2); - assert!(jet::eq_8(fittingU8, 2)); + match if_test_this_function(4, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: Option = checked_multiply_8(first_arg, second_arg); + assert!(is_none::(overflowingU8)); + }, + false => { + let fittingU8: Option = checked_multiply_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fittingU8), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(5, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: u8 = safe_multiply_8(first_arg, second_arg); + }, + false => { + let fittingU8: u8 = safe_multiply_8(first_arg, second_arg); + assert!(jet::eq_8(fittingU8, result)); + } + } + }, + false => (), + }; + + // divide + match if_test_this_function(6, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: Option = checked_divide_8(first_arg, second_arg); + assert!(is_none::(overflowingU8)); + }, + false => { + let fittingU8: Option = checked_divide_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fittingU8), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(7, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU8: u8 = safe_divide_8(first_arg, second_arg); + }, + false => { + let fittingU8: u8 = safe_divide_8(first_arg, second_arg); + assert!(jet::eq_8(fittingU8, result)); + } + } + }, + false => (), + }; } diff --git a/tests/u8_test.rs b/tests/u8_test.rs index 6ee5f9c..2b680e1 100644 --- a/tests/u8_test.rs +++ b/tests/u8_test.rs @@ -5,6 +5,19 @@ use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, Require use simplicityhl_std::artifacts::mock::u8_mock::U8MockProgram; use simplicityhl_std::artifacts::mock::u8_mock::derived_u8_mock::{U8MockArguments, U8MockWitness}; +use rand::Rng; + +enum FunctionToTest { + CheckedAdd8, + SafeAdd8, + CheckedSubtract8, + SafeSubtract8, + CheckedMultiply8, + SafeMultiply8, + CheckedDivide8, + SafeDivide8 +} + fn get_script(context: &simplex::TestContext) -> (U8MockProgram, Script) { let arguments = U8MockArguments {}; @@ -26,7 +39,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u8, second_arg: u8, result: u8,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -36,7 +49,7 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { let mut ft = FinalTransaction::new(); - let witness = U8MockWitness {}; + let witness = U8MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -51,9 +64,277 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { } #[simplex::test] -fn u8_test(context: simplex::TestContext) -> anyhow::Result<()> { +fn u8_test_checked_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd8; + let if_test_overflow = true; + + let first_arg = u8::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd8; + let if_test_overflow = true; + + let first_arg = u8::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); + let result = 0; + fund_script(&context)?; - spend_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract8; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract8; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply8; + let if_test_overflow = true; + + let first_arg = u8::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply8; + let if_test_overflow = true; + + let first_arg = u8::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_checked_divide_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide8; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide8; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u8_test_safe_divide_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide8; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); Ok(()) } From 490c39f8802d8ed6bb40ec60579abab19e433287 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 18:01:48 +0300 Subject: [PATCH 09/23] typo --- simf/mock/u16_mock.simf | 2 +- simf/mock/u32_mock.simf | 2 +- simf/mock/u64_mock.simf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf index 5484606..23127c1 100644 --- a/simf/mock/u16_mock.simf +++ b/simf/mock/u16_mock.simf @@ -63,7 +63,7 @@ fn main() { let fittingU16: u16 = safe_add_16(1, 2); assert!(jet::eq_16(fittingU16, 3)); - // substract + // subtract let fittingU16: Option = checked_subtract_16(maxU16, 1); assert!(jet::eq_16(unwrap(fittingU16), 0xfffe)); diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf index 10df2b7..1617225 100644 --- a/simf/mock/u32_mock.simf +++ b/simf/mock/u32_mock.simf @@ -64,7 +64,7 @@ fn main() { let fittingU32: u32 = safe_add_32(1, 2); assert!(jet::eq_32(fittingU32, 3)); - // substract + // subtract let fittingU32: Option = checked_subtract_32(maxU32, 1); assert!(jet::eq_32(unwrap(fittingU32), 0xfffffffe)); diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf index 5c2a7b3..27ef6de 100644 --- a/simf/mock/u64_mock.simf +++ b/simf/mock/u64_mock.simf @@ -64,7 +64,7 @@ fn main() { let fittingU64: u64 = safe_add_64(1, 2); assert!(jet::eq_64(fittingU64, 3)); - // substract + // subtract let fittingU64: Option = checked_subtract_64(maxU64, 1); assert!(jet::eq_64(unwrap(fittingU64), 0xfffffffffffffffe)); From 49727c095533d0ad09700c4cce2453c399e4552b Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 19:54:17 +0300 Subject: [PATCH 10/23] refactored tests for u16 --- simf/mock/u16_mock.simf | 170 ++++++++++++++++++----- tests/u16_test.rs | 289 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 419 insertions(+), 40 deletions(-) diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf index 23127c1..93b9b5a 100644 --- a/simf/mock/u16_mock.simf +++ b/simf/mock/u16_mock.simf @@ -50,46 +50,144 @@ fn safe_divide_16(a: u16, b: u16) -> u16 { unwrap(checked_divide_16(a, b)) } -fn main() { - let maxU16: u16 = 0xffff; - - // add - let fittingU16: Option = checked_add_16(1, 2); - assert!(jet::eq_16(unwrap(fittingU16), 3)); +// helper +fn if_test_this_function(index: u8, flag: u8) -> bool { + jet::eq_8(index, flag) +} - let overflowingU16: Option = checked_add_16(maxU16, 1); - assert!(is_none::(overflowingU16)); +fn main() { + let function_index: u8 = witness::FUNCTION_INDEX; + let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - let fittingU16: u16 = safe_add_16(1, 2); - assert!(jet::eq_16(fittingU16, 3)); + let first_arg: u16 = witness::FIRST_ARG; + let second_arg: u16 = witness::SECOND_ARG; + let result: u16 = witness::RESULT; + // add + match if_test_this_function(0, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: Option = checked_add_16(first_arg, second_arg); + assert!(is_none::(overflowingU16)); + }, + false => { + let fittingU16: Option = checked_add_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fittingU16), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(1, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: u16 = safe_add_16(first_arg, second_arg); + }, + false => { + let fittingU16: u16 = safe_add_16(first_arg, second_arg); + assert!(jet::eq_16(fittingU16, result)); + } + } + }, + false => (), + }; + // subtract - let fittingU16: Option = checked_subtract_16(maxU16, 1); - assert!(jet::eq_16(unwrap(fittingU16), 0xfffe)); - - let overflowingU16: Option = checked_subtract_16(1, 2); - assert!(is_none::(overflowingU16)); - - let fittingU16: u16 = safe_subtract_16(10, 2); - assert!(jet::eq_16(fittingU16, 8)); + match if_test_this_function(2, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: Option = checked_subtract_16(first_arg, second_arg); + assert!(is_none::(overflowingU16)); + }, + false => { + let fittingU16: Option = checked_subtract_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fittingU16), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(3, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: u16 = safe_subtract_16(first_arg, second_arg); + }, + false => { + let fittingU16: u16 = safe_subtract_16(first_arg, second_arg); + assert!(jet::eq_16(fittingU16, result)); + } + } + }, + false => (), + }; // multiply - let fittingU16: Option = checked_multiply_16(3, 2); - assert!(jet::eq_16(unwrap(fittingU16), 6)); - - let overflowingU16: Option = checked_multiply_16(maxU16, 2); - assert!(is_none::(overflowingU16)); - - let fittingU16: u16 = safe_multiply_16(1, 2); - assert!(jet::eq_16(fittingU16, 2)); - - // divide - let fittingU16: Option = checked_divide_16(4, 2); - assert!(jet::eq_16(unwrap(fittingU16), 2)); - - let overflowingU16: Option = checked_divide_16(maxU16, 0); - assert!(is_none::(overflowingU16)); - - let fittingU16: u16 = safe_divide_16(4, 2); - assert!(jet::eq_16(fittingU16, 2)); + match if_test_this_function(4, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: Option = checked_multiply_16(first_arg, second_arg); + assert!(is_none::(overflowingU16)); + }, + false => { + let fittingU16: Option = checked_multiply_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fittingU16), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(5, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: u16 = safe_multiply_16(first_arg, second_arg); + }, + false => { + let fittingU16: u16 = safe_multiply_16(first_arg, second_arg); + assert!(jet::eq_16(fittingU16, result)); + } + } + }, + false => (), + }; + + // divide + match if_test_this_function(6, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: Option = checked_divide_16(first_arg, second_arg); + assert!(is_none::(overflowingU16)); + }, + false => { + let fittingU16: Option = checked_divide_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fittingU16), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(7, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU16: u16 = safe_divide_16(first_arg, second_arg); + }, + false => { + let fittingU16: u16 = safe_divide_16(first_arg, second_arg); + assert!(jet::eq_16(fittingU16, result)); + } + } + }, + false => (), + }; } diff --git a/tests/u16_test.rs b/tests/u16_test.rs index 8ddcd18..0b1b760 100644 --- a/tests/u16_test.rs +++ b/tests/u16_test.rs @@ -5,6 +5,19 @@ use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, Require use simplicityhl_std::artifacts::mock::u16_mock::U16MockProgram; use simplicityhl_std::artifacts::mock::u16_mock::derived_u16_mock::{U16MockArguments, U16MockWitness}; +use rand::Rng; + +enum FunctionToTest { + CheckedAdd16, + SafeAdd16, + CheckedSubtract16, + SafeSubtract16, + CheckedMultiply16, + SafeMultiply16, + CheckedDivide16, + SafeDivide16 +} + fn get_script(context: &simplex::TestContext) -> (U16MockProgram, Script) { let arguments = U16MockArguments {}; @@ -26,7 +39,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u16, second_arg: u16, result: u16,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -36,7 +49,7 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { let mut ft = FinalTransaction::new(); - let witness = U16MockWitness {}; + let witness = U16MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -51,9 +64,277 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { } #[simplex::test] -fn u16_test(context: simplex::TestContext) -> anyhow::Result<()> { +fn u16_test_checked_add_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_add_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd16; + let if_test_overflow = true; + + let first_arg = u16::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_add_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_add_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd16; + let if_test_overflow = true; + + let first_arg = u16::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); + let result = 0; + fund_script(&context)?; - spend_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_subtract_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_subtract_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract16; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u16::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_subtract_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_subtract_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract16; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u16::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_multiply_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_multiply_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply16; + let if_test_overflow = true; + + let first_arg = u16::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u16::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_multiply_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_multiply_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply16; + let if_test_overflow = true; + + let first_arg = u16::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u16::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_divide_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_checked_divide_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide16; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_divide_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide16; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u16_test_safe_divide_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide16; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); Ok(()) } From d58e2455e3793c6b13b6d2874f1961dbb4c72898 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 19:57:14 +0300 Subject: [PATCH 11/23] refactored tests for u32 --- simf/mock/u32_mock.simf | 170 ++++++++++++++++++----- tests/u32_test.rs | 289 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 419 insertions(+), 40 deletions(-) diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf index 1617225..eebb124 100644 --- a/simf/mock/u32_mock.simf +++ b/simf/mock/u32_mock.simf @@ -51,46 +51,144 @@ fn safe_divide_32(a: u32, b: u32) -> u32 { unwrap(checked_divide_32(a, b)) } -fn main() { - let maxU32: u32 = 0xffffffff; - - // add - let fittingU32: Option = checked_add_32(1, 2); - assert!(jet::eq_32(unwrap(fittingU32), 3)); +// helper +fn if_test_this_function(index: u8, flag: u8) -> bool { + jet::eq_8(index, flag) +} - let overflowingU32: Option = checked_add_32(maxU32, 1); - assert!(is_none::(overflowingU32)); +fn main() { + let function_index: u8 = witness::FUNCTION_INDEX; + let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - let fittingU32: u32 = safe_add_32(1, 2); - assert!(jet::eq_32(fittingU32, 3)); + let first_arg: u32 = witness::FIRST_ARG; + let second_arg: u32 = witness::SECOND_ARG; + let result: u32 = witness::RESULT; + // add + match if_test_this_function(0, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: Option = checked_add_32(first_arg, second_arg); + assert!(is_none::(overflowingU32)); + }, + false => { + let fittingU32: Option = checked_add_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fittingU32), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(1, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: u32 = safe_add_32(first_arg, second_arg); + }, + false => { + let fittingU32: u32 = safe_add_32(first_arg, second_arg); + assert!(jet::eq_32(fittingU32, result)); + } + } + }, + false => (), + }; + // subtract - let fittingU32: Option = checked_subtract_32(maxU32, 1); - assert!(jet::eq_32(unwrap(fittingU32), 0xfffffffe)); - - let overflowingU32: Option = checked_subtract_32(1, 2); - assert!(is_none::(overflowingU32)); - - let fittingU32: u32 = safe_subtract_32(10, 2); - assert!(jet::eq_32(fittingU32, 8)); + match if_test_this_function(2, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: Option = checked_subtract_32(first_arg, second_arg); + assert!(is_none::(overflowingU32)); + }, + false => { + let fittingU32: Option = checked_subtract_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fittingU32), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(3, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: u32 = safe_subtract_32(first_arg, second_arg); + }, + false => { + let fittingU32: u32 = safe_subtract_32(first_arg, second_arg); + assert!(jet::eq_32(fittingU32, result)); + } + } + }, + false => (), + }; // multiply - let fittingU32: Option = checked_multiply_32(3, 2); - assert!(jet::eq_32(unwrap(fittingU32), 6)); - - let overflowingU32: Option = checked_multiply_32(maxU32, 2); - assert!(is_none::(overflowingU32)); - - let fittingU32: u32 = safe_multiply_32(1, 2); - assert!(jet::eq_32(fittingU32, 2)); - - // divide - let fittingU32: Option = checked_divide_32(4, 2); - assert!(jet::eq_32(unwrap(fittingU32), 2)); - - let overflowingU32: Option = checked_divide_32(5, 0); - assert!(is_none::(overflowingU32)); - - let fittingU32: u32 = safe_divide_32(5, 2); - assert!(jet::eq_32(fittingU32, 2)); + match if_test_this_function(4, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: Option = checked_multiply_32(first_arg, second_arg); + assert!(is_none::(overflowingU32)); + }, + false => { + let fittingU32: Option = checked_multiply_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fittingU32), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(5, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: u32 = safe_multiply_32(first_arg, second_arg); + }, + false => { + let fittingU32: u32 = safe_multiply_32(first_arg, second_arg); + assert!(jet::eq_32(fittingU32, result)); + } + } + }, + false => (), + }; + + // divide + match if_test_this_function(6, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: Option = checked_divide_32(first_arg, second_arg); + assert!(is_none::(overflowingU32)); + }, + false => { + let fittingU32: Option = checked_divide_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fittingU32), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(7, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU32: u32 = safe_divide_32(first_arg, second_arg); + }, + false => { + let fittingU32: u32 = safe_divide_32(first_arg, second_arg); + assert!(jet::eq_32(fittingU32, result)); + } + } + }, + false => (), + }; } diff --git a/tests/u32_test.rs b/tests/u32_test.rs index 280e5d6..7d4420f 100644 --- a/tests/u32_test.rs +++ b/tests/u32_test.rs @@ -5,6 +5,19 @@ use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, Require use simplicityhl_std::artifacts::mock::u32_mock::U32MockProgram; use simplicityhl_std::artifacts::mock::u32_mock::derived_u32_mock::{U32MockArguments, U32MockWitness}; +use rand::Rng; + +enum FunctionToTest { + CheckedAdd32, + SafeAdd32, + CheckedSubtract32, + SafeSubtract32, + CheckedMultiply32, + SafeMultiply32, + CheckedDivide32, + SafeDivide32 +} + fn get_script(context: &simplex::TestContext) -> (U32MockProgram, Script) { let arguments = U32MockArguments {}; @@ -26,7 +39,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u32, second_arg: u32, result: u32,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -36,7 +49,7 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { let mut ft = FinalTransaction::new(); - let witness = U32MockWitness {}; + let witness = U32MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -51,9 +64,277 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { } #[simplex::test] -fn u32_test(context: simplex::TestContext) -> anyhow::Result<()> { +fn u32_test_checked_add_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_add_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd32; + let if_test_overflow = true; + + let first_arg = u32::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_add_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_add_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd32; + let if_test_overflow = true; + + let first_arg = u32::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); + let result = 0; + fund_script(&context)?; - spend_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_subtract_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_subtract_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract32; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u32::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_subtract_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_subtract_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract32; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u32::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_multiply_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_multiply_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply32; + let if_test_overflow = true; + + let first_arg = u32::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u32::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_multiply_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_multiply_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply32; + let if_test_overflow = true; + + let first_arg = u32::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u32::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_divide_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_checked_divide_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide32; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_divide_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide32; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u32_test_safe_divide_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide32; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); Ok(()) } From d25c324f5d4cd5893de4bddb4e07e1b73e11df85 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 20:00:18 +0300 Subject: [PATCH 12/23] refactored tests for u64 --- simf/mock/u64_mock.simf | 170 ++++++++++++++++++----- tests/u64_test.rs | 289 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 419 insertions(+), 40 deletions(-) diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf index 27ef6de..e647257 100644 --- a/simf/mock/u64_mock.simf +++ b/simf/mock/u64_mock.simf @@ -51,46 +51,144 @@ fn safe_divide_64(a: u64, b: u64) -> u64 { unwrap(checked_divide_64(a, b)) } -fn main() { - let maxU64: u64 = 0xffffffffffffffff; - - // add - let fittingU64: Option = checked_add_64(1, 2); - assert!(jet::eq_64(unwrap(fittingU64), 3)); +// helper +fn if_test_this_function(index: u8, flag: u8) -> bool { + jet::eq_8(index, flag) +} - let overflowingU64: Option = checked_add_64(maxU64, 1); - assert!(is_none::(overflowingU64)); +fn main() { + let function_index: u8 = witness::FUNCTION_INDEX; + let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - let fittingU64: u64 = safe_add_64(1, 2); - assert!(jet::eq_64(fittingU64, 3)); + let first_arg: u64 = witness::FIRST_ARG; + let second_arg: u64 = witness::SECOND_ARG; + let result: u64 = witness::RESULT; + // add + match if_test_this_function(0, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: Option = checked_add_64(first_arg, second_arg); + assert!(is_none::(overflowingU64)); + }, + false => { + let fittingU64: Option = checked_add_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fittingU64), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(1, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: u64 = safe_add_64(first_arg, second_arg); + }, + false => { + let fittingU64: u64 = safe_add_64(first_arg, second_arg); + assert!(jet::eq_64(fittingU64, result)); + } + } + }, + false => (), + }; + // subtract - let fittingU64: Option = checked_subtract_64(maxU64, 1); - assert!(jet::eq_64(unwrap(fittingU64), 0xfffffffffffffffe)); - - let overflowingU64: Option = checked_subtract_64(1, 2); - assert!(is_none::(overflowingU64)); - - let fittingU64: u64 = safe_subtract_64(10, 2); - assert!(jet::eq_64(fittingU64, 8)); + match if_test_this_function(2, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: Option = checked_subtract_64(first_arg, second_arg); + assert!(is_none::(overflowingU64)); + }, + false => { + let fittingU64: Option = checked_subtract_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fittingU64), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(3, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: u64 = safe_subtract_64(first_arg, second_arg); + }, + false => { + let fittingU64: u64 = safe_subtract_64(first_arg, second_arg); + assert!(jet::eq_64(fittingU64, result)); + } + } + }, + false => (), + }; // multiply - let fittingU64: Option = checked_multiply_64(3, 2); - assert!(jet::eq_64(unwrap(fittingU64), 6)); - - let overflowingU64: Option = checked_multiply_64(maxU64, 2); - assert!(is_none::(overflowingU64)); - - let fittingU64: u64 = safe_multiply_64(1, 2); - assert!(jet::eq_64(fittingU64, 2)); - - // divide - let fittingU64: Option = checked_divide_64(4, 2); - assert!(jet::eq_64(unwrap(fittingU64), 2)); - - let overflowingU64: Option = checked_divide_64(5, 0); - assert!(is_none::(overflowingU64)); - - let fittingU64: u64 = safe_divide_64(5, 2); - assert!(jet::eq_64(fittingU64, 2)); + match if_test_this_function(4, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: Option = checked_multiply_64(first_arg, second_arg); + assert!(is_none::(overflowingU64)); + }, + false => { + let fittingU64: Option = checked_multiply_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fittingU64), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(5, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: u64 = safe_multiply_64(first_arg, second_arg); + }, + false => { + let fittingU64: u64 = safe_multiply_64(first_arg, second_arg); + assert!(jet::eq_64(fittingU64, result)); + } + } + }, + false => (), + }; + + // divide + match if_test_this_function(6, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: Option = checked_divide_64(first_arg, second_arg); + assert!(is_none::(overflowingU64)); + }, + false => { + let fittingU64: Option = checked_divide_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fittingU64), result)); + } + } + }, + false => (), + }; + + match if_test_this_function(7, function_index) { + true => { + match if_test_overflow { + true => { + let overflowingU64: u64 = safe_divide_64(first_arg, second_arg); + }, + false => { + let fittingU64: u64 = safe_divide_64(first_arg, second_arg); + assert!(jet::eq_64(fittingU64, result)); + } + } + }, + false => (), + }; } diff --git a/tests/u64_test.rs b/tests/u64_test.rs index 9dce803..51287b9 100644 --- a/tests/u64_test.rs +++ b/tests/u64_test.rs @@ -5,6 +5,19 @@ use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, Require use simplicityhl_std::artifacts::mock::u64_mock::U64MockProgram; use simplicityhl_std::artifacts::mock::u64_mock::derived_u64_mock::{U64MockArguments, U64MockWitness}; +use rand::Rng; + +enum FunctionToTest { + CheckedAdd64, + SafeAdd64, + CheckedSubtract64, + SafeSubtract64, + CheckedMultiply64, + SafeMultiply64, + CheckedDivide64, + SafeDivide64 +} + fn get_script(context: &simplex::TestContext) -> (U64MockProgram, Script) { let arguments = U64MockArguments {}; @@ -26,7 +39,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u64, second_arg: u64, result: u64,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -36,7 +49,7 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { let mut ft = FinalTransaction::new(); - let witness = U64MockWitness {}; + let witness = U64MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -51,9 +64,277 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { } #[simplex::test] -fn u64_test(context: simplex::TestContext) -> anyhow::Result<()> { +fn u64_test_checked_add_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_add_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedAdd64; + let if_test_overflow = true; + + let first_arg = u64::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_add_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let second_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let result = first_arg + second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_add_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeAdd64; + let if_test_overflow = true; + + let first_arg = u64::MAX; + let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); + let result = 0; + fund_script(&context)?; - spend_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_subtract_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_subtract_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedSubtract64; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u64::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_subtract_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = rand::thread_rng().gen_range(0..=first_arg); + let result = first_arg - second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_subtract_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeSubtract64; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX-1); + let second_arg = rand::thread_rng().gen_range(first_arg+1..=u64::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_multiply_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_multiply_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedMultiply64; + let if_test_overflow = true; + + let first_arg = u64::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u64::MAX); + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_multiply_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); + let second_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); + let result = first_arg * second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_multiply_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeMultiply64; + let if_test_overflow = true; + + let first_arg = u64::MAX; + let second_arg = rand::thread_rng().gen_range(2..=u64::MAX); + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_divide_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_checked_divide_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::CheckedDivide64; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_divide_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide64; + let if_test_overflow = false; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); + let result = first_arg / second_arg; + + fund_script(&context)?; + spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + + Ok(()) +} + +#[simplex::test] +fn u64_test_safe_divide_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { + let function_index = FunctionToTest::SafeDivide64; + let if_test_overflow = true; + + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); + let second_arg = 0; + let result = 0; + + fund_script(&context)?; + + let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + + assert!( + txid_result.is_err(), + "Expected this test to fail but it succeeded" + ); + + let err: String = txid_result.unwrap_err().to_string(); + assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); Ok(()) } From c64b995ab9d28e63185cb9ce5f090152dfa78a2c Mon Sep 17 00:00:00 2001 From: aritkulova Date: Wed, 3 Jun 2026 20:33:07 +0300 Subject: [PATCH 13/23] added enum to asserts test --- simf/asserts.simf | 2 ++ simf/mock/asserts_mock.simf | 31 +++++++++-------- tests/asserts_test.rs | 67 +++++++++++++++++++++++-------------- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/simf/asserts.simf b/simf/asserts.simf index 0085d2d..e2729e4 100644 --- a/simf/asserts.simf +++ b/simf/asserts.simf @@ -18,6 +18,8 @@ fn assert_eq64(a: u64, b: u64) { assert!(jet::eq_64(a, b)); } +// todo: assert_eq128 + /// Asserts that two u256 are equal fn assert_eq256(a: u256, b: u256) { assert!(jet::eq_256(a, b)); diff --git a/simf/mock/asserts_mock.simf b/simf/mock/asserts_mock.simf index 5004777..efe95b7 100644 --- a/simf/mock/asserts_mock.simf +++ b/simf/mock/asserts_mock.simf @@ -15,6 +15,8 @@ fn assert_eq64(a: u64, b: u64) { // 4 assert!(jet::eq_64(a, b)); } +// todo: assert_eq128 + fn assert_eq256(a: u256, b: u256) { // 5 assert!(jet::eq_256(a, b)); } @@ -43,13 +45,14 @@ fn assert_none256(val: Option) { // 11 assert!(is_none::(val)); } +// helper fn if_test_this_function(index: u8, flag: u8) -> bool { jet::eq_8(index, flag) } fn main() { - let flag: u8 = witness::FLAG; - let ifHappyPath: bool = if_test_this_function(0, flag); + let function_index: u8 = witness::FUNCTION_INDEX; + let if_happy_path: bool = if_test_this_function(0, function_index); let some_u8: u8 = 255; let some_u16: u16 = 65535; @@ -58,7 +61,7 @@ fn main() { let some_u128: u128 = 340282366920938463463374607431768211455; let some_u256: u256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935; - match ifHappyPath { + match if_happy_path { true => { assert_eq8(some_u8, some_u8); assert_eq16(some_u16, some_u16); @@ -73,57 +76,57 @@ fn main() { assert_none128(None); assert_none256(None); }, false => { - match if_test_this_function(1, flag) { + match if_test_this_function(1, function_index) { true => assert_eq8(1, 2), false => (), }; - match if_test_this_function(2, flag) { + match if_test_this_function(2, function_index) { true => assert_eq16(1, 2), false => (), }; - match if_test_this_function(3, flag) { + match if_test_this_function(3, function_index) { true => assert_eq32(1, 2), false => (), }; - match if_test_this_function(4, flag) { + match if_test_this_function(4, function_index) { true => assert_eq64(1, 2), false => (), }; - match if_test_this_function(5, flag) { + match if_test_this_function(5, function_index) { true => assert_eq256(1, 2), false => (), }; - match if_test_this_function(6, flag) { + match if_test_this_function(6, function_index) { true => assert_none8(Some(some_u8)), false => (), }; - match if_test_this_function(7, flag) { + match if_test_this_function(7, function_index) { true => assert_none16(Some(some_u16)), false => (), }; - match if_test_this_function(8, flag) { + match if_test_this_function(8, function_index) { true => assert_none32(Some(some_u32)), false => (), }; - match if_test_this_function(9, flag) { + match if_test_this_function(9, function_index) { true => assert_none64(Some(some_u64)), false => (), }; - match if_test_this_function(10, flag) { + match if_test_this_function(10, function_index) { true => assert_none128(Some(some_u128)), false => (), }; - match if_test_this_function(11, flag) { + match if_test_this_function(11, function_index) { true => assert_none256(Some(some_u256)), false => (), }; diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index 468340c..e3d92ca 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -5,6 +5,21 @@ use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, Require use simplicityhl_std::artifacts::mock::asserts_mock::AssertsMockProgram; use simplicityhl_std::artifacts::mock::asserts_mock::derived_asserts_mock::{AssertsMockWitness, AssertsMockArguments}; +enum FunctionToTest { + HappyPath, + AssertEq8, + AssertEq16, + AssertEq32, + AssertEq64, + AssertEq256, + AssertNone8, + AssertNone16, + AssertNone32, + AssertNone64, + AssertNone128, + AssertNone256 +} + fn get_asserts_test_script(context: &simplex::TestContext) -> (AssertsMockProgram, Script) { let arguments = AssertsMockArguments {}; @@ -26,7 +41,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext, flag: u8) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: u8,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -36,7 +51,7 @@ fn spend_script(context: &simplex::TestContext, flag: u8) -> anyhow::Result<()> let mut ft = FinalTransaction::new(); - let witness = AssertsMockWitness {flag: flag}; + let witness = AssertsMockWitness {function_index: function_index}; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -52,21 +67,21 @@ fn spend_script(context: &simplex::TestContext, flag: u8) -> anyhow::Result<()> #[simplex::test] fn asserts_test_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 0; + let function_index = FunctionToTest::HappyPath; fund_script(&context)?; - spend_script(&context, flag)?; + spend_script(&context, function_index as u8)?; Ok(()) } #[simplex::test] fn assert_eq8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 1; + let function_index = FunctionToTest::AssertEq8; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -81,11 +96,11 @@ fn assert_eq8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 2; + let function_index = FunctionToTest::AssertEq16; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -100,11 +115,11 @@ fn assert_eq16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 3; + let function_index = FunctionToTest::AssertEq32; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -119,11 +134,11 @@ fn assert_eq32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 4; + let function_index = FunctionToTest::AssertEq64; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -138,11 +153,11 @@ fn assert_eq64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 5; + let function_index = FunctionToTest::AssertEq256; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -157,11 +172,11 @@ fn assert_eq256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 6; + let function_index = FunctionToTest::AssertNone8; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -176,11 +191,11 @@ fn assert_none8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 7; + let function_index = FunctionToTest::AssertNone16; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -195,11 +210,11 @@ fn assert_none16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 8; + let function_index = FunctionToTest::AssertNone32; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -214,11 +229,11 @@ fn assert_none32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 9; + let function_index = FunctionToTest::AssertNone64; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -233,11 +248,11 @@ fn assert_none64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 10; + let function_index = FunctionToTest::AssertNone128; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), @@ -252,11 +267,11 @@ fn assert_none128_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let flag: u8 = 11; + let function_index = FunctionToTest::AssertNone256; fund_script(&context)?; - let txid_result = spend_script(&context, flag); + let txid_result = spend_script(&context, function_index as u8); assert!( txid_result.is_err(), From 99521cc67f5a6c9bd2dd4b8234f50efed644d90b Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 4 Jun 2026 12:54:27 +0300 Subject: [PATCH 14/23] standardize naming convention --- simf/asserts.simf | 24 ++++++------- simf/mock/asserts_mock.simf | 68 ++++++++++++++++++------------------- tests/asserts_test.rs | 22 ++++++------ 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/simf/asserts.simf b/simf/asserts.simf index e2729e4..7707a59 100644 --- a/simf/asserts.simf +++ b/simf/asserts.simf @@ -1,57 +1,57 @@ /// Asserts that two u8 are equal -fn assert_eq8(a: u8, b: u8) { +fn assert_eq_8(a: u8, b: u8) { assert!(jet::eq_8(a, b)); } /// Asserts that two u16 are equal -fn assert_eq16(a: u16, b: u16) { +fn assert_eq_16(a: u16, b: u16) { assert!(jet::eq_16(a, b)); } /// Asserts that two u32 are equal -fn assert_eq32(a: u32, b: u32) { +fn assert_eq_32(a: u32, b: u32) { assert!(jet::eq_32(a, b)); } /// Asserts that two u64 are equal -fn assert_eq64(a: u64, b: u64) { +fn assert_eq_64(a: u64, b: u64) { assert!(jet::eq_64(a, b)); } -// todo: assert_eq128 +// todo: assert_eq_128 /// Asserts that two u256 are equal -fn assert_eq256(a: u256, b: u256) { +fn assert_eq_256(a: u256, b: u256) { assert!(jet::eq_256(a, b)); } /// Asserts that provided u8 Option value is a None -fn assert_none8(val: Option) { +fn assert_none_8(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u16 Option value is a None -fn assert_none16(val: Option) { +fn assert_none_16(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u32 Option value is a None -fn assert_none32(val: Option) { +fn assert_none_32(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u64 Option value is a None -fn assert_none64(val: Option) { +fn assert_none_64(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u128 Option value is a None -fn assert_none128(val: Option) { +fn assert_none_128(val: Option) { assert!(is_none::(val)); } /// Asserts that provided u256 Option value is a None -fn assert_none256(val: Option) { +fn assert_none_256(val: Option) { assert!(is_none::(val)); } diff --git a/simf/mock/asserts_mock.simf b/simf/mock/asserts_mock.simf index efe95b7..364ae8b 100644 --- a/simf/mock/asserts_mock.simf +++ b/simf/mock/asserts_mock.simf @@ -1,47 +1,47 @@ // todo: switch to function import when available -fn assert_eq8(a: u8, b: u8) { // 1 +fn assert_eq_8(a: u8, b: u8) { // 1 assert!(jet::eq_8(a, b)); } -fn assert_eq16(a: u16, b: u16) { // 2 +fn assert_eq_16(a: u16, b: u16) { // 2 assert!(jet::eq_16(a, b)); } -fn assert_eq32(a: u32, b: u32) { // 3 +fn assert_eq_32(a: u32, b: u32) { // 3 assert!(jet::eq_32(a, b)); } -fn assert_eq64(a: u64, b: u64) { // 4 +fn assert_eq_64(a: u64, b: u64) { // 4 assert!(jet::eq_64(a, b)); } -// todo: assert_eq128 +// todo: assert_eq_128 -fn assert_eq256(a: u256, b: u256) { // 5 +fn assert_eq_256(a: u256, b: u256) { // 5 assert!(jet::eq_256(a, b)); } -fn assert_none8(val: Option) { // 6 +fn assert_none_8(val: Option) { // 6 assert!(is_none::(val)); } -fn assert_none16(val: Option) { // 7 +fn assert_none_16(val: Option) { // 7 assert!(is_none::(val)); } -fn assert_none32(val: Option) { // 8 +fn assert_none_32(val: Option) { // 8 assert!(is_none::(val)); } -fn assert_none64(val: Option) { // 9 +fn assert_none_64(val: Option) { // 9 assert!(is_none::(val)); } -fn assert_none128(val: Option) { // 10 +fn assert_none_128(val: Option) { // 10 assert!(is_none::(val)); } -fn assert_none256(val: Option) { // 11 +fn assert_none_256(val: Option) { // 11 assert!(is_none::(val)); } @@ -63,71 +63,71 @@ fn main() { match if_happy_path { true => { - assert_eq8(some_u8, some_u8); - assert_eq16(some_u16, some_u16); - assert_eq32(some_u32, some_u32); - assert_eq64(some_u64, some_u64); - assert_eq256(some_u256, some_u256); + assert_eq_8(some_u8, some_u8); + assert_eq_16(some_u16, some_u16); + assert_eq_32(some_u32, some_u32); + assert_eq_64(some_u64, some_u64); + assert_eq_256(some_u256, some_u256); - assert_none8(None); - assert_none16(None); - assert_none32(None); - assert_none64(None); - assert_none128(None); - assert_none256(None); + assert_none_8(None); + assert_none_16(None); + assert_none_32(None); + assert_none_64(None); + assert_none_128(None); + assert_none_256(None); }, false => { match if_test_this_function(1, function_index) { - true => assert_eq8(1, 2), + true => assert_eq_8(1, 2), false => (), }; match if_test_this_function(2, function_index) { - true => assert_eq16(1, 2), + true => assert_eq_16(1, 2), false => (), }; match if_test_this_function(3, function_index) { - true => assert_eq32(1, 2), + true => assert_eq_32(1, 2), false => (), }; match if_test_this_function(4, function_index) { - true => assert_eq64(1, 2), + true => assert_eq_64(1, 2), false => (), }; match if_test_this_function(5, function_index) { - true => assert_eq256(1, 2), + true => assert_eq_256(1, 2), false => (), }; match if_test_this_function(6, function_index) { - true => assert_none8(Some(some_u8)), + true => assert_none_8(Some(some_u8)), false => (), }; match if_test_this_function(7, function_index) { - true => assert_none16(Some(some_u16)), + true => assert_none_16(Some(some_u16)), false => (), }; match if_test_this_function(8, function_index) { - true => assert_none32(Some(some_u32)), + true => assert_none_32(Some(some_u32)), false => (), }; match if_test_this_function(9, function_index) { - true => assert_none64(Some(some_u64)), + true => assert_none_64(Some(some_u64)), false => (), }; match if_test_this_function(10, function_index) { - true => assert_none128(Some(some_u128)), + true => assert_none_128(Some(some_u128)), false => (), }; match if_test_this_function(11, function_index) { - true => assert_none256(Some(some_u256)), + true => assert_none_256(Some(some_u256)), false => (), }; } diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index e3d92ca..d87d15c 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -76,7 +76,7 @@ fn asserts_test_happy_path(context: simplex::TestContext) -> anyhow::Result<()> } #[simplex::test] -fn assert_eq8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertEq8; fund_script(&context)?; @@ -95,7 +95,7 @@ fn assert_eq8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> } #[simplex::test] -fn assert_eq16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertEq16; fund_script(&context)?; @@ -114,7 +114,7 @@ fn assert_eq16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> } #[simplex::test] -fn assert_eq32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertEq32; fund_script(&context)?; @@ -133,7 +133,7 @@ fn assert_eq32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> } #[simplex::test] -fn assert_eq64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertEq64; fund_script(&context)?; @@ -152,7 +152,7 @@ fn assert_eq64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> } #[simplex::test] -fn assert_eq256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertEq256; fund_script(&context)?; @@ -171,7 +171,7 @@ fn assert_eq256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() } #[simplex::test] -fn assert_none8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone8; fund_script(&context)?; @@ -190,7 +190,7 @@ fn assert_none8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() } #[simplex::test] -fn assert_none16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone16; fund_script(&context)?; @@ -209,7 +209,7 @@ fn assert_none16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( } #[simplex::test] -fn assert_none32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone32; fund_script(&context)?; @@ -228,7 +228,7 @@ fn assert_none32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( } #[simplex::test] -fn assert_none64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone64; fund_script(&context)?; @@ -247,7 +247,7 @@ fn assert_none64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( } #[simplex::test] -fn assert_none128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone128; fund_script(&context)?; @@ -266,7 +266,7 @@ fn assert_none128_unhappy_path(context: simplex::TestContext) -> anyhow::Result< } #[simplex::test] -fn assert_none256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { let function_index = FunctionToTest::AssertNone256; fund_script(&context)?; From 56285ce3af0482c527d12858f9fc8cf6999d5af9 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 4 Jun 2026 14:33:43 +0300 Subject: [PATCH 15/23] standardize naming convention --- simf/mock/u16_mock.simf | 56 ++++++++++++++++++++--------------------- simf/mock/u32_mock.simf | 56 ++++++++++++++++++++--------------------- simf/mock/u64_mock.simf | 56 ++++++++++++++++++++--------------------- simf/mock/u8_mock.simf | 56 ++++++++++++++++++++--------------------- 4 files changed, 112 insertions(+), 112 deletions(-) diff --git a/simf/mock/u16_mock.simf b/simf/mock/u16_mock.simf index 93b9b5a..a7df2a9 100644 --- a/simf/mock/u16_mock.simf +++ b/simf/mock/u16_mock.simf @@ -68,12 +68,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: Option = checked_add_16(first_arg, second_arg); - assert!(is_none::(overflowingU16)); + let overflowing_u16: Option = checked_add_16(first_arg, second_arg); + assert!(is_none::(overflowing_u16)); }, false => { - let fittingU16: Option = checked_add_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fittingU16), result)); + let fitting_u16: Option = checked_add_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fitting_u16), result)); } } }, @@ -84,11 +84,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: u16 = safe_add_16(first_arg, second_arg); + let overflowing_u16: u16 = safe_add_16(first_arg, second_arg); }, false => { - let fittingU16: u16 = safe_add_16(first_arg, second_arg); - assert!(jet::eq_16(fittingU16, result)); + let fitting_u16: u16 = safe_add_16(first_arg, second_arg); + assert!(jet::eq_16(fitting_u16, result)); } } }, @@ -100,12 +100,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: Option = checked_subtract_16(first_arg, second_arg); - assert!(is_none::(overflowingU16)); + let overflowing_u16: Option = checked_subtract_16(first_arg, second_arg); + assert!(is_none::(overflowing_u16)); }, false => { - let fittingU16: Option = checked_subtract_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fittingU16), result)); + let fitting_u16: Option = checked_subtract_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fitting_u16), result)); } } }, @@ -116,11 +116,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: u16 = safe_subtract_16(first_arg, second_arg); + let overflowing_u16: u16 = safe_subtract_16(first_arg, second_arg); }, false => { - let fittingU16: u16 = safe_subtract_16(first_arg, second_arg); - assert!(jet::eq_16(fittingU16, result)); + let fitting_u16: u16 = safe_subtract_16(first_arg, second_arg); + assert!(jet::eq_16(fitting_u16, result)); } } }, @@ -132,12 +132,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: Option = checked_multiply_16(first_arg, second_arg); - assert!(is_none::(overflowingU16)); + let overflowing_u16: Option = checked_multiply_16(first_arg, second_arg); + assert!(is_none::(overflowing_u16)); }, false => { - let fittingU16: Option = checked_multiply_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fittingU16), result)); + let fitting_u16: Option = checked_multiply_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fitting_u16), result)); } } }, @@ -148,11 +148,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: u16 = safe_multiply_16(first_arg, second_arg); + let overflowing_u16: u16 = safe_multiply_16(first_arg, second_arg); }, false => { - let fittingU16: u16 = safe_multiply_16(first_arg, second_arg); - assert!(jet::eq_16(fittingU16, result)); + let fitting_u16: u16 = safe_multiply_16(first_arg, second_arg); + assert!(jet::eq_16(fitting_u16, result)); } } }, @@ -164,12 +164,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: Option = checked_divide_16(first_arg, second_arg); - assert!(is_none::(overflowingU16)); + let overflowing_u16: Option = checked_divide_16(first_arg, second_arg); + assert!(is_none::(overflowing_u16)); }, false => { - let fittingU16: Option = checked_divide_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fittingU16), result)); + let fitting_u16: Option = checked_divide_16(first_arg, second_arg); + assert!(jet::eq_16(unwrap(fitting_u16), result)); } } }, @@ -180,11 +180,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU16: u16 = safe_divide_16(first_arg, second_arg); + let overflowing_u16: u16 = safe_divide_16(first_arg, second_arg); }, false => { - let fittingU16: u16 = safe_divide_16(first_arg, second_arg); - assert!(jet::eq_16(fittingU16, result)); + let fitting_u16: u16 = safe_divide_16(first_arg, second_arg); + assert!(jet::eq_16(fitting_u16, result)); } } }, diff --git a/simf/mock/u32_mock.simf b/simf/mock/u32_mock.simf index eebb124..d2c609a 100644 --- a/simf/mock/u32_mock.simf +++ b/simf/mock/u32_mock.simf @@ -69,12 +69,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: Option = checked_add_32(first_arg, second_arg); - assert!(is_none::(overflowingU32)); + let overflowing_u32: Option = checked_add_32(first_arg, second_arg); + assert!(is_none::(overflowing_u32)); }, false => { - let fittingU32: Option = checked_add_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fittingU32), result)); + let fitting_u32: Option = checked_add_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fitting_u32), result)); } } }, @@ -85,11 +85,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: u32 = safe_add_32(first_arg, second_arg); + let overflowing_u32: u32 = safe_add_32(first_arg, second_arg); }, false => { - let fittingU32: u32 = safe_add_32(first_arg, second_arg); - assert!(jet::eq_32(fittingU32, result)); + let fitting_u32: u32 = safe_add_32(first_arg, second_arg); + assert!(jet::eq_32(fitting_u32, result)); } } }, @@ -101,12 +101,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: Option = checked_subtract_32(first_arg, second_arg); - assert!(is_none::(overflowingU32)); + let overflowing_u32: Option = checked_subtract_32(first_arg, second_arg); + assert!(is_none::(overflowing_u32)); }, false => { - let fittingU32: Option = checked_subtract_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fittingU32), result)); + let fitting_u32: Option = checked_subtract_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fitting_u32), result)); } } }, @@ -117,11 +117,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: u32 = safe_subtract_32(first_arg, second_arg); + let overflowing_u32: u32 = safe_subtract_32(first_arg, second_arg); }, false => { - let fittingU32: u32 = safe_subtract_32(first_arg, second_arg); - assert!(jet::eq_32(fittingU32, result)); + let fitting_u32: u32 = safe_subtract_32(first_arg, second_arg); + assert!(jet::eq_32(fitting_u32, result)); } } }, @@ -133,12 +133,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: Option = checked_multiply_32(first_arg, second_arg); - assert!(is_none::(overflowingU32)); + let overflowing_u32: Option = checked_multiply_32(first_arg, second_arg); + assert!(is_none::(overflowing_u32)); }, false => { - let fittingU32: Option = checked_multiply_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fittingU32), result)); + let fitting_u32: Option = checked_multiply_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fitting_u32), result)); } } }, @@ -149,11 +149,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: u32 = safe_multiply_32(first_arg, second_arg); + let overflowing_u32: u32 = safe_multiply_32(first_arg, second_arg); }, false => { - let fittingU32: u32 = safe_multiply_32(first_arg, second_arg); - assert!(jet::eq_32(fittingU32, result)); + let fitting_u32: u32 = safe_multiply_32(first_arg, second_arg); + assert!(jet::eq_32(fitting_u32, result)); } } }, @@ -165,12 +165,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: Option = checked_divide_32(first_arg, second_arg); - assert!(is_none::(overflowingU32)); + let overflowing_u32: Option = checked_divide_32(first_arg, second_arg); + assert!(is_none::(overflowing_u32)); }, false => { - let fittingU32: Option = checked_divide_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fittingU32), result)); + let fitting_u32: Option = checked_divide_32(first_arg, second_arg); + assert!(jet::eq_32(unwrap(fitting_u32), result)); } } }, @@ -181,11 +181,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU32: u32 = safe_divide_32(first_arg, second_arg); + let overflowing_u32: u32 = safe_divide_32(first_arg, second_arg); }, false => { - let fittingU32: u32 = safe_divide_32(first_arg, second_arg); - assert!(jet::eq_32(fittingU32, result)); + let fitting_u32: u32 = safe_divide_32(first_arg, second_arg); + assert!(jet::eq_32(fitting_u32, result)); } } }, diff --git a/simf/mock/u64_mock.simf b/simf/mock/u64_mock.simf index e647257..6189a0d 100644 --- a/simf/mock/u64_mock.simf +++ b/simf/mock/u64_mock.simf @@ -69,12 +69,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: Option = checked_add_64(first_arg, second_arg); - assert!(is_none::(overflowingU64)); + let overflowing_u64: Option = checked_add_64(first_arg, second_arg); + assert!(is_none::(overflowing_u64)); }, false => { - let fittingU64: Option = checked_add_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fittingU64), result)); + let fitting_u64: Option = checked_add_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fitting_u64), result)); } } }, @@ -85,11 +85,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: u64 = safe_add_64(first_arg, second_arg); + let overflowing_u64: u64 = safe_add_64(first_arg, second_arg); }, false => { - let fittingU64: u64 = safe_add_64(first_arg, second_arg); - assert!(jet::eq_64(fittingU64, result)); + let fitting_u64: u64 = safe_add_64(first_arg, second_arg); + assert!(jet::eq_64(fitting_u64, result)); } } }, @@ -101,12 +101,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: Option = checked_subtract_64(first_arg, second_arg); - assert!(is_none::(overflowingU64)); + let overflowing_u64: Option = checked_subtract_64(first_arg, second_arg); + assert!(is_none::(overflowing_u64)); }, false => { - let fittingU64: Option = checked_subtract_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fittingU64), result)); + let fitting_u64: Option = checked_subtract_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fitting_u64), result)); } } }, @@ -117,11 +117,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: u64 = safe_subtract_64(first_arg, second_arg); + let overflowing_u64: u64 = safe_subtract_64(first_arg, second_arg); }, false => { - let fittingU64: u64 = safe_subtract_64(first_arg, second_arg); - assert!(jet::eq_64(fittingU64, result)); + let fitting_u64: u64 = safe_subtract_64(first_arg, second_arg); + assert!(jet::eq_64(fitting_u64, result)); } } }, @@ -133,12 +133,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: Option = checked_multiply_64(first_arg, second_arg); - assert!(is_none::(overflowingU64)); + let overflowing_u64: Option = checked_multiply_64(first_arg, second_arg); + assert!(is_none::(overflowing_u64)); }, false => { - let fittingU64: Option = checked_multiply_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fittingU64), result)); + let fitting_u64: Option = checked_multiply_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fitting_u64), result)); } } }, @@ -149,11 +149,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: u64 = safe_multiply_64(first_arg, second_arg); + let overflowing_u64: u64 = safe_multiply_64(first_arg, second_arg); }, false => { - let fittingU64: u64 = safe_multiply_64(first_arg, second_arg); - assert!(jet::eq_64(fittingU64, result)); + let fitting_u64: u64 = safe_multiply_64(first_arg, second_arg); + assert!(jet::eq_64(fitting_u64, result)); } } }, @@ -165,12 +165,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: Option = checked_divide_64(first_arg, second_arg); - assert!(is_none::(overflowingU64)); + let overflowing_u64: Option = checked_divide_64(first_arg, second_arg); + assert!(is_none::(overflowing_u64)); }, false => { - let fittingU64: Option = checked_divide_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fittingU64), result)); + let fitting_u64: Option = checked_divide_64(first_arg, second_arg); + assert!(jet::eq_64(unwrap(fitting_u64), result)); } } }, @@ -181,11 +181,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU64: u64 = safe_divide_64(first_arg, second_arg); + let overflowing_u64: u64 = safe_divide_64(first_arg, second_arg); }, false => { - let fittingU64: u64 = safe_divide_64(first_arg, second_arg); - assert!(jet::eq_64(fittingU64, result)); + let fitting_u64: u64 = safe_divide_64(first_arg, second_arg); + assert!(jet::eq_64(fitting_u64, result)); } } }, diff --git a/simf/mock/u8_mock.simf b/simf/mock/u8_mock.simf index 1bc71fd..de59f39 100644 --- a/simf/mock/u8_mock.simf +++ b/simf/mock/u8_mock.simf @@ -69,12 +69,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: Option = checked_add_8(first_arg, second_arg); - assert!(is_none::(overflowingU8)); + let overflowing_u8: Option = checked_add_8(first_arg, second_arg); + assert!(is_none::(overflowing_u8)); }, false => { - let fittingU8: Option = checked_add_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fittingU8), result)); + let fitting_u8: Option = checked_add_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fitting_u8), result)); } } }, @@ -85,11 +85,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: u8 = safe_add_8(first_arg, second_arg); + let overflowing_u8: u8 = safe_add_8(first_arg, second_arg); }, false => { - let fittingU8: u8 = safe_add_8(first_arg, second_arg); - assert!(jet::eq_8(fittingU8, result)); + let fitting_u8: u8 = safe_add_8(first_arg, second_arg); + assert!(jet::eq_8(fitting_u8, result)); } } }, @@ -101,12 +101,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: Option = checked_subtract_8(first_arg, second_arg); - assert!(is_none::(overflowingU8)); + let overflowing_u8: Option = checked_subtract_8(first_arg, second_arg); + assert!(is_none::(overflowing_u8)); }, false => { - let fittingU8: Option = checked_subtract_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fittingU8), result)); + let fitting_u8: Option = checked_subtract_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fitting_u8), result)); } } }, @@ -117,11 +117,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: u8 = safe_subtract_8(first_arg, second_arg); + let overflowing_u8: u8 = safe_subtract_8(first_arg, second_arg); }, false => { - let fittingU8: u8 = safe_subtract_8(first_arg, second_arg); - assert!(jet::eq_8(fittingU8, result)); + let fitting_u8: u8 = safe_subtract_8(first_arg, second_arg); + assert!(jet::eq_8(fitting_u8, result)); } } }, @@ -133,12 +133,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: Option = checked_multiply_8(first_arg, second_arg); - assert!(is_none::(overflowingU8)); + let overflowing_u8: Option = checked_multiply_8(first_arg, second_arg); + assert!(is_none::(overflowing_u8)); }, false => { - let fittingU8: Option = checked_multiply_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fittingU8), result)); + let fitting_u8: Option = checked_multiply_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fitting_u8), result)); } } }, @@ -149,11 +149,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: u8 = safe_multiply_8(first_arg, second_arg); + let overflowing_u8: u8 = safe_multiply_8(first_arg, second_arg); }, false => { - let fittingU8: u8 = safe_multiply_8(first_arg, second_arg); - assert!(jet::eq_8(fittingU8, result)); + let fitting_u8: u8 = safe_multiply_8(first_arg, second_arg); + assert!(jet::eq_8(fitting_u8, result)); } } }, @@ -165,12 +165,12 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: Option = checked_divide_8(first_arg, second_arg); - assert!(is_none::(overflowingU8)); + let overflowing_u8: Option = checked_divide_8(first_arg, second_arg); + assert!(is_none::(overflowing_u8)); }, false => { - let fittingU8: Option = checked_divide_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fittingU8), result)); + let fitting_u8: Option = checked_divide_8(first_arg, second_arg); + assert!(jet::eq_8(unwrap(fitting_u8), result)); } } }, @@ -181,11 +181,11 @@ fn main() { true => { match if_test_overflow { true => { - let overflowingU8: u8 = safe_divide_8(first_arg, second_arg); + let overflowing_u8: u8 = safe_divide_8(first_arg, second_arg); }, false => { - let fittingU8: u8 = safe_divide_8(first_arg, second_arg); - assert!(jet::eq_8(fittingU8, result)); + let fitting_u8: u8 = safe_divide_8(first_arg, second_arg); + assert!(jet::eq_8(fitting_u8, result)); } } }, From 99ab488d7687363aaf461910c18dec57f08a455f Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 4 Jun 2026 16:43:37 +0300 Subject: [PATCH 16/23] pass enum variable to the spend_script function --- tests/helper.rs | 8 ++ tests/u16_test.rs | 292 +++++++++++++++++++++++++++++++--------------- tests/u32_test.rs | 292 +++++++++++++++++++++++++++++++--------------- tests/u64_test.rs | 266 ++++++++++++++++++++++++++++------------- tests/u8_test.rs | 93 +++++---------- 5 files changed, 607 insertions(+), 344 deletions(-) create mode 100644 tests/helper.rs diff --git a/tests/helper.rs b/tests/helper.rs new file mode 100644 index 0000000..32060f1 --- /dev/null +++ b/tests/helper.rs @@ -0,0 +1,8 @@ +pub enum IfTestOverflow { + NotOverflow, + Overflow, +} + +pub fn cast_to_bool(if_overflow: IfTestOverflow) -> bool { + if_overflow as u8 == 1 +} diff --git a/tests/u16_test.rs b/tests/u16_test.rs index 0b1b760..0d2b321 100644 --- a/tests/u16_test.rs +++ b/tests/u16_test.rs @@ -1,12 +1,17 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; use simplicityhl_std::artifacts::mock::u16_mock::U16MockProgram; -use simplicityhl_std::artifacts::mock::u16_mock::derived_u16_mock::{U16MockArguments, U16MockWitness}; +use simplicityhl_std::artifacts::mock::u16_mock::derived_u16_mock::{ + U16MockArguments, U16MockWitness, +}; use rand::Rng; +mod helper; +use helper::{IfTestOverflow, cast_to_bool}; + enum FunctionToTest { CheckedAdd16, SafeAdd16, @@ -15,7 +20,7 @@ enum FunctionToTest { CheckedMultiply16, SafeMultiply16, CheckedDivide16, - SafeDivide16 + SafeDivide16, } fn get_script(context: &simplex::TestContext) -> (U16MockProgram, Script) { @@ -23,7 +28,8 @@ fn get_script(context: &simplex::TestContext) -> (U16MockProgram, Script) { let logical_operations_program = U16MockProgram::new(arguments); - let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + let logical_operations_script = + logical_operations_program.get_script_pubkey(context.get_network()); (logical_operations_program, logical_operations_script) } @@ -36,10 +42,17 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u16, second_arg: u16, result: u16,) -> anyhow::Result<()> { +fn spend_script( + context: &simplex::TestContext, + function_index: FunctionToTest, + if_test_overflow: IfTestOverflow, + first_arg: u16, + second_arg: u16, + result: u16, +) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -49,11 +62,20 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over let mut ft = FinalTransaction::new(); - let witness = U16MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; + let witness = U16MockWitness { + function_index: function_index as u8, + if_test_overflow: cast_to_bool(if_test_overflow), + first_arg: first_arg, + second_arg: second_arg, + result: result, + }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(logical_operations_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); @@ -65,61 +87,77 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over #[simplex::test] fn u16_test_checked_add_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd16; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u16::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_checked_add_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd16; - let if_test_overflow = true; - let first_arg = u16::MAX; let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_add_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd16; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u16::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u16::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeAdd16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_add_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd16; - let if_test_overflow = true; - let first_arg = u16::MAX; let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeAdd16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -127,68 +165,87 @@ fn u16_test_safe_add_16_overflow(context: simplex::TestContext) -> anyhow::Resul ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u16_test_checked_subtract_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_checked_subtract_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract16; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u16::MAX); + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u16::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_subtract_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeSubtract16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_subtract_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract16; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u16::MAX); - let result = 0; + let first_arg = rand::thread_rng().gen_range(0..=u16::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u16::MAX); + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeSubtract16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -196,68 +253,87 @@ fn u16_test_safe_subtract_16_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u16_test_checked_multiply_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_checked_multiply_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply16; - let if_test_overflow = true; - let first_arg = u16::MAX; let second_arg = rand::thread_rng().gen_range(2..=u16::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_multiply_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u16.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeMultiply16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_multiply_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply16; - let if_test_overflow = true; - let first_arg = u16::MAX; let second_arg = rand::thread_rng().gen_range(2..=u16::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeMultiply16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -265,68 +341,87 @@ fn u16_test_safe_multiply_16_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u16_test_checked_divide_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_checked_divide_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide16; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_divide_16_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide16; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = rand::thread_rng().gen_range(1..=u16::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeDivide16, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u16_test_safe_divide_16_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide16; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u16::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeDivide16, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -334,7 +429,10 @@ fn u16_test_safe_divide_16_overflow(context: simplex::TestContext) -> anyhow::Re ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } diff --git a/tests/u32_test.rs b/tests/u32_test.rs index 7d4420f..80d50c2 100644 --- a/tests/u32_test.rs +++ b/tests/u32_test.rs @@ -1,12 +1,17 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; use simplicityhl_std::artifacts::mock::u32_mock::U32MockProgram; -use simplicityhl_std::artifacts::mock::u32_mock::derived_u32_mock::{U32MockArguments, U32MockWitness}; +use simplicityhl_std::artifacts::mock::u32_mock::derived_u32_mock::{ + U32MockArguments, U32MockWitness, +}; use rand::Rng; +mod helper; +use helper::{IfTestOverflow, cast_to_bool}; + enum FunctionToTest { CheckedAdd32, SafeAdd32, @@ -15,7 +20,7 @@ enum FunctionToTest { CheckedMultiply32, SafeMultiply32, CheckedDivide32, - SafeDivide32 + SafeDivide32, } fn get_script(context: &simplex::TestContext) -> (U32MockProgram, Script) { @@ -23,7 +28,8 @@ fn get_script(context: &simplex::TestContext) -> (U32MockProgram, Script) { let logical_operations_program = U32MockProgram::new(arguments); - let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + let logical_operations_script = + logical_operations_program.get_script_pubkey(context.get_network()); (logical_operations_program, logical_operations_script) } @@ -36,10 +42,17 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u32, second_arg: u32, result: u32,) -> anyhow::Result<()> { +fn spend_script( + context: &simplex::TestContext, + function_index: FunctionToTest, + if_test_overflow: IfTestOverflow, + first_arg: u32, + second_arg: u32, + result: u32, +) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -49,11 +62,20 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over let mut ft = FinalTransaction::new(); - let witness = U32MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; + let witness = U32MockWitness { + function_index: function_index as u8, + if_test_overflow: cast_to_bool(if_test_overflow), + first_arg: first_arg, + second_arg: second_arg, + result: result, + }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(logical_operations_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); @@ -65,61 +87,77 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over #[simplex::test] fn u32_test_checked_add_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd32; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u32::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_checked_add_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd32; - let if_test_overflow = true; - let first_arg = u32::MAX; let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_add_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd32; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u32::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u32::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeAdd32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_add_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd32; - let if_test_overflow = true; - let first_arg = u32::MAX; let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeAdd32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -127,68 +165,87 @@ fn u32_test_safe_add_32_overflow(context: simplex::TestContext) -> anyhow::Resul ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u32_test_checked_subtract_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_checked_subtract_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract32; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u32::MAX); + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u32::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_subtract_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeSubtract32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_subtract_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract32; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u32::MAX); - let result = 0; + let first_arg = rand::thread_rng().gen_range(0..=u32::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u32::MAX); + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeSubtract32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -196,68 +253,87 @@ fn u32_test_safe_subtract_32_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u32_test_checked_multiply_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_checked_multiply_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply32; - let if_test_overflow = true; - let first_arg = u32::MAX; let second_arg = rand::thread_rng().gen_range(2..=u32::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_multiply_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u32.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeMultiply32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_multiply_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply32; - let if_test_overflow = true; - let first_arg = u32::MAX; let second_arg = rand::thread_rng().gen_range(2..=u32::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeMultiply32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -265,68 +341,87 @@ fn u32_test_safe_multiply_32_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u32_test_checked_divide_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_checked_divide_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide32; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_divide_32_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide32; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = rand::thread_rng().gen_range(1..=u32::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeDivide32, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u32_test_safe_divide_32_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide32; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u32::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeDivide32, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -334,7 +429,10 @@ fn u32_test_safe_divide_32_overflow(context: simplex::TestContext) -> anyhow::Re ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } diff --git a/tests/u64_test.rs b/tests/u64_test.rs index 51287b9..8fb7ca9 100644 --- a/tests/u64_test.rs +++ b/tests/u64_test.rs @@ -1,12 +1,17 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; use simplicityhl_std::artifacts::mock::u64_mock::U64MockProgram; -use simplicityhl_std::artifacts::mock::u64_mock::derived_u64_mock::{U64MockArguments, U64MockWitness}; +use simplicityhl_std::artifacts::mock::u64_mock::derived_u64_mock::{ + U64MockArguments, U64MockWitness, +}; use rand::Rng; +mod helper; +use helper::{IfTestOverflow, cast_to_bool}; + enum FunctionToTest { CheckedAdd64, SafeAdd64, @@ -15,7 +20,7 @@ enum FunctionToTest { CheckedMultiply64, SafeMultiply64, CheckedDivide64, - SafeDivide64 + SafeDivide64, } fn get_script(context: &simplex::TestContext) -> (U64MockProgram, Script) { @@ -23,7 +28,8 @@ fn get_script(context: &simplex::TestContext) -> (U64MockProgram, Script) { let logical_operations_program = U64MockProgram::new(arguments); - let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + let logical_operations_script = + logical_operations_program.get_script_pubkey(context.get_network()); (logical_operations_program, logical_operations_script) } @@ -36,10 +42,17 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u64, second_arg: u64, result: u64,) -> anyhow::Result<()> { +fn spend_script( + context: &simplex::TestContext, + function_index: FunctionToTest, + if_test_overflow: IfTestOverflow, + first_arg: u64, + second_arg: u64, + result: u64, +) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -49,11 +62,20 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over let mut ft = FinalTransaction::new(); - let witness = U64MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; + let witness = U64MockWitness { + function_index: function_index as u8, + if_test_overflow: cast_to_bool(if_test_overflow), + first_arg: first_arg, + second_arg: second_arg, + result: result, + }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(logical_operations_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); @@ -65,61 +87,77 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over #[simplex::test] fn u64_test_checked_add_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd64; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u64::MAX / 2); let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_checked_add_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd64; - let if_test_overflow = true; - let first_arg = u64::MAX; let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_add_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd64; - let if_test_overflow = false; - - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u64::MAX/2); + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u64::MAX / 2); let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeAdd64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_add_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd64; - let if_test_overflow = true; - let first_arg = u64::MAX; let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeAdd64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -127,68 +165,87 @@ fn u64_test_safe_add_64_overflow(context: simplex::TestContext) -> anyhow::Resul ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u64_test_checked_subtract_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_checked_subtract_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract64; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u64::MAX); + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u64::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_subtract_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeSubtract64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_subtract_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract64; - let if_test_overflow = true; - - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u64::MAX); + let first_arg = rand::thread_rng().gen_range(0..=u64::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u64::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeSubtract64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -196,68 +253,87 @@ fn u64_test_safe_subtract_64_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u64_test_checked_multiply_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_checked_multiply_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply64; - let if_test_overflow = true; - let first_arg = u64::MAX; let second_arg = rand::thread_rng().gen_range(2..=u64::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_multiply_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u64.pow(4)); let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeMultiply64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_multiply_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply64; - let if_test_overflow = true; - let first_arg = u64::MAX; let second_arg = rand::thread_rng().gen_range(2..=u64::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeMultiply64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -265,68 +341,87 @@ fn u64_test_safe_multiply_64_overflow(context: simplex::TestContext) -> anyhow:: ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } #[simplex::test] fn u64_test_checked_divide_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_checked_divide_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide64; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_divide_64_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide64; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = rand::thread_rng().gen_range(1..=u64::MAX); let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeDivide64, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u64_test_safe_divide_64_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide64; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u64::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeDivide64, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -334,7 +429,10 @@ fn u64_test_safe_divide_64_overflow(context: simplex::TestContext) -> anyhow::Re ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } diff --git a/tests/u8_test.rs b/tests/u8_test.rs index 2b680e1..a887688 100644 --- a/tests/u8_test.rs +++ b/tests/u8_test.rs @@ -18,6 +18,15 @@ enum FunctionToTest { SafeDivide8 } +enum IfTestOverflow { + NotOverflow, + Overflow +} + +fn cast_to_bool (if_overflow: IfTestOverflow) -> bool { + if_overflow as u8 == 1 +} + fn get_script(context: &simplex::TestContext) -> (U8MockProgram, Script) { let arguments = U8MockArguments {}; @@ -39,7 +48,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_overflow: bool, first_arg: u8, second_arg: u8, result: u8,) -> anyhow::Result<()> { +fn spend_script(context: &simplex::TestContext, function_index: FunctionToTest, if_test_overflow: bool, first_arg: u8, second_arg: u8, result: u8,) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -49,7 +58,7 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over let mut ft = FinalTransaction::new(); - let witness = U8MockWitness {function_index: function_index, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; + let witness = U8MockWitness {function_index: function_index as u8, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -65,61 +74,49 @@ fn spend_script(context: &simplex::TestContext, function_index: u8, if_test_over #[simplex::test] fn u8_test_checked_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedAdd8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_checked_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedAdd8; - let if_test_overflow = true; - let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedAdd8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::SafeAdd8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeAdd8; - let if_test_overflow = true; - let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script(&context, FunctionToTest::SafeAdd8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); assert!( txid_result.is_err(), @@ -134,61 +131,49 @@ fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn u8_test_checked_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedSubtract8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_checked_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedSubtract8; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedSubtract8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::SafeSubtract8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeSubtract8; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script(&context, FunctionToTest::SafeSubtract8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); assert!( txid_result.is_err(), @@ -203,61 +188,49 @@ fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Re #[simplex::test] fn u8_test_checked_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedMultiply8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_checked_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedMultiply8; - let if_test_overflow = true; - let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedMultiply8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::SafeMultiply8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeMultiply8; - let if_test_overflow = true; - let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script(&context, FunctionToTest::SafeMultiply8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); assert!( txid_result.is_err(), @@ -272,61 +245,49 @@ fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Re #[simplex::test] fn u8_test_checked_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedDivide8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_checked_divide_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::CheckedDivide8; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::CheckedDivide8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide8; - let if_test_overflow = false; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result)?; + spend_script(&context, FunctionToTest::SafeDivide8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; Ok(()) } #[simplex::test] fn u8_test_safe_divide_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::SafeDivide8; - let if_test_overflow = true; - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = 0; let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8, if_test_overflow, first_arg, second_arg, result); + let txid_result = spend_script(&context, FunctionToTest::SafeDivide8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); assert!( txid_result.is_err(), From eba85112d932cd42776c068053d465f299b72b48 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Thu, 4 Jun 2026 16:43:47 +0300 Subject: [PATCH 17/23] linting --- tests/asserts_test.rs | 72 ++++----- tests/logical_operations_test.rs | 16 +- tests/u8_test.rs | 249 ++++++++++++++++++++++++------- 3 files changed, 232 insertions(+), 105 deletions(-) diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index d87d15c..74a4bdd 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -1,9 +1,11 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; use simplicityhl_std::artifacts::mock::asserts_mock::AssertsMockProgram; -use simplicityhl_std::artifacts::mock::asserts_mock::derived_asserts_mock::{AssertsMockWitness, AssertsMockArguments}; +use simplicityhl_std::artifacts::mock::asserts_mock::derived_asserts_mock::{ + AssertsMockArguments, AssertsMockWitness, +}; enum FunctionToTest { HappyPath, @@ -17,7 +19,7 @@ enum FunctionToTest { AssertNone32, AssertNone64, AssertNone128, - AssertNone256 + AssertNone256, } fn get_asserts_test_script(context: &simplex::TestContext) -> (AssertsMockProgram, Script) { @@ -38,10 +40,13 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(asserts_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: u8,) -> anyhow::Result<()> { +fn spend_script( + context: &simplex::TestContext, + function_index: FunctionToTest, +) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -51,11 +56,16 @@ fn spend_script(context: &simplex::TestContext, function_index: u8,) -> anyhow:: let mut ft = FinalTransaction::new(); - let witness = AssertsMockWitness {function_index: function_index}; + let witness = AssertsMockWitness { + function_index: function_index as u8, + }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(asserts_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(asserts_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); @@ -67,21 +77,17 @@ fn spend_script(context: &simplex::TestContext, function_index: u8,) -> anyhow:: #[simplex::test] fn asserts_test_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::HappyPath; - fund_script(&context)?; - spend_script(&context, function_index as u8)?; + spend_script(&context, FunctionToTest::HappyPath)?; Ok(()) } #[simplex::test] fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertEq8; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertEq8); assert!( txid_result.is_err(), @@ -96,11 +102,9 @@ fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertEq16; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertEq16); assert!( txid_result.is_err(), @@ -115,11 +119,9 @@ fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertEq32; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertEq32); assert!( txid_result.is_err(), @@ -134,11 +136,9 @@ fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertEq64; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertEq64); assert!( txid_result.is_err(), @@ -153,11 +153,9 @@ fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertEq256; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertEq256); assert!( txid_result.is_err(), @@ -172,11 +170,9 @@ fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone8; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone8); assert!( txid_result.is_err(), @@ -191,11 +187,9 @@ fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone16; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone16); assert!( txid_result.is_err(), @@ -210,11 +204,9 @@ fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone32; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone32); assert!( txid_result.is_err(), @@ -229,11 +221,9 @@ fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone64; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone64); assert!( txid_result.is_err(), @@ -248,11 +238,9 @@ fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone128; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone128); assert!( txid_result.is_err(), @@ -267,11 +255,9 @@ fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result #[simplex::test] fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let function_index = FunctionToTest::AssertNone256; - fund_script(&context)?; - let txid_result = spend_script(&context, function_index as u8); + let txid_result = spend_script(&context, FunctionToTest::AssertNone256); assert!( txid_result.is_err(), diff --git a/tests/logical_operations_test.rs b/tests/logical_operations_test.rs index 320d86c..035211d 100644 --- a/tests/logical_operations_test.rs +++ b/tests/logical_operations_test.rs @@ -1,16 +1,19 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; use simplicityhl_std::artifacts::mock::logical_operations_mock::LogicalOperationsMockProgram; -use simplicityhl_std::artifacts::mock::logical_operations_mock::derived_logical_operations_mock::{LogicalOperationsMockArguments, LogicalOperationsMockWitness}; +use simplicityhl_std::artifacts::mock::logical_operations_mock::derived_logical_operations_mock::{ + LogicalOperationsMockArguments, LogicalOperationsMockWitness, +}; fn get_script(context: &simplex::TestContext) -> (LogicalOperationsMockProgram, Script) { let arguments = LogicalOperationsMockArguments {}; let logical_operations_program = LogicalOperationsMockProgram::new(arguments); - let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + let logical_operations_script = + logical_operations_program.get_script_pubkey(context.get_network()); (logical_operations_program, logical_operations_script) } @@ -23,7 +26,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { @@ -40,7 +43,10 @@ fn spend_script(context: &simplex::TestContext) -> anyhow::Result<()> { ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(logical_operations_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); diff --git a/tests/u8_test.rs b/tests/u8_test.rs index a887688..8c6ae51 100644 --- a/tests/u8_test.rs +++ b/tests/u8_test.rs @@ -1,4 +1,4 @@ -use simplex::simplicityhl::elements::{Script}; +use simplex::simplicityhl::elements::Script; use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; @@ -7,6 +7,9 @@ use simplicityhl_std::artifacts::mock::u8_mock::derived_u8_mock::{U8MockArgument use rand::Rng; +mod helper; +use helper::{IfTestOverflow, cast_to_bool}; + enum FunctionToTest { CheckedAdd8, SafeAdd8, @@ -15,16 +18,7 @@ enum FunctionToTest { CheckedMultiply8, SafeMultiply8, CheckedDivide8, - SafeDivide8 -} - -enum IfTestOverflow { - NotOverflow, - Overflow -} - -fn cast_to_bool (if_overflow: IfTestOverflow) -> bool { - if_overflow as u8 == 1 + SafeDivide8, } fn get_script(context: &simplex::TestContext) -> (U8MockProgram, Script) { @@ -32,7 +26,8 @@ fn get_script(context: &simplex::TestContext) -> (U8MockProgram, Script) { let logical_operations_program = U8MockProgram::new(arguments); - let logical_operations_script = logical_operations_program.get_script_pubkey(context.get_network()); + let logical_operations_script = + logical_operations_program.get_script_pubkey(context.get_network()); (logical_operations_program, logical_operations_script) } @@ -45,10 +40,17 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { let tx_receipt = signer.send(logical_operations_script.clone(), 50)?; println!("Broadcast: {}", tx_receipt); - Ok(()) + Ok(()) } -fn spend_script(context: &simplex::TestContext, function_index: FunctionToTest, if_test_overflow: bool, first_arg: u8, second_arg: u8, result: u8,) -> anyhow::Result<()> { +fn spend_script( + context: &simplex::TestContext, + function_index: FunctionToTest, + if_test_overflow: IfTestOverflow, + first_arg: u8, + second_arg: u8, + result: u8, +) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -58,11 +60,20 @@ fn spend_script(context: &simplex::TestContext, function_index: FunctionToTest, let mut ft = FinalTransaction::new(); - let witness = U8MockWitness {function_index: function_index as u8, if_test_overflow: if_test_overflow, first_arg: first_arg, second_arg: second_arg, result: result }; + let witness = U8MockWitness { + function_index: function_index as u8, + if_test_overflow: cast_to_bool(if_test_overflow), + first_arg: first_arg, + second_arg: second_arg, + result: result, + }; ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), - ProgramInput::new(Box::new(logical_operations_program.as_ref().clone()), Box::new(witness.clone())), + ProgramInput::new( + Box::new(logical_operations_program.as_ref().clone()), + Box::new(witness.clone()), + ), RequiredSignature::None, ); @@ -74,12 +85,19 @@ fn spend_script(context: &simplex::TestContext, function_index: FunctionToTest, #[simplex::test] fn u8_test_checked_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u8::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedAdd8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -88,22 +106,36 @@ fn u8_test_checked_add_8_not_overflow(context: simplex::TestContext) -> anyhow:: fn u8_test_checked_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedAdd8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedAdd8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u8_test_safe_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); - let second_arg = rand::thread_rng().gen_range(0..=u8::MAX/2); - let result = first_arg + second_arg; + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX / 2); + let second_arg = rand::thread_rng().gen_range(0..=u8::MAX / 2); + let result = first_arg + second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::SafeAdd8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeAdd8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -112,11 +144,18 @@ fn u8_test_safe_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Res fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::SafeAdd8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeAdd8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -124,7 +163,10 @@ fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result< ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } @@ -133,22 +175,36 @@ fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result< fn u8_test_checked_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedSubtract8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u8_test_checked_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u8::MAX); let result = 0; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedSubtract8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedSubtract8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -157,23 +213,37 @@ fn u8_test_checked_subtract_8_overflow(context: simplex::TestContext) -> anyhow: fn u8_test_safe_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(0..=first_arg); - let result = first_arg - second_arg; + let result = first_arg - second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::SafeSubtract8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeSubtract8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } #[simplex::test] fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { - let first_arg = rand::thread_rng().gen_range(0..=u8::MAX-1); - let second_arg = rand::thread_rng().gen_range(first_arg+1..=u8::MAX); - let result = 0; + let first_arg = rand::thread_rng().gen_range(0..=u8::MAX - 1); + let second_arg = rand::thread_rng().gen_range(first_arg + 1..=u8::MAX); + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::SafeSubtract8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeSubtract8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -181,7 +251,10 @@ fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Re ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } @@ -190,10 +263,17 @@ fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Re fn u8_test_checked_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedMultiply8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -202,10 +282,17 @@ fn u8_test_checked_multiply_8_not_overflow(context: simplex::TestContext) -> any fn u8_test_checked_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedMultiply8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedMultiply8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -214,10 +301,17 @@ fn u8_test_checked_multiply_8_overflow(context: simplex::TestContext) -> anyhow: fn u8_test_safe_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); let second_arg = rand::thread_rng().gen_range(0..=2_u8.pow(4)); - let result = first_arg * second_arg; + let result = first_arg * second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::SafeMultiply8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeMultiply8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -226,11 +320,18 @@ fn u8_test_safe_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = u8::MAX; let second_arg = rand::thread_rng().gen_range(2..=u8::MAX); - let result = 0; + let result = 0; fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::SafeMultiply8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeMultiply8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -238,7 +339,10 @@ fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Re ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } @@ -247,10 +351,17 @@ fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Re fn u8_test_checked_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedDivide8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -262,7 +373,14 @@ fn u8_test_checked_divide_8_overflow(context: simplex::TestContext) -> anyhow::R let result = 0; fund_script(&context)?; - spend_script(&context, FunctionToTest::CheckedDivide8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::CheckedDivide8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -271,10 +389,17 @@ fn u8_test_checked_divide_8_overflow(context: simplex::TestContext) -> anyhow::R fn u8_test_safe_divide_8_not_overflow(context: simplex::TestContext) -> anyhow::Result<()> { let first_arg = rand::thread_rng().gen_range(0..=u8::MAX); let second_arg = rand::thread_rng().gen_range(1..=u8::MAX); - let result = first_arg / second_arg; + let result = first_arg / second_arg; fund_script(&context)?; - spend_script(&context, FunctionToTest::SafeDivide8, cast_to_bool(IfTestOverflow::NotOverflow), first_arg, second_arg, result)?; + spend_script( + &context, + FunctionToTest::SafeDivide8, + IfTestOverflow::NotOverflow, + first_arg, + second_arg, + result, + )?; Ok(()) } @@ -287,7 +412,14 @@ fn u8_test_safe_divide_8_overflow(context: simplex::TestContext) -> anyhow::Resu fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::SafeDivide8, cast_to_bool(IfTestOverflow::Overflow), first_arg, second_arg, result); + let txid_result = spend_script( + &context, + FunctionToTest::SafeDivide8, + IfTestOverflow::Overflow, + first_arg, + second_arg, + result, + ); assert!( txid_result.is_err(), @@ -295,7 +427,10 @@ fn u8_test_safe_divide_8_overflow(context: simplex::TestContext) -> anyhow::Resu ); let err: String = txid_result.unwrap_err().to_string(); - assert_eq!(err, "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317"); + assert_eq!( + err, + "Failed to prune program: Execution reached a pruned branch: 744339c859e7ff6f8d33f9afa73734e1c908684feedc8c4d0a6112d3bf361317" + ); Ok(()) } From 847be9e0fed6e1f5af39a5f9408c06c8cc0458d5 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 14:25:37 +0300 Subject: [PATCH 18/23] refactored asserts test to be consistent with the other tests --- simf/mock/asserts_mock.simf | 191 +++++++------- tests/asserts_test.rs | 488 ++++++++++++++++++++++++++++++++++-- 2 files changed, 577 insertions(+), 102 deletions(-) diff --git a/simf/mock/asserts_mock.simf b/simf/mock/asserts_mock.simf index 364ae8b..fe2fb62 100644 --- a/simf/mock/asserts_mock.simf +++ b/simf/mock/asserts_mock.simf @@ -1,47 +1,47 @@ // todo: switch to function import when available -fn assert_eq_8(a: u8, b: u8) { // 1 +fn assert_eq_8(a: u8, b: u8) { // 0 assert!(jet::eq_8(a, b)); } -fn assert_eq_16(a: u16, b: u16) { // 2 +fn assert_eq_16(a: u16, b: u16) { // 1 assert!(jet::eq_16(a, b)); } -fn assert_eq_32(a: u32, b: u32) { // 3 +fn assert_eq_32(a: u32, b: u32) { // 2 assert!(jet::eq_32(a, b)); } -fn assert_eq_64(a: u64, b: u64) { // 4 +fn assert_eq_64(a: u64, b: u64) { // 3 assert!(jet::eq_64(a, b)); } // todo: assert_eq_128 -fn assert_eq_256(a: u256, b: u256) { // 5 +fn assert_eq_256(a: u256, b: u256) { // 4 assert!(jet::eq_256(a, b)); } -fn assert_none_8(val: Option) { // 6 +fn assert_none_8(val: Option) { // 5 assert!(is_none::(val)); } -fn assert_none_16(val: Option) { // 7 +fn assert_none_16(val: Option) { // 6 assert!(is_none::(val)); } -fn assert_none_32(val: Option) { // 8 +fn assert_none_32(val: Option) { // 7 assert!(is_none::(val)); } -fn assert_none_64(val: Option) { // 9 +fn assert_none_64(val: Option) { // 8 assert!(is_none::(val)); } -fn assert_none_128(val: Option) { // 10 +fn assert_none_128(val: Option) { // 9 assert!(is_none::(val)); } -fn assert_none_256(val: Option) { // 11 +fn assert_none_256(val: Option) { // 10 assert!(is_none::(val)); } @@ -52,84 +52,99 @@ fn if_test_this_function(index: u8, flag: u8) -> bool { fn main() { let function_index: u8 = witness::FUNCTION_INDEX; - let if_happy_path: bool = if_test_this_function(0, function_index); - let some_u8: u8 = 255; - let some_u16: u16 = 65535; - let some_u32: u32 = 4294967295; - let some_u64: u64 = 18446744073709551615; - let some_u128: u128 = 340282366920938463463374607431768211455; - let some_u256: u256 = 115792089237316195423570985008687907853269984665640564039457584007913129639935; + let first_arg_u8: Option = witness::FIRST_ARG_U8; + let second_arg_u8: Option = witness::SECOND_ARG_U8; - match if_happy_path { + let first_arg_u16: Option = witness::FIRST_ARG_U16; + let second_arg_u16: Option = witness::SECOND_ARG_U16; + + let first_arg_u32: Option = witness::FIRST_ARG_U32; + let second_arg_u32: Option = witness::SECOND_ARG_U32; + + let first_arg_u64: Option = witness::FIRST_ARG_U64; + let second_arg_u64: Option = witness::SECOND_ARG_U64; + + let first_arg_u128: Option = witness::FIRST_ARG_U128; + let second_arg_u128: Option = witness::SECOND_ARG_U128; + + let first_arg_u256: Option = witness::FIRST_ARG_U256; + let second_arg_u256: Option = witness::SECOND_ARG_U256; + + match if_test_this_function(0, function_index) { + true => { + assert_eq_8(unwrap(first_arg_u8), unwrap(second_arg_u8)); + }, + false => (), + }; + + match if_test_this_function(1, function_index) { + true => { + assert_eq_16(unwrap(first_arg_u16), unwrap(second_arg_u16)); + }, + false => (), + }; + + match if_test_this_function(2, function_index) { + true => { + assert_eq_32(unwrap(first_arg_u32), unwrap(second_arg_u32)); + }, + false => (), + }; + + match if_test_this_function(3, function_index) { + true => { + assert_eq_64(unwrap(first_arg_u64), unwrap(second_arg_u64)); + }, + false => (), + }; + + match if_test_this_function(4, function_index) { + true => { + assert_eq_256(unwrap(first_arg_u256), unwrap(second_arg_u256)); + }, + false => (), + }; + + match if_test_this_function(5, function_index) { + true => { + assert_none_8(first_arg_u8); + }, + false => (), + }; + + match if_test_this_function(6, function_index) { + true => { + assert_none_16(first_arg_u16); + }, + false => (), + }; + + match if_test_this_function(7, function_index) { + true => { + assert_none_32(first_arg_u32); + }, + false => (), + }; + + match if_test_this_function(8, function_index) { + true => { + assert_none_64(first_arg_u64); + }, + false => (), + }; + + match if_test_this_function(9, function_index) { + true => { + assert_none_128(first_arg_u128); + }, + false => (), + }; + + match if_test_this_function(10, function_index) { true => { - assert_eq_8(some_u8, some_u8); - assert_eq_16(some_u16, some_u16); - assert_eq_32(some_u32, some_u32); - assert_eq_64(some_u64, some_u64); - assert_eq_256(some_u256, some_u256); - - assert_none_8(None); - assert_none_16(None); - assert_none_32(None); - assert_none_64(None); - assert_none_128(None); - assert_none_256(None); - }, false => { - match if_test_this_function(1, function_index) { - true => assert_eq_8(1, 2), - false => (), - }; - - match if_test_this_function(2, function_index) { - true => assert_eq_16(1, 2), - false => (), - }; - - match if_test_this_function(3, function_index) { - true => assert_eq_32(1, 2), - false => (), - }; - - match if_test_this_function(4, function_index) { - true => assert_eq_64(1, 2), - false => (), - }; - - match if_test_this_function(5, function_index) { - true => assert_eq_256(1, 2), - false => (), - }; - - match if_test_this_function(6, function_index) { - true => assert_none_8(Some(some_u8)), - false => (), - }; - - match if_test_this_function(7, function_index) { - true => assert_none_16(Some(some_u16)), - false => (), - }; - - match if_test_this_function(8, function_index) { - true => assert_none_32(Some(some_u32)), - false => (), - }; - - match if_test_this_function(9, function_index) { - true => assert_none_64(Some(some_u64)), - false => (), - }; - - match if_test_this_function(10, function_index) { - true => assert_none_128(Some(some_u128)), - false => (), - }; - - match if_test_this_function(11, function_index) { - true => assert_none_256(Some(some_u256)), - false => (), - }; - } - } + assert_none_256(first_arg_u256); + }, + false => (), + }; } diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index 74a4bdd..37f79af 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -7,8 +7,9 @@ use simplicityhl_std::artifacts::mock::asserts_mock::derived_asserts_mock::{ AssertsMockArguments, AssertsMockWitness, }; +use rand::Rng; + enum FunctionToTest { - HappyPath, AssertEq8, AssertEq16, AssertEq32, @@ -46,6 +47,18 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, + first_arg_u8: Option, + second_arg_u8: Option, + first_arg_u16: Option, + second_arg_u16: Option, + first_arg_u32: Option, + second_arg_u32: Option, + first_arg_u64: Option, + second_arg_u64: Option, + first_arg_u128: Option, + second_arg_u128: Option, + first_arg_u256: Option<[u8; 32]>, + second_arg_u256: Option<[u8; 32]>, ) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -58,6 +71,18 @@ fn spend_script( let witness = AssertsMockWitness { function_index: function_index as u8, + first_arg_u8, + second_arg_u8, + first_arg_u16, + second_arg_u16, + first_arg_u32, + second_arg_u32, + first_arg_u64, + second_arg_u64, + first_arg_u128, + second_arg_u128, + first_arg_u256, + second_arg_u256, }; ft.add_program_input( @@ -76,18 +101,52 @@ fn spend_script( } #[simplex::test] -fn asserts_test_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { +fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + fund_script(&context)?; - spend_script(&context, FunctionToTest::HappyPath)?; + spend_script( + &context, + FunctionToTest::AssertEq8, + Some(some_u8), + Some(some_u8), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; Ok(()) } #[simplex::test] fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u8 = rand::thread_rng().gen_range(1..=u8::MAX); + fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertEq8); + let txid_result = spend_script( + &context, + FunctionToTest::AssertEq8, + Some(some_u8), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -100,11 +159,53 @@ fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> Ok(()) } +#[simplex::test] +fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u16: u16 = rand::thread_rng().gen_range(1..=u16::MAX); + + fund_script(&context)?; + spend_script( + &context, + FunctionToTest::AssertEq16, + Some(0), + Some(0), + Some(some_u16), + Some(some_u16), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u16: u16 = rand::thread_rng().gen_range(1..=u16::MAX); + fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertEq16); + let txid_result = spend_script( + &context, + FunctionToTest::AssertEq16, + Some(0), + Some(0), + Some(some_u16), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -117,11 +218,53 @@ fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() Ok(()) } +#[simplex::test] +fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u32: u32 = rand::thread_rng().gen_range(1..=u32::MAX); + + fund_script(&context)?; + spend_script( + &context, + FunctionToTest::AssertEq32, + Some(0), + Some(0), + Some(0), + Some(0), + Some(some_u32), + Some(some_u32), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u32: u32 = rand::thread_rng().gen_range(1..=u32::MAX); + fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertEq32); + let txid_result = spend_script( + &context, + FunctionToTest::AssertEq32, + Some(0), + Some(0), + Some(0), + Some(0), + Some(some_u32), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -134,11 +277,53 @@ fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() Ok(()) } +#[simplex::test] +fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u64: u64 = rand::thread_rng().gen_range(1..=u64::MAX); + + fund_script(&context)?; + spend_script( + &context, + FunctionToTest::AssertEq64, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(some_u64), + Some(some_u64), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u64: u64 = rand::thread_rng().gen_range(1..=u64::MAX); + fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertEq64); + let txid_result = spend_script( + &context, + FunctionToTest::AssertEq64, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(some_u64), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -151,11 +336,53 @@ fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() Ok(()) } +#[simplex::test] +fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u8: u8 = rand::thread_rng().gen_range(1..=u8::MAX); + + fund_script(&context)?; + spend_script( + &context, + FunctionToTest::AssertEq256, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([some_u8; 32]), + Some([some_u8; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let some_u8: u8 = rand::thread_rng().gen_range(1..=u8::MAX); + fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertEq256); + let txid_result = spend_script( + &context, + FunctionToTest::AssertEq256, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([some_u8; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -168,11 +395,49 @@ fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( Ok(()) } +#[simplex::test] +fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + spend_script( + &context, + FunctionToTest::AssertNone8, + None, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone8); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone8, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -185,11 +450,50 @@ fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( Ok(()) } +#[simplex::test] +fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + + spend_script( + &context, + FunctionToTest::AssertNone16, + Some(0), + Some(0), + None, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone16); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone16, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -202,11 +506,50 @@ fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result< Ok(()) } +#[simplex::test] +fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + + spend_script( + &context, + FunctionToTest::AssertNone32, + Some(0), + Some(0), + Some(0), + Some(0), + None, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone32); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone32, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -219,11 +562,50 @@ fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result< Ok(()) } +#[simplex::test] +fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + + spend_script( + &context, + FunctionToTest::AssertNone64, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + None, + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone64); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone64, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -236,11 +618,50 @@ fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result< Ok(()) } +#[simplex::test] +fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + + spend_script( + &context, + FunctionToTest::AssertNone128, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + None, + Some(0), + Some([0; 32]), + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone128); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone128, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), @@ -253,11 +674,50 @@ fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result Ok(()) } +#[simplex::test] +fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + fund_script(&context)?; + + spend_script( + &context, + FunctionToTest::AssertNone256, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + None, + Some([0; 32]), + )?; + + Ok(()) +} + #[simplex::test] fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { fund_script(&context)?; - let txid_result = spend_script(&context, FunctionToTest::AssertNone256); + let txid_result = spend_script( + &context, + FunctionToTest::AssertNone256, + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some(0), + Some([0; 32]), + Some([0; 32]), + ); assert!( txid_result.is_err(), From 940373563782ce0cecb6ae93469cb07a6454cd46 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 15:53:00 +0300 Subject: [PATCH 19/23] added constants to asserts test --- tests/asserts_test.rs | 483 +++++++++++++++++++++--------------------- 1 file changed, 245 insertions(+), 238 deletions(-) diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index 37f79af..f1559eb 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -23,6 +23,13 @@ enum FunctionToTest { AssertNone256, } +const DEFAULT_SOME_U8: Option = Some(0); +const DEFAULT_SOME_U16: Option = Some(0); +const DEFAULT_SOME_U32: Option = Some(0); +const DEFAULT_SOME_U64: Option = Some(0); +const DEFAULT_SOME_U128: Option = Some(0); +const DEFAULT_SOME_U256: Option<[u8; 32]> = Some([0; 32]); + fn get_asserts_test_script(context: &simplex::TestContext) -> (AssertsMockProgram, Script) { let arguments = AssertsMockArguments {}; @@ -110,16 +117,16 @@ fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { FunctionToTest::AssertEq8, Some(some_u8), Some(some_u8), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -136,16 +143,16 @@ fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> FunctionToTest::AssertEq8, Some(some_u8), Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -167,18 +174,18 @@ fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> spend_script( &context, FunctionToTest::AssertEq16, - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, Some(some_u16), Some(some_u16), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -193,18 +200,18 @@ fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() let txid_result = spend_script( &context, FunctionToTest::AssertEq16, - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, Some(some_u16), Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -226,18 +233,18 @@ fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> spend_script( &context, FunctionToTest::AssertEq32, - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, Some(some_u32), Some(some_u32), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -252,18 +259,18 @@ fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() let txid_result = spend_script( &context, FunctionToTest::AssertEq32, - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, Some(some_u32), Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -285,18 +292,18 @@ fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> spend_script( &context, FunctionToTest::AssertEq64, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, Some(some_u64), Some(some_u64), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -311,18 +318,18 @@ fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() let txid_result = spend_script( &context, FunctionToTest::AssertEq64, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, Some(some_u64), Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -344,16 +351,16 @@ fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> spend_script( &context, FunctionToTest::AssertEq256, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, Some([some_u8; 32]), Some([some_u8; 32]), )?; @@ -370,16 +377,16 @@ fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( let txid_result = spend_script( &context, FunctionToTest::AssertEq256, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, Some([some_u8; 32]), Some([0; 32]), ); @@ -402,17 +409,17 @@ fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> &context, FunctionToTest::AssertNone8, None, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -425,18 +432,18 @@ fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( let txid_result = spend_script( &context, FunctionToTest::AssertNone8, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -457,18 +464,18 @@ fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<() spend_script( &context, FunctionToTest::AssertNone16, - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, None, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -481,18 +488,18 @@ fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result< let txid_result = spend_script( &context, FunctionToTest::AssertNone16, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -513,18 +520,18 @@ fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<() spend_script( &context, FunctionToTest::AssertNone32, - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, None, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -537,18 +544,18 @@ fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result< let txid_result = spend_script( &context, FunctionToTest::AssertNone32, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -569,18 +576,18 @@ fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<() spend_script( &context, FunctionToTest::AssertNone64, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, None, - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -593,18 +600,18 @@ fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result< let txid_result = spend_script( &context, FunctionToTest::AssertNone64, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -625,18 +632,18 @@ fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<( spend_script( &context, FunctionToTest::AssertNone128, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, None, - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, )?; Ok(()) @@ -649,18 +656,18 @@ fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result let txid_result = spend_script( &context, FunctionToTest::AssertNone128, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( @@ -681,18 +688,18 @@ fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<( spend_script( &context, FunctionToTest::AssertNone256, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, None, - Some([0; 32]), + DEFAULT_SOME_U256, )?; Ok(()) @@ -705,18 +712,18 @@ fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result let txid_result = spend_script( &context, FunctionToTest::AssertNone256, - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some(0), - Some([0; 32]), - Some([0; 32]), + DEFAULT_SOME_U8, + DEFAULT_SOME_U8, + DEFAULT_SOME_U16, + DEFAULT_SOME_U16, + DEFAULT_SOME_U32, + DEFAULT_SOME_U32, + DEFAULT_SOME_U64, + DEFAULT_SOME_U64, + DEFAULT_SOME_U128, + DEFAULT_SOME_U128, + DEFAULT_SOME_U256, + DEFAULT_SOME_U256, ); assert!( From 0048a432003d8ef3c150079f5614b4c2668e771d Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 17:54:32 +0300 Subject: [PATCH 20/23] added function for optimized test data generation for asserts test --- tests/asserts_test.rs | 503 +++++++++++++++++------------------------- 1 file changed, 202 insertions(+), 301 deletions(-) diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index f1559eb..cd503e4 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -51,21 +51,109 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { Ok(()) } +fn generate_test_data( + function_index: FunctionToTest, + if_same_values: bool, + if_none_value: bool, +) -> AssertsMockWitness { + let mut witness: AssertsMockWitness = AssertsMockWitness { + function_index: 0, + first_arg_u8: DEFAULT_SOME_U8, + second_arg_u8: DEFAULT_SOME_U8, + first_arg_u16: DEFAULT_SOME_U16, + second_arg_u16: DEFAULT_SOME_U16, + first_arg_u32: DEFAULT_SOME_U32, + second_arg_u32: DEFAULT_SOME_U32, + first_arg_u64: DEFAULT_SOME_U64, + second_arg_u64: DEFAULT_SOME_U64, + first_arg_u128: DEFAULT_SOME_U128, + second_arg_u128: DEFAULT_SOME_U128, + first_arg_u256: DEFAULT_SOME_U256, + second_arg_u256: DEFAULT_SOME_U256, + }; + + match function_index { + FunctionToTest::AssertEq8 => { + let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + witness.first_arg_u8 = Some(some_u8); + + if if_same_values { + witness.second_arg_u8 = Some(some_u8); + }; + } + FunctionToTest::AssertEq16 => { + let some_u16 = rand::thread_rng().gen_range(0..=u16::MAX); + witness.first_arg_u16 = Some(some_u16); + + if if_same_values { + witness.second_arg_u16 = Some(some_u16); + } + } + FunctionToTest::AssertEq32 => { + let some_u32 = rand::thread_rng().gen_range(0..=u32::MAX); + witness.first_arg_u32 = Some(some_u32); + + if if_same_values { + witness.second_arg_u32 = Some(some_u32); + } + } + FunctionToTest::AssertEq64 => { + let some_u64 = rand::thread_rng().gen_range(0..=u64::MAX); + witness.first_arg_u64 = Some(some_u64); + + if if_same_values { + witness.second_arg_u64 = Some(some_u64); + } + } + FunctionToTest::AssertEq256 => { + let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + witness.first_arg_u256 = Some([some_u8; 32]); + + if if_same_values { + witness.second_arg_u256 = Some([some_u8; 32]); + } + } + FunctionToTest::AssertNone8 => { + if if_none_value { + witness.first_arg_u8 = None; + }; + } + FunctionToTest::AssertNone16 => { + if if_none_value { + witness.first_arg_u16 = None; + }; + } + FunctionToTest::AssertNone32 => { + if if_none_value { + witness.first_arg_u32 = None; + }; + } + FunctionToTest::AssertNone64 => { + if if_none_value { + witness.first_arg_u64 = None; + }; + } + FunctionToTest::AssertNone128 => { + if if_none_value { + witness.first_arg_u128 = None; + }; + } + FunctionToTest::AssertNone256 => { + if if_none_value { + witness.first_arg_u256 = None; + }; + } + } + + witness.function_index = function_index as u8; + witness +} + fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, - first_arg_u8: Option, - second_arg_u8: Option, - first_arg_u16: Option, - second_arg_u16: Option, - first_arg_u32: Option, - second_arg_u32: Option, - first_arg_u64: Option, - second_arg_u64: Option, - first_arg_u128: Option, - second_arg_u128: Option, - first_arg_u256: Option<[u8; 32]>, - second_arg_u256: Option<[u8; 32]>, + if_same_values: bool, + if_none_value: bool, ) -> anyhow::Result<()> { let signer = context.get_default_signer(); let provider = context.get_default_provider(); @@ -76,21 +164,8 @@ fn spend_script( let mut ft = FinalTransaction::new(); - let witness = AssertsMockWitness { - function_index: function_index as u8, - first_arg_u8, - second_arg_u8, - first_arg_u16, - second_arg_u16, - first_arg_u32, - second_arg_u32, - first_arg_u64, - second_arg_u64, - first_arg_u128, - second_arg_u128, - first_arg_u256, - second_arg_u256, - }; + let witness: AssertsMockWitness = + generate_test_data(function_index, if_same_values, if_none_value); ft.add_program_input( PartialInput::new(asserts_utxos[0].clone()), @@ -109,24 +184,15 @@ fn spend_script( #[simplex::test] fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + let if_same_values = true; + let if_none_value = false; fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq8, - Some(some_u8), - Some(some_u8), - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -134,25 +200,16 @@ fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { #[simplex::test] fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u8 = rand::thread_rng().gen_range(1..=u8::MAX); + let if_same_values = false; + let if_none_value = false; fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq8, - Some(some_u8), - Some(0), - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -168,24 +225,15 @@ fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u16: u16 = rand::thread_rng().gen_range(1..=u16::MAX); + let if_same_values = true; + let if_none_value = false; fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq16, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - Some(some_u16), - Some(some_u16), - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -193,25 +241,16 @@ fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u16: u16 = rand::thread_rng().gen_range(1..=u16::MAX); + let if_same_values = false; + let if_none_value = false; fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq16, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - Some(some_u16), - Some(0), - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -227,24 +266,15 @@ fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u32: u32 = rand::thread_rng().gen_range(1..=u32::MAX); + let if_same_values = true; + let if_none_value = false; fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq32, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - Some(some_u32), - Some(some_u32), - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -252,25 +282,16 @@ fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u32: u32 = rand::thread_rng().gen_range(1..=u32::MAX); + let if_same_values = false; + let if_none_value = false; fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq32, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - Some(some_u32), - Some(0), - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -286,24 +307,15 @@ fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u64: u64 = rand::thread_rng().gen_range(1..=u64::MAX); + let if_same_values = true; + let if_none_value = false; fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq64, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - Some(some_u64), - Some(some_u64), - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -311,25 +323,16 @@ fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u64: u64 = rand::thread_rng().gen_range(1..=u64::MAX); + let if_same_values = false; + let if_none_value = false; fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq64, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - Some(some_u64), - Some(0), - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -345,24 +348,15 @@ fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u8: u8 = rand::thread_rng().gen_range(1..=u8::MAX); + let if_same_values = true; + let if_none_value = false; fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq256, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - Some([some_u8; 32]), - Some([some_u8; 32]), + if_same_values, + if_none_value, )?; Ok(()) @@ -370,25 +364,16 @@ fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let some_u8: u8 = rand::thread_rng().gen_range(1..=u8::MAX); + let if_same_values = false; + let if_none_value = false; fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq256, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - Some([some_u8; 32]), - Some([0; 32]), + if_same_values, + if_none_value, ); assert!( @@ -404,22 +389,15 @@ fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone8, - None, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -427,23 +405,16 @@ fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -459,23 +430,16 @@ fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone16, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - None, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -483,23 +447,16 @@ fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone16, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -515,23 +472,16 @@ fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone32, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - None, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -539,23 +489,16 @@ fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone32, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -571,23 +514,16 @@ fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone64, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - None, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -595,23 +531,16 @@ fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone64, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -627,23 +556,16 @@ fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone128, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - None, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -651,23 +573,16 @@ fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone128, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( @@ -683,23 +598,16 @@ fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result #[simplex::test] fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = true; + fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone256, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - None, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, )?; Ok(()) @@ -707,23 +615,16 @@ fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { + let if_same_values: bool = false; + let if_none_value = false; + fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone256, - DEFAULT_SOME_U8, - DEFAULT_SOME_U8, - DEFAULT_SOME_U16, - DEFAULT_SOME_U16, - DEFAULT_SOME_U32, - DEFAULT_SOME_U32, - DEFAULT_SOME_U64, - DEFAULT_SOME_U64, - DEFAULT_SOME_U128, - DEFAULT_SOME_U128, - DEFAULT_SOME_U256, - DEFAULT_SOME_U256, + if_same_values, + if_none_value, ); assert!( From f4b8e034ae5705300c082198c8cb64a8634dae88 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 17:58:38 +0300 Subject: [PATCH 21/23] linter fixes --- tests/u16_test.rs | 6 +++--- tests/u32_test.rs | 6 +++--- tests/u64_test.rs | 6 +++--- tests/u8_test.rs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/u16_test.rs b/tests/u16_test.rs index 0d2b321..c000723 100644 --- a/tests/u16_test.rs +++ b/tests/u16_test.rs @@ -65,9 +65,9 @@ fn spend_script( let witness = U16MockWitness { function_index: function_index as u8, if_test_overflow: cast_to_bool(if_test_overflow), - first_arg: first_arg, - second_arg: second_arg, - result: result, + first_arg, + second_arg, + result, }; ft.add_program_input( diff --git a/tests/u32_test.rs b/tests/u32_test.rs index 80d50c2..ed34139 100644 --- a/tests/u32_test.rs +++ b/tests/u32_test.rs @@ -65,9 +65,9 @@ fn spend_script( let witness = U32MockWitness { function_index: function_index as u8, if_test_overflow: cast_to_bool(if_test_overflow), - first_arg: first_arg, - second_arg: second_arg, - result: result, + first_arg, + second_arg, + result, }; ft.add_program_input( diff --git a/tests/u64_test.rs b/tests/u64_test.rs index 8fb7ca9..cb84acd 100644 --- a/tests/u64_test.rs +++ b/tests/u64_test.rs @@ -65,9 +65,9 @@ fn spend_script( let witness = U64MockWitness { function_index: function_index as u8, if_test_overflow: cast_to_bool(if_test_overflow), - first_arg: first_arg, - second_arg: second_arg, - result: result, + first_arg, + second_arg, + result, }; ft.add_program_input( diff --git a/tests/u8_test.rs b/tests/u8_test.rs index 8c6ae51..81f1604 100644 --- a/tests/u8_test.rs +++ b/tests/u8_test.rs @@ -63,9 +63,9 @@ fn spend_script( let witness = U8MockWitness { function_index: function_index as u8, if_test_overflow: cast_to_bool(if_test_overflow), - first_arg: first_arg, - second_arg: second_arg, - result: result, + first_arg, + second_arg, + result, }; ft.add_program_input( From 8759bf8e8d6bcf8220187e176194d60ad4554939 Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 19:08:32 +0300 Subject: [PATCH 22/23] added constants to test --- tests/asserts_test.rs | 169 ++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 115 deletions(-) diff --git a/tests/asserts_test.rs b/tests/asserts_test.rs index cd503e4..aaf44ee 100644 --- a/tests/asserts_test.rs +++ b/tests/asserts_test.rs @@ -30,6 +30,11 @@ const DEFAULT_SOME_U64: Option = Some(0); const DEFAULT_SOME_U128: Option = Some(0); const DEFAULT_SOME_U256: Option<[u8; 32]> = Some([0; 32]); +const TEST_SAME_VALUES: bool = true; +const TEST_DIFFERENT_VALUES: bool = false; +const TEST_NONE_VALUES: bool = true; +const TEST_NOT_NONE_VALUES: bool = false; + fn get_asserts_test_script(context: &simplex::TestContext) -> (AssertsMockProgram, Script) { let arguments = AssertsMockArguments {}; @@ -74,7 +79,7 @@ fn generate_test_data( match function_index { FunctionToTest::AssertEq8 => { - let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + let some_u8 = rand::thread_rng().gen_range(1..=u8::MAX); witness.first_arg_u8 = Some(some_u8); if if_same_values { @@ -82,7 +87,7 @@ fn generate_test_data( }; } FunctionToTest::AssertEq16 => { - let some_u16 = rand::thread_rng().gen_range(0..=u16::MAX); + let some_u16 = rand::thread_rng().gen_range(1..=u16::MAX); witness.first_arg_u16 = Some(some_u16); if if_same_values { @@ -90,7 +95,7 @@ fn generate_test_data( } } FunctionToTest::AssertEq32 => { - let some_u32 = rand::thread_rng().gen_range(0..=u32::MAX); + let some_u32 = rand::thread_rng().gen_range(1..=u32::MAX); witness.first_arg_u32 = Some(some_u32); if if_same_values { @@ -98,7 +103,7 @@ fn generate_test_data( } } FunctionToTest::AssertEq64 => { - let some_u64 = rand::thread_rng().gen_range(0..=u64::MAX); + let some_u64 = rand::thread_rng().gen_range(1..=u64::MAX); witness.first_arg_u64 = Some(some_u64); if if_same_values { @@ -106,7 +111,7 @@ fn generate_test_data( } } FunctionToTest::AssertEq256 => { - let some_u8 = rand::thread_rng().gen_range(0..=u8::MAX); + let some_u8 = rand::thread_rng().gen_range(1..=u8::MAX); witness.first_arg_u256 = Some([some_u8; 32]); if if_same_values { @@ -184,15 +189,12 @@ fn spend_script( #[simplex::test] fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = true; - let if_none_value = false; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq8, - if_same_values, - if_none_value, + TEST_SAME_VALUES, + TEST_NOT_NONE_VALUES, )?; Ok(()) @@ -200,16 +202,13 @@ fn assert_eq_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { #[simplex::test] fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq8, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -225,15 +224,12 @@ fn assert_eq_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = true; - let if_none_value = false; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq16, - if_same_values, - if_none_value, + TEST_SAME_VALUES, + TEST_NOT_NONE_VALUES, )?; Ok(()) @@ -241,16 +237,13 @@ fn assert_eq_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq16, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -266,15 +259,12 @@ fn assert_eq_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = true; - let if_none_value = false; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq32, - if_same_values, - if_none_value, + TEST_SAME_VALUES, + TEST_NOT_NONE_VALUES, )?; Ok(()) @@ -282,16 +272,13 @@ fn assert_eq_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq32, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -307,15 +294,12 @@ fn assert_eq_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = true; - let if_none_value = false; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq64, - if_same_values, - if_none_value, + TEST_SAME_VALUES, + TEST_NOT_NONE_VALUES, )?; Ok(()) @@ -323,16 +307,13 @@ fn assert_eq_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq64, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -348,15 +329,12 @@ fn assert_eq_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = true; - let if_none_value = false; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertEq256, - if_same_values, - if_none_value, + TEST_SAME_VALUES, + TEST_NOT_NONE_VALUES, )?; Ok(()) @@ -364,16 +342,13 @@ fn assert_eq_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertEq256, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -389,15 +364,12 @@ fn assert_eq_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone8, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -405,16 +377,13 @@ fn assert_none_8_happy_path(context: simplex::TestContext) -> anyhow::Result<()> #[simplex::test] fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone8, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -430,16 +399,13 @@ fn assert_none_8_unhappy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone16, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -447,16 +413,13 @@ fn assert_none_16_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone16, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -472,16 +435,13 @@ fn assert_none_16_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone32, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -489,16 +449,13 @@ fn assert_none_32_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone32, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -514,16 +471,13 @@ fn assert_none_32_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone64, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -531,16 +485,13 @@ fn assert_none_64_happy_path(context: simplex::TestContext) -> anyhow::Result<() #[simplex::test] fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone64, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -556,16 +507,13 @@ fn assert_none_64_unhappy_path(context: simplex::TestContext) -> anyhow::Result< #[simplex::test] fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone128, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -573,16 +521,13 @@ fn assert_none_128_happy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone128, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( @@ -598,16 +543,13 @@ fn assert_none_128_unhappy_path(context: simplex::TestContext) -> anyhow::Result #[simplex::test] fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = true; - fund_script(&context)?; spend_script( &context, FunctionToTest::AssertNone256, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NONE_VALUES, )?; Ok(()) @@ -615,16 +557,13 @@ fn assert_none_256_happy_path(context: simplex::TestContext) -> anyhow::Result<( #[simplex::test] fn assert_none_256_unhappy_path(context: simplex::TestContext) -> anyhow::Result<()> { - let if_same_values: bool = false; - let if_none_value = false; - fund_script(&context)?; let txid_result = spend_script( &context, FunctionToTest::AssertNone256, - if_same_values, - if_none_value, + TEST_DIFFERENT_VALUES, + TEST_NOT_NONE_VALUES, ); assert!( From 42cecb54e76c2f7454ed4ea2645866d71e7a6afc Mon Sep 17 00:00:00 2001 From: aritkulova Date: Fri, 5 Jun 2026 19:38:49 +0300 Subject: [PATCH 23/23] switched from enum to constants for consistency --- tests/helper.rs | 10 ++-------- tests/u16_test.rs | 38 +++++++++++++++++++------------------- tests/u32_test.rs | 38 +++++++++++++++++++------------------- tests/u64_test.rs | 38 +++++++++++++++++++------------------- tests/u8_test.rs | 38 +++++++++++++++++++------------------- 5 files changed, 78 insertions(+), 84 deletions(-) diff --git a/tests/helper.rs b/tests/helper.rs index 32060f1..ea695c6 100644 --- a/tests/helper.rs +++ b/tests/helper.rs @@ -1,8 +1,2 @@ -pub enum IfTestOverflow { - NotOverflow, - Overflow, -} - -pub fn cast_to_bool(if_overflow: IfTestOverflow) -> bool { - if_overflow as u8 == 1 -} +pub const TEST_OVERFLOW: bool = true; +pub const NOT_TEST_OVERFLOW: bool = false; diff --git a/tests/u16_test.rs b/tests/u16_test.rs index c000723..6548316 100644 --- a/tests/u16_test.rs +++ b/tests/u16_test.rs @@ -10,7 +10,7 @@ use simplicityhl_std::artifacts::mock::u16_mock::derived_u16_mock::{ use rand::Rng; mod helper; -use helper::{IfTestOverflow, cast_to_bool}; +use crate::helper::{NOT_TEST_OVERFLOW, TEST_OVERFLOW}; enum FunctionToTest { CheckedAdd16, @@ -48,7 +48,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, - if_test_overflow: IfTestOverflow, + if_test_overflow: bool, first_arg: u16, second_arg: u16, result: u16, @@ -64,7 +64,7 @@ fn spend_script( let witness = U16MockWitness { function_index: function_index as u8, - if_test_overflow: cast_to_bool(if_test_overflow), + if_test_overflow, first_arg, second_arg, result, @@ -95,7 +95,7 @@ fn u16_test_checked_add_16_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::CheckedAdd16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -114,7 +114,7 @@ fn u16_test_checked_add_16_overflow(context: simplex::TestContext) -> anyhow::Re spend_script( &context, FunctionToTest::CheckedAdd16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -133,7 +133,7 @@ fn u16_test_safe_add_16_not_overflow(context: simplex::TestContext) -> anyhow::R spend_script( &context, FunctionToTest::SafeAdd16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -153,7 +153,7 @@ fn u16_test_safe_add_16_overflow(context: simplex::TestContext) -> anyhow::Resul let txid_result = spend_script( &context, FunctionToTest::SafeAdd16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -183,7 +183,7 @@ fn u16_test_checked_subtract_16_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedSubtract16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -202,7 +202,7 @@ fn u16_test_checked_subtract_16_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedSubtract16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -221,7 +221,7 @@ fn u16_test_safe_subtract_16_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeSubtract16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -241,7 +241,7 @@ fn u16_test_safe_subtract_16_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeSubtract16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -271,7 +271,7 @@ fn u16_test_checked_multiply_16_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedMultiply16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -290,7 +290,7 @@ fn u16_test_checked_multiply_16_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedMultiply16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -309,7 +309,7 @@ fn u16_test_safe_multiply_16_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeMultiply16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -329,7 +329,7 @@ fn u16_test_safe_multiply_16_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeMultiply16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -359,7 +359,7 @@ fn u16_test_checked_divide_16_not_overflow(context: simplex::TestContext) -> any spend_script( &context, FunctionToTest::CheckedDivide16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -378,7 +378,7 @@ fn u16_test_checked_divide_16_overflow(context: simplex::TestContext) -> anyhow: spend_script( &context, FunctionToTest::CheckedDivide16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -397,7 +397,7 @@ fn u16_test_safe_divide_16_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::SafeDivide16, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -417,7 +417,7 @@ fn u16_test_safe_divide_16_overflow(context: simplex::TestContext) -> anyhow::Re let txid_result = spend_script( &context, FunctionToTest::SafeDivide16, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, diff --git a/tests/u32_test.rs b/tests/u32_test.rs index ed34139..ed0145b 100644 --- a/tests/u32_test.rs +++ b/tests/u32_test.rs @@ -10,7 +10,7 @@ use simplicityhl_std::artifacts::mock::u32_mock::derived_u32_mock::{ use rand::Rng; mod helper; -use helper::{IfTestOverflow, cast_to_bool}; +use crate::helper::{NOT_TEST_OVERFLOW, TEST_OVERFLOW}; enum FunctionToTest { CheckedAdd32, @@ -48,7 +48,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, - if_test_overflow: IfTestOverflow, + if_test_overflow: bool, first_arg: u32, second_arg: u32, result: u32, @@ -64,7 +64,7 @@ fn spend_script( let witness = U32MockWitness { function_index: function_index as u8, - if_test_overflow: cast_to_bool(if_test_overflow), + if_test_overflow, first_arg, second_arg, result, @@ -95,7 +95,7 @@ fn u32_test_checked_add_32_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::CheckedAdd32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -114,7 +114,7 @@ fn u32_test_checked_add_32_overflow(context: simplex::TestContext) -> anyhow::Re spend_script( &context, FunctionToTest::CheckedAdd32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -133,7 +133,7 @@ fn u32_test_safe_add_32_not_overflow(context: simplex::TestContext) -> anyhow::R spend_script( &context, FunctionToTest::SafeAdd32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -153,7 +153,7 @@ fn u32_test_safe_add_32_overflow(context: simplex::TestContext) -> anyhow::Resul let txid_result = spend_script( &context, FunctionToTest::SafeAdd32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -183,7 +183,7 @@ fn u32_test_checked_subtract_32_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedSubtract32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -202,7 +202,7 @@ fn u32_test_checked_subtract_32_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedSubtract32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -221,7 +221,7 @@ fn u32_test_safe_subtract_32_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeSubtract32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -241,7 +241,7 @@ fn u32_test_safe_subtract_32_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeSubtract32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -271,7 +271,7 @@ fn u32_test_checked_multiply_32_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedMultiply32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -290,7 +290,7 @@ fn u32_test_checked_multiply_32_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedMultiply32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -309,7 +309,7 @@ fn u32_test_safe_multiply_32_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeMultiply32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -329,7 +329,7 @@ fn u32_test_safe_multiply_32_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeMultiply32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -359,7 +359,7 @@ fn u32_test_checked_divide_32_not_overflow(context: simplex::TestContext) -> any spend_script( &context, FunctionToTest::CheckedDivide32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -378,7 +378,7 @@ fn u32_test_checked_divide_32_overflow(context: simplex::TestContext) -> anyhow: spend_script( &context, FunctionToTest::CheckedDivide32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -397,7 +397,7 @@ fn u32_test_safe_divide_32_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::SafeDivide32, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -417,7 +417,7 @@ fn u32_test_safe_divide_32_overflow(context: simplex::TestContext) -> anyhow::Re let txid_result = spend_script( &context, FunctionToTest::SafeDivide32, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, diff --git a/tests/u64_test.rs b/tests/u64_test.rs index cb84acd..56d1ae9 100644 --- a/tests/u64_test.rs +++ b/tests/u64_test.rs @@ -10,7 +10,7 @@ use simplicityhl_std::artifacts::mock::u64_mock::derived_u64_mock::{ use rand::Rng; mod helper; -use helper::{IfTestOverflow, cast_to_bool}; +use crate::helper::{NOT_TEST_OVERFLOW, TEST_OVERFLOW}; enum FunctionToTest { CheckedAdd64, @@ -48,7 +48,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, - if_test_overflow: IfTestOverflow, + if_test_overflow: bool, first_arg: u64, second_arg: u64, result: u64, @@ -64,7 +64,7 @@ fn spend_script( let witness = U64MockWitness { function_index: function_index as u8, - if_test_overflow: cast_to_bool(if_test_overflow), + if_test_overflow, first_arg, second_arg, result, @@ -95,7 +95,7 @@ fn u64_test_checked_add_64_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::CheckedAdd64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -114,7 +114,7 @@ fn u64_test_checked_add_64_overflow(context: simplex::TestContext) -> anyhow::Re spend_script( &context, FunctionToTest::CheckedAdd64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -133,7 +133,7 @@ fn u64_test_safe_add_64_not_overflow(context: simplex::TestContext) -> anyhow::R spend_script( &context, FunctionToTest::SafeAdd64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -153,7 +153,7 @@ fn u64_test_safe_add_64_overflow(context: simplex::TestContext) -> anyhow::Resul let txid_result = spend_script( &context, FunctionToTest::SafeAdd64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -183,7 +183,7 @@ fn u64_test_checked_subtract_64_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedSubtract64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -202,7 +202,7 @@ fn u64_test_checked_subtract_64_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedSubtract64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -221,7 +221,7 @@ fn u64_test_safe_subtract_64_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeSubtract64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -241,7 +241,7 @@ fn u64_test_safe_subtract_64_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeSubtract64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -271,7 +271,7 @@ fn u64_test_checked_multiply_64_not_overflow(context: simplex::TestContext) -> a spend_script( &context, FunctionToTest::CheckedMultiply64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -290,7 +290,7 @@ fn u64_test_checked_multiply_64_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedMultiply64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -309,7 +309,7 @@ fn u64_test_safe_multiply_64_not_overflow(context: simplex::TestContext) -> anyh spend_script( &context, FunctionToTest::SafeMultiply64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -329,7 +329,7 @@ fn u64_test_safe_multiply_64_overflow(context: simplex::TestContext) -> anyhow:: let txid_result = spend_script( &context, FunctionToTest::SafeMultiply64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -359,7 +359,7 @@ fn u64_test_checked_divide_64_not_overflow(context: simplex::TestContext) -> any spend_script( &context, FunctionToTest::CheckedDivide64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -378,7 +378,7 @@ fn u64_test_checked_divide_64_overflow(context: simplex::TestContext) -> anyhow: spend_script( &context, FunctionToTest::CheckedDivide64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -397,7 +397,7 @@ fn u64_test_safe_divide_64_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::SafeDivide64, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -417,7 +417,7 @@ fn u64_test_safe_divide_64_overflow(context: simplex::TestContext) -> anyhow::Re let txid_result = spend_script( &context, FunctionToTest::SafeDivide64, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, diff --git a/tests/u8_test.rs b/tests/u8_test.rs index 81f1604..3732867 100644 --- a/tests/u8_test.rs +++ b/tests/u8_test.rs @@ -8,7 +8,7 @@ use simplicityhl_std::artifacts::mock::u8_mock::derived_u8_mock::{U8MockArgument use rand::Rng; mod helper; -use helper::{IfTestOverflow, cast_to_bool}; +use crate::helper::{NOT_TEST_OVERFLOW, TEST_OVERFLOW}; enum FunctionToTest { CheckedAdd8, @@ -46,7 +46,7 @@ fn fund_script(context: &simplex::TestContext) -> anyhow::Result<()> { fn spend_script( context: &simplex::TestContext, function_index: FunctionToTest, - if_test_overflow: IfTestOverflow, + if_test_overflow: bool, first_arg: u8, second_arg: u8, result: u8, @@ -62,7 +62,7 @@ fn spend_script( let witness = U8MockWitness { function_index: function_index as u8, - if_test_overflow: cast_to_bool(if_test_overflow), + if_test_overflow, first_arg, second_arg, result, @@ -93,7 +93,7 @@ fn u8_test_checked_add_8_not_overflow(context: simplex::TestContext) -> anyhow:: spend_script( &context, FunctionToTest::CheckedAdd8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -112,7 +112,7 @@ fn u8_test_checked_add_8_overflow(context: simplex::TestContext) -> anyhow::Resu spend_script( &context, FunctionToTest::CheckedAdd8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -131,7 +131,7 @@ fn u8_test_safe_add_8_not_overflow(context: simplex::TestContext) -> anyhow::Res spend_script( &context, FunctionToTest::SafeAdd8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -151,7 +151,7 @@ fn u8_test_safe_add_8_overflow(context: simplex::TestContext) -> anyhow::Result< let txid_result = spend_script( &context, FunctionToTest::SafeAdd8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -181,7 +181,7 @@ fn u8_test_checked_subtract_8_not_overflow(context: simplex::TestContext) -> any spend_script( &context, FunctionToTest::CheckedSubtract8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -200,7 +200,7 @@ fn u8_test_checked_subtract_8_overflow(context: simplex::TestContext) -> anyhow: spend_script( &context, FunctionToTest::CheckedSubtract8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -219,7 +219,7 @@ fn u8_test_safe_subtract_8_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::SafeSubtract8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -239,7 +239,7 @@ fn u8_test_safe_subtract_8_overflow(context: simplex::TestContext) -> anyhow::Re let txid_result = spend_script( &context, FunctionToTest::SafeSubtract8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -269,7 +269,7 @@ fn u8_test_checked_multiply_8_not_overflow(context: simplex::TestContext) -> any spend_script( &context, FunctionToTest::CheckedMultiply8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -288,7 +288,7 @@ fn u8_test_checked_multiply_8_overflow(context: simplex::TestContext) -> anyhow: spend_script( &context, FunctionToTest::CheckedMultiply8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -307,7 +307,7 @@ fn u8_test_safe_multiply_8_not_overflow(context: simplex::TestContext) -> anyhow spend_script( &context, FunctionToTest::SafeMultiply8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -327,7 +327,7 @@ fn u8_test_safe_multiply_8_overflow(context: simplex::TestContext) -> anyhow::Re let txid_result = spend_script( &context, FunctionToTest::SafeMultiply8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -357,7 +357,7 @@ fn u8_test_checked_divide_8_not_overflow(context: simplex::TestContext) -> anyho spend_script( &context, FunctionToTest::CheckedDivide8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -376,7 +376,7 @@ fn u8_test_checked_divide_8_overflow(context: simplex::TestContext) -> anyhow::R spend_script( &context, FunctionToTest::CheckedDivide8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result, @@ -395,7 +395,7 @@ fn u8_test_safe_divide_8_not_overflow(context: simplex::TestContext) -> anyhow:: spend_script( &context, FunctionToTest::SafeDivide8, - IfTestOverflow::NotOverflow, + NOT_TEST_OVERFLOW, first_arg, second_arg, result, @@ -415,7 +415,7 @@ fn u8_test_safe_divide_8_overflow(context: simplex::TestContext) -> anyhow::Resu let txid_result = spend_script( &context, FunctionToTest::SafeDivide8, - IfTestOverflow::Overflow, + TEST_OVERFLOW, first_arg, second_arg, result,