diff --git a/docs/stdlib.json b/docs/stdlib.json index 801701e..e67086b 100644 --- a/docs/stdlib.json +++ b/docs/stdlib.json @@ -104,6 +104,174 @@ "output_type": "()", "description": "Assert that two `bool` values are equal.\n\n## Panics\nThe assertion fails." }, + { + "simplicityhl_name": "get_explicit_amount", + "section": "Amount getters", + "input_type": "u32, bool", + "output_type": "u64", + "description": "Returns the explicit amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its amount is confidential." + }, + { + "simplicityhl_name": "get_confidential_amount", + "section": "Amount getters", + "input_type": "u32, bool", + "output_type": "Confidential1", + "description": "Returns the confidential amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its amount is explicit." + }, + { + "simplicityhl_name": "get_explicit_input_amount", + "section": "Amount getters", + "input_type": "u32", + "output_type": "u64", + "description": "Returns the explicit amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its amount is confidential." + }, + { + "simplicityhl_name": "get_confidential_input_amount", + "section": "Amount getters", + "input_type": "u32", + "output_type": "Confidential1", + "description": "Returns the confidential amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its amount is explicit." + }, + { + "simplicityhl_name": "get_explicit_output_amount", + "section": "Amount getters", + "input_type": "u32", + "output_type": "u64", + "description": "Returns the explicit amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its amount is confidential." + }, + { + "simplicityhl_name": "get_confidential_output_amount", + "section": "Amount getters", + "input_type": "u32", + "output_type": "Confidential1", + "description": "Returns the confidential amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its amount is explicit." + }, + { + "simplicityhl_name": "get_explicit_current_amount", + "section": "Amount getters", + "input_type": "()", + "output_type": "u64", + "description": "Returns the explicit input amount at the current_index.\n\n## Panics\nPanics if amount is confidential." + }, + { + "simplicityhl_name": "get_confidential_current_amount", + "section": "Amount getters", + "input_type": "()", + "output_type": "Confidential1", + "description": "Returns the confidential input amount at the current_index.\n\n## Panics\nPanics if amount is explicit." + }, + { + "simplicityhl_name": "get_explicit_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32, bool", + "output_type": "(u256, u64)", + "description": "Returns explicit asset_id and amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id and amount are confidential." + }, + { + "simplicityhl_name": "get_confidential_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32, bool", + "output_type": "(Confidential1, Confidential1)", + "description": "Returns confidential asset_id and amount at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id and amount are explicit." + }, + { + "simplicityhl_name": "get_explicit_input_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32", + "output_type": "(u256, u64)", + "description": "Returns explicit asset_id and amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id and amount are confidential." + }, + { + "simplicityhl_name": "get_confidential_input_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32", + "output_type": "(Confidential1, Confidential1)", + "description": "Returns confidential asset_id and amount at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id and amount are explicit." + }, + { + "simplicityhl_name": "get_explicit_output_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32", + "output_type": "(u256, u64)", + "description": "Returns explicit asset_id and amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id and amount are confidential." + }, + { + "simplicityhl_name": "get_confidential_output_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "u32", + "output_type": "(Confidential1, Confidential1)", + "description": "Returns confidential asset_id and amount at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id and amount are explicit." + }, + { + "simplicityhl_name": "get_explicit_current_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "()", + "output_type": "(u256, u64)", + "description": "Returns explicit input asset_id and amount at the current_index.\n\n## Panics\nPanics if asset_id and amount are confidential." + }, + { + "simplicityhl_name": "get_confidential_current_asset_id_with_amount", + "section": "AssetId and Amount getters", + "input_type": "()", + "output_type": "(Confidential1, Confidential1)", + "description": "Returns confidential input asset_id and amount at the current_index.\n\n## Panics\nPanics if asset_id and amount are explicit." + }, + { + "simplicityhl_name": "get_explicit_asset_id", + "section": "AssetId getters", + "input_type": "u32, bool", + "output_type": "u256", + "description": "Returns the explicit asset_id at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id is confidential." + }, + { + "simplicityhl_name": "get_confidential_asset_id", + "section": "AssetId getters", + "input_type": "u32, bool", + "output_type": "Confidential1", + "description": "Returns the confidential asset_id at the specified input or output index.\n\n## Panics\nPanics if the specified input or output does not exist or if its asset_id is explicit." + }, + { + "simplicityhl_name": "get_explicit_input_asset_id", + "section": "AssetId getters", + "input_type": "u32", + "output_type": "u256", + "description": "Returns the explicit asset_id at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id is confidential." + }, + { + "simplicityhl_name": "get_confidential_input_asset_id", + "section": "AssetId getters", + "input_type": "u32", + "output_type": "Confidential1", + "description": "Returns the confidential asset_id at the specified input index.\n\n## Panics\nPanics if the specified input does not exist or if its asset_id is explicit." + }, + { + "simplicityhl_name": "get_explicit_output_asset_id", + "section": "AssetId getters", + "input_type": "u32", + "output_type": "u256", + "description": "Returns the explicit asset_id at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id is confidential." + }, + { + "simplicityhl_name": "get_confidential_output_asset_id", + "section": "AssetId getters", + "input_type": "u32", + "output_type": "Confidential1", + "description": "Returns the confidential asset_id at the specified output index.\n\n## Panics\nPanics if the specified output does not exist or if its asset_id is explicit." + }, + { + "simplicityhl_name": "get_explicit_current_asset_id", + "section": "AssetId getters", + "input_type": "()", + "output_type": "u256", + "description": "Returns the explicit input asset_id at the current_index.\n\n## Panics\nPanics if asset_id is confidential." + }, + { + "simplicityhl_name": "get_confidential_current_asset_id", + "section": "AssetId getters", + "input_type": "()", + "output_type": "Confidential1", + "description": "Returns the confidential input asset_id at the current_index.\n\n## Panics\nPanics if asset_id is explicit." + }, { "simplicityhl_name": "not", "section": "Binary logic", diff --git a/simf/lib/utxo/getters/amount.simf b/simf/lib/utxo/getters/amount.simf new file mode 100644 index 0000000..55c2f75 --- /dev/null +++ b/simf/lib/utxo/getters/amount.simf @@ -0,0 +1,80 @@ +/// Functions for retrieving Amount +/// +/// If you need both `Amount` and `AssetId`, it is recommended to use the corresponding +/// function from the `asset_id_with_amount` file, because all `get_amount` functions +/// also return the `AssetId`. Using `get_amount` and `get_asset_id` together results +/// in unnecessary overhead. + +/// Returns the explicit amount at the specified input or output. +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_explicit_amount(index: u32, is_input_index: bool) -> u64 { + let ( + _, + amount + ): (Asset1, Amount1) = match is_input_index { + true => unwrap(jet::input_amount(index)), + false => unwrap(jet::output_amount(index)), + }; + + unwrap_right::<(u1, u256)>(amount) +} + +/// Returns the confidential amount at the specified input or output +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_confidential_amount(index: u32, is_input_index: bool) -> Confidential1 { + let ( + _, + amount + ): (Asset1, Amount1) = match is_input_index { + true => unwrap(jet::input_amount(index)), + false => unwrap(jet::output_amount(index)), + }; + + unwrap_left::(amount) +} + +/// Returns the explicit amount at the specified input +pub fn get_explicit_input_amount(index: u32) -> u64 { + let (_, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index)); + + unwrap_right::<(u1, u256)>(amount) +} + +/// Returns the confidential amount at the specified input +pub fn get_confidential_input_amount(index: u32) -> Confidential1 { + let (_, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index)); + + unwrap_left::(amount) +} + +/// Returns the explicit amount at the specified output +pub fn get_explicit_output_amount(index: u32) -> u64 { + let (_, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index)); + + unwrap_right::<(u1, u256)>(amount) +} + +/// Returns the confidential amount at the specified output +pub fn get_confidential_output_amount(index: u32) -> Confidential1 { + let (_, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index)); + + unwrap_left::(amount) +} + +/// Returns the explicit input amount at the current_index +pub fn get_explicit_current_amount() -> u64 { + let (_, amount): (Asset1, Amount1) = jet::current_amount(); + + unwrap_right::<(u1, u256)>(amount) +} + +/// Returns the confidential input amount at the current_index +pub fn get_confidential_current_amount() -> Confidential1 { + let (_, amount): (Asset1, Amount1) = jet::current_amount(); + + unwrap_left::(amount) +} diff --git a/simf/lib/utxo/getters/asset_id.simf b/simf/lib/utxo/getters/asset_id.simf new file mode 100644 index 0000000..3e2b8f1 --- /dev/null +++ b/simf/lib/utxo/getters/asset_id.simf @@ -0,0 +1,69 @@ +/// Functions for retrieving AssetId + +/// Returns the explicit asset_id at the specified input or output +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_explicit_asset_id(index: u32, is_input_index: bool) -> u256 { + let asset: Asset1 = match is_input_index { + true => unwrap(jet::input_asset(index)), + false => unwrap(jet::output_asset(index)), + }; + + unwrap_right::<(u1, u256)>(asset) +} + +/// Returns the confidential asset_id at the specified input or output +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_confidential_asset_id(index: u32, is_input_index: bool) -> Confidential1 { + let asset: Asset1 = match is_input_index { + true => unwrap(jet::input_asset(index)), + false => unwrap(jet::output_asset(index)), + }; + + unwrap_left::(asset) +} + +/// Returns the explicit asset_id at the specified input +pub fn get_explicit_input_asset_id(index: u32) -> u256 { + let asset: Asset1 = unwrap(jet::input_asset(index)); + + unwrap_right::<(u1, u256)>(asset) +} + +/// Returns the confidential asset_id at the specified input +pub fn get_confidential_input_asset_id(index: u32) -> Confidential1 { + let asset: Asset1 = unwrap(jet::input_asset(index)); + + unwrap_left::(asset) +} + +/// Returns the explicit asset_id at the specified output +pub fn get_explicit_output_asset_id(index: u32) -> u256 { + let asset: Asset1 = unwrap(jet::output_asset(index)); + + unwrap_right::<(u1, u256)>(asset) +} + +/// Returns the confidential asset_id at the specified output +pub fn get_confidential_output_asset_id(index: u32) -> Confidential1 { + let asset: Asset1 = unwrap(jet::output_asset(index)); + + unwrap_left::(asset) +} + +/// Returns the explicit input asset_id at the current_index +pub fn get_explicit_current_asset_id() -> u256 { + let asset: Asset1 = jet::current_asset(); + + unwrap_right::<(u1, u256)>(asset) +} + +/// Returns the confidential input asset_id at the current_index +pub fn get_confidential_current_asset_id() -> Confidential1 { + let asset: Asset1 = jet::current_asset(); + + unwrap_left::(asset) +} diff --git a/simf/lib/utxo/getters/asset_id_with_amount.simf b/simf/lib/utxo/getters/asset_id_with_amount.simf new file mode 100644 index 0000000..d555e6d --- /dev/null +++ b/simf/lib/utxo/getters/asset_id_with_amount.simf @@ -0,0 +1,78 @@ +/// Functions for retrieving an `AssetId` along with an `Amount` + +/// Returns explicit asset_id and amount at the specified input or output. +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_explicit_asset_id_with_amount(index: u32, is_input_index: bool) -> (u256, u64) { + let ( + asset, + amount + ): (Asset1, Amount1) = match is_input_index { + true => unwrap(jet::input_amount(index)), + false => unwrap(jet::output_amount(index)), + }; + + (unwrap_right::<(u1, u256)>(asset), unwrap_right::<(u1, u256)>(amount)) +} + +/// Returns confidential asset_id and amount at the specified input or output +/// +/// Warning: using this incurs the overhead, and should be used only when the input/output selection +/// needs to be determined at runtime; otherwise, use the input- or output- specific getter directly. +pub fn get_confidential_asset_id_with_amount( + index: u32, + is_input_index: bool +) -> (Confidential1, Confidential1) { + let ( + asset, + amount + ): (Asset1, Amount1) = match is_input_index { + true => unwrap(jet::input_amount(index)), + false => unwrap(jet::output_amount(index)), + }; + + (unwrap_left::(asset), unwrap_left::(amount)) +} + +/// Returns explicit asset_id and amount at the specified input +pub fn get_explicit_input_asset_id_with_amount(index: u32) -> (u256, u64) { + let (asset, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index)); + + (unwrap_right::<(u1, u256)>(asset), unwrap_right::<(u1, u256)>(amount)) +} + +/// Returns confidential asset_id and amount at the specified input +pub fn get_confidential_input_asset_id_with_amount(index: u32) -> (Confidential1, Confidential1) { + let (asset, amount): (Asset1, Amount1) = unwrap(jet::input_amount(index)); + + (unwrap_left::(asset), unwrap_left::(amount)) +} + +/// Returns explicit asset_id and amount at the specified output +pub fn get_explicit_output_asset_id_with_amount(index: u32) -> (u256, u64) { + let (asset, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index)); + + (unwrap_right::<(u1, u256)>(asset), unwrap_right::<(u1, u256)>(amount)) +} + +/// Returns confidential asset_id and amount at the specified output +pub fn get_confidential_output_asset_id_with_amount(index: u32) -> (Confidential1, Confidential1) { + let (asset, amount): (Asset1, Amount1) = unwrap(jet::output_amount(index)); + + (unwrap_left::(asset), unwrap_left::(amount)) +} + +/// Returns explicit input asset_id and amount at the current_index +pub fn get_explicit_current_asset_id_with_amount() -> (u256, u64) { + let (asset, amount): (Asset1, Amount1) = jet::current_amount(); + + (unwrap_right::<(u1, u256)>(asset), unwrap_right::<(u1, u256)>(amount)) +} + +/// Returns confidential input asset_id and amount at the current_index +pub fn get_confidential_current_asset_id_with_amount() -> (Confidential1, Confidential1) { + let (asset, amount): (Asset1, Amount1) = jet::current_amount(); + + (unwrap_left::(asset), unwrap_left::(amount)) +} diff --git a/simf/tests/utxo/getters/amount.simf b/simf/tests/utxo/getters/amount.simf new file mode 100644 index 0000000..08b6b0a --- /dev/null +++ b/simf/tests/utxo/getters/amount.simf @@ -0,0 +1,104 @@ +use crate::lib::utxo::getters::amount::{ + get_explicit_amount, + get_confidential_amount, + get_explicit_input_amount, + get_confidential_input_amount, + get_explicit_output_amount, + get_confidential_output_amount, + get_explicit_current_amount, + get_confidential_current_amount +}; +use crate::lib::asserts::{assert_eq_1, assert_eq_64, assert_eq_256}; + +use crate::tests::support::dispatch::is_selected; + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let index: u32 = witness::INDEX; + let is_input_index: bool = witness::IS_INPUT_INDEX; + + let expected_amount: u64 = witness::EXPECTED; + let expected_parity: u1 = witness::EXPECTED_PARITY; + let expected_confidential_amount: u256 = witness::EXPECTED_CONF; + + match is_selected(0, fn_idx) { + true => { + assert_eq_64(get_explicit_amount(index, is_input_index), expected_amount); + }, + false => (), + }; + + match is_selected(1, fn_idx) { + true => { + let ( + parity_bit, + confidential_amount + ): Confidential1 = get_confidential_amount(index, is_input_index); + + assert_eq_1(parity_bit,expected_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(2, fn_idx) { + true => { + assert_eq_64(get_explicit_input_amount(index), expected_amount); + }, + false => (), + }; + + match is_selected(3, fn_idx) { + true => { + let ( + parity_bit, + confidential_amount + ): Confidential1 = get_confidential_input_amount(index); + + assert_eq_1(parity_bit,expected_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(4, fn_idx) { + true => { + assert_eq_64(get_explicit_output_amount(index), expected_amount); + }, + false => (), + }; + + match is_selected(5, fn_idx) { + true => { + let ( + parity_bit, + confidential_amount + ): Confidential1 = get_confidential_output_amount(index); + + assert_eq_1(parity_bit,expected_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(6, fn_idx) { + true => { + assert_eq_64(get_explicit_current_amount(), expected_amount); + }, + false => (), + }; + + match is_selected(7, fn_idx) { + true => { + let ( + parity_bit, + confidential_amount + ): Confidential1 = get_confidential_current_amount(); + + assert_eq_1(parity_bit,expected_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; +} diff --git a/simf/tests/utxo/getters/asset_id.simf b/simf/tests/utxo/getters/asset_id.simf new file mode 100644 index 0000000..1655758 --- /dev/null +++ b/simf/tests/utxo/getters/asset_id.simf @@ -0,0 +1,104 @@ +use crate::lib::utxo::getters::asset_id::{ + get_explicit_asset_id, + get_confidential_asset_id, + get_explicit_input_asset_id, + get_confidential_input_asset_id, + get_explicit_output_asset_id, + get_confidential_output_asset_id, + get_explicit_current_asset_id, + get_confidential_current_asset_id +}; +use crate::lib::asserts::{assert_eq_1, assert_eq_256}; + +use crate::tests::support::dispatch::is_selected; + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let index: u32 = witness::INDEX; + let is_input_index: bool = witness::IS_INPUT_INDEX; + + let expected_asset_id: u256 = witness::EXPECTED; + let expected_parity: u1 = witness::EXPECTED_PARITY; + let expected_confidential_asset_id: u256 = witness::EXPECTED_CONF; + + match is_selected(0, fn_idx) { + true => { + assert_eq_256(get_explicit_asset_id(index, is_input_index), expected_asset_id); + }, + false => (), + }; + + match is_selected(1, fn_idx) { + true => { + let ( + parity_bit, + confidential_asset_id + ): Confidential1 = get_confidential_asset_id(index, is_input_index); + + assert_eq_1(parity_bit, expected_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + }, + false => (), + }; + + match is_selected(2, fn_idx) { + true => { + assert_eq_256(get_explicit_input_asset_id(index), expected_asset_id); + }, + false => (), + }; + + match is_selected(3, fn_idx) { + true => { + let ( + parity_bit, + confidential_asset_id + ): Confidential1 = get_confidential_input_asset_id(index); + + assert_eq_1(parity_bit, expected_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + }, + false => (), + }; + + match is_selected(4, fn_idx) { + true => { + assert_eq_256(get_explicit_output_asset_id(index), expected_asset_id); + }, + false => (), + }; + + match is_selected(5, fn_idx) { + true => { + let ( + parity_bit, + confidential_asset_id + ): Confidential1 = get_confidential_output_asset_id(index); + + assert_eq_1(parity_bit, expected_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + }, + false => (), + }; + + match is_selected(6, fn_idx) { + true => { + assert_eq_256(get_explicit_current_asset_id(), expected_asset_id); + }, + false => (), + }; + + match is_selected(7, fn_idx) { + true => { + let ( + parity_bit, + confidential_asset_id + ): Confidential1 = get_confidential_current_asset_id(); + + assert_eq_1(parity_bit, expected_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + }, + false => (), + }; +} diff --git a/simf/tests/utxo/getters/asset_id_with_amount.simf b/simf/tests/utxo/getters/asset_id_with_amount.simf new file mode 100644 index 0000000..298b265 --- /dev/null +++ b/simf/tests/utxo/getters/asset_id_with_amount.simf @@ -0,0 +1,162 @@ +use crate::lib::utxo::getters::asset_id_with_amount::{ + get_explicit_asset_id_with_amount, + get_confidential_asset_id_with_amount, + get_explicit_input_asset_id_with_amount, + get_confidential_input_asset_id_with_amount, + get_explicit_output_asset_id_with_amount, + get_confidential_output_asset_id_with_amount, + get_explicit_current_asset_id_with_amount, + get_confidential_current_asset_id_with_amount +}; +use crate::lib::asserts::{assert_eq_1, assert_eq_64, assert_eq_256}; + +use crate::tests::support::dispatch::is_selected; + +fn main() { + let fn_idx: u8 = witness::FUNCTION_INDEX; + + let index: u32 = witness::INDEX; + let is_input_index: bool = witness::IS_INPUT_INDEX; + + let expected_asset_id: u256 = witness::EXPECTED_ASSET; + let expected_asset_parity: u1 = witness::EXPECTED_ASSET_PARITY; + let expected_confidential_asset_id: u256 = witness::EXPECTED_CONF_ASSET; + + let expected_amount: u64 = witness::EXPECTED_AMOUNT; + let expected_amount_parity: u1 = witness::EXPECTED_AMOUNT_PARITY; + let expected_confidential_amount: u256 = witness::EXPECTED_CONF_AMOUNT; + + match is_selected(0, fn_idx) { + true => { + let ( + asset_id, + amount + ): (u256, u64) = get_explicit_asset_id_with_amount(index, is_input_index); + + assert_eq_256(asset_id, expected_asset_id); + assert_eq_64(amount, expected_amount); + }, + false => (), + }; + + match is_selected(1, fn_idx) { + true => { + let ( + ( + parity_bit_asset_id, + confidential_asset_id + ), + ( + parity_bit_amount, + confidential_amount + ) + ): (Confidential1, Confidential1) = get_confidential_asset_id_with_amount( + index, + is_input_index + ); + + assert_eq_1(parity_bit_asset_id, expected_asset_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + + assert_eq_1(parity_bit_amount, expected_amount_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(2, fn_idx) { + true => { + let (asset_id, amount): (u256, u64) = get_explicit_input_asset_id_with_amount(index); + + assert_eq_256(asset_id, expected_asset_id); + assert_eq_64(amount, expected_amount); + }, + false => (), + }; + + match is_selected(3, fn_idx) { + true => { + let ( + ( + parity_bit_asset_id, + confidential_asset_id + ), + ( + parity_bit_amount, + confidential_amount + ) + ): (Confidential1, Confidential1) = get_confidential_input_asset_id_with_amount(index); + + assert_eq_1(parity_bit_asset_id, expected_asset_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + + assert_eq_1(parity_bit_amount, expected_amount_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(4, fn_idx) { + true => { + let (asset_id, amount): (u256, u64) = get_explicit_output_asset_id_with_amount(index); + + assert_eq_256(asset_id, expected_asset_id); + assert_eq_64(amount, expected_amount); + }, + false => (), + }; + + match is_selected(5, fn_idx) { + true => { + let ( + ( + parity_bit_asset_id, + confidential_asset_id + ), + ( + parity_bit_amount, + confidential_amount + ) + ): (Confidential1, Confidential1) = get_confidential_output_asset_id_with_amount(index); + + assert_eq_1(parity_bit_asset_id, expected_asset_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + + assert_eq_1(parity_bit_amount, expected_amount_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; + + match is_selected(6, fn_idx) { + true => { + let (asset_id, amount): (u256, u64) = get_explicit_current_asset_id_with_amount(); + + assert_eq_256(asset_id, expected_asset_id); + assert_eq_64(amount, expected_amount); + }, + false => (), + }; + + match is_selected(7, fn_idx) { + true => { + let ( + ( + parity_bit_asset_id, + confidential_asset_id + ), + ( + parity_bit_amount, + confidential_amount + ) + ): (Confidential1, Confidential1) = get_confidential_current_asset_id_with_amount(); + + assert_eq_1(parity_bit_asset_id, expected_asset_parity); + assert_eq_256(confidential_asset_id, expected_confidential_asset_id); + + assert_eq_1(parity_bit_amount, expected_amount_parity); + assert_eq_256(confidential_amount, expected_confidential_amount); + }, + false => (), + }; +} diff --git a/tests/stdlib/common/core.rs b/tests/stdlib/common/core.rs index ada5e42..9569c14 100644 --- a/tests/stdlib/common/core.rs +++ b/tests/stdlib/common/core.rs @@ -2,12 +2,17 @@ // part of it, so per-crate dead-code analysis would warn about the rest. #![allow(dead_code)] +use secp256k1_zkp::Secp256k1; use simplex::program::{Program, WitnessTrait}; -use simplex::simplicityhl::elements::Script; +use simplex::signer::Signer; +use simplex::simplicityhl::elements::{AssetId, Script, Txid}; +use simplex::transaction::partial_input::IssuanceInput; use simplex::transaction::{ - FinalTransaction, PartialInput, PartialOutput, ProgramInput, RequiredSignature, + FinalTransaction, PartialInput, PartialOutput, ProgramInput, RequiredSignature, UTXO, }; +use crate::common::utxo_helper::{DEFAULT_SEND_AMOUNT, search_utxo_by_txid}; + #[derive(Clone, Copy)] pub enum Expect { /// The spend succeeds. @@ -35,14 +40,66 @@ impl Expect { pub fn fund( context: &simplex::TestContext, program: &impl AsRef, + amount_to_send: u64, ) -> anyhow::Result