From eeaaab5ab76a94a25a4ed7fc4bef04aa5868269e Mon Sep 17 00:00:00 2001 From: aritkulova Date: Sat, 17 Oct 2026 00:16:30 +0300 Subject: [PATCH 1/5] added getters for script hash --- docs/stdlib.json | 28 +++ simf/lib/utxo/getters/script_hash.simf | 34 +++ simf/tests/mock.simf | 1 + simf/tests/utxo/getters/script_hash.simf | 46 ++++ tests/stdlib/common/core.rs | 210 +++++++++++------- tests/stdlib/common/utxo_helper.rs | 84 +++++-- tests/stdlib/utxo/asserts/amount.rs | 13 +- tests/stdlib/utxo/asserts/asset_id.rs | 13 +- .../utxo/asserts/asset_id_with_amount.rs | 13 +- tests/stdlib/utxo/getters/amount.rs | 13 +- tests/stdlib/utxo/getters/asset_id.rs | 15 +- .../utxo/getters/asset_id_with_amount.rs | 13 +- tests/stdlib/utxo/getters/mod.rs | 1 + tests/stdlib/utxo/getters/script_hash.rs | 209 +++++++++++++++++ 14 files changed, 584 insertions(+), 109 deletions(-) create mode 100644 simf/lib/utxo/getters/script_hash.simf create mode 100644 simf/tests/mock.simf create mode 100644 simf/tests/utxo/getters/script_hash.simf create mode 100644 tests/stdlib/utxo/getters/script_hash.rs diff --git a/docs/stdlib.json b/docs/stdlib.json index 1c7e670..8ce29a1 100644 --- a/docs/stdlib.json +++ b/docs/stdlib.json @@ -440,6 +440,34 @@ "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": "get_script_hash", + "section": "Script hash getters", + "input_type": "u32, bool", + "output_type": "u256", + "description": "Returns the SHA256 hash of the scriptPubKey at the specified input or output.\n\n## Panics\nPanics if the specified input or output does not exist." + }, + { + "simplicityhl_name": "get_input_script_hash", + "section": "Script hash getters", + "input_type": "u32", + "output_type": "u256", + "description": "Returns the SHA256 hash of the scriptPubKey of the input at the given index.\n\n## Panics\nPanics if the specified input does not exist." + }, + { + "simplicityhl_name": "get_output_script_hash", + "section": "Script hash getters", + "input_type": "u32", + "output_type": "u256", + "description": " Returns the SHA256 hash of the scriptPubKey of the output at the given index.\n\n## Panics\nPanics if the specified output does not exist." + }, + { + "simplicityhl_name": "get_current_script_hash", + "section": "Script hash getters", + "input_type": "()", + "output_type": "u256", + "description": "Returns the SHA256 hash of the scriptPubKey at the current_index." + }, { "simplicityhl_name": "not", "section": "Binary logic", diff --git a/simf/lib/utxo/getters/script_hash.simf b/simf/lib/utxo/getters/script_hash.simf new file mode 100644 index 0000000..8f16728 --- /dev/null +++ b/simf/lib/utxo/getters/script_hash.simf @@ -0,0 +1,34 @@ +/// Returns the SHA256 hash of the scriptPubKey of the UTXO at the specified input or output. +/// Panics if the specified input or output does not exist. +/// +/// 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_script_hash(index: u32, is_input_index: bool) -> u256 { + let script_hash: Option = match is_input_index { + true => jet::input_script_hash(index), + false => jet::output_script_hash(index), + }; + + unwrap(script_hash) +} + +/// Returns the SHA256 hash of the scriptPubKey of the UTXO of the input at the given index. +/// Panics if the specified input does not exist +pub fn get_input_script_hash(index: u32) -> u256 { + let script_hash: Option = jet::input_script_hash(index); + + unwrap(script_hash) +} + +/// Returns the SHA256 hash of the scriptPubKey of the UTXO of the output at the given index. +/// Panics if the specified output does not exist +pub fn get_output_script_hash(index: u32) -> u256 { + let script_hash: Option = jet::output_script_hash(index); + + unwrap(script_hash) +} + +/// Returns the SHA256 hash of the scriptPubKey of the UTXO at the current_index +pub fn get_current_script_hash() -> u256 { + jet::current_script_hash() +} diff --git a/simf/tests/mock.simf b/simf/tests/mock.simf new file mode 100644 index 0000000..e71fdf5 --- /dev/null +++ b/simf/tests/mock.simf @@ -0,0 +1 @@ +fn main() {} \ No newline at end of file diff --git a/simf/tests/utxo/getters/script_hash.simf b/simf/tests/utxo/getters/script_hash.simf new file mode 100644 index 0000000..95795e9 --- /dev/null +++ b/simf/tests/utxo/getters/script_hash.simf @@ -0,0 +1,46 @@ +use crate::lib::utxo::getters::script_hash::{ + get_script_hash, + get_input_script_hash, + get_output_script_hash, + get_current_script_hash +}; +use crate::lib::asserts::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_hash: u256 = witness::EXPECTED; + + match is_selected(0, fn_idx) { + true => { + assert_eq_256(get_script_hash(index, is_input_index), expected_hash); + }, + false => (), + }; + + match is_selected(1, fn_idx) { + true => { + assert_eq_256(get_input_script_hash(index), expected_hash); + }, + false => (), + }; + + match is_selected(2, fn_idx) { + true => { + assert_eq_256(get_output_script_hash(index), expected_hash); + }, + false => (), + }; + + match is_selected(3, fn_idx) { + true => { + assert_eq_256(get_current_script_hash(), expected_hash); + }, + false => (), + }; +} diff --git a/tests/stdlib/common/core.rs b/tests/stdlib/common/core.rs index 054768a..743667f 100644 --- a/tests/stdlib/common/core.rs +++ b/tests/stdlib/common/core.rs @@ -5,11 +5,14 @@ use secp256k1_zkp::Secp256k1; use simplex::program::{Program, WitnessTrait}; use simplex::signer::Signer; +use simplex::simplicityhl::elements::bitcoin::PublicKey; use simplex::simplicityhl::elements::{AssetId, Script, Txid}; use simplex::transaction::partial_input::IssuanceInput; use simplex::transaction::{ FinalTransaction, PartialInput, PartialOutput, ProgramInput, RequiredSignature, UTXO, }; +use simplicityhl_std::artifacts::tests::mock::MockProgram; +use simplicityhl_std::artifacts::tests::mock::derived_mock::MockWitness; use crate::common::utxo_helper::{DEFAULT_SEND_AMOUNT, search_utxo_by_txid}; @@ -54,6 +57,7 @@ pub fn send_explicit(signer: &Signer, to: &Script, amount_to_send: u64) -> anyho Ok(signer.send(to.clone(), amount_to_send)?.txid()) } +/// Send sats to the specified script confidentialy. pub fn send_blinded( signer: &Signer, to: &Script, @@ -71,7 +75,7 @@ pub fn send_blinded( } /// Issue `amount_to_send` of a new asset to the specified script, so the UTXO holds an asset that -/// nothing else in the wallet has. Returns the funding txid and the new asset id. +/// nothing else in the wallet has. pub fn send_issued( context: &simplex::TestContext, to: &Script, @@ -104,39 +108,24 @@ pub fn send_issued( pub fn construct_final_tx( context: &simplex::TestContext, program: &impl AsRef, - script: &Script, witness: W, data: Option<&[u8]>, txids: Vec, + program_for_test: Option<&impl AsRef>, ) -> anyhow::Result where W: WitnessTrait + 'static, { let signer = context.get_default_signer(); - let script_to_send_to = signer.get_address().script_pubkey(); - let policy_asset = context.get_network().policy_asset(); - - // Every output amount is one less than the corresponding input amount. - // The signer handles leftovers for the policy asset, but for other assets, we need to handle it here. - let mut leftover_asset = policy_asset; - - let utxos = context - .get_default_provider() - .fetch_scripthash_utxos(script)?; - - let mut program_utxo = if txids.is_empty() { - utxos[0].clone() - } else { - search_utxo_by_txid(&txids[0], &utxos)? - }; + let network = context.get_network(); + let policy_asset = network.policy_asset(); - let first_input_confidential = program_utxo.txout.value.is_confidential(); - - if first_input_confidential { - program_utxo = unblind(signer, program_utxo)?; - } + let default_script = signer.get_address().script_pubkey(); + let program_script = &program.as_ref().get_script_pubkey(network); + let mut leftover_asset: Option = None; let mut ft = FinalTransaction::new(); + let program_utxo = prepare_utxo(context, program_script, txids.first())?; ft.add_program_input( PartialInput::new(program_utxo.clone()), @@ -144,63 +133,66 @@ where RequiredSignature::None, ); - // it is not an op_return path if data.unwrap_or_default().is_empty() { - let mut output = PartialOutput::new( - script_to_send_to.clone(), - // amounts in input and output on the same index should be different for the test purposes - program_utxo.amount() - 1, - program_utxo.asset(), + (ft, leftover_asset) = add_mirror_output( + ft, + &program_utxo, + signer.get_blinding_public_key(), + policy_asset, ); - - if first_input_confidential { - output = output.with_blinding_key(signer.get_blinding_public_key()) - } - - ft.add_output(output); - - if program_utxo.asset() != policy_asset { - leftover_asset = program_utxo.asset(); - } } if txids.len() > 1 { let unblinded_utxos = signer.get_utxos()?; + let last = txids.len() - 1; - for txid in txids.iter().skip(1) { + for txid in &txids[1..last] { let utxo = search_utxo_by_txid(txid, &unblinded_utxos)?; - if !utxo.txout.value.is_confidential() { - ft.add_input(PartialInput::new(utxo.clone()), RequiredSignature::None); - - ft.add_output(PartialOutput::new( - script_to_send_to.clone(), - utxo.explicit_amount() - 1, - utxo.explicit_asset(), - )); - - if utxo.explicit_asset() != policy_asset { - leftover_asset = utxo.asset(); - } - // filtering out fund transaction - } else { - ft.add_input(PartialInput::new(utxo.clone()), RequiredSignature::None); - - ft.add_output( - PartialOutput::new( - script_to_send_to.clone(), - utxo.unblinded_amount() - 1, - utxo.unblinded_asset(), - ) - .with_blinding_key(signer.get_blinding_public_key()), + ft.add_input(PartialInput::new(utxo.clone()), RequiredSignature::None); + + (ft, _) = add_mirror_output(ft, &utxo, signer.get_blinding_public_key(), policy_asset); + } + + let last_utxo = match program_for_test { + Some(program_for_test) => { + let last_script = &program_for_test.as_ref().get_script_pubkey(network); + let last_utxo = prepare_utxo(context, last_script, txids.last())?; + + ft.add_program_input( + PartialInput::new(last_utxo.clone()), + ProgramInput::new( + Box::new(program_for_test.as_ref().clone()), + Box::new(MockWitness {}), + ), + RequiredSignature::None, ); + + last_utxo } - } + None => { + let last_utxo = search_utxo_by_txid(txids.last().unwrap(), &unblinded_utxos)?; + + ft.add_input( + PartialInput::new(last_utxo.clone()), + RequiredSignature::None, + ); + + last_utxo + } + }; + + (ft, leftover_asset) = add_mirror_output( + ft, + &last_utxo, + signer.get_blinding_public_key(), + policy_asset, + ); } - if leftover_asset != policy_asset { + if let Some(leftover_asset) = leftover_asset { ft.add_output(PartialOutput::new( - script_to_send_to.clone(), + default_script.clone(), 1, leftover_asset, )); @@ -213,6 +205,32 @@ where Ok(ft) } +/// Fetch the UTXO for script, unblind if confidential. +fn prepare_utxo( + context: &simplex::TestContext, + script: &Script, + txid: Option<&Txid>, +) -> anyhow::Result { + let utxos = context + .get_default_provider() + .fetch_scripthash_utxos(script)?; + + let utxo = match txid { + Some(txid) => search_utxo_by_txid(txid, &utxos)?, + None => utxos + .into_iter() + .next() + .expect("Missing UTXO for the script"), + }; + + if utxo.txout.value.is_confidential() { + Ok(unblind(context.get_default_signer(), utxo)?) + } else { + Ok(utxo) + } +} + +/// Unblind the utxo. fn unblind(signer: &Signer, mut utxo: UTXO) -> anyhow::Result { let secp = Secp256k1::new(); let secrets = utxo @@ -222,19 +240,48 @@ fn unblind(signer: &Signer, mut utxo: UTXO) -> anyhow::Result { Ok(utxo) } +// Add an output mirroring utxo's asset with amount - 1 and the same script. +fn add_mirror_output( + mut ft: FinalTransaction, + utxo: &UTXO, + binding_key: PublicKey, + policy_asset: AssetId, +) -> (FinalTransaction, Option) { + let mut output = PartialOutput::new( + utxo.txout.script_pubkey.clone(), + // amounts in input and output on the same index should be different for the test + utxo.amount() - 1, + utxo.asset(), + ); + + if utxo.txout.value.is_confidential() { + output = output.with_blinding_key(binding_key) + } + + ft.add_output(output); + + let leftover_asset = if utxo.asset() != policy_asset { + Some(utxo.asset()) + } else { + None + }; + + (ft, leftover_asset) +} + /// Spend the funded UTXO with `witness`. Return the broadcast result. pub fn spend( context: &simplex::TestContext, program: &impl AsRef, - script: &Script, witness: W, data: Option<&[u8]>, txids: Vec, + program_for_test: Option<&impl AsRef>, ) -> anyhow::Result where W: WitnessTrait + 'static, { - let ft = construct_final_tx(context, program, script, witness, data, txids)?; + let ft = construct_final_tx(context, program, witness, data, txids, program_for_test)?; Ok(context.get_default_signer().broadcast(&ft)?.to_string()) } @@ -269,8 +316,15 @@ pub fn run( where W: WitnessTrait + 'static, { - let script = fund(context, &program, DEFAULT_SEND_AMOUNT)?; - let result = spend(context, &program, &script, witness, None, Vec::new()); + fund(context, &program, DEFAULT_SEND_AMOUNT)?; + let result = spend( + context, + &program, + witness, + None, + Vec::new(), + None::<&MockProgram>, + ); assert_error_msg(result, expect) } @@ -287,8 +341,15 @@ pub fn run_with_op_return( where W: WitnessTrait + 'static, { - let script = fund(context, &program, DEFAULT_SEND_AMOUNT)?; - let result = spend(context, &program, &script, witness, Some(data), Vec::new()); + fund(context, &program, DEFAULT_SEND_AMOUNT)?; + let result = spend( + context, + &program, + witness, + Some(data), + Vec::new(), + None::<&MockProgram>, + ); assert_error_msg(result, expect) } @@ -300,13 +361,12 @@ pub fn run_with_inputs_outputs( witness: W, expect: Expect, txids: Vec, + program_for_test: Option<&impl AsRef>, ) -> anyhow::Result<()> where W: WitnessTrait + 'static, { - let script = program.as_ref().get_script_pubkey(context.get_network()); - - let result = spend(context, &program, &script, witness, None, txids); + let result = spend(context, &program, witness, None, txids, program_for_test); assert_error_msg(result, expect) } diff --git a/tests/stdlib/common/utxo_helper.rs b/tests/stdlib/common/utxo_helper.rs index 1cf4714..230c8be 100644 --- a/tests/stdlib/common/utxo_helper.rs +++ b/tests/stdlib/common/utxo_helper.rs @@ -1,8 +1,11 @@ use primitive_types::U256; use rand::Rng; +use secp256k1_zkp::hashes::Hash; + use simplex::program::Program; use simplex::simplicityhl::elements::AssetId; use simplex::simplicityhl::elements::OutPoint; +use simplex::simplicityhl::elements::Script; use simplex::simplicityhl::elements::Txid; use simplex::simplicityhl::elements::pset::serialize::Serialize; use simplex::transaction::UTXO; @@ -34,8 +37,9 @@ pub fn create_utxos( is_explicit: bool, is_input: bool, expected_amount: u64, + last_script: &Script, program: impl AsRef, -) -> anyhow::Result<(Option, Vec)> { +) -> anyhow::Result<(UTXO, Vec)> { let signer = context.get_default_signer(); let pubkey_script = &signer.get_address().script_pubkey(); let program_script = &program.as_ref().get_script_pubkey(context.get_network()); @@ -43,10 +47,14 @@ pub fn create_utxos( let mut txids = Vec::new(); for i in 0..=index { - let script = match i == 0 { - true => program_script, - false => pubkey_script, + let script = if i == 0 { + program_script + } else if i == index { + last_script + } else { + pubkey_script }; + let mut amount_to_send = match index == i { true => expected_amount, false => DEFAULT_SEND_AMOUNT, @@ -69,24 +77,68 @@ pub fn create_utxos( } } - if !is_explicit { - let script = match index == 0 { - true => program_script, - false => pubkey_script, - }; + let script = match index == 0 { + true => program_script, + false => last_script, + }; - let utxos = context - .get_default_provider() - .fetch_scripthash_utxos(script)?; + let utxos = context + .get_default_provider() + .fetch_scripthash_utxos(script)?; - let conf_utxo = search_utxo_by_txid(txids.last().unwrap(), &utxos)?; + let last_utxo = search_utxo_by_txid(txids.last().unwrap(), &utxos)?; - Ok((Some(get_asset_id_amount_from_conf_utxo(conf_utxo)?), txids)) - } else { - Ok((None, txids)) + Ok((last_utxo, txids)) +} + +pub fn create_utxos_and_return_conf_assets( + context: &simplex::TestContext, + index: u32, + is_explicit: bool, + is_input: bool, + expected_amount: u64, + program: impl AsRef, +) -> anyhow::Result<(Option, Vec)> { + let last_script = &context.get_default_signer().get_address().script_pubkey(); + + let (last_utxo, txids) = create_utxos( + context, + index, + is_explicit, + is_input, + expected_amount, + last_script, + program, + )?; + + match is_explicit { + true => Ok((None, txids)), + false => Ok((Some(get_asset_id_amount_from_conf_utxo(last_utxo)?), txids)), } } +pub fn create_utxos_and_return_script_hash( + context: &simplex::TestContext, + index: u32, + is_input: bool, + last_script: &Script, + program: impl AsRef, +) -> anyhow::Result<([u8; 32], Vec)> { + let (last_utxo, txids) = create_utxos( + context, + index, + true, + is_input, + DEFAULT_SEND_AMOUNT, + last_script, + program, + )?; + + let hash = (last_utxo.txout.script_pubkey).wscript_hash(); + + Ok((hash.to_byte_array(), txids)) +} + pub fn create_utxos_with_new_asset( context: &simplex::TestContext, index: u32, diff --git a/tests/stdlib/utxo/asserts/amount.rs b/tests/stdlib/utxo/asserts/amount.rs index 9930aa1..97c99bf 100644 --- a/tests/stdlib/utxo/asserts/amount.rs +++ b/tests/stdlib/utxo/asserts/amount.rs @@ -5,7 +5,7 @@ use simplex::simplicityhl::elements::Txid; use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAmount; -use crate::common::utxo_helper::create_utxos; +use crate::common::utxo_helper::create_utxos_and_return_conf_assets; use crate::common::utxo_helper::generate_different_amounts; use crate::common::utxo_helper::generate_random_confidential; use crate::common::utxo_helper::random_expected_amount; @@ -103,7 +103,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAmountProgram>, + ) } } @@ -127,7 +134,7 @@ fn create_utxos_wrapper( is_input: bool, expected_amount: u64, ) -> anyhow::Result<(Option, Vec)> { - let (result, txids) = create_utxos( + let (result, txids) = create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/asserts/asset_id.rs b/tests/stdlib/utxo/asserts/asset_id.rs index 7a4dc6c..1b2cfa1 100644 --- a/tests/stdlib/utxo/asserts/asset_id.rs +++ b/tests/stdlib/utxo/asserts/asset_id.rs @@ -6,7 +6,7 @@ use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAssetId; use crate::common::utxo_helper::DEFAULT_SEND_AMOUNT; -use crate::common::utxo_helper::create_utxos; +use crate::common::utxo_helper::create_utxos_and_return_conf_assets; use crate::common::utxo_helper::create_utxos_with_new_asset; use crate::common::utxo_helper::generate_random_confidential; @@ -105,7 +105,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAssetIdProgram>, + ) } } @@ -127,7 +134,7 @@ fn create_utxos_wrapper( index: u32, is_explicit: bool, ) -> anyhow::Result<(Option, Vec)> { - let (result, txids) = create_utxos( + let (result, txids) = create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs index d681124..f33c4b6 100644 --- a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs +++ b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs @@ -4,7 +4,7 @@ use simplex::simplicityhl::elements::Txid; use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAsset; -use crate::common::utxo_helper::create_utxos; +use crate::common::utxo_helper::create_utxos_and_return_conf_assets; use crate::common::utxo_helper::create_utxos_with_new_asset; use crate::common::utxo_helper::generate_different_amounts; use crate::common::utxo_helper::generate_random_confidential; @@ -113,7 +113,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAssetIdWithAmountProgram>, + ) } } @@ -137,7 +144,7 @@ fn create_utxos_wrapper( is_input: bool, expected_amount: u64, ) -> anyhow::Result<(Option, Vec)> { - create_utxos( + create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/getters/amount.rs b/tests/stdlib/utxo/getters/amount.rs index 855235b..3336a21 100644 --- a/tests/stdlib/utxo/getters/amount.rs +++ b/tests/stdlib/utxo/getters/amount.rs @@ -5,7 +5,7 @@ use simplex::simplicityhl::elements::Txid; use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAmount; -use crate::common::utxo_helper::{create_utxos, random_expected_amount}; +use crate::common::utxo_helper::{create_utxos_and_return_conf_assets, random_expected_amount}; use simplicityhl_std::artifacts::tests::utxo::getters::amount::AmountProgram as TestAmountProgram; use simplicityhl_std::artifacts::tests::utxo::getters::amount::derived_amount::{ @@ -101,7 +101,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAmountProgram>, + ) } } @@ -125,7 +132,7 @@ fn create_utxos_wrapper( is_input: bool, expected_amount: u64, ) -> anyhow::Result<(Option, Vec)> { - let (result, txids) = create_utxos( + let (result, txids) = create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/getters/asset_id.rs b/tests/stdlib/utxo/getters/asset_id.rs index 728ffbe..d92c6a7 100644 --- a/tests/stdlib/utxo/getters/asset_id.rs +++ b/tests/stdlib/utxo/getters/asset_id.rs @@ -6,7 +6,9 @@ use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAssetId; use crate::common::utxo_helper::DEFAULT_SEND_AMOUNT; -use crate::common::utxo_helper::{create_utxos, create_utxos_with_new_asset}; +use crate::common::utxo_helper::{ + create_utxos_and_return_conf_assets, create_utxos_with_new_asset, +}; use simplicityhl_std::artifacts::tests::utxo::getters::asset_id::AssetIdProgram as TestAssetIdProgram; use simplicityhl_std::artifacts::tests::utxo::getters::asset_id::derived_asset_id::{ @@ -104,7 +106,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAssetIdProgram>, + ) } } @@ -126,7 +135,7 @@ fn create_utxos_wrapper( index: u32, is_explicit: bool, ) -> anyhow::Result<(Option, Vec)> { - let (result, txids) = create_utxos( + let (result, txids) = create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/getters/asset_id_with_amount.rs b/tests/stdlib/utxo/getters/asset_id_with_amount.rs index af2f9db..d9941da 100644 --- a/tests/stdlib/utxo/getters/asset_id_with_amount.rs +++ b/tests/stdlib/utxo/getters/asset_id_with_amount.rs @@ -5,7 +5,7 @@ use crate::common::core::Expect; use crate::common::core::run_with_inputs_outputs; use crate::common::utxo_helper::ConfidentialAsset; use crate::common::utxo_helper::{ - create_utxos, create_utxos_with_new_asset, random_expected_amount, + create_utxos_and_return_conf_assets, create_utxos_with_new_asset, random_expected_amount, }; use simplicityhl_std::artifacts::tests::utxo::getters::asset_id_with_amount::AssetIdWithAmountProgram as TestAssetIdWithAmountProgram; @@ -112,7 +112,14 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs(context, program(), self.witness, expect, txids) + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + None::<&TestAssetIdWithAmountProgram>, + ) } } @@ -136,7 +143,7 @@ fn create_utxos_wrapper( is_input: bool, expected_amount: u64, ) -> anyhow::Result<(Option, Vec)> { - create_utxos( + create_utxos_and_return_conf_assets( context, index, is_explicit, diff --git a/tests/stdlib/utxo/getters/mod.rs b/tests/stdlib/utxo/getters/mod.rs index 6cbabb2..c2cea35 100644 --- a/tests/stdlib/utxo/getters/mod.rs +++ b/tests/stdlib/utxo/getters/mod.rs @@ -1,3 +1,4 @@ mod amount; mod asset_id; mod asset_id_with_amount; +mod script_hash; diff --git a/tests/stdlib/utxo/getters/script_hash.rs b/tests/stdlib/utxo/getters/script_hash.rs new file mode 100644 index 0000000..45661e5 --- /dev/null +++ b/tests/stdlib/utxo/getters/script_hash.rs @@ -0,0 +1,209 @@ +use rand::Rng; +use simplex::simplicityhl::elements::Txid; + +use crate::common::core::Expect; +use crate::common::core::run_with_inputs_outputs; +use crate::common::utxo_helper::create_utxos_and_return_script_hash; + +use simplicityhl_std::artifacts::tests::utxo::getters::script_hash::ScriptHashProgram as TestScriptHashProgram; +use simplicityhl_std::artifacts::tests::utxo::getters::script_hash::derived_script_hash::{ + ScriptHashArguments as TestScriptHashArguments, ScriptHashWitness as TestScriptHashWitness, +}; + +use simplicityhl_std::artifacts::tests::mock::MockProgram as TestMockProgram; +use simplicityhl_std::artifacts::tests::mock::derived_mock::MockArguments as TestMockArguments; + +use FunctionToTest::*; + +enum FunctionToTest { + Script, + InputScript, + OutputScript, + CurrentScript, +} +#[derive(PartialEq, Eq)] +enum IndexType { + Input, + Output, +} + +fn is_input(o: IndexType) -> bool { + o == IndexType::Input +} + +fn program() -> TestScriptHashProgram { + TestScriptHashProgram::new(&TestScriptHashArguments {}) +} + +fn mock() -> TestMockProgram { + TestMockProgram::new(&TestMockArguments {}) +} + +/// One dispatch arm of the contract, plus the witness it reads. +struct Case { + witness: TestScriptHashWitness, +} + +fn case(function: FunctionToTest) -> Case { + Case { + witness: TestScriptHashWitness { + function_index: function as u8, + index: 0, + is_input_index: false, + expected: [0; 32], + }, + } +} + +impl Case { + /// `index`: the input/output the arm inspects. + fn index(mut self, index: u32) -> Self { + self.witness.index = index; + self + } + + /// `is_input`: whether the arm inspects an input. + fn index_type(mut self, index_type: IndexType) -> Self { + self.witness.is_input_index = is_input(index_type); + self + } + + /// `expected`: value the arm should produce. + fn expect(mut self, expected: [u8; 32]) -> Self { + self.witness.expected = expected; + self + } + + /// Fund, spend, and expect the spend to succeed. + fn run(self, context: &simplex::TestContext, txids: Vec) -> anyhow::Result<()> { + self.expecting(context, Expect::Ok, txids) + } + + /// Fund, spend, and expect `expect`. + fn expecting( + self, + context: &simplex::TestContext, + expect: Expect, + txids: Vec, + ) -> anyhow::Result<()> { + run_with_inputs_outputs( + context, + program(), + self.witness, + expect, + txids, + Some(&mock()), + ) + } +} + +fn create_utxos_wrapper( + context: &simplex::TestContext, + index: u32, + is_input: bool, +) -> anyhow::Result<([u8; 32], Vec)> { + let last_script = &mock().as_ref().get_script_pubkey(context.get_network()); + let (hash, txids) = + create_utxos_and_return_script_hash(context, index, is_input, last_script, program())?; + + Ok((hash, txids)) +} + +#[simplex::test] +fn get_script_hash_for_random_input(context: simplex::TestContext) -> anyhow::Result<()> { + let index = rand::thread_rng().gen_range(0..=20) as u32; // not a big value to not to slow down tests + let (expected_hash, txids) = create_utxos_wrapper(&context, index, is_input(IndexType::Input))?; + + case(Script) + .index(index) + .index_type(IndexType::Input) + .expect(expected_hash) + .run(&context, txids) +} + +#[simplex::test] +fn get_script_hash_for_random_output(context: simplex::TestContext) -> anyhow::Result<()> { + let index = rand::thread_rng().gen_range(0..=20) as u32; // not a big value to not to slow down tests + let (expected_hash, txids) = + create_utxos_wrapper(&context, index, is_input(IndexType::Output))?; + + case(Script) + .index(index) + .index_type(IndexType::Output) + .expect(expected_hash) + .run(&context, txids) +} + +#[simplex::test] +fn get_script_hash_for_missing_input_fail(context: simplex::TestContext) -> anyhow::Result<()> { + let (_, txids) = create_utxos_wrapper(&context, 0, is_input(IndexType::Input))?; + + case(Script) + .index(u32::MAX) + .index_type(IndexType::Input) + .expecting(&context, Expect::PrunedBranch, txids) +} + +#[simplex::test] +fn get_script_hash_for_missing_output_fail(context: simplex::TestContext) -> anyhow::Result<()> { + let (_, txids) = create_utxos_wrapper(&context, 0, is_input(IndexType::Output))?; + + case(Script) + .index(u32::MAX) + .index_type(IndexType::Output) + .expecting(&context, Expect::PrunedBranch, txids) +} + +#[simplex::test] +fn get_input_script_hash(context: simplex::TestContext) -> anyhow::Result<()> { + let index = rand::thread_rng().gen_range(0..=3) as u32; + let (expected_hash, txids) = create_utxos_wrapper(&context, index, is_input(IndexType::Input))?; + + case(InputScript) + .index(index) + .expect(expected_hash) + .run(&context, txids) +} + +#[simplex::test] +fn get_input_script_hash_missing_input_fail(context: simplex::TestContext) -> anyhow::Result<()> { + let (_, txids) = create_utxos_wrapper(&context, 0, is_input(IndexType::Input))?; + + case(InputScript) + .index(u32::MAX) + .expecting(&context, Expect::PrunedBranch, txids) +} + +#[simplex::test] +fn get_output_script_hash(context: simplex::TestContext) -> anyhow::Result<()> { + let index = rand::thread_rng().gen_range(0..=3) as u32; + + let (expected_hash, txids) = + create_utxos_wrapper(&context, index, is_input(IndexType::Output))?; + + case(OutputScript) + .index(index) + .expect(expected_hash) + .run(&context, txids) +} + +#[simplex::test] +fn get_output_script_hash_missing_output_fail(context: simplex::TestContext) -> anyhow::Result<()> { + let (_, txids) = create_utxos_wrapper(&context, 0, is_input(IndexType::Output))?; + + case(OutputScript) + .index(u32::MAX) + .expecting(&context, Expect::PrunedBranch, txids) +} + +#[simplex::test] +fn get_current_script_hash(context: simplex::TestContext) -> anyhow::Result<()> { + let index = 0; + + let (expected_hash, txids) = create_utxos_wrapper(&context, index, is_input(IndexType::Input))?; + + case(CurrentScript) + .index(index) + .expect(expected_hash) + .run(&context, txids) +} From a5bedc42cbd1a9ad0c0fd75b27c16baee7c19d0a Mon Sep 17 00:00:00 2001 From: aritkulova Date: Sun, 18 Oct 2026 00:00:30 +0300 Subject: [PATCH 2/5] added script tweaking for tests --- tests/stdlib/common/core.rs | 29 +++++++++++++++++++---------- tests/stdlib/common/utxo_helper.rs | 10 +++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/tests/stdlib/common/core.rs b/tests/stdlib/common/core.rs index 743667f..d30e0a2 100644 --- a/tests/stdlib/common/core.rs +++ b/tests/stdlib/common/core.rs @@ -223,10 +223,9 @@ fn prepare_utxo( .expect("Missing UTXO for the script"), }; - if utxo.txout.value.is_confidential() { - Ok(unblind(context.get_default_signer(), utxo)?) - } else { - Ok(utxo) + match utxo.txout.value.is_confidential() { + true => Ok(unblind(context.get_default_signer(), utxo)?), + false => Ok(utxo), } } @@ -240,7 +239,7 @@ fn unblind(signer: &Signer, mut utxo: UTXO) -> anyhow::Result { Ok(utxo) } -// Add an output mirroring utxo's asset with amount - 1 and the same script. +// Add an output mirroring utxo's asset with amount - 1 and the tweaked script. fn add_mirror_output( mut ft: FinalTransaction, utxo: &UTXO, @@ -248,7 +247,8 @@ fn add_mirror_output( policy_asset: AssetId, ) -> (FinalTransaction, Option) { let mut output = PartialOutput::new( - utxo.txout.script_pubkey.clone(), + // scripts in input and output on the same index should be different for the test + tweak_script(&utxo.txout.script_pubkey), // amounts in input and output on the same index should be different for the test utxo.amount() - 1, utxo.asset(), @@ -260,15 +260,24 @@ fn add_mirror_output( ft.add_output(output); - let leftover_asset = if utxo.asset() != policy_asset { - Some(utxo.asset()) - } else { - None + let leftover_asset = match utxo.asset() == policy_asset { + true => None, + false => Some(utxo.asset()), }; (ft, leftover_asset) } +/// Change the lowest bit of the last byte (used for test purposes). +pub fn tweak_script(script: &Script) -> Script { + let mut bytes = script.as_bytes().to_vec(); + + let last = bytes.last_mut().expect("Empty script"); + *last ^= 0x01; + + Script::from(bytes) +} + /// Spend the funded UTXO with `witness`. Return the broadcast result. pub fn spend( context: &simplex::TestContext, diff --git a/tests/stdlib/common/utxo_helper.rs b/tests/stdlib/common/utxo_helper.rs index 230c8be..043555c 100644 --- a/tests/stdlib/common/utxo_helper.rs +++ b/tests/stdlib/common/utxo_helper.rs @@ -10,6 +10,7 @@ use simplex::simplicityhl::elements::Txid; use simplex::simplicityhl::elements::pset::serialize::Serialize; use simplex::transaction::UTXO; +use crate::common::core::tweak_script; use crate::common::core::{send_blinded, send_explicit, send_issued}; use crate::common::helper::generate_u256; pub const DEFAULT_SEND_AMOUNT: u64 = 50; @@ -134,7 +135,14 @@ pub fn create_utxos_and_return_script_hash( program, )?; - let hash = (last_utxo.txout.script_pubkey).wscript_hash(); + // when testing an input amount, we expect the actual script; + // the output script will be tweaked to differ from the input script + let script = match is_input { + true => last_utxo.txout.script_pubkey, + false => tweak_script(&last_utxo.txout.script_pubkey), + }; + + let hash = script.wscript_hash(); Ok((hash.to_byte_array(), txids)) } From 9b3f430e2dd36f3cf6c3b863dba43956e8efe9bc Mon Sep 17 00:00:00 2001 From: aritkulova Date: Mon, 19 Oct 2026 16:43:39 +0300 Subject: [PATCH 3/5] updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20e7693..cbe975b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [Unreleased] +- Added functions for retrieving script hashes. + ## [0.0.2] - Added `mul_div` functions. From 744ee6ea8f6827c83c3be00a3ec6ac3ae0511feb Mon Sep 17 00:00:00 2001 From: aritkulova Date: Mon, 19 Oct 2026 20:15:23 +0300 Subject: [PATCH 4/5] removed get_current_script_hash; minor refactoring; fixed typos --- docs/stdlib.json | 9 +---- simf/lib/utxo/getters/script_hash.simf | 13 +----- simf/tests/utxo/getters/script_hash.simf | 10 +---- tests/stdlib/common/core.rs | 40 +++++-------------- tests/stdlib/common/utxo_helper.rs | 2 +- tests/stdlib/utxo/asserts/amount.rs | 9 +---- tests/stdlib/utxo/asserts/asset_id.rs | 9 +---- .../utxo/asserts/asset_id_with_amount.rs | 9 +---- tests/stdlib/utxo/getters/amount.rs | 9 +---- tests/stdlib/utxo/getters/asset_id.rs | 9 +---- .../utxo/getters/asset_id_with_amount.rs | 9 +---- tests/stdlib/utxo/getters/script_hash.rs | 15 +------ 12 files changed, 21 insertions(+), 122 deletions(-) diff --git a/docs/stdlib.json b/docs/stdlib.json index 8ce29a1..dd91cf6 100644 --- a/docs/stdlib.json +++ b/docs/stdlib.json @@ -459,14 +459,7 @@ "section": "Script hash getters", "input_type": "u32", "output_type": "u256", - "description": " Returns the SHA256 hash of the scriptPubKey of the output at the given index.\n\n## Panics\nPanics if the specified output does not exist." - }, - { - "simplicityhl_name": "get_current_script_hash", - "section": "Script hash getters", - "input_type": "()", - "output_type": "u256", - "description": "Returns the SHA256 hash of the scriptPubKey at the current_index." + "description": "Returns the SHA256 hash of the scriptPubKey of the output at the given index.\n\n## Panics\nPanics if the specified output does not exist." }, { "simplicityhl_name": "not", diff --git a/simf/lib/utxo/getters/script_hash.simf b/simf/lib/utxo/getters/script_hash.simf index 8f16728..c3732f3 100644 --- a/simf/lib/utxo/getters/script_hash.simf +++ b/simf/lib/utxo/getters/script_hash.simf @@ -15,20 +15,11 @@ pub fn get_script_hash(index: u32, is_input_index: bool) -> u256 { /// Returns the SHA256 hash of the scriptPubKey of the UTXO of the input at the given index. /// Panics if the specified input does not exist pub fn get_input_script_hash(index: u32) -> u256 { - let script_hash: Option = jet::input_script_hash(index); - - unwrap(script_hash) + unwrap(jet::input_script_hash(index)) } /// Returns the SHA256 hash of the scriptPubKey of the UTXO of the output at the given index. /// Panics if the specified output does not exist pub fn get_output_script_hash(index: u32) -> u256 { - let script_hash: Option = jet::output_script_hash(index); - - unwrap(script_hash) -} - -/// Returns the SHA256 hash of the scriptPubKey of the UTXO at the current_index -pub fn get_current_script_hash() -> u256 { - jet::current_script_hash() + unwrap(jet::output_script_hash(index)) } diff --git a/simf/tests/utxo/getters/script_hash.simf b/simf/tests/utxo/getters/script_hash.simf index 95795e9..68aff1c 100644 --- a/simf/tests/utxo/getters/script_hash.simf +++ b/simf/tests/utxo/getters/script_hash.simf @@ -1,8 +1,7 @@ use crate::lib::utxo::getters::script_hash::{ get_script_hash, get_input_script_hash, - get_output_script_hash, - get_current_script_hash + get_output_script_hash }; use crate::lib::asserts::assert_eq_256; @@ -36,11 +35,4 @@ fn main() { }, false => (), }; - - match is_selected(3, fn_idx) { - true => { - assert_eq_256(get_current_script_hash(), expected_hash); - }, - false => (), - }; } diff --git a/tests/stdlib/common/core.rs b/tests/stdlib/common/core.rs index d30e0a2..96ac097 100644 --- a/tests/stdlib/common/core.rs +++ b/tests/stdlib/common/core.rs @@ -11,7 +11,6 @@ use simplex::transaction::partial_input::IssuanceInput; use simplex::transaction::{ FinalTransaction, PartialInput, PartialOutput, ProgramInput, RequiredSignature, UTXO, }; -use simplicityhl_std::artifacts::tests::mock::MockProgram; use simplicityhl_std::artifacts::tests::mock::derived_mock::MockWitness; use crate::common::utxo_helper::{DEFAULT_SEND_AMOUNT, search_utxo_by_txid}; @@ -57,7 +56,7 @@ pub fn send_explicit(signer: &Signer, to: &Script, amount_to_send: u64) -> anyho Ok(signer.send(to.clone(), amount_to_send)?.txid()) } -/// Send sats to the specified script confidentialy. +/// Send sats to the specified script confidentially. pub fn send_blinded( signer: &Signer, to: &Script, @@ -111,7 +110,7 @@ pub fn construct_final_tx( witness: W, data: Option<&[u8]>, txids: Vec, - program_for_test: Option<&impl AsRef>, + program_for_test: Option, ) -> anyhow::Result where W: WitnessTrait + 'static, @@ -156,15 +155,12 @@ where let last_utxo = match program_for_test { Some(program_for_test) => { - let last_script = &program_for_test.as_ref().get_script_pubkey(network); + let last_script = &program_for_test.get_script_pubkey(network); let last_utxo = prepare_utxo(context, last_script, txids.last())?; ft.add_program_input( PartialInput::new(last_utxo.clone()), - ProgramInput::new( - Box::new(program_for_test.as_ref().clone()), - Box::new(MockWitness {}), - ), + ProgramInput::new(Box::new(program_for_test.clone()), Box::new(MockWitness {})), RequiredSignature::None, ); @@ -191,11 +187,7 @@ where } if let Some(leftover_asset) = leftover_asset { - ft.add_output(PartialOutput::new( - default_script.clone(), - 1, - leftover_asset, - )); + ft.add_output(PartialOutput::new(default_script, 1, leftover_asset)); } if let Some(data) = data { @@ -285,7 +277,7 @@ pub fn spend( witness: W, data: Option<&[u8]>, txids: Vec, - program_for_test: Option<&impl AsRef>, + program_for_test: Option, ) -> anyhow::Result where W: WitnessTrait + 'static, @@ -326,14 +318,7 @@ where W: WitnessTrait + 'static, { fund(context, &program, DEFAULT_SEND_AMOUNT)?; - let result = spend( - context, - &program, - witness, - None, - Vec::new(), - None::<&MockProgram>, - ); + let result = spend(context, &program, witness, None, Vec::new(), None); assert_error_msg(result, expect) } @@ -351,14 +336,7 @@ where W: WitnessTrait + 'static, { fund(context, &program, DEFAULT_SEND_AMOUNT)?; - let result = spend( - context, - &program, - witness, - Some(data), - Vec::new(), - None::<&MockProgram>, - ); + let result = spend(context, &program, witness, Some(data), Vec::new(), None); assert_error_msg(result, expect) } @@ -370,7 +348,7 @@ pub fn run_with_inputs_outputs( witness: W, expect: Expect, txids: Vec, - program_for_test: Option<&impl AsRef>, + program_for_test: Option, ) -> anyhow::Result<()> where W: WitnessTrait + 'static, diff --git a/tests/stdlib/common/utxo_helper.rs b/tests/stdlib/common/utxo_helper.rs index 043555c..90cad21 100644 --- a/tests/stdlib/common/utxo_helper.rs +++ b/tests/stdlib/common/utxo_helper.rs @@ -136,7 +136,7 @@ pub fn create_utxos_and_return_script_hash( )?; // when testing an input amount, we expect the actual script; - // the output script will be tweaked to differ from the input script + // the output script is tweaked to differ from the input script let script = match is_input { true => last_utxo.txout.script_pubkey, false => tweak_script(&last_utxo.txout.script_pubkey), diff --git a/tests/stdlib/utxo/asserts/amount.rs b/tests/stdlib/utxo/asserts/amount.rs index 97c99bf..3644110 100644 --- a/tests/stdlib/utxo/asserts/amount.rs +++ b/tests/stdlib/utxo/asserts/amount.rs @@ -103,14 +103,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAmountProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/asserts/asset_id.rs b/tests/stdlib/utxo/asserts/asset_id.rs index 1b2cfa1..6408829 100644 --- a/tests/stdlib/utxo/asserts/asset_id.rs +++ b/tests/stdlib/utxo/asserts/asset_id.rs @@ -105,14 +105,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAssetIdProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs index f33c4b6..de17bc4 100644 --- a/tests/stdlib/utxo/asserts/asset_id_with_amount.rs +++ b/tests/stdlib/utxo/asserts/asset_id_with_amount.rs @@ -113,14 +113,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAssetIdWithAmountProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/getters/amount.rs b/tests/stdlib/utxo/getters/amount.rs index 3336a21..00144e0 100644 --- a/tests/stdlib/utxo/getters/amount.rs +++ b/tests/stdlib/utxo/getters/amount.rs @@ -101,14 +101,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAmountProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/getters/asset_id.rs b/tests/stdlib/utxo/getters/asset_id.rs index d92c6a7..bb3fab0 100644 --- a/tests/stdlib/utxo/getters/asset_id.rs +++ b/tests/stdlib/utxo/getters/asset_id.rs @@ -106,14 +106,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAssetIdProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/getters/asset_id_with_amount.rs b/tests/stdlib/utxo/getters/asset_id_with_amount.rs index d9941da..312e0f7 100644 --- a/tests/stdlib/utxo/getters/asset_id_with_amount.rs +++ b/tests/stdlib/utxo/getters/asset_id_with_amount.rs @@ -112,14 +112,7 @@ impl Case { expect: Expect, txids: Vec, ) -> anyhow::Result<()> { - run_with_inputs_outputs( - context, - program(), - self.witness, - expect, - txids, - None::<&TestAssetIdWithAmountProgram>, - ) + run_with_inputs_outputs(context, program(), self.witness, expect, txids, None) } } diff --git a/tests/stdlib/utxo/getters/script_hash.rs b/tests/stdlib/utxo/getters/script_hash.rs index 45661e5..ee00835 100644 --- a/tests/stdlib/utxo/getters/script_hash.rs +++ b/tests/stdlib/utxo/getters/script_hash.rs @@ -19,7 +19,6 @@ enum FunctionToTest { Script, InputScript, OutputScript, - CurrentScript, } #[derive(PartialEq, Eq)] enum IndexType { @@ -92,7 +91,7 @@ impl Case { self.witness, expect, txids, - Some(&mock()), + Some(mock().as_ref().clone()), ) } } @@ -195,15 +194,3 @@ fn get_output_script_hash_missing_output_fail(context: simplex::TestContext) -> .index(u32::MAX) .expecting(&context, Expect::PrunedBranch, txids) } - -#[simplex::test] -fn get_current_script_hash(context: simplex::TestContext) -> anyhow::Result<()> { - let index = 0; - - let (expected_hash, txids) = create_utxos_wrapper(&context, index, is_input(IndexType::Input))?; - - case(CurrentScript) - .index(index) - .expect(expected_hash) - .run(&context, txids) -} From f3dcf8cf457d8d7e200a9b041d51edeaa69da23e Mon Sep 17 00:00:00 2001 From: aritkulova Date: Tue, 20 Oct 2026 13:16:01 +0300 Subject: [PATCH 5/5] fixed typo in version counter --- CHANGELOG.md | 6 +-- Cargo.lock | 110 +++++++++++++++++++++++++-------------------------- Cargo.toml | 2 +- 3 files changed, 58 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbe975b..6657aa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,15 @@ # Changelog ## [Unreleased] -- Added functions for retrieving script hashes. - -## [0.0.2] - Added `mul_div` functions. - Organized code into modules. - Refactored test structure. - Removed `safe_` prefixes from math functions, so the default versions are overflow-checked. - Added functions for retrieving and asserting `AssetId` and `Amount`. +- Added functions for retrieving script hashes. -## [0.0.1] +## [0.1.0] Initial release! - Сhecked arithmetic operations for `u8`, `u16`, `u32`, `u64`, `u128` and `u256`. diff --git a/Cargo.lock b/Cargo.lock index 86877ca..97cef9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,9 +106,9 @@ checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "aws-lc-rs" -version = "1.18.1" +version = "1.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b281d307588d634de920874890732659e2e7672f72b5e10e81badc1a8a83621e" +checksum = "faac5829c2b74c28f830747e7818ccfb684261b5f48a1118b1e2a13d36dfab13" dependencies = [ "aws-lc-sys", "zeroize", @@ -116,9 +116,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bff6c3b54fad79a2e60b8102caf565819711497c1f5f092f49508e2f5c31b27" +checksum = "f1622d8446a2d4b2ce0c7eefc73dd43a99779028d5ee5c2dd8073a658ba8a2bc" dependencies = [ "cc", "cmake", @@ -338,9 +338,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.5.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f360145194ee8e21db5ee7f3fcd4fe52210864c75c985dae33218202c8bbe040" +checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df" dependencies = [ "find-msvc-tools", "jobserver", @@ -506,9 +506,9 @@ checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" [[package]] name = "either" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" dependencies = [ "serde", ] @@ -565,9 +565,9 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" [[package]] name = "errno" @@ -587,9 +587,9 @@ checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" [[package]] name = "find-msvc-tools" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aedcfb3409746eddb02b9e19ebda1c3394f759a152e48ee875a0844d1b955484" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" [[package]] name = "fixed-hash" @@ -897,9 +897,9 @@ checksum = "a4933f3f57a8e9d9da04db23fb153356ecaf00cbd14aee46279c33dc80925c37" [[package]] name = "libc" -version = "0.2.189" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "linux-raw-sys" @@ -1072,9 +1072,9 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pin-utils" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "13bee6c73da26345c729282832b60b0363cf3dd9f4bfd81d8551b7a1c889a113" [[package]] name = "pkg-config" @@ -1273,9 +1273,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.45" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "aws-lc-rs", "log", @@ -1297,9 +1297,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "aws-lc-rs", "ring", @@ -1345,9 +1345,9 @@ dependencies = [ [[package]] name = "secp256k1-zkp" -version = "0.11.0" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52a44aed3002b5ae975f8624c5df3a949cfbf00479e18778b6058fcd213b76e3" +checksum = "403f6ab6ef5189ded7d11cb384a96a9f871001e50b391a8fcbb310c9ebc2099b" dependencies = [ "bitcoin-private", "rand", @@ -1399,14 +1399,14 @@ checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] name = "serde_json" -version = "1.0.151" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", "memchr", @@ -1417,9 +1417,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" dependencies = [ "serde_core", ] @@ -1490,7 +1490,7 @@ dependencies = [ [[package]] name = "simplicityhl-std" -version = "0.0.1" +version = "0.1.0" dependencies = [ "anyhow", "num-bigint", @@ -1651,9 +1651,9 @@ dependencies = [ [[package]] name = "syn" -version = "3.0.6" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" dependencies = [ "proc-macro2", "quote", @@ -1696,7 +1696,7 @@ checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" dependencies = [ "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", ] [[package]] @@ -1731,21 +1731,21 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "1.1.1+spec-1.1.0" +version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053" dependencies = [ "serde_core", ] [[package]] name = "toml_edit" -version = "0.25.15+spec-1.1.0" +version = "0.25.17+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1340ea94a5856333492c9064b02c778b191dd2c853778d9609debdcdfea3a614" +checksum = "e3641d5bbb5349a79e1020a242d251efbc546ad8048d133958323ce9c40a9c9c" dependencies = [ "indexmap", - "toml_datetime 1.1.1+spec-1.1.0", + "toml_datetime 1.1.2+spec-1.1.0", "toml_parser", "toml_writer", "winnow 1.0.4", @@ -1753,18 +1753,18 @@ dependencies = [ [[package]] name = "toml_parser" -version = "1.1.3+spec-1.1.0" +version = "1.1.5+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d38ac1cf9b95face32296c0a3ede1fdc270627c9d9c02a7274dd6d960dc4d56" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" dependencies = [ "winnow 1.0.4", ] [[package]] name = "toml_writer" -version = "1.1.2+spec-1.1.0" +version = "1.1.3+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" +checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770" [[package]] name = "typenum" @@ -1774,9 +1774,9 @@ checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "uint" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f9227a75a5a540a464c832ad4a4195dbdbecd8787610a56262721fde6f04f90" +checksum = "2833f28e3adbd1b867292ee4053252ea89ab85e44e5e4701ffead8cada0539fa" dependencies = [ "byteorder", "crunchy", @@ -1786,15 +1786,15 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.26" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "unicode-normalization" -version = "0.1.25" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +checksum = "75cd3fb03d5288b3ba9a1ee103ac7e9cbb59f0b03d64f8ddfcc04dd42758a85d" dependencies = [ "tinyvec", ] @@ -1883,7 +1883,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 3.0.6", + "syn 3.0.9", "wasm-bindgen-shared", ] @@ -1898,9 +1898,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" dependencies = [ "rustls-pki-types", ] @@ -2055,18 +2055,18 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "zerocopy" -version = "0.8.59" +version = "0.8.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6df92bf3d9227be3d53173901ddbffac2babc27ae50f397776ffd6dc33f800cb" +checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.59" +version = "0.8.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac4f328cf2f05d084e496c3e9c3f33ed0a183656a16e1fcec4d464d8373aec82" +checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" dependencies = [ "proc-macro2", "quote", @@ -2075,9 +2075,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.9.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index 7703add..422ac42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simplicityhl-std" -version = "0.0.1" +version = "0.1.0" description = "SimplicityHL Standard Library" edition = "2024" rust-version = "1.91.0"