From 24b937185ba166eaea40d2eb65b40b22f062dc89 Mon Sep 17 00:00:00 2001 From: LesterEvSe Date: Mon, 29 Jun 2026 18:50:28 +0300 Subject: [PATCH] feat: recode `uint` operations for clarity --- ...ations_mock.simf => logical_ops_test.simf} | 0 simf/u16_mock.simf | 140 ------ simf/u16_test.simf | 37 ++ simf/u32_mock.simf | 140 ------ simf/u32_test.simf | 34 ++ simf/u64_mock.simf | 140 ------ simf/u64_test.simf | 34 ++ simf/u8_mock.simf | 140 ------ simf/u8_test.simf | 37 ++ tests/common/mod.rs | 77 +++ tests/common/uint.rs | 267 ++++++++++ tests/helper.rs | 20 +- tests/logical_operations_test.rs | 65 --- tests/logical_ops_test.rs | 14 + tests/u16_test.rs | 442 ++--------------- tests/u32_test.rs | 459 ++---------------- tests/u64_test.rs | 442 ++--------------- tests/u8_test.rs | 443 ++--------------- 18 files changed, 631 insertions(+), 2300 deletions(-) rename simf/{logical_operations_mock.simf => logical_ops_test.simf} (100%) delete mode 100644 simf/u16_mock.simf create mode 100644 simf/u16_test.simf delete mode 100644 simf/u32_mock.simf create mode 100644 simf/u32_test.simf delete mode 100644 simf/u64_mock.simf create mode 100644 simf/u64_test.simf delete mode 100644 simf/u8_mock.simf create mode 100644 simf/u8_test.simf create mode 100644 tests/common/mod.rs create mode 100644 tests/common/uint.rs delete mode 100644 tests/logical_operations_test.rs create mode 100644 tests/logical_ops_test.rs diff --git a/simf/logical_operations_mock.simf b/simf/logical_ops_test.simf similarity index 100% rename from simf/logical_operations_mock.simf rename to simf/logical_ops_test.simf diff --git a/simf/u16_mock.simf b/simf/u16_mock.simf deleted file mode 100644 index ffe58c0..0000000 --- a/simf/u16_mock.simf +++ /dev/null @@ -1,140 +0,0 @@ -use crate::lib::u16::{checked_add_16, safe_add_16, checked_sub_16, safe_sub_16, checked_mul_16, safe_mul_16, checked_div_16, safe_div_16}; - -use crate::helper::if_test_this_function; - -fn main() { - let function_index: u8 = witness::FUNCTION_INDEX; - let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - - 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 overflowing_u16: Option = checked_add_16(first_arg, second_arg); - assert!(is_none::(overflowing_u16)); - }, - false => { - let fitting_u16: Option = checked_add_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fitting_u16), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(1, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: u16 = safe_add_16(first_arg, second_arg); - }, - false => { - let fitting_u16: u16 = safe_add_16(first_arg, second_arg); - assert!(jet::eq_16(fitting_u16, result)); - } - } - }, - false => (), - }; - - // subtract - match if_test_this_function(2, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: Option = checked_sub_16(first_arg, second_arg); - assert!(is_none::(overflowing_u16)); - }, - false => { - let fitting_u16: Option = checked_sub_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fitting_u16), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(3, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: u16 = safe_sub_16(first_arg, second_arg); - }, - false => { - let fitting_u16: u16 = safe_sub_16(first_arg, second_arg); - assert!(jet::eq_16(fitting_u16, result)); - } - } - }, - false => (), - }; - - // multiply - match if_test_this_function(4, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: Option = checked_mul_16(first_arg, second_arg); - assert!(is_none::(overflowing_u16)); - }, - false => { - let fitting_u16: Option = checked_mul_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fitting_u16), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(5, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: u16 = safe_mul_16(first_arg, second_arg); - }, - false => { - let fitting_u16: u16 = safe_mul_16(first_arg, second_arg); - assert!(jet::eq_16(fitting_u16, result)); - } - } - }, - false => (), - }; - - // divide - match if_test_this_function(6, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: Option = checked_div_16(first_arg, second_arg); - assert!(is_none::(overflowing_u16)); - }, - false => { - let fitting_u16: Option = checked_div_16(first_arg, second_arg); - assert!(jet::eq_16(unwrap(fitting_u16), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(7, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u16: u16 = safe_div_16(first_arg, second_arg); - }, - false => { - let fitting_u16: u16 = safe_div_16(first_arg, second_arg); - assert!(jet::eq_16(fitting_u16, result)); - } - } - }, - false => (), - }; -} diff --git a/simf/u16_test.simf b/simf/u16_test.simf new file mode 100644 index 0000000..d603ec2 --- /dev/null +++ b/simf/u16_test.simf @@ -0,0 +1,37 @@ +use crate::lib::u16::{checked_add_16, safe_add_16, checked_sub_16, safe_sub_16, checked_mul_16, safe_mul_16, checked_div_16, safe_div_16}; + +use crate::helper::if_test_this_function; + +// Asserts a `checked_*` result equals the expected Option. +// `None` encodes the overflow case, `Some(e)` the fitting case, so a single +// witness value carries both, removing the need for a separate overflow flag. +fn assert_eq_opt(result: Option, expected: Option) { + match expected { + None => assert!(is_none::(result)), + Some(e: u16) => assert!(jet::eq_16(unwrap(result), e)), + } +} + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let a: u16 = witness::FIRST_ARG; + let b: u16 = witness::SECOND_ARG; + let expected: Option = witness::EXPECTED; + + // add + match if_test_this_function(0, fn_idx) { true => { assert_eq_opt(checked_add_16(a, b), expected); }, false => (), }; + match if_test_this_function(1, fn_idx) { true => { assert!(jet::eq_16(safe_add_16(a, b), unwrap(expected))); }, false => (), }; + + // sub + match if_test_this_function(2, fn_idx) { true => { assert_eq_opt(checked_sub_16(a, b), expected); }, false => (), }; + match if_test_this_function(3, fn_idx) { true => { assert!(jet::eq_16(safe_sub_16(a, b), unwrap(expected))); }, false => (), }; + + // mul + match if_test_this_function(4, fn_idx) { true => { assert_eq_opt(checked_mul_16(a, b), expected); }, false => (), }; + match if_test_this_function(5, fn_idx) { true => { assert!(jet::eq_16(safe_mul_16(a, b), unwrap(expected))); }, false => (), }; + + // div + match if_test_this_function(6, fn_idx) { true => { assert_eq_opt(checked_div_16(a, b), expected); }, false => (), }; + match if_test_this_function(7, fn_idx) { true => { assert!(jet::eq_16(safe_div_16(a, b), unwrap(expected))); }, false => (), }; +} diff --git a/simf/u32_mock.simf b/simf/u32_mock.simf deleted file mode 100644 index a1ae4b4..0000000 --- a/simf/u32_mock.simf +++ /dev/null @@ -1,140 +0,0 @@ -use crate::lib::u32::{checked_add_32, safe_add_32, checked_sub_32, safe_sub_32, checked_mul_32, safe_mul_32, checked_div_32, safe_div_32}; - -use crate::helper::if_test_this_function; - -fn main() { - let function_index: u8 = witness::FUNCTION_INDEX; - let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - - 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 overflowing_u32: Option = checked_add_32(first_arg, second_arg); - assert!(is_none::(overflowing_u32)); - }, - false => { - let fitting_u32: Option = checked_add_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fitting_u32), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(1, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: u32 = safe_add_32(first_arg, second_arg); - }, - false => { - let fitting_u32: u32 = safe_add_32(first_arg, second_arg); - assert!(jet::eq_32(fitting_u32, result)); - } - } - }, - false => (), - }; - - // subtract - match if_test_this_function(2, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: Option = checked_sub_32(first_arg, second_arg); - assert!(is_none::(overflowing_u32)); - }, - false => { - let fitting_u32: Option = checked_sub_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fitting_u32), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(3, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: u32 = safe_sub_32(first_arg, second_arg); - }, - false => { - let fitting_u32: u32 = safe_sub_32(first_arg, second_arg); - assert!(jet::eq_32(fitting_u32, result)); - } - } - }, - false => (), - }; - - // multiply - match if_test_this_function(4, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: Option = checked_mul_32(first_arg, second_arg); - assert!(is_none::(overflowing_u32)); - }, - false => { - let fitting_u32: Option = checked_mul_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fitting_u32), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(5, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: u32 = safe_mul_32(first_arg, second_arg); - }, - false => { - let fitting_u32: u32 = safe_mul_32(first_arg, second_arg); - assert!(jet::eq_32(fitting_u32, result)); - } - } - }, - false => (), - }; - - // divide - match if_test_this_function(6, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: Option = checked_div_32(first_arg, second_arg); - assert!(is_none::(overflowing_u32)); - }, - false => { - let fitting_u32: Option = checked_div_32(first_arg, second_arg); - assert!(jet::eq_32(unwrap(fitting_u32), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(7, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u32: u32 = safe_div_32(first_arg, second_arg); - }, - false => { - let fitting_u32: u32 = safe_div_32(first_arg, second_arg); - assert!(jet::eq_32(fitting_u32, result)); - } - } - }, - false => (), - }; -} diff --git a/simf/u32_test.simf b/simf/u32_test.simf new file mode 100644 index 0000000..f5654cc --- /dev/null +++ b/simf/u32_test.simf @@ -0,0 +1,34 @@ +use crate::lib::u32::{checked_add_32, safe_add_32, checked_sub_32, safe_sub_32, checked_mul_32, safe_mul_32, checked_div_32, safe_div_32}; + +use crate::helper::if_test_this_function; + +fn assert_eq_opt(result: Option, expected: Option) { + match expected { + None => assert!(is_none::(result)), + Some(e: u32) => assert!(jet::eq_32(unwrap(result), e)), + } +} + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let a: u32 = witness::FIRST_ARG; + let b: u32 = witness::SECOND_ARG; + let expected: Option = witness::EXPECTED; + + // add + match if_test_this_function(0, fn_idx) { true => { assert_eq_opt(checked_add_32(a, b), expected); }, false => (), }; + match if_test_this_function(1, fn_idx) { true => { assert!(jet::eq_32(safe_add_32(a, b), unwrap(expected))); }, false => (), }; + + // sub + match if_test_this_function(2, fn_idx) { true => { assert_eq_opt(checked_sub_32(a, b), expected); }, false => (), }; + match if_test_this_function(3, fn_idx) { true => { assert!(jet::eq_32(safe_sub_32(a, b), unwrap(expected))); }, false => (), }; + + // mul + match if_test_this_function(4, fn_idx) { true => { assert_eq_opt(checked_mul_32(a, b), expected); }, false => (), }; + match if_test_this_function(5, fn_idx) { true => { assert!(jet::eq_32(safe_mul_32(a, b), unwrap(expected))); }, false => (), }; + + // div + match if_test_this_function(6, fn_idx) { true => { assert_eq_opt(checked_div_32(a, b), expected); }, false => (), }; + match if_test_this_function(7, fn_idx) { true => { assert!(jet::eq_32(safe_div_32(a, b), unwrap(expected))); }, false => (), }; +} diff --git a/simf/u64_mock.simf b/simf/u64_mock.simf deleted file mode 100644 index 5f20922..0000000 --- a/simf/u64_mock.simf +++ /dev/null @@ -1,140 +0,0 @@ -use crate::lib::u64::{checked_add_64, safe_add_64, checked_sub_64, safe_sub_64, checked_mul_64, safe_mul_64, checked_div_64, safe_div_64}; - -use crate::helper::if_test_this_function; - -fn main() { - let function_index: u8 = witness::FUNCTION_INDEX; - let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - - 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 overflowing_u64: Option = checked_add_64(first_arg, second_arg); - assert!(is_none::(overflowing_u64)); - }, - false => { - let fitting_u64: Option = checked_add_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fitting_u64), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(1, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: u64 = safe_add_64(first_arg, second_arg); - }, - false => { - let fitting_u64: u64 = safe_add_64(first_arg, second_arg); - assert!(jet::eq_64(fitting_u64, result)); - } - } - }, - false => (), - }; - - // subtract - match if_test_this_function(2, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: Option = checked_sub_64(first_arg, second_arg); - assert!(is_none::(overflowing_u64)); - }, - false => { - let fitting_u64: Option = checked_sub_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fitting_u64), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(3, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: u64 = safe_sub_64(first_arg, second_arg); - }, - false => { - let fitting_u64: u64 = safe_sub_64(first_arg, second_arg); - assert!(jet::eq_64(fitting_u64, result)); - } - } - }, - false => (), - }; - - // multiply - match if_test_this_function(4, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: Option = checked_mul_64(first_arg, second_arg); - assert!(is_none::(overflowing_u64)); - }, - false => { - let fitting_u64: Option = checked_mul_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fitting_u64), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(5, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: u64 = safe_mul_64(first_arg, second_arg); - }, - false => { - let fitting_u64: u64 = safe_mul_64(first_arg, second_arg); - assert!(jet::eq_64(fitting_u64, result)); - } - } - }, - false => (), - }; - - // divide - match if_test_this_function(6, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: Option = checked_div_64(first_arg, second_arg); - assert!(is_none::(overflowing_u64)); - }, - false => { - let fitting_u64: Option = checked_div_64(first_arg, second_arg); - assert!(jet::eq_64(unwrap(fitting_u64), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(7, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u64: u64 = safe_div_64(first_arg, second_arg); - }, - false => { - let fitting_u64: u64 = safe_div_64(first_arg, second_arg); - assert!(jet::eq_64(fitting_u64, result)); - } - } - }, - false => (), - }; -} diff --git a/simf/u64_test.simf b/simf/u64_test.simf new file mode 100644 index 0000000..8d01e15 --- /dev/null +++ b/simf/u64_test.simf @@ -0,0 +1,34 @@ +use crate::lib::u64::{checked_add_64, safe_add_64, checked_sub_64, safe_sub_64, checked_mul_64, safe_mul_64, checked_div_64, safe_div_64}; + +use crate::helper::if_test_this_function; + +fn assert_eq_opt(result: Option, expected: Option) { + match expected { + None => assert!(is_none::(result)), + Some(e: u64) => assert!(jet::eq_64(unwrap(result), e)), + } +} + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let a: u64 = witness::FIRST_ARG; + let b: u64 = witness::SECOND_ARG; + let expected: Option = witness::EXPECTED; + + match if_test_this_function(0, fn_idx) { true => { assert_eq_opt(checked_add_64(a, b), expected); }, false => (), }; + match if_test_this_function(1, fn_idx) { true => { assert!(jet::eq_64(safe_add_64(a, b), unwrap(expected))); }, false => (), }; + + // sub + match if_test_this_function(2, fn_idx) { true => { assert_eq_opt(checked_sub_64(a, b), expected); }, false => (), }; + match if_test_this_function(3, fn_idx) { true => { assert!(jet::eq_64(safe_sub_64(a, b), unwrap(expected))); }, false => (), }; + + // mul + match if_test_this_function(4, fn_idx) { true => { assert_eq_opt(checked_mul_64(a, b), expected); }, false => (), }; + match if_test_this_function(5, fn_idx) { true => { assert!(jet::eq_64(safe_mul_64(a, b), unwrap(expected))); }, false => (), }; + + // div + match if_test_this_function(6, fn_idx) { true => { assert_eq_opt(checked_div_64(a, b), expected); }, false => (), }; + match if_test_this_function(7, fn_idx) { true => { assert!(jet::eq_64(safe_div_64(a, b), unwrap(expected))); }, false => (), }; + +} diff --git a/simf/u8_mock.simf b/simf/u8_mock.simf deleted file mode 100644 index d45fcd3..0000000 --- a/simf/u8_mock.simf +++ /dev/null @@ -1,140 +0,0 @@ -use crate::lib::u8::{checked_add_8, safe_add_8, checked_sub_8, safe_sub_8, checked_mul_8, safe_mul_8, checked_div_8, safe_div_8}; - -use crate::helper::if_test_this_function; - -fn main() { - let function_index: u8 = witness::FUNCTION_INDEX; - let if_test_overflow: bool = witness::IF_TEST_OVERFLOW; - - let first_arg: u8 = witness::FIRST_ARG; - let second_arg: u8 = witness::SECOND_ARG; - let result: u8 = witness::RESULT; - - // add - match if_test_this_function(0, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: Option = checked_add_8(first_arg, second_arg); - assert!(is_none::(overflowing_u8)); - }, - false => { - let fitting_u8: Option = checked_add_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fitting_u8), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(1, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: u8 = safe_add_8(first_arg, second_arg); - }, - false => { - let fitting_u8: u8 = safe_add_8(first_arg, second_arg); - assert!(jet::eq_8(fitting_u8, result)); - } - } - }, - false => (), - }; - - // subtract - match if_test_this_function(2, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: Option = checked_sub_8(first_arg, second_arg); - assert!(is_none::(overflowing_u8)); - }, - false => { - let fitting_u8: Option = checked_sub_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fitting_u8), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(3, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: u8 = safe_sub_8(first_arg, second_arg); - }, - false => { - let fitting_u8: u8 = safe_sub_8(first_arg, second_arg); - assert!(jet::eq_8(fitting_u8, result)); - } - } - }, - false => (), - }; - - // multiply - match if_test_this_function(4, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: Option = checked_mul_8(first_arg, second_arg); - assert!(is_none::(overflowing_u8)); - }, - false => { - let fitting_u8: Option = checked_mul_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fitting_u8), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(5, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: u8 = safe_mul_8(first_arg, second_arg); - }, - false => { - let fitting_u8: u8 = safe_mul_8(first_arg, second_arg); - assert!(jet::eq_8(fitting_u8, result)); - } - } - }, - false => (), - }; - - // divide - match if_test_this_function(6, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: Option = checked_div_8(first_arg, second_arg); - assert!(is_none::(overflowing_u8)); - }, - false => { - let fitting_u8: Option = checked_div_8(first_arg, second_arg); - assert!(jet::eq_8(unwrap(fitting_u8), result)); - } - } - }, - false => (), - }; - - match if_test_this_function(7, function_index) { - true => { - match if_test_overflow { - true => { - let overflowing_u8: u8 = safe_div_8(first_arg, second_arg); - }, - false => { - let fitting_u8: u8 = safe_div_8(first_arg, second_arg); - assert!(jet::eq_8(fitting_u8, result)); - } - } - }, - false => (), - }; -} diff --git a/simf/u8_test.simf b/simf/u8_test.simf new file mode 100644 index 0000000..40fa44e --- /dev/null +++ b/simf/u8_test.simf @@ -0,0 +1,37 @@ +use crate::lib::u8::{checked_add_8, safe_add_8, checked_sub_8, safe_sub_8, checked_mul_8, safe_mul_8, checked_div_8, safe_div_8}; + +use crate::helper::if_test_this_function; + +// Asserts a `checked_*` result equals the expected Option. +// `None` encodes the overflow case, `Some(e)` the fitting case, so a single +// witness value carries both, removing the need for a separate overflow flag. +fn assert_eq_opt(result: Option, expected: Option) { + match expected { + None => assert!(is_none::(result)), + Some(e: u8) => assert!(jet::eq_8(unwrap(result), e)), + } +} + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let a: u8 = witness::FIRST_ARG; + let b: u8 = witness::SECOND_ARG; + let expected: Option = witness::EXPECTED; + + // add + match if_test_this_function(0, fn_idx) { true => { assert_eq_opt(checked_add_8(a, b), expected); }, false => (), }; + match if_test_this_function(1, fn_idx) { true => { assert!(jet::eq_8(safe_add_8(a, b), unwrap(expected))); }, false => (), }; + + // sub + match if_test_this_function(2, fn_idx) { true => { assert_eq_opt(checked_sub_8(a, b), expected); }, false => (), }; + match if_test_this_function(3, fn_idx) { true => { assert!(jet::eq_8(safe_sub_8(a, b), unwrap(expected))); }, false => (), }; + + // mul + match if_test_this_function(4, fn_idx) { true => { assert_eq_opt(checked_mul_8(a, b), expected); }, false => (), }; + match if_test_this_function(5, fn_idx) { true => { assert!(jet::eq_8(safe_mul_8(a, b), unwrap(expected))); }, false => (), }; + + // div + match if_test_this_function(6, fn_idx) { true => { assert_eq_opt(checked_div_8(a, b), expected); }, false => (), }; + match if_test_this_function(7, fn_idx) { true => { assert!(jet::eq_8(safe_div_8(a, b), unwrap(expected))); }, false => (), }; +} diff --git a/tests/common/mod.rs b/tests/common/mod.rs new file mode 100644 index 0000000..b654011 --- /dev/null +++ b/tests/common/mod.rs @@ -0,0 +1,77 @@ +use simplex::program::{Program, WitnessTrait}; +use simplex::simplicityhl::elements::Script; +use simplex::transaction::{FinalTransaction, PartialInput, ProgramInput, RequiredSignature}; + +pub mod uint; + +// --------------------------------------------------------------------------- +// Spend plumbing (shared by every test, of every category) +// --------------------------------------------------------------------------- + +pub enum Expect { + Ok, + PrunedFail, // safe_* overflow, div-by-zero, etc. +} + +/// Send sats to the program's script so it has a UTXO to spend. +pub fn fund( + context: &simplex::TestContext, + program: &impl AsRef, +) -> anyhow::Result