From 4ba6547f4d91644a70956e752b86347184a44a5a Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 13 Nov 2023 21:44:07 +0800 Subject: [PATCH 1/9] replace new_ref_input_with_lang_ver by new_ref_input --- rust/src/builders/script_structs.rs | 19 +------------------ rust/src/tests/builders/tx_builder.rs | 6 +++--- rust/src/tests/builders/voting_builder.rs | 2 +- .../tests/builders/voting_proposal_builder.rs | 2 +- 4 files changed, 6 insertions(+), 23 deletions(-) diff --git a/rust/src/builders/script_structs.rs b/rust/src/builders/script_structs.rs index 085c70cd..8f2339e2 100644 --- a/rust/src/builders/script_structs.rs +++ b/rust/src/builders/script_structs.rs @@ -31,24 +31,7 @@ impl PlutusScriptSource { pub fn new(script: &PlutusScript) -> Self { Self(PlutusScriptSourceEnum::Script(script.clone())) } - - /// !!! DEPRECATED !!! - /// This constructor has missed information about plutus script language vesrion. That can affect - /// the script data hash calculation. - /// Use `.new_ref_input_with_lang_ver` instead - #[deprecated( - since = "11.3.0", - note = "This constructor has missed information about plutus script language vesrion. That can affect the script data hash calculation. Use `.new_ref_input_with_lang_ver` instead." - )] - pub fn new_ref_input(script_hash: &ScriptHash, input: &TransactionInput) -> Self { - Self(PlutusScriptSourceEnum::RefInput( - input.clone(), - script_hash.clone(), - None, - )) - } - - pub fn new_ref_input_with_lang_ver( + pub fn new_ref_input( script_hash: &ScriptHash, input: &TransactionInput, lang_ver: &Language, diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index c03df3b6..ab42c740 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -5764,7 +5764,7 @@ fn plutus_mint_with_script_ref_test() { let asset_name = AssetName::from_hex("44544e4654").unwrap(); let mut mint_builder = MintBuilder::new(); let plutus_script_source = PlutusScriptSource::new(&plutus_script); - let plutus_script_source_ref = PlutusScriptSource::new_ref_input_with_lang_ver( + let plutus_script_source_ref = PlutusScriptSource::new_ref_input( &plutus_script2.hash(), &tx_input_ref, &Language::new_plutus_v2(), @@ -6240,12 +6240,12 @@ fn build_tx_with_certs_withdrawals_plutus_script_address() { let ref_cert_script_input_3 = fake_tx_input(1); let ref_cert_withdrawal_input_2 = fake_tx_input(2); - let plutus_cert_source = PlutusScriptSource::new_ref_input_with_lang_ver( + let plutus_cert_source = PlutusScriptSource::new_ref_input( &cert_script_hash3, &ref_cert_script_input_3, &Language::new_plutus_v2(), ); - let plutus_withdrawal_source = PlutusScriptSource::new_ref_input_with_lang_ver( + let plutus_withdrawal_source = PlutusScriptSource::new_ref_input( &withdraw_script_hash2, &ref_cert_withdrawal_input_2, &Language::new_plutus_v2(), diff --git a/rust/src/tests/builders/voting_builder.rs b/rust/src/tests/builders/voting_builder.rs index eefd4932..49883ab7 100644 --- a/rust/src/tests/builders/voting_builder.rs +++ b/rust/src/tests/builders/voting_builder.rs @@ -188,7 +188,7 @@ fn voting_builder_plutus_ref_witness() { let action_id = GovernanceActionId::new(&fake_tx_hash(1), 1); let vote = VotingProcedure::new(VoteKind::No); - let script_source = PlutusScriptSource::new_ref_input_with_lang_ver( + let script_source = PlutusScriptSource::new_ref_input( &script_hash, &ref_input, &Language::new_plutus_v2(), diff --git a/rust/src/tests/builders/voting_proposal_builder.rs b/rust/src/tests/builders/voting_proposal_builder.rs index e570e82a..c26cd47c 100644 --- a/rust/src/tests/builders/voting_proposal_builder.rs +++ b/rust/src/tests/builders/voting_proposal_builder.rs @@ -316,7 +316,7 @@ fn voting_proposal_builder_with_ref_plutus_script_witness() { ); let expected_redeemer = redeemer.clone_with_index_and_tag(&BigNum::from(1u64), &RedeemerTag::new_voting_proposal()); - let plutus_source = PlutusScriptSource::new_ref_input_with_lang_ver(&script_hash, &ref_input, &Language::new_plutus_v2()); + let plutus_source = PlutusScriptSource::new_ref_input(&script_hash, &ref_input, &Language::new_plutus_v2()); let plutus_witness = PlutusWitness::new_with_ref_without_datum( &plutus_source, &redeemer, From 177774e67014def040f74fe5496a4e3cd2a7ca98 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 14 Nov 2023 19:09:44 +0800 Subject: [PATCH 2/9] remove ability to add a script input without witness --- rust/src/address.rs | 14 +- rust/src/builders/tx_builder.rs | 72 +--- rust/src/builders/tx_inputs_builder.rs | 248 +++----------- rust/src/error.rs | 15 + rust/src/tests/builders/tx_builder.rs | 437 +++++-------------------- rust/src/tests/mock_objects.rs | 10 +- 6 files changed, 161 insertions(+), 635 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 962bbead..469e97ed 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -645,9 +645,9 @@ impl Deserialize for Address { #[wasm_bindgen] #[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)] pub struct BaseAddress { - network: u8, - payment: Credential, - stake: Credential, + pub(crate) network: u8, + pub(crate) payment: Credential, + pub(crate) stake: Credential, } #[wasm_bindgen] @@ -683,8 +683,8 @@ impl BaseAddress { #[wasm_bindgen] #[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)] pub struct EnterpriseAddress { - network: u8, - payment: Credential, + pub(crate) network: u8, + pub(crate) payment: Credential, } #[wasm_bindgen] @@ -715,8 +715,8 @@ impl EnterpriseAddress { #[wasm_bindgen] #[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct RewardAddress { - network: u8, - payment: Credential, + pub(crate) network: u8, + pub(crate) payment: Credential, } #[wasm_bindgen] diff --git a/rust/src/builders/tx_builder.rs b/rust/src/builders/tx_builder.rs index 2ba005ce..fd0a8874 100644 --- a/rust/src/builders/tx_builder.rs +++ b/rust/src/builders/tx_builder.rs @@ -414,7 +414,7 @@ impl TransactionBuilder { &input.input, &input.output.amount, )?; - self.add_input(&input.output.address, &input.input, &input.output.amount); + self.add_regular_input(&input.output.address, &input.input, &input.output.amount); input_total = input_total.checked_add(&input.output.amount)?; output_total = output_total.checked_add(&Value::new(&input_fee))?; } @@ -494,7 +494,7 @@ impl TransactionBuilder { &input.input, &input.output.amount, )?; - self.add_input(&input.output.address, &input.input, &input.output.amount); + self.add_regular_input(&input.output.address, &input.input, &input.output.amount); input_total = input_total.checked_add(&input.output.amount)?; output_total = output_total.checked_add(&Value::new(&input_fee))?; } @@ -532,7 +532,7 @@ impl TransactionBuilder { // differing from CIP2, we include the needed fees in the targets instead of just output values let input_fee = self.fee_for_input(&input.output.address, &input.input, &input.output.amount)?; - self.add_input(&input.output.address, &input.input, &input.output.amount); + self.add_regular_input(&input.output.address, &input.input, &input.output.amount); *input_total = input_total.checked_add(&input.output.amount)?; *output_total = output_total.checked_add(&Value::new(&input_fee))?; available_indices.swap_remove(available_indices.iter().position(|j| i == j).unwrap()); @@ -650,7 +650,7 @@ impl TransactionBuilder { &input.input, &input.output.amount, )?; - self.add_input(&input.output.address, &input.input, &input.output.amount); + self.add_regular_input(&input.output.address, &input.input, &input.output.amount); *input_total = input_total.checked_add(&input.output.amount)?; *output_total = output_total.checked_add(&Value::new(&input_fee))?; } @@ -763,23 +763,6 @@ impl TransactionBuilder { self.inputs.add_key_input(hash, input, amount); } - /// This method adds the input to the builder BUT leaves a missing spot for the witness native script - /// - /// After adding the input with this method, use `.add_required_native_input_scripts` - /// and `.add_required_plutus_input_scripts` to add the witness scripts - /// - /// Or instead use `.add_native_script_input` and `.add_plutus_script_input` - /// to add inputs right along with the script, instead of the script hash - #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] - pub fn add_script_input( - &mut self, - hash: &ScriptHash, - input: &TransactionInput, - amount: &Value, - ) { - self.inputs.add_script_input(hash, input, amount); - } - /// This method will add the input to the builder and also register the required native script witness #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] pub fn add_native_script_input( @@ -812,41 +795,15 @@ impl TransactionBuilder { self.inputs.add_bootstrap_input(hash, input, amount); } - /// Note that for script inputs this method will use underlying generic `.add_script_input` - /// which leaves a required empty spot for the script witness (or witnesses in case of Plutus). - /// You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness. - #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] - pub fn add_input(&mut self, address: &Address, input: &TransactionInput, amount: &Value) { - self.inputs.add_input(address, input, amount); - } - - /// Returns the number of still missing input scripts (either native or plutus) - /// Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts - #[deprecated( - since = "10.2.0", - note = "Use `.count_missing_input_scripts` from `TxInputsBuilder`" - )] - pub fn count_missing_input_scripts(&self) -> usize { - self.inputs.count_missing_input_scripts() - } - - /// Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - /// Any scripts that don't match any of the previously added inputs will be ignored - /// Returns the number of remaining required missing witness scripts - /// Use `.count_missing_input_scripts` to find the number of still missing scripts - #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] - pub fn add_required_native_input_scripts(&mut self, scripts: &NativeScripts) -> usize { - self.inputs.add_required_native_input_scripts(scripts) + /// This function is replace for previous one add_input. + /// The functions adds a non script input, if it is a script input it returns an error. + /// To add script input you need to use add_native_script_input or add_plutus_script_input. + /// Also we recommend to use TxInputsBuilder and .set_inputs, because all add_*_input functions might be removed from transaction builder. + #[deprecated(since = "12.0.0", note = "Use `.set_inputs`")] + pub fn add_regular_input(&mut self, address: &Address, input: &TransactionInput, amount: &Value) -> Result<(), JsError>{ + self.inputs.add_regular_input(address, input, amount) } - /// Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - /// Any scripts that don't match any of the previously added inputs will be ignored - /// Returns the number of remaining required missing witness scripts - /// Use `.count_missing_input_scripts` to find the number of still missing scripts - #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] - pub fn add_required_plutus_input_scripts(&mut self, scripts: &PlutusWitnesses) -> usize { - self.inputs.add_required_plutus_input_scripts(scripts) - } /// Returns a copy of the current script input witness scripts in the builder #[deprecated(since = "10.2.0", note = "Use `.set_inputs`")] @@ -877,7 +834,7 @@ impl TransactionBuilder { let fee_before = min_fee(&self_copy)?; - self_copy.add_input(&address, &input, &amount); + self_copy.add_regular_input(&address, &input, &amount); let fee_after = min_fee(&self_copy)?; fee_after.checked_sub(&fee_before) } @@ -2164,11 +2121,6 @@ impl TransactionBuilder { /// NOTE: is_valid set to true /// NOTE: Will fail in case there are any script inputs added with no corresponding witness pub fn build_tx(&self) -> Result { - if self.count_missing_input_scripts() > 0 { - return Err(JsError::from_str( - "There are some script inputs added that don't have the corresponding script provided as a witness!", - )); - } if self.has_plutus_inputs() { if self.script_data_hash.is_none() { return Err(JsError::from_str( diff --git a/rust/src/builders/tx_inputs_builder.rs b/rust/src/builders/tx_inputs_builder.rs index 0d987d5e..2e15cedf 100644 --- a/rust/src/builders/tx_inputs_builder.rs +++ b/rust/src/builders/tx_inputs_builder.rs @@ -8,60 +8,6 @@ pub(crate) struct TxBuilderInput { pub(crate) amount: Value, // we need to keep track of the amount in the inputs for input selection } -#[wasm_bindgen] -#[derive(Clone, Debug)] -pub struct InputWithScriptWitness { - pub(crate) input: TransactionInput, - pub(crate) witness: ScriptWitnessType, -} - -#[wasm_bindgen] -impl InputWithScriptWitness { - pub fn new_with_native_script_witness( - input: &TransactionInput, - witness: &NativeScript, - ) -> Self { - Self { - input: input.clone(), - witness: ScriptWitnessType::NativeScriptWitness(NativeScriptSourceEnum::NativeScript( - witness.clone(), - )), - } - } - - pub fn new_with_plutus_witness(input: &TransactionInput, witness: &PlutusWitness) -> Self { - Self { - input: input.clone(), - witness: ScriptWitnessType::PlutusScriptWitness(witness.clone()), - } - } - - pub fn input(&self) -> TransactionInput { - self.input.clone() - } -} - -#[wasm_bindgen] -pub struct InputsWithScriptWitness(Vec); - -#[wasm_bindgen] -impl InputsWithScriptWitness { - pub fn new() -> Self { - Self(Vec::new()) - } - - pub fn add(&mut self, input: &InputWithScriptWitness) { - self.0.push(input.clone()); - } - - pub fn get(&self, index: usize) -> InputWithScriptWitness { - self.0[index].clone() - } - - pub fn len(&self) -> usize { - self.0.len() - } -} // We need to know how many of each type of witness will be in the transaction so we can calculate the tx fee #[derive(Clone, Debug)] @@ -116,20 +62,7 @@ impl TxInputsBuilder { self.required_witnesses.vkeys.insert(hash.clone()); } - #[deprecated( - since = "11.2.0", - note = "Use `.add_native_script_input` or `.add_plutus_script_input` instead." - )] - /// !!! DEPRECATED !!! - /// This function can make a mistake in choosing right input index. Use `.add_native_script_input` or `.add_plutus_script_input` instead. - /// This method adds the input to the builder BUT leaves a missing spot for the witness native script - /// - /// After adding the input with this method, use `.add_required_native_input_scripts` - /// and `.add_required_plutus_input_scripts` to add the witness scripts - /// - /// Or instead use `.add_native_script_input` and `.add_plutus_script_input` - /// to add inputs right along with the script, instead of the script hash - pub fn add_script_input( + fn add_script_input( &mut self, hash: &ScriptHash, input: &TransactionInput, @@ -186,151 +119,52 @@ impl TxInputsBuilder { self.required_witnesses.bootstraps.insert(hash.to_bytes()); } - /// Note that for script inputs this method will use underlying generic `.add_script_input` - /// which leaves a required empty spot for the script witness (or witnesses in case of Plutus). - /// You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness. - pub fn add_input(&mut self, address: &Address, input: &TransactionInput, amount: &Value) { - match &BaseAddress::from_address(address) { - Some(addr) => { - match &addr.payment_cred().to_keyhash() { - Some(hash) => return self.add_key_input(hash, input, amount), - None => (), - } - match &addr.payment_cred().to_scripthash() { - Some(hash) => return self.add_script_input(hash, input, amount), - None => (), - } - } - None => (), - } - match &EnterpriseAddress::from_address(address) { - Some(addr) => { - match &addr.payment_cred().to_keyhash() { - Some(hash) => return self.add_key_input(hash, input, amount), - None => (), + /// Adds non script input, in case of script or reward address input it will return an error + pub fn add_regular_input(&mut self, address: &Address, input: &TransactionInput, amount: &Value) -> Result<(), JsError>{ + match &address.0 { + AddrType::Base(base_addr) => { + match &base_addr.payment.0 { + CredType::Key(key) => { + self.add_key_input(key, input, amount); + Ok(()) + }, + CredType::Script(_) => { + Err(JsError::from_str(BuilderError::RegularInputIsScript.as_str())) + }, } - match &addr.payment_cred().to_scripthash() { - Some(hash) => return self.add_script_input(hash, input, amount), - None => (), - } - } - None => (), - } - match &PointerAddress::from_address(address) { - Some(addr) => { - match &addr.payment_cred().to_keyhash() { - Some(hash) => return self.add_key_input(hash, input, amount), - None => (), + }, + AddrType::Enterprise(ent_aaddr) => { + match &ent_aaddr.payment.0 { + CredType::Key(key) => { + self.add_key_input(key, input, amount); + Ok(()) + }, + CredType::Script(_) => { + Err(JsError::from_str(BuilderError::RegularInputIsScript.as_str())) + }, } - match &addr.payment_cred().to_scripthash() { - Some(hash) => return self.add_script_input(hash, input, amount), - None => (), + }, + AddrType::Ptr(ptr_addr) => { + match &ptr_addr.payment.0 { + CredType::Key(key) => { + self.add_key_input(key, input, amount); + Ok(()) + }, + CredType::Script(_) => { + Err(JsError::from_str(BuilderError::RegularInputIsScript.as_str())) + }, } - } - None => (), - } - match &ByronAddress::from_address(address) { - Some(addr) => { - return self.add_bootstrap_input(addr, input, amount); - } - None => (), + }, + AddrType::Byron(byron_addr) => { + self.add_bootstrap_input(byron_addr, input, amount); + Ok(()) + }, + AddrType::Reward(_) => { + Err(JsError::from_str(BuilderError::RegularInputIsFromRewardAddress.as_str())) + }, } } - /// Returns the number of still missing input scripts (either native or plutus) - /// Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts - pub fn count_missing_input_scripts(&self) -> usize { - self.required_witnesses - .scripts - .values() - .flat_map(|v| v.values()) - .filter(|s| s.is_none()) - .count() - } - - /// Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - /// Any scripts that don't match any of the previously added inputs will be ignored - /// Returns the number of remaining required missing witness scripts - /// Use `.count_missing_input_scripts` to find the number of still missing scripts - pub fn add_required_native_input_scripts(&mut self, scripts: &NativeScripts) -> usize { - scripts.0.iter().for_each(|s: &NativeScript| { - let hash = s.hash(); - if let Some(script_wits) = self.required_witnesses.scripts.get_mut(&hash) { - let mut tx_in = None; - for script_wit in script_wits { - if script_wit.1.is_none() { - tx_in = Some(script_wit.0.clone()); - break; - } - } - - if let Some(tx_in) = tx_in { - let witness = ScriptWitnessType::NativeScriptWitness( - NativeScriptSourceEnum::NativeScript(s.clone()), - ); - self.insert_input_with_witness(&hash, &tx_in, &witness); - } - } - }); - self.count_missing_input_scripts() - } - - #[deprecated( - since = "11.2.0", - note = "This function can make a mistake in choosing right input index. Use `.add_required_script_input_witnesses` instead." - )] - /// !!! DEPRECATED !!! - /// This function can make a mistake in choosing right input index. Use `.add_required_script_input_witnesses` instead. - /// Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - /// Any scripts that don't match any of the previously added inputs will be ignored - /// Returns the number of remaining required missing witness scripts - /// Use `.count_missing_input_scripts` to find the number of still missing scripts - pub fn add_required_plutus_input_scripts(&mut self, scripts: &PlutusWitnesses) -> usize { - scripts.0.iter().for_each(|s: &PlutusWitness| { - let hash = s.script.script_hash(); - if let Some(script_wits) = self.required_witnesses.scripts.get_mut(&hash) { - let mut tx_in = None; - for script_wit in script_wits { - if script_wit.1.is_none() { - tx_in = Some(script_wit.0.clone()); - break; - } - } - - if let Some(tx_in) = tx_in { - let witness = ScriptWitnessType::PlutusScriptWitness(s.clone()); - self.insert_input_with_witness(&hash, &tx_in, &witness); - } - } - }); - self.count_missing_input_scripts() - } - - /// Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - /// Any scripts that don't match any of the previously added inputs will be ignored - /// Returns the number of remaining required missing witness scripts - /// Use `.count_missing_input_scripts` to find the number of still missing scripts - pub fn add_required_script_input_witnesses( - &mut self, - inputs_with_wit: &InputsWithScriptWitness, - ) -> usize { - inputs_with_wit - .0 - .iter() - .for_each(|input_with_wit: &InputWithScriptWitness| { - let hash = input_with_wit.witness.script_hash(); - if let Some(script_wits) = self.required_witnesses.scripts.get_mut(&hash) { - if script_wits.contains_key(&input_with_wit.input) { - script_wits.insert( - input_with_wit.input.clone(), - Some(input_with_wit.witness.clone()), - ); - } - } - }); - self.count_missing_input_scripts() - } - pub fn get_ref_inputs(&self) -> TransactionInputs { let mut inputs = Vec::new(); for wintess in self diff --git a/rust/src/error.rs b/rust/src/error.rs index 79dc9917..c1c32b88 100644 --- a/rust/src/error.rs +++ b/rust/src/error.rs @@ -1,3 +1,4 @@ +use std::string::ToString; use super::*; use crate::chain_crypto; use cbor_event::{self}; @@ -222,3 +223,17 @@ impl std::fmt::Display for JsError { #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] impl std::error::Error for JsError {} + +pub(crate) enum BuilderError { + RegularInputIsScript, + RegularInputIsFromRewardAddress, +} + +impl BuilderError { + pub(crate) fn as_str(&self) -> &'static str { + match self { + BuilderError::RegularInputIsScript => "You can't add a script input to this function. You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness.", + BuilderError::RegularInputIsFromRewardAddress => "You can't use an input from reward address. To spend funds from reward address you to use withdrawal mechanism.", + } + } +} diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index ab42c740..b0649b7b 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -570,13 +570,13 @@ fn build_tx_with_inputs() { .to_str(), "69500" ); - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); } - tx_builder.add_input( + tx_builder.add_regular_input( &BaseAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, @@ -586,7 +586,7 @@ fn build_tx_with_inputs() { &TransactionInput::new(&genesis_id(), 1), &Value::new(&to_bignum(1_000_000)), ); - tx_builder.add_input( + tx_builder.add_regular_input( &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, @@ -596,7 +596,7 @@ fn build_tx_with_inputs() { &TransactionInput::new(&genesis_id(), 2), &Value::new(&to_bignum(1_000_000)), ); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::icarus_from_key(&spend, NetworkInfo::testnet().protocol_magic()) .to_address(), &TransactionInput::new(&genesis_id(), 3), @@ -651,7 +651,7 @@ fn build_tx_with_script_ref() { tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 3)); tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 4)); - tx_builder.add_input( + tx_builder.add_regular_input( &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, @@ -732,7 +732,7 @@ fn serialization_tx_body_with_script_ref() { tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 3)); tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 4)); - tx_builder.add_input( + tx_builder.add_regular_input( &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, @@ -813,7 +813,7 @@ fn json_serialization_tx_body_with_script_ref() { tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 3)); tx_builder.add_reference_input(&TransactionInput::new(&genesis_id(), 4)); - tx_builder.add_input( + tx_builder.add_regular_input( &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, @@ -892,7 +892,7 @@ fn build_tx_with_mint_all_sent() { let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); // Input with 150 coins - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(500)), @@ -980,7 +980,7 @@ fn build_tx_with_mint_in_change() { let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); // Input with 600 coins - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(600)), @@ -1089,13 +1089,13 @@ fn change_with_input_and_mint_not_enough_ada() { mass_input.insert(&policy_id, &asset_input); // Input with 600 coins - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(600)), ); - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 1), &Value::new_with_assets(&to_bignum(1), &mass_input), @@ -1185,13 +1185,13 @@ fn change_with_input_and_mint_not_enough_assets() { mass_input.insert(&policy_id, &asset_input); // Input with 600 coins - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(100000)), ); - tx_builder.add_input( + tx_builder.add_regular_input( &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 1), &Value::new_with_assets(&to_bignum(1), &mass_input), @@ -1708,7 +1708,7 @@ fn build_tx_burn_less_than_min_ada() { ) .unwrap(); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -1760,7 +1760,7 @@ fn build_tx_burn_empty_assets() { let mut input_value = Value::new(&to_bignum(2_400_000)); input_value.set_multiasset(&MultiAsset::new()); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -1810,7 +1810,7 @@ fn build_tx_no_useless_multiasset() { }); input_amount.set_multiasset(&input_multiasset); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -1892,7 +1892,7 @@ fn build_tx_add_change_split_nfts() { let mut input_value = Value::new(&to_bignum(1000)); input_value.set_multiasset(&multiasset); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -1952,7 +1952,7 @@ fn build_tx_add_change_split_nfts() { fn build_tx_too_big_output() { let mut tx_builder = create_tx_builder_with_fee_and_val_size(&create_linear_fee(0, 1), 10); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -2013,7 +2013,7 @@ fn build_tx_add_change_nfts_not_enough_ada() { let mut input_value = Value::new(&to_bignum(58)); input_value.set_multiasset(&multiasset); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -2357,7 +2357,7 @@ fn tx_builder_cip2_random_improve_multiasset() { .unwrap(); let input_for_cover_change = make_input(10u8, Value::new(&to_bignum(1000))); - tx_builder.add_input( + tx_builder.add_regular_input( &input_for_cover_change.output.address, &input_for_cover_change.input, &input_for_cover_change.output.amount, @@ -2651,7 +2651,7 @@ fn build_tx_multisig_spend_1on1_unsigned() { ) .to_address(); - tx_builder.add_input( + tx_builder.add_regular_input( &addr_multisig, &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), @@ -2842,7 +2842,7 @@ fn add_change_splits_change_into_multiple_outputs_when_nfts_overflow_output_size let mut input_value = Value::new(&to_bignum(1200)); input_value.set_multiasset(&multiasset); - tx_builder.add_input( + tx_builder.add_regular_input( &ByronAddress::from_base58("Ae2tdPwUPEZ5uzkzh1o2DHECiUi3iugvnnKHRisPgRRP3CTF4KCMvy54Xd3") .unwrap() .to_address(), @@ -3764,75 +3764,13 @@ fn create_base_address_from_script_hash(sh: &ScriptHash) -> Address { .to_address() } -#[test] -fn test_set_input_scripts() { - let mut tx_builder = create_reallistic_tx_builder(); - let (script1, hash1) = mint_script_and_policy(0); - let (script2, hash2) = mint_script_and_policy(1); - let (script3, _hash3) = mint_script_and_policy(2); - // Trying to set native scripts to the builder - let rem0 = tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![ - script1.clone(), - script2.clone(), - script3.clone(), - ])); - assert_eq!(rem0, 0); - let missing0 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing0, 0); - // Adding two script inputs using script1 and script2 hashes - tx_builder.add_input( - &create_base_address_from_script_hash(&hash1), - &TransactionInput::new(&genesis_id(), 0), - &Value::new(&to_bignum(1_000_000)), - ); - tx_builder.add_input( - &create_base_address_from_script_hash(&hash2), - &TransactionInput::new(&genesis_id(), 0), - &Value::new(&to_bignum(1_000_000)), - ); - // Setting a non-matching script will not change anything - let rem1 = - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![script3.clone()])); - assert_eq!(rem1, 2); - let missing1 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing1, 2); - // Setting one of the required scripts leaves one to be required - let rem2 = tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![ - script1.clone(), - script3.clone(), - ])); - assert_eq!(rem2, 1); - let missing2 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing2, 1); - // Setting one non-required script again does not change anything - // But shows the state has changed - let rem3 = - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![script3.clone()])); - assert_eq!(rem3, 1); - let missing3 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing3, 1); - // Setting two required scripts will show both of them added - // And the remainder required is zero - let rem4 = tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![ - script1.clone(), - script2.clone(), - ])); - assert_eq!(rem4, 0); - let missing4 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing4, 0); - // Setting empty scripts does not change anything - // But shows the state has changed - let rem5 = tx_builder.add_required_native_input_scripts(&NativeScripts::new()); - assert_eq!(rem5, 0); -} - #[test] fn test_add_native_script_input() { let mut tx_builder = create_reallistic_tx_builder(); - let (script1, _hash1) = mint_script_and_policy(0); - let (script2, _hash2) = mint_script_and_policy(1); - let (script3, hash3) = mint_script_and_policy(2); - // Adding two script inputs directly with their witness + let (script1, _) = mint_script_and_policy(0); + let (script2, _) = mint_script_and_policy(1); + + // Adding two script inputs using script1 and script2 hashes tx_builder.add_native_script_input( &script1, &TransactionInput::new(&genesis_id(), 0), @@ -3843,22 +3781,8 @@ fn test_add_native_script_input() { &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - // Adding one script input indirectly via hash3 address - tx_builder.add_input( - &create_base_address_from_script_hash(&hash3), - &TransactionInput::new(&genesis_id(), 0), - &Value::new(&to_bignum(1_000_000)), - ); - // Checking missing input scripts shows one - // Because first two inputs already have their witness - let missing1 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing1, 1); - // Setting the required script leaves none to be required` - let rem1 = - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![script3.clone()])); - assert_eq!(rem1, 0); - let missing2 = tx_builder.count_missing_input_scripts(); - assert_eq!(missing2, 0); + + assert_eq!(tx_builder.inputs.get_native_input_scripts().unwrap().len(), 2); } fn unsafe_tx_len(b: &TransactionBuilder) -> usize { @@ -3868,34 +3792,21 @@ fn unsafe_tx_len(b: &TransactionBuilder) -> usize { #[test] fn test_native_input_scripts_are_added_to_the_witnesses() { let mut tx_builder = create_reallistic_tx_builder(); - let (script1, _hash1) = mint_script_and_policy(0); - let (script2, hash2) = mint_script_and_policy(1); + let (script1, _) = mint_script_and_policy(0); + let (script2, _) = mint_script_and_policy(1); tx_builder.set_fee(&to_bignum(42)); + tx_builder.add_native_script_input( &script1, &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - let tx_len_before_new_script_input = unsafe_tx_len(&tx_builder); - tx_builder.add_input( - &create_base_address_from_script_hash(&hash2), + tx_builder.add_native_script_input( + &script2, &TransactionInput::new(&genesis_id(), 1), &Value::new(&to_bignum(1_000_000)), ); - let tx_len_after_new_script_input = unsafe_tx_len(&tx_builder); - // Tx size increased cuz input is added even without the witness - assert!(tx_len_after_new_script_input > tx_len_before_new_script_input); - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![script2.clone()])); - let tx_len_after_adding_script_witness = unsafe_tx_len(&tx_builder); - // Tx size increased cuz the witness is added to the witnesses - assert!(tx_len_after_adding_script_witness > tx_len_after_new_script_input); - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![ - script1.clone(), - script2.clone(), - ])); - let tx_len_after_adding_script_witness_again = unsafe_tx_len(&tx_builder); - // Tx size did not change because calling to add same witnesses again doesn't change anything - assert!(tx_len_after_adding_script_witness == tx_len_after_adding_script_witness_again); + let tx: Transaction = tx_builder.build_tx_unsafe().unwrap(); assert!(tx.witness_set.native_scripts.is_some()); let native_scripts = tx.witness_set.native_scripts.unwrap(); @@ -3904,38 +3815,6 @@ fn test_native_input_scripts_are_added_to_the_witnesses() { assert_eq!(native_scripts.get(1), script2); } -#[test] -fn test_building_with_missing_witness_script_fails() { - let mut tx_builder = create_reallistic_tx_builder(); - let (script1, _hash1) = mint_script_and_policy(0); - let (script2, hash2) = mint_script_and_policy(1); - tx_builder.set_fee(&to_bignum(42)); - // Ok to build before any inputs - assert!(tx_builder.build_tx().is_ok()); - // Adding native script input which adds the witness right away - tx_builder.add_native_script_input( - &script1, - &TransactionInput::new(&genesis_id(), 0), - &Value::new(&to_bignum(1_000_000)), - ); - // Ok to build when witness is added along with the input - assert!(tx_builder.build_tx().is_ok()); - // Adding script input without the witness - tx_builder.add_input( - &create_base_address_from_script_hash(&hash2), - &TransactionInput::new(&genesis_id(), 0), - &Value::new(&to_bignum(1_000_000)), - ); - // Not ok to build when missing a witness - assert!(tx_builder.build_tx().is_err()); - // Can force to build using unsafe - assert!(tx_builder.build_tx_unsafe().is_ok()); - // Adding the missing witness script - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![script2.clone()])); - // Ok to build when all witnesses are added - assert!(tx_builder.build_tx().is_ok()); -} - #[test] fn test_adding_plutus_script_input() { let mut tx_builder = create_reallistic_tx_builder(); @@ -3955,7 +3834,6 @@ fn test_adding_plutus_script_input() { ); tx_builder.set_fee(&to_bignum(42)); // There are no missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 0); let tx: Transaction = tx_builder.build_tx_unsafe().unwrap(); assert!(tx.witness_set.plutus_scripts.is_some()); assert_eq!(tx.witness_set.plutus_scripts.unwrap().get(0), script1); @@ -3969,9 +3847,8 @@ fn test_adding_plutus_script_input() { fn test_adding_plutus_script_witnesses() { let mut tx_builder = create_reallistic_tx_builder(); tx_builder.set_fee(&to_bignum(42)); - let (script1, hash1) = plutus_script_and_hash(0); - let (script2, hash2) = plutus_script_and_hash(1); - let (script3, _hash3) = plutus_script_and_hash(3); + let (script1, _ ) = plutus_script_and_hash(0); + let (script2, _ ) = plutus_script_and_hash(1); let datum1 = PlutusData::new_bytes(fake_bytes_32(10)); let datum2 = PlutusData::new_bytes(fake_bytes_32(11)); let redeemer1 = Redeemer::new( @@ -3986,31 +3863,17 @@ fn test_adding_plutus_script_witnesses() { &PlutusData::new_bytes(fake_bytes_32(21)), &ExUnits::new(&to_bignum(1), &to_bignum(2)), ); - tx_builder.add_input( - &create_base_address_from_script_hash(&hash1), + tx_builder.add_plutus_script_input( + &PlutusWitness::new(&script1, &datum1, &redeemer1), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - tx_builder.add_input( - &create_base_address_from_script_hash(&hash2), + tx_builder.add_plutus_script_input( + &PlutusWitness::new(&script2, &datum2, &redeemer2), &TransactionInput::new(&genesis_id(), 1), &Value::new(&to_bignum(1_000_000)), ); - // There are TWO missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 2); - // Calling to add two plutus witnesses, one of which is irrelevant - tx_builder.add_required_plutus_input_scripts(&PlutusWitnesses::from(vec![ - PlutusWitness::new(&script1, &datum1, &redeemer1), - PlutusWitness::new(&script3, &datum2, &redeemer2), - ])); - // There is now ONE missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 1); - // Calling to add the one remaining relevant plutus witness now - tx_builder.add_required_plutus_input_scripts(&PlutusWitnesses::from(vec![PlutusWitness::new( - &script2, &datum2, &redeemer2, - )])); - // There is now no missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 0); + let tx: Transaction = tx_builder.build_tx_unsafe().unwrap(); // Check there are two correct scripts assert!(tx.witness_set.plutus_scripts.is_some()); @@ -4034,11 +3897,11 @@ fn test_adding_plutus_script_witnesses() { fn create_collateral() -> TxInputsBuilder { let mut collateral_builder = TxInputsBuilder::new(); - collateral_builder.add_input( + collateral_builder.add_regular_input( &byron_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), - ); + ).unwrap(); collateral_builder } @@ -4148,7 +4011,7 @@ fn test_plutus_witness_redeemer_index_auto_changing() { ); // Add a regular NON-script input first - tx_builder.add_input( + tx_builder.add_regular_input( &byron_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), @@ -4231,35 +4094,18 @@ fn test_native_and_plutus_scripts_together() { &Value::new(&to_bignum(1_000_000)), ); // Add one plutus input generically without witness - tx_builder.add_input( - &create_base_address_from_script_hash(&phash2), + tx_builder.add_plutus_script_input( + &PlutusWitness::new(&pscript2, &datum2, &redeemer2), &TransactionInput::new(&genesis_id(), 2), &Value::new(&to_bignum(1_000_000)), ); // Add one native input generically without witness - tx_builder.add_input( - &create_base_address_from_script_hash(&nhash2), + tx_builder.add_native_script_input( + &nscript2, &TransactionInput::new(&genesis_id(), 3), &Value::new(&to_bignum(1_000_000)), ); - // There are two missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 2); - - let remaining1 = tx_builder.add_required_plutus_input_scripts(&PlutusWitnesses::from(vec![ - PlutusWitness::new(&pscript2, &datum2, &redeemer2), - ])); - - // There is one missing script witness now - assert_eq!(remaining1, 1); - assert_eq!(tx_builder.count_missing_input_scripts(), 1); - - let remaining2 = - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![nscript2.clone()])); - - // There are no missing script witnesses now - assert_eq!(remaining2, 0); - assert_eq!(tx_builder.count_missing_input_scripts(), 0); tx_builder .calc_script_data_hash(&TxBuilderConstants::plutus_default_cost_models()) @@ -4335,36 +4181,18 @@ fn test_json_serialization_native_and_plutus_scripts_together() { &Value::new(&to_bignum(1_000_000)), ); // Add one plutus input generically without witness - tx_builder.add_input( - &create_base_address_from_script_hash(&phash2), + tx_builder.add_plutus_script_input( + &PlutusWitness::new(&pscript2, &datum2, &redeemer2), &TransactionInput::new(&genesis_id(), 2), &Value::new(&to_bignum(1_000_000)), ); // Add one native input generically without witness - tx_builder.add_input( - &create_base_address_from_script_hash(&nhash2), + tx_builder.add_native_script_input( + &nscript2, &TransactionInput::new(&genesis_id(), 3), &Value::new(&to_bignum(1_000_000)), ); - // There are two missing script witnesses - assert_eq!(tx_builder.count_missing_input_scripts(), 2); - - let remaining1 = tx_builder.add_required_plutus_input_scripts(&PlutusWitnesses::from(vec![ - PlutusWitness::new(&pscript2, &datum2, &redeemer2), - ])); - - // There is one missing script witness now - assert_eq!(remaining1, 1); - assert_eq!(tx_builder.count_missing_input_scripts(), 1); - - let remaining2 = - tx_builder.add_required_native_input_scripts(&NativeScripts::from(vec![nscript2.clone()])); - - // There are no missing script witnesses now - assert_eq!(remaining2, 0); - assert_eq!(tx_builder.count_missing_input_scripts(), 0); - tx_builder.calc_script_data_hash(&TxBuilderConstants::plutus_default_cost_models()); let tx: Transaction = tx_builder.build_tx().unwrap(); @@ -4382,12 +4210,12 @@ fn test_regular_and_collateral_inputs_same_keyhash() { let mut collateral_builder = TxInputsBuilder::new(); // Add a single input of both kinds with the SAME keyhash - input_builder.add_input( + input_builder.add_regular_input( &fake_base_address(0), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - collateral_builder.add_input( + collateral_builder.add_regular_input( &fake_base_address(0), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), @@ -4407,12 +4235,12 @@ fn test_regular_and_collateral_inputs_same_keyhash() { assert_eq!(get_fake_vkeys_count(&input_builder, &collateral_builder), 1); // Add a new input of each kind with DIFFERENT keyhashes - input_builder.add_input( + input_builder.add_regular_input( &fake_base_address(1), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - collateral_builder.add_input( + collateral_builder.add_regular_input( &fake_base_address(2), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), @@ -4513,12 +4341,12 @@ fn test_ex_unit_costs_are_added_to_the_fees() { let mut collateral_builder = TxInputsBuilder::new(); // Add a single input of both kinds with the SAME keyhash - input_builder.add_input( + input_builder.add_regular_input( &fake_base_address(0), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); - collateral_builder.add_input( + collateral_builder.add_regular_input( &fake_base_address(0), &TransactionInput::new(&genesis_id(), 1), &Value::new(&to_bignum(1_000_000)), @@ -4644,7 +4472,7 @@ fn test_required_signers_are_added_to_the_witness_estimate() { fn count_fake_witnesses_with_required_signers(keys: &Ed25519KeyHashes) -> usize { let mut tx_builder = create_reallistic_tx_builder(); tx_builder.set_fee(&to_bignum(42)); - tx_builder.add_input( + tx_builder.add_regular_input( &fake_base_address(0), &TransactionInput::new(&fake_tx_hash(0), 0), &Value::new(&to_bignum(10_000_000)), @@ -4703,7 +4531,7 @@ fn collateral_return_and_total_collateral_setters() { tx_builder.set_fee(&to_bignum(123456)); let mut inp = TxInputsBuilder::new(); - inp.add_input(&fake_base_address(0), &fake_tx_input(0), &fake_value()); + inp.add_regular_input(&fake_base_address(0), &fake_tx_input(0), &fake_value()); tx_builder.set_inputs(&inp); tx_builder.set_collateral(&inp); @@ -4738,14 +4566,14 @@ fn inputs_builder_total_value() { let mut b = TxInputsBuilder::new(); assert_eq!(b.total_value().unwrap(), Value::zero()); - b.add_input( + b.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &fake_value2(100_000), ); assert_eq!(b.total_value().unwrap(), Value::new(&to_bignum(100_000))); - b.add_input( + b.add_regular_input( &fake_base_address(1), &fake_tx_input(1), &fake_value2(200_000), @@ -4754,7 +4582,7 @@ fn inputs_builder_total_value() { let masset = fake_multiasset(123); - b.add_input( + b.add_regular_input( &fake_base_address(2), &fake_tx_input(2), &Value::new_with_assets(&to_bignum(300_000), &masset), @@ -4772,7 +4600,7 @@ fn test_auto_calc_total_collateral() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &fake_value2(collateral_input_value.clone()), @@ -4809,7 +4637,7 @@ fn test_auto_calc_total_collateral_with_assets() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new_with_assets(&to_bignum(collateral_input_value.clone()), &masset), @@ -4846,7 +4674,7 @@ fn test_auto_calc_total_collateral_fails_with_assets() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new_with_assets(&to_bignum(collateral_input_value.clone()), &masset), @@ -4896,7 +4724,7 @@ fn test_auto_calc_total_collateral_fails_on_no_ada() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new(&to_bignum(collateral_input_value.clone())), @@ -4924,7 +4752,7 @@ fn test_auto_calc_collateral_return() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &fake_value2(collateral_input_value.clone()), @@ -4966,7 +4794,7 @@ fn test_auto_calc_collateral_return_with_assets() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new_with_assets(&to_bignum(collateral_input_value.clone()), &masset), @@ -5011,7 +4839,7 @@ fn test_add_collateral_return_succeed_with_border_amount() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new_with_assets(&to_bignum(collateral_input_value.clone()), &masset), @@ -5050,7 +4878,7 @@ fn test_add_zero_collateral_return() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new(&to_bignum(collateral_input_value.clone())), @@ -5080,7 +4908,7 @@ fn test_add_collateral_return_fails_no_enough_ada() { let mut inp = TxInputsBuilder::new(); let collateral_input_value = 2_000_000; - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new_with_assets(&to_bignum(collateral_input_value.clone()), &masset), @@ -5676,14 +5504,14 @@ fn plutus_mint_test() { let output = TransactionOutput::new(&output_adress, &output_value); let mut col_builder = TxInputsBuilder::new(); - col_builder.add_input( + col_builder.add_regular_input( &colateral_adress, &colateral_input, &Value::new(&Coin::from(1000000000u64)), ); tx_builder.set_collateral(&col_builder); tx_builder.add_output(&output); - tx_builder.add_input( + tx_builder.add_regular_input( &output_adress, &tx_input, &Value::new(&BigNum::from(100000000000u64)), @@ -5787,14 +5615,14 @@ fn plutus_mint_with_script_ref_test() { let output = TransactionOutput::new(&output_adress, &output_value); let mut col_builder = TxInputsBuilder::new(); - col_builder.add_input( + col_builder.add_regular_input( &colateral_adress, &colateral_input, &Value::new(&Coin::from(1000000000u64)), ); tx_builder.set_collateral(&col_builder); tx_builder.add_output(&output); - tx_builder.add_input( + tx_builder.add_regular_input( &output_adress, &tx_input, &Value::new(&BigNum::from(100000000000u64)), @@ -5882,14 +5710,14 @@ fn plutus_mint_defferent_redeemers_test() { let output = TransactionOutput::new(&output_adress, &output_value); let mut col_builder = TxInputsBuilder::new(); - col_builder.add_input( + col_builder.add_regular_input( &colateral_adress, &colateral_input, &Value::new(&Coin::from(1000000000u64)), ); tx_builder.set_collateral(&col_builder); tx_builder.add_output(&output).unwrap(); - tx_builder.add_input( + tx_builder.add_regular_input( &output_adress, &tx_input, &Value::new(&BigNum::from(100000000000u64)), @@ -5981,7 +5809,7 @@ fn multiple_plutus_inputs_test() { tx_builder.add_output(&output); let mut col_builder = TxInputsBuilder::new(); - col_builder.add_input( + col_builder.add_regular_input( &colateral_adress, &colateral_input, &Value::new(&Coin::from(1000000000u64)), @@ -6008,109 +5836,6 @@ fn multiple_plutus_inputs_test() { assert_eq!(tx.witness_set.redeemers.unwrap().len(), 2usize); } -#[test] -fn multiple_plutus_inputs_with_missed_wit_test() { - let mut tx_builder = create_reallistic_tx_builder(); - let plutus_script = PlutusScript::from_hex("5907d2010000332323232323232323232323232323322323232323222232325335332201b3333573466e1cd55ce9baa0044800080608c98c8060cd5ce00c80c00b1999ab9a3370e6aae7540092000233221233001003002323232323232323232323232323333573466e1cd55cea8062400046666666666664444444444442466666666666600201a01801601401201000e00c00a00800600466a02a02c6ae854030cd4054058d5d0a80599a80a80b9aba1500a3335501975ca0306ae854024ccd54065d7280c1aba1500833501502035742a00e666aa032042eb4d5d0a8031919191999ab9a3370e6aae75400920002332212330010030023232323333573466e1cd55cea8012400046644246600200600466a056eb4d5d0a80118161aba135744a004464c6405c66ae700bc0b80b04d55cf280089baa00135742a0046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40add69aba15002302c357426ae8940088c98c80b8cd5ce01781701609aab9e5001137540026ae84d5d1280111931901519ab9c02b02a028135573ca00226ea8004d5d0a80299a80abae35742a008666aa03203a40026ae85400cccd54065d710009aba15002301f357426ae8940088c98c8098cd5ce01381301209aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226aae7940044dd50009aba15002300f357426ae8940088c98c8060cd5ce00c80c00b080b89931900b99ab9c4910350543500017135573ca00226ea800448c88c008dd6000990009aa80a911999aab9f0012500a233500930043574200460066ae880080508c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8050cd5ce00a80a00909aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c8064cd5ce00d00c80b89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403666ae7007006c06406005c4d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201533573802c02a02626ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355012223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301213574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900819ab9c01101000e00d135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900819ab9c01101000e00d00c00b135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900619ab9c00d00c00a135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8028cd5ce00580500409baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c804ccd5ce00a00980880800780700680600589aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401866ae700340300280244d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200933573801401200e00c26aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401466ae7002c02802001c0184d55cea80089baa0012323333573466e1d40052002200723333573466e1d40092000212200123263200633573800e00c00800626aae74dd5000a4c24002920103505431001220021123230010012233003300200200133351222335122335004335500248811c2b194b7d10a3d2d3152c5f3a628ff50cb9fc11e59453e8ac7a1aea4500488104544e4654005005112212330010030021120011122002122122330010040031200101").unwrap(); - let redeemer1 = Redeemer::from_json( - "\ - { - \"tag\": \"Mint\", - \"index\": \"0\", - \"data\": \"{\\\"constructor\\\":0,\\\"fields\\\":[]}\", - \"ex_units\": { - \"mem\": \"1042996\", - \"steps\": \"446100241\" - } - }", - ) - .unwrap(); - - let redeemer2 = Redeemer::from_json( - "\ - { - \"tag\": \"Mint\", - \"index\": \"0\", - \"data\": \"{\\\"constructor\\\":0,\\\"fields\\\":[]}\", - \"ex_units\": { - \"mem\": \"1042996\", - \"steps\": \"446100241\" - } - }", - ) - .unwrap(); - - let mut in_builder = TxInputsBuilder::new(); - let input_1 = TransactionInput::new( - &TransactionHash::from_bytes( - hex::decode("3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7") - .unwrap(), - ) - .unwrap(), - 1, - ); - let input_2 = TransactionInput::new( - &TransactionHash::from_bytes( - hex::decode("3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7") - .unwrap(), - ) - .unwrap(), - 2, - ); - - let colateral_adress = Address::from_bech32("addr_test1qpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5ewvxwdrt70qlcpeeagscasafhffqsxy36t90ldv06wqrk2qum8x5w").unwrap(); - let colateral_input = TransactionInput::new( - &TransactionHash::from_bytes( - hex::decode("3b40265111d8bb3c3c608d95b3a0bf83461ace32d79336579a1939b3aad1c0b7") - .unwrap(), - ) - .unwrap(), - 3, - ); - - let output_adress = Address::from_bech32("addr_test1qpm5njmgzf4t7225v6j34wl30xfrufzt3jtqtdzf3en9ahpmnhtmynpasyc8fq75zv0uaj86vzsr7g3g8q5ypgu5fwtqr9zsgj").unwrap(); - let output_value = Value::new(&Coin::from(5000000u64)); - let output = TransactionOutput::new(&output_adress, &output_value); - - tx_builder.add_output(&output).unwrap(); - let mut col_builder = TxInputsBuilder::new(); - col_builder.add_input( - &colateral_adress, - &colateral_input, - &Value::new(&Coin::from(1000000000u64)), - ); - tx_builder.set_collateral(&col_builder); - - let datum = PlutusData::new_bytes(fake_bytes_32(11)); - let plutus_wit1 = PlutusWitness::new(&plutus_script, &datum, &redeemer1); - - let plutus_wit2 = PlutusWitness::new(&plutus_script, &datum, &redeemer2); - - let value = Value::new(&Coin::from(100000000u64)); - - in_builder.add_plutus_script_input(&plutus_wit1, &input_1, &value); - let script_addr = create_base_address_from_script_hash(&plutus_script.hash()); - in_builder.add_input(&script_addr, &input_2, &value); - - assert_eq!(in_builder.count_missing_input_scripts(), 1usize); - let mut inputs_with_wit = InputsWithScriptWitness::new(); - let in_with_wit = InputWithScriptWitness::new_with_plutus_witness(&input_2, &plutus_wit2); - inputs_with_wit.add(&in_with_wit); - in_builder.add_required_script_input_witnesses(&inputs_with_wit); - - tx_builder.set_inputs(&in_builder); - - tx_builder - .calc_script_data_hash(&TxBuilderConstants::plutus_vasil_cost_models()) - .unwrap(); - tx_builder.add_change_if_needed(&output_adress).unwrap(); - let build_res = tx_builder.build_tx(); - assert!(&build_res.is_ok()); - let tx = build_res.unwrap(); - assert_eq!(tx.witness_set.plutus_scripts.unwrap().len(), 1usize); - assert_eq!(tx.witness_set.redeemers.unwrap().len(), 2usize); -} - #[test] fn build_tx_with_certs_withdrawals_plutus_script_address() { let mut tx_builder = create_tx_builder_with_key_deposit(1_000_000); @@ -6337,7 +6062,7 @@ fn build_tx_with_certs_withdrawals_plutus_script_address() { ) .to_address(); let mut collateral_builder = TxInputsBuilder::new(); - collateral_builder.add_input( + collateral_builder.add_regular_input( &collateral_addr, &collateral_input, &Value::new(&Coin::from(123u32)), @@ -6406,7 +6131,7 @@ pub fn test_extra_datum() { tx_builder.add_extra_witness_datum(&datum); let mut inp = TxInputsBuilder::new(); - inp.add_input( + inp.add_regular_input( &fake_base_address(0), &fake_tx_input(0), &Value::new(&to_bignum(1000000u64)), diff --git a/rust/src/tests/mock_objects.rs b/rust/src/tests/mock_objects.rs index 1dbbf373..4dc0e184 100644 --- a/rust/src/tests/mock_objects.rs +++ b/rust/src/tests/mock_objects.rs @@ -297,7 +297,7 @@ pub(crate) fn create_rich_tx_builder(with_collateral: bool) -> TransactionBuilde let input = TransactionInput::new(&fake_tx_hash(1), 0); let address = generate_address(1); let mut input_builder = TxInputsBuilder::new(); - input_builder.add_input(&address, &input, &Value::new(&Coin::from(u64::MAX / 2))); + input_builder.add_regular_input(&address, &input, &Value::new(&Coin::from(u64::MAX / 2))); tx_builder.set_inputs(&input_builder); if with_collateral { tx_builder.set_collateral(&input_builder); @@ -314,12 +314,12 @@ pub(crate) fn create_tx_builder_with_amount( let input = TransactionInput::new(&fake_tx_hash(1), 0); let address = generate_address(1); let mut input_builder = TxInputsBuilder::new(); - input_builder.add_input(&address, &input, &Value::new(&Coin::from(amount))); + input_builder.add_regular_input(&address, &input, &Value::new(&Coin::from(amount))); tx_builder.set_inputs(&input_builder); if with_collateral { let col_input = TransactionInput::new(&fake_tx_hash(1), 0); let mut col_input_builder = TxInputsBuilder::new(); - col_input_builder.add_input(&address, &col_input, &Value::new(&Coin::from(u64::MAX / 2))); + col_input_builder.add_regular_input(&address, &col_input, &Value::new(&Coin::from(u64::MAX / 2))); tx_builder.set_collateral(&col_input_builder); } @@ -341,12 +341,12 @@ pub(crate) fn create_tx_builder_with_amount_and_deposit_params( let input = TransactionInput::new(&fake_tx_hash(1), 0); let address = generate_address(1); let mut input_builder = TxInputsBuilder::new(); - input_builder.add_input(&address, &input, &Value::new(&Coin::from(amount))); + input_builder.add_regular_input(&address, &input, &Value::new(&Coin::from(amount))); tx_builder.set_inputs(&input_builder); if with_collateral { let col_input = TransactionInput::new(&fake_tx_hash(1), 0); let mut col_input_builder = TxInputsBuilder::new(); - col_input_builder.add_input(&address, &col_input, &Value::new(&Coin::from(u64::MAX / 2))); + col_input_builder.add_regular_input(&address, &col_input, &Value::new(&Coin::from(u64::MAX / 2))); tx_builder.set_collateral(&col_input_builder); } From 3ebe73bbf0fb33595a449b414e5098b96b77d159 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 14 Nov 2023 20:12:53 +0800 Subject: [PATCH 3/9] remove deprecated testnet from NetworkInfo --- rust/src/address.rs | 16 --- rust/src/fakes.rs | 4 +- rust/src/fees.rs | 2 +- rust/src/tests/address.rs | 38 ++---- .../tests/builders/certificates_builder.rs | 6 +- rust/src/tests/builders/tx_builder.rs | 118 +++++++++--------- rust/src/tests/mock_objects.rs | 4 +- rust/src/tests/serialization/certificates.rs | 2 +- .../tests/serialization/transaction_body.rs | 2 +- 9 files changed, 81 insertions(+), 111 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 469e97ed..1de8c104 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -65,18 +65,6 @@ impl NetworkInfo { protocol_magic: 1, } } - /// !!! DEPRECATED !!! - /// This network does not exist anymore. Use `.testnet_preview()` or `.testnet_preprod()` - #[deprecated( - since = "11.2.0", - note = "Use `.testnet_preview` or `.testnet_preprod`" - )] - pub fn testnet() -> NetworkInfo { - NetworkInfo { - network_id: 0b0000, - protocol_magic: 1097911063, - } - } pub fn mainnet() -> NetworkInfo { NetworkInfo { network_id: 0b0001, @@ -285,9 +273,6 @@ impl ByronAddress { magic if magic == NetworkInfo::mainnet().protocol_magic() => { Ok(NetworkInfo::mainnet().network_id()) } - magic if magic == NetworkInfo::testnet().protocol_magic() => { - Ok(NetworkInfo::testnet().network_id()) - } magic if magic == NetworkInfo::testnet_preprod().protocol_magic() => { Ok(NetworkInfo::testnet_preprod().network_id()) } @@ -597,7 +582,6 @@ impl Address { _ => "addr", }; let prefix_tail = match self.network_id()? { - id if id == NetworkInfo::testnet().network_id() => "_test", id if id == NetworkInfo::testnet_preprod().network_id() => "_test", id if id == NetworkInfo::testnet_preview().network_id() => "_test", _ => "", diff --git a/rust/src/fakes.rs b/rust/src/fakes.rs index 8e7a3947..9d679d95 100644 --- a/rust/src/fakes.rs +++ b/rust/src/fakes.rs @@ -58,7 +58,7 @@ pub(crate) fn fake_script_data_hash(x: u8) -> ScriptDataHash { pub(crate) fn fake_base_address(x: u8) -> Address { BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &Credential::from_keyhash(&fake_key_hash(x)), &Credential::from_keyhash(&fake_key_hash(0)), ) @@ -67,7 +67,7 @@ pub(crate) fn fake_base_address(x: u8) -> Address { pub(crate) fn fake_reward_address(x: u8) -> RewardAddress { RewardAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &Credential::from_keyhash(&fake_key_hash(x)), ) } diff --git a/rust/src/fees.rs b/rust/src/fees.rs index 03682537..4dcca559 100644 --- a/rust/src/fees.rs +++ b/rust/src/fees.rs @@ -470,7 +470,7 @@ mod tests { // to_bignum(1), // to_bignum(5), // &UnitInterval::new(to_bignum(1), to_bignum(10)), - // &RewardAddress::new(NetworkInfo::testnet().network_id(), &alice_stake()), + // &RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &alice_stake()), // &owners, // &relays, // Some(PoolMetadata::new(String::from("alice.pool"), &MetadataHash::from([0u8; MetadataHash::BYTE_COUNT]))) diff --git a/rust/src/tests/address.rs b/rust/src/tests/address.rs index 68416752..f205c94f 100644 --- a/rust/src/tests/address.rs +++ b/rust/src/tests/address.rs @@ -118,20 +118,6 @@ fn byron_magic_parsing() { addr.network_id().unwrap(), NetworkInfo::mainnet().network_id() ); - - // original Byron testnet address - let addr = ByronAddress::from_base58( - "2cWKMJemoBaipzQe9BArYdo2iPUfJQdZAjm4iCzDA1AfNxJSTgm9FZQTmFCYhKkeYrede", - ) - .unwrap(); - assert_eq!( - addr.byron_protocol_magic(), - NetworkInfo::testnet().protocol_magic() - ); - assert_eq!( - addr.network_id().unwrap(), - NetworkInfo::testnet().network_id() - ); } #[test] @@ -153,7 +139,7 @@ fn bip32_12_base() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -179,7 +165,7 @@ fn bip32_12_enterprise() { .to_public(); let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = - EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(); + EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(); assert_eq!( addr_net_0.to_bech32(None).unwrap(), "addr_test1vz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspjrlsz" @@ -204,7 +190,7 @@ fn bip32_12_pointer() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3)), ) @@ -244,7 +230,7 @@ fn bip32_15_base() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -270,7 +256,7 @@ fn bip32_15_enterprise() { .to_public(); let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = - EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(); + EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(); assert_eq!( addr_net_0.to_bech32(None).unwrap(), "addr_test1vpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5eg57c2qv" @@ -294,7 +280,7 @@ fn bip32_15_pointer() { .to_public(); let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3)), ) @@ -378,7 +364,7 @@ fn bip32_24_base() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -404,7 +390,7 @@ fn bip32_24_enterprise() { .to_public(); let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = - EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(); + EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(); assert_eq!( addr_net_0.to_bech32(None).unwrap(), "addr_test1vqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqtjtf68" @@ -428,7 +414,7 @@ fn bip32_24_pointer() { .to_public(); let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3)), ) @@ -460,7 +446,7 @@ fn bip32_12_reward() { .to_public(); let staking_cred = Credential::from_keyhash(&staking_key.to_raw_key().hash()); let addr_net_0 = - RewardAddress::new(NetworkInfo::testnet().network_id(), &staking_cred).to_address(); + RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &staking_cred).to_address(); assert_eq!( addr_net_0.to_bech32(None).unwrap(), "stake_test1uqevw2xnsc0pvn9t9r9c7qryfqfeerchgrlm3ea2nefr9hqp8n5xl" @@ -492,7 +478,7 @@ fn bip32_24_base_multisig_hd_derivation() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -531,7 +517,7 @@ fn multisig_from_script() { let spend_cred = Credential::from_scripthash(&script_hash); let stake_cred = Credential::from_scripthash(&script_hash); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) diff --git a/rust/src/tests/builders/certificates_builder.rs b/rust/src/tests/builders/certificates_builder.rs index 740f10e2..13e8eb6a 100644 --- a/rust/src/tests/builders/certificates_builder.rs +++ b/rust/src/tests/builders/certificates_builder.rs @@ -53,7 +53,7 @@ fn certificatess_builder_deposit_test() { ); let staking_cred = Credential::from_keyhash(&fake_key_hash(10)); - let reward_address = RewardAddress::new(NetworkInfo::testnet().network_id(), &staking_cred); + let reward_address = RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &staking_cred); let mut owners = Ed25519KeyHashes::new(); owners.add(&fake_key_hash(11)); owners.add(&fake_key_hash(12)); @@ -221,7 +221,7 @@ fn certificatess_builder_no_deposit_test() { ); let staking_cred = Credential::from_keyhash(&fake_key_hash(10)); - let reward_address = RewardAddress::new(NetworkInfo::testnet().network_id(), &staking_cred); + let reward_address = RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &staking_cred); let mut owners = Ed25519KeyHashes::new(); owners.add(&fake_key_hash(11)); owners.add(&fake_key_hash(12)); @@ -378,7 +378,7 @@ fn certificatess_builder_req_signers_test() { ); let staking_cred = Credential::from_keyhash(&key_hash_10); - let reward_address = RewardAddress::new(NetworkInfo::testnet().network_id(), &staking_cred); + let reward_address = RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &staking_cred); let mut owners = Ed25519KeyHashes::new(); owners.add(&key_hash_11); owners.add(&key_hash_12); diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index b0649b7b..e3d07349 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -65,7 +65,7 @@ fn build_tx_with_change() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -90,7 +90,7 @@ fn build_tx_with_change() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -136,7 +136,7 @@ fn build_tx_with_change_with_datum() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -164,7 +164,7 @@ fn build_tx_with_change_with_datum() { let (_, script_hash) = plutus_script_and_hash(15); let change_cred = Credential::from_scripthash(&script_hash); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -217,7 +217,7 @@ fn build_tx_without_change() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -242,7 +242,7 @@ fn build_tx_without_change() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -310,7 +310,7 @@ fn build_tx_with_certs() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -370,7 +370,7 @@ fn build_tx_exact_amount() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -390,7 +390,7 @@ fn build_tx_exact_amount() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -434,7 +434,7 @@ fn build_tx_exact_change() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -454,7 +454,7 @@ fn build_tx_exact_change() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -500,7 +500,7 @@ fn build_tx_insufficient_deposit() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -527,7 +527,7 @@ fn build_tx_insufficient_deposit() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -561,7 +561,7 @@ fn build_tx_with_inputs() { assert_eq!( tx_builder .fee_for_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred) + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred) .to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)) @@ -571,14 +571,14 @@ fn build_tx_with_inputs() { "69500" ); tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(1_000_000)), ); } tx_builder.add_regular_input( &BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -588,7 +588,7 @@ fn build_tx_with_inputs() { ); tx_builder.add_regular_input( &PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(0), &to_bignum(0), &to_bignum(0)), ) @@ -597,7 +597,7 @@ fn build_tx_with_inputs() { &Value::new(&to_bignum(1_000_000)), ); tx_builder.add_regular_input( - &ByronAddress::icarus_from_key(&spend, NetworkInfo::testnet().protocol_magic()) + &ByronAddress::icarus_from_key(&spend, NetworkInfo::testnet_preprod().protocol_magic()) .to_address(), &TransactionInput::new(&genesis_id(), 3), &Value::new(&to_bignum(1_000_000)), @@ -653,7 +653,7 @@ fn build_tx_with_script_ref() { tx_builder.add_regular_input( &PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(0), &to_bignum(0), &to_bignum(0)), ) @@ -663,7 +663,7 @@ fn build_tx_with_script_ref() { ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -685,7 +685,7 @@ fn build_tx_with_script_ref() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -734,7 +734,7 @@ fn serialization_tx_body_with_script_ref() { tx_builder.add_regular_input( &PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(0), &to_bignum(0), &to_bignum(0)), ) @@ -744,7 +744,7 @@ fn serialization_tx_body_with_script_ref() { ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -766,7 +766,7 @@ fn serialization_tx_body_with_script_ref() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -815,7 +815,7 @@ fn json_serialization_tx_body_with_script_ref() { tx_builder.add_regular_input( &PointerAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(0), &to_bignum(0), &to_bignum(0)), ) @@ -825,7 +825,7 @@ fn json_serialization_tx_body_with_script_ref() { ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -847,7 +847,7 @@ fn json_serialization_tx_body_with_script_ref() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -893,13 +893,13 @@ fn build_tx_with_mint_all_sent() { // Input with 150 coins tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(500)), ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -935,7 +935,7 @@ fn build_tx_with_mint_all_sent() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -981,13 +981,13 @@ fn build_tx_with_mint_in_change() { // Input with 600 coins tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(600)), ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1025,7 +1025,7 @@ fn build_tx_with_mint_in_change() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1090,19 +1090,19 @@ fn change_with_input_and_mint_not_enough_ada() { // Input with 600 coins tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(600)), ); tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 1), &Value::new_with_assets(&to_bignum(1), &mass_input), ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1134,7 +1134,7 @@ fn change_with_input_and_mint_not_enough_ada() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1186,19 +1186,19 @@ fn change_with_input_and_mint_not_enough_assets() { // Input with 600 coins tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 0), &Value::new(&to_bignum(100000)), ); tx_builder.add_regular_input( - &EnterpriseAddress::new(NetworkInfo::testnet().network_id(), &spend_cred).to_address(), + &EnterpriseAddress::new(NetworkInfo::testnet_preprod().network_id(), &spend_cred).to_address(), &TransactionInput::new(&genesis_id(), 1), &Value::new_with_assets(&to_bignum(1), &mass_input), ); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1230,7 +1230,7 @@ fn change_with_input_and_mint_not_enough_assets() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1304,7 +1304,7 @@ fn build_tx_with_native_assets_change() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1327,7 +1327,7 @@ fn build_tx_with_native_assets_change() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1419,7 +1419,7 @@ fn build_tx_with_native_assets_change_and_purification() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1442,7 +1442,7 @@ fn build_tx_with_native_assets_change_and_purification() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1546,7 +1546,7 @@ fn build_tx_with_native_assets_change_and_no_purification_cuz_not_enough_pure_co let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1569,7 +1569,7 @@ fn build_tx_with_native_assets_change_and_no_purification_cuz_not_enough_pure_co let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -1627,7 +1627,7 @@ fn build_tx_leftover_assets() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -1665,7 +1665,7 @@ fn build_tx_leftover_assets() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -2555,7 +2555,7 @@ fn build_tx_pay_to_multisig() { let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -2639,13 +2639,13 @@ fn build_tx_multisig_spend_1on1_unsigned() { let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let addr_multisig = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) .to_address(); let addr_output = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -2731,7 +2731,7 @@ fn build_tx_multisig_1on1_signed() { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr_net_0 = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ) @@ -3757,7 +3757,7 @@ fn total_input_output_with_mint_and_burn() { fn create_base_address_from_script_hash(sh: &ScriptHash) -> Address { BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &Credential::from_scripthash(sh), &Credential::from_keyhash(&fake_key_hash(0)), ) @@ -6026,20 +6026,20 @@ fn build_tx_with_certs_withdrawals_plutus_script_address() { let reward_cred = Credential::from_keyhash(&reward.to_raw_key().hash()); withdrawals .add( - &RewardAddress::new(NetworkInfo::testnet().network_id(), &reward_cred), + &RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &reward_cred), &Coin::from(1u32), ) .unwrap(); withdrawals .add_with_plutus_witness( - &RewardAddress::new(NetworkInfo::testnet().network_id(), &withdraw_script_cred1), + &RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &withdraw_script_cred1), &Coin::from(2u32), &withdraw_witness1, ) .unwrap(); withdrawals .add_with_plutus_witness( - &RewardAddress::new(NetworkInfo::testnet().network_id(), &withdraw_script_cred2), + &RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &withdraw_script_cred2), &Coin::from(3u32), &withdraw_witness2, ) @@ -6048,7 +6048,7 @@ fn build_tx_with_certs_withdrawals_plutus_script_address() { let change_cred = Credential::from_keyhash(&change_key.to_raw_key().hash()); let change_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &change_cred, &stake_cred, ) @@ -6056,7 +6056,7 @@ fn build_tx_with_certs_withdrawals_plutus_script_address() { let cost_models = TxBuilderConstants::plutus_default_cost_models(); let collateral_input = fake_tx_input(1); let collateral_addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &Credential::from_keyhash(&fake_key_hash(1)), &Credential::from_keyhash(&fake_key_hash(2)), ) diff --git a/rust/src/tests/mock_objects.rs b/rust/src/tests/mock_objects.rs index 4dc0e184..19d19a24 100644 --- a/rust/src/tests/mock_objects.rs +++ b/rust/src/tests/mock_objects.rs @@ -37,7 +37,7 @@ pub(crate) fn generate_address(index: u32) -> Address { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ); @@ -285,7 +285,7 @@ pub(crate) fn create_change_address() -> Address { let spend_cred = Credential::from_keyhash(&spend.to_raw_key().hash()); let stake_cred = Credential::from_keyhash(&stake.to_raw_key().hash()); let addr = BaseAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &spend_cred, &stake_cred, ); diff --git a/rust/src/tests/serialization/certificates.rs b/rust/src/tests/serialization/certificates.rs index 1fd065f1..37c53ec4 100644 --- a/rust/src/tests/serialization/certificates.rs +++ b/rust/src/tests/serialization/certificates.rs @@ -193,7 +193,7 @@ fn move_instantaneous_reward_to_stake_creds_ser_round_trip() { #[test] fn pool_registration_ser_round_trip() { let staking_cred = Credential::from_keyhash(&fake_key_hash(1)); - let reward_address = RewardAddress::new(NetworkInfo::testnet().network_id(), &staking_cred); + let reward_address = RewardAddress::new(NetworkInfo::testnet_preprod().network_id(), &staking_cred); let mut owners = Ed25519KeyHashes::new(); owners.add(&fake_key_hash(2)); owners.add(&fake_key_hash(3)); diff --git a/rust/src/tests/serialization/transaction_body.rs b/rust/src/tests/serialization/transaction_body.rs index b4c9fc0f..de4f4e5a 100644 --- a/rust/src/tests/serialization/transaction_body.rs +++ b/rust/src/tests/serialization/transaction_body.rs @@ -32,7 +32,7 @@ fn transaction_round_trip_test() { let mut withdrawals = Withdrawals::new(); withdrawals.insert( &RewardAddress::new( - NetworkInfo::testnet().network_id(), + NetworkInfo::testnet_preprod().network_id(), &Credential::from_keyhash(&fake_key_hash(9)), ), &Coin::from(1_000_010u64), From 71e0ea857df91ae7536ade1ad1ec823570e3c2db Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 14 Nov 2023 20:25:26 +0800 Subject: [PATCH 4/9] remove coins_per_utxo_byte from tx builder config --- rust/src/builders/tx_builder.rs | 12 ------------ rust/src/tests/builders/batch_tools.rs | 24 ++++++++++++------------ rust/src/tests/builders/tx_builder.rs | 6 +++--- rust/src/tests/mock_objects.rs | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/rust/src/builders/tx_builder.rs b/rust/src/builders/tx_builder.rs index fd0a8874..a1d998d5 100644 --- a/rust/src/builders/tx_builder.rs +++ b/rust/src/builders/tx_builder.rs @@ -230,18 +230,6 @@ impl TransactionBuilderConfigBuilder { cfg } - /// !!! DEPRECATED !!! - /// Since babbage era cardano nodes use coins per byte. Use '.coins_per_utxo_byte' instead. - #[deprecated( - since = "11.0.0", - note = "Since babbage era cardano nodes use coins per byte. Use '.coins_per_utxo_byte' instead." - )] - pub fn coins_per_utxo_word(&self, coins_per_utxo_word: &Coin) -> Self { - let mut cfg = self.clone(); - cfg.data_cost = Some(DataCost::new_coins_per_word(coins_per_utxo_word)); - cfg - } - pub fn coins_per_utxo_byte(&self, coins_per_utxo_byte: &Coin) -> Self { let mut cfg = self.clone(); cfg.data_cost = Some(DataCost::new_coins_per_byte(coins_per_utxo_byte)); diff --git a/rust/src/tests/builders/batch_tools.rs b/rust/src/tests/builders/batch_tools.rs index 232e4964..fefd40fa 100644 --- a/rust/src/tests/builders/batch_tools.rs +++ b/rust/src/tests/builders/batch_tools.rs @@ -222,7 +222,7 @@ pub fn test_big_utoxs_batch() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -251,7 +251,7 @@ pub fn test_big_utoxs_ada_batch() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -294,7 +294,7 @@ pub fn test_one_utxo() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -361,7 +361,7 @@ pub fn test_one_utxo_one_asset_per_output() { .key_deposit(&to_bignum(2000000)) .max_value_size(80) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -440,7 +440,7 @@ pub fn test_one_utxo_one_asset_per_tx() { .key_deposit(&to_bignum(2000000)) .max_value_size(80) .max_tx_size(300) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -496,7 +496,7 @@ pub fn test_only_ada_utxo() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -529,7 +529,7 @@ pub fn test_not_enough_ada() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -565,7 +565,7 @@ pub fn test_value_limit_error() { .key_deposit(&to_bignum(2000000)) .max_value_size(10) .max_tx_size(8000000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -601,7 +601,7 @@ pub fn test_tx_limit_error() { .key_deposit(&to_bignum(2000000)) .max_value_size(100) .max_tx_size(2000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -624,7 +624,7 @@ pub fn test_no_utxos() { .key_deposit(&to_bignum(2000000)) .max_value_size(10) .max_tx_size(8000000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -653,7 +653,7 @@ pub fn test_script_input_error() { .key_deposit(&to_bignum(2000000)) .max_value_size(10) .max_tx_size(8000000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -713,7 +713,7 @@ pub fn test_two_asset_utxo_one_ada_utxo() { .key_deposit(&to_bignum(2000000)) .max_value_size(4000) .max_tx_size(8000) - .coins_per_utxo_word(&to_bignum(34_482)) + .coins_per_utxo_byte(&to_bignum(34_482 / 8)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index e3d07349..970aa75a 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -2455,7 +2455,7 @@ fn tx_builder_cip2_random_improve_when_using_all_available_inputs() { .key_deposit(&to_bignum(0)) .max_value_size(9999) .max_tx_size(9999) - .coins_per_utxo_word(&Coin::zero()) + .coins_per_utxo_byte(&Coin::zero()) .build() .unwrap(); let mut tx_builder = TransactionBuilder::new(&cfg); @@ -2494,7 +2494,7 @@ fn tx_builder_cip2_random_improve_adds_enough_for_fees() { .key_deposit(&to_bignum(0)) .max_value_size(9999) .max_tx_size(9999) - .coins_per_utxo_word(&Coin::zero()) + .coins_per_utxo_byte(&Coin::zero()) .build() .unwrap(); let mut tx_builder = TransactionBuilder::new(&cfg); @@ -2818,7 +2818,7 @@ fn add_change_splits_change_into_multiple_outputs_when_nfts_overflow_output_size .key_deposit(&to_bignum(0)) .max_value_size(max_value_size) .max_tx_size(MAX_TX_SIZE) - .coins_per_utxo_word(&to_bignum(8)) + .coins_per_utxo_byte(&to_bignum(1)) .prefer_pure_change(true) .build() .unwrap(), diff --git a/rust/src/tests/mock_objects.rs b/rust/src/tests/mock_objects.rs index 19d19a24..128aa986 100644 --- a/rust/src/tests/mock_objects.rs +++ b/rust/src/tests/mock_objects.rs @@ -8,7 +8,7 @@ use crate::*; const MAX_VALUE_SIZE: u32 = 4000; const MAX_TX_SIZE: u32 = 8000; // might be out of date but suffices for our tests // this is what is used in mainnet -static COINS_PER_UTXO_WORD: u64 = 34_482; +static COINS_PER_UTXO_BYTE: u64 = 34_482 / 8; pub(crate) fn root_key() -> Bip32PrivateKey { // art forum devote street sure rather head chuckle guard poverty release quote oak craft enemy @@ -189,7 +189,7 @@ pub(crate) fn create_tx_builder_full( pool_deposit: u64, key_deposit: u64, max_val_size: u32, - coins_per_utxo_word: u64, + coins_per_utxo_byte: u64, ) -> TransactionBuilder { let cfg = TransactionBuilderConfigBuilder::new() .fee_algo(linear_fee) @@ -197,7 +197,7 @@ pub(crate) fn create_tx_builder_full( .key_deposit(&to_bignum(key_deposit)) .max_value_size(max_val_size) .max_tx_size(MAX_TX_SIZE) - .coins_per_utxo_word(&to_bignum(coins_per_utxo_word)) + .coins_per_utxo_byte(&to_bignum(coins_per_utxo_byte)) .ex_unit_prices(&ExUnitPrices::new( &SubCoin::new(&to_bignum(577), &to_bignum(10000)), &SubCoin::new(&to_bignum(721), &to_bignum(10000000)), @@ -209,7 +209,7 @@ pub(crate) fn create_tx_builder_full( pub(crate) fn create_tx_builder( linear_fee: &LinearFee, - coins_per_utxo_word: u64, + coins_per_utxo_byte: u64, pool_deposit: u64, key_deposit: u64, ) -> TransactionBuilder { @@ -218,14 +218,14 @@ pub(crate) fn create_tx_builder( pool_deposit, key_deposit, MAX_VALUE_SIZE, - coins_per_utxo_word, + coins_per_utxo_byte, ) } pub(crate) fn create_reallistic_tx_builder() -> TransactionBuilder { create_tx_builder( &create_linear_fee(44, 155381), - COINS_PER_UTXO_WORD, + COINS_PER_UTXO_BYTE, 500000000, 2000000, ) @@ -235,11 +235,11 @@ pub(crate) fn create_tx_builder_with_fee_and_val_size( linear_fee: &LinearFee, max_val_size: u32, ) -> TransactionBuilder { - create_tx_builder_full(linear_fee, 1, 1, max_val_size, 8) + create_tx_builder_full(linear_fee, 1, 1, max_val_size, 1) } pub(crate) fn create_tx_builder_with_fee(linear_fee: &LinearFee) -> TransactionBuilder { - create_tx_builder(linear_fee, 8, 1, 1) + create_tx_builder(linear_fee, 1, 1, 1) } pub(crate) fn create_tx_builder_with_fee_and_pure_change( @@ -252,7 +252,7 @@ pub(crate) fn create_tx_builder_with_fee_and_pure_change( .key_deposit(&to_bignum(1)) .max_value_size(MAX_VALUE_SIZE) .max_tx_size(MAX_TX_SIZE) - .coins_per_utxo_word(&to_bignum(8)) + .coins_per_utxo_byte(&to_bignum(1)) .prefer_pure_change(true) .build() .unwrap(), @@ -334,7 +334,7 @@ pub(crate) fn create_tx_builder_with_amount_and_deposit_params( ) -> TransactionBuilder { let mut tx_builder = create_tx_builder( &create_linear_fee(44, 155381), - COINS_PER_UTXO_WORD, + COINS_PER_UTXO_BYTE, pool_deposit, key_deposit ); From 65136fab9a0fa5f3ee7fcf706520c8db8065589e Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 15 Nov 2023 13:58:00 +0800 Subject: [PATCH 5/9] remove deprecated functions that uses coins per word --- rust/src/builders/output_builder.rs | 15 --- rust/src/lib.rs | 14 --- rust/src/tests/builders/tx_builder.rs | 9 +- rust/src/utils.rs | 169 -------------------------- 4 files changed, 4 insertions(+), 203 deletions(-) diff --git a/rust/src/builders/output_builder.rs b/rust/src/builders/output_builder.rs index 72ccc796..583e8ad4 100644 --- a/rust/src/builders/output_builder.rs +++ b/rust/src/builders/output_builder.rs @@ -93,21 +93,6 @@ impl TransactionOutputAmountBuilder { cfg } - /// !!! DEPRECATED !!! - /// Since babbage era cardano nodes use coins per byte. Use '.with_asset_and_min_required_coin_by_utxo_cost' instead. - #[deprecated( - since = "11.0.0", - note = "Since babbage era cardano nodes use coins per byte. Use '.with_asset_and_min_required_coin_by_utxo_cost' instead." - )] - pub fn with_asset_and_min_required_coin( - &self, - multiasset: &MultiAsset, - coins_per_utxo_word: &Coin, - ) -> Result { - let data_cost = DataCost::new_coins_per_word(coins_per_utxo_word); - self.with_asset_and_min_required_coin_by_utxo_cost(multiasset, &data_cost) - } - pub fn with_asset_and_min_required_coin_by_utxo_cost( &self, multiasset: &MultiAsset, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 211ab139..1937687d 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -260,20 +260,6 @@ pub struct DataCost(DataCostEnum); #[wasm_bindgen] impl DataCost { - /// !!! DEPRECATED !!! - /// Since babbage era we should use coins per byte. Use `.new_coins_per_byte` instead. - #[deprecated( - since = "11.0.0", - note = "Since babbage era we should use coins per byte. Use `.new_coins_per_byte` instead." - )] - pub fn new_coins_per_word(coins_per_word: &Coin) -> DataCost { - if coins_per_word != &BigNum::zero() { - DataCost(DataCostEnum::CoinsPerWord(coins_per_word.clone())) - } else { - DataCost(DataCostEnum::CoinsPerByte(BigNum::zero())) - } - } - pub fn new_coins_per_byte(coins_per_byte: &Coin) -> DataCost { DataCost(DataCostEnum::CoinsPerByte(coins_per_byte.clone())) } diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index 970aa75a..63cb7666 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -1355,7 +1355,7 @@ fn build_tx_with_native_assets_change() { #[test] fn build_tx_with_native_assets_change_and_purification() { - let coin_per_utxo_word = to_bignum(8); + let coin_per_utxo_byte = to_bignum(1); // Prefer pure change! let mut tx_builder = create_tx_builder_with_fee_and_pure_change(&create_linear_fee(0, 1)); let spend = root_key_15() @@ -1467,10 +1467,9 @@ fn build_tx_with_native_assets_change_and_purification() { to_bignum(ma_input1 + ma_input2 - ma_output1) ); // The first change output that contains all the tokens contain minimum required Coin - let min_coin_for_dirty_change = min_ada_required( - &final_tx.outputs().get(1).amount(), - false, - &coin_per_utxo_word, + let min_coin_for_dirty_change = min_ada_for_output( + &final_tx.outputs().get(1), + &DataCost::new_coins_per_byte(&coin_per_utxo_byte), ) .unwrap(); assert_eq!( diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 1a66c40b..7290d285 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -1440,25 +1440,6 @@ pub fn min_ada_for_output( MinOutputAdaCalculator::new(output, data_cost).calculate_ada() } -/// !!! DEPRECATED !!! -/// This function uses outdated set of arguments. -/// Use `min_ada_for_output` instead -#[wasm_bindgen] -#[deprecated(since = "11.0.0", note = "Use `min_ada_for_output` instead")] -pub fn min_ada_required( - assets: &Value, - has_data_hash: bool, // whether the output includes a data hash - coins_per_utxo_word: &BigNum, // protocol parameter (in lovelace) -) -> Result { - let data_cost = DataCost::new_coins_per_word(coins_per_utxo_word); - let mut calc = MinOutputAdaCalculator::new_empty(&data_cost)?; - calc.set_amount(assets); - if has_data_hash { - calc.set_data_hash(&fake_data_hash(0)); - } - calc.calculate_ada() -} - /// Used to choosed the schema for a script JSON string #[wasm_bindgen] pub enum ScriptSchema { @@ -1841,156 +1822,6 @@ mod tests { } } - #[test] - fn min_ada_value_no_multiasset() { - assert_eq!( - from_bignum( - &min_ada_required( - &Value::new(&Coin::zero()), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 969750, - ); - } - - #[test] - fn min_ada_value_one_policy_one_0_char_asset() { - assert_eq!( - from_bignum( - &min_ada_required( - &one_policy_one_0_char_asset(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_120_600, - ); - } - - #[test] - fn min_ada_value_one_policy_one_1_char_asset() { - assert_eq!( - from_bignum( - &min_ada_required( - &one_policy_one_1_char_asset(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_124_910, - ); - } - - #[test] - fn min_ada_value_one_policy_three_1_char_assets() { - assert_eq!( - from_bignum( - &min_ada_required( - &one_policy_three_1_char_assets(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_150_770, - ); - } - - #[test] - fn min_ada_value_two_policies_one_0_char_asset() { - assert_eq!( - from_bignum( - &min_ada_required( - &two_policies_one_0_char_asset(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_262_830, - ); - } - - #[test] - fn min_ada_value_two_policies_one_1_char_asset() { - assert_eq!( - from_bignum( - &min_ada_required( - &two_policies_one_1_char_asset(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_271_450, - ); - } - - #[test] - fn min_ada_value_three_policies_96_1_char_assets() { - assert_eq!( - from_bignum( - &min_ada_required( - &three_policies_96_1_char_assets(), - false, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 2_633_410, - ); - } - - #[test] - fn min_ada_value_one_policy_one_0_char_asset_datum_hash() { - assert_eq!( - from_bignum( - &min_ada_required( - &one_policy_one_0_char_asset(), - true, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_267_140, - ); - } - - #[test] - fn min_ada_value_one_policy_three_32_char_assets_datum_hash() { - assert_eq!( - from_bignum( - &min_ada_required( - &one_policy_three_32_char_assets(), - true, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_711_070, - ); - } - - #[test] - fn min_ada_value_two_policies_one_0_char_asset_datum_hash() { - assert_eq!( - from_bignum( - &min_ada_required( - &two_policies_one_0_char_asset(), - true, - &to_bignum(COINS_PER_UTXO_WORD), - ) - .unwrap() - ), - 1_409_370, - ); - } - #[test] fn subtract_values() { let policy1 = PolicyID::from([0; ScriptHash::BYTE_COUNT]); From ca1f54b78569db50fde2e868b6827794b5edb495 Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 15 Nov 2023 16:23:59 +0800 Subject: [PATCH 6/9] remove wrong named function --- rust/src/protocol_types/transaction_body.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/rust/src/protocol_types/transaction_body.rs b/rust/src/protocol_types/transaction_body.rs index cef72692..ddca6642 100644 --- a/rust/src/protocol_types/transaction_body.rs +++ b/rust/src/protocol_types/transaction_body.rs @@ -147,13 +147,6 @@ impl TransactionBody { self.mint.clone() } - /// This function returns the mint value of the transaction - /// Use `.mint()` instead. - #[deprecated(since = "10.0.0", note = "Weird naming. Use `.mint()`")] - pub fn multiassets(&self) -> Option { - self.mint() - } - pub fn set_reference_inputs(&mut self, reference_inputs: &TransactionInputs) { self.reference_inputs = Some(reference_inputs.clone()) } From 82672d4c88836c6d87f69deb1b9404f4ef59594c Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 28 Nov 2023 20:43:12 +0800 Subject: [PATCH 7/9] replace get by get_all in MintsAssets --- rust/src/lib.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 1937687d..8dc402fd 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2527,6 +2527,10 @@ impl MintsAssets { pub fn get(&self, index: usize) -> Option { self.0.get(index).map(|v| v.clone()) } + + pub fn len(&self) -> usize { + self.0.len() + } } #[wasm_bindgen] @@ -2611,22 +2615,7 @@ impl Mint { None } - /// !!! DEPRECATED !!! - /// Mint can store multiple entries for the same policy id. - /// Use `.get_all` instead. - #[deprecated( - since = "11.2.0", - note = "Mint can store multiple entries for the same policy id. Use `.get_all` instead." - )] - pub fn get(&self, key: &PolicyID) -> Option { - self.0 - .iter() - .filter(|(k, _)| k.eq(key)) - .next() - .map(|(_k, v)| v.clone()) - } - - pub fn get_all(&self, key: &PolicyID) -> Option { + pub fn get(&self, key: &PolicyID) -> Option { let mints: Vec = self .0 .iter() From 6a588602275c47ef3eb50334ebc9e33d2b1c9975 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 28 Nov 2023 20:49:51 +0800 Subject: [PATCH 8/9] fix test --- rust/src/tests/builders/tx_builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/tests/builders/tx_builder.rs b/rust/src/tests/builders/tx_builder.rs index 63cb7666..031b294d 100644 --- a/rust/src/tests/builders/tx_builder.rs +++ b/rust/src/tests/builders/tx_builder.rs @@ -3101,7 +3101,7 @@ fn assert_mint_asset(mint: &Mint, policy_id: &PolicyID) { let result_asset = mint.get(&policy_id).unwrap(); assert_eq!(result_asset.len(), 1); assert_eq!( - result_asset.get(&create_asset_name()).unwrap(), + result_asset.get(0).unwrap().get(&create_asset_name()).unwrap(), Int::new_i32(1234) ); } From 190b825006ea6aeac221308716a8a40206f01e0c Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 28 Nov 2023 20:53:16 +0800 Subject: [PATCH 9/9] js flow update --- rust/pkg/cardano_serialization_lib.js.flow | 315 +++------------------ 1 file changed, 39 insertions(+), 276 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 35b1d2e9..3e1ef470 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -171,21 +171,6 @@ declare export function min_ada_for_output( data_cost: DataCost ): BigNum; -/** - * !!! DEPRECATED !!! - * This function uses outdated set of arguments. - * Use `min_ada_for_output` instead - * @param {Value} assets - * @param {boolean} has_data_hash - * @param {BigNum} coins_per_utxo_word - * @returns {BigNum} - */ -declare export function min_ada_required( - assets: Value, - has_data_hash: boolean, - coins_per_utxo_word: BigNum -): BigNum; - /** * Receives a script JSON string * and returns a NativeScript. @@ -265,17 +250,11 @@ declare export function decode_metadatum_to_json_str( /** */ -declare export var MIRPot: {| - +Reserves: 0, // 0 - +Treasury: 1, // 1 -|}; - -/** - */ - -declare export var MIRKind: {| - +ToOtherPot: 0, // 0 - +ToStakeCredentials: 1, // 1 +declare export var CoinSelectionStrategyCIP2: {| + +LargestFirst: 0, // 0 + +RandomImprove: 1, // 1 + +LargestFirstMultiAsset: 2, // 2 + +RandomImproveMultiAsset: 3, // 3 |}; /** @@ -484,11 +463,17 @@ declare export var MetadataJsonSchema: {| /** */ -declare export var CoinSelectionStrategyCIP2: {| - +LargestFirst: 0, // 0 - +RandomImprove: 1, // 1 - +LargestFirstMultiAsset: 2, // 2 - +RandomImproveMultiAsset: 3, // 3 +declare export var MIRPot: {| + +Reserves: 0, // 0 + +Treasury: 1, // 1 +|}; + +/** + */ + +declare export var MIRKind: {| + +ToOtherPot: 0, // 0 + +ToStakeCredentials: 1, // 1 |}; /** @@ -1840,19 +1825,19 @@ declare export class Certificate { ): Certificate; /** - * @param {CommitteeHotAuth} committee_hot_key_registration + * @param {CommitteeHotAuth} committee_hot_auth * @returns {Certificate} */ static new_committee_hot_auth( - committee_hot_key_registration: CommitteeHotAuth + committee_hot_auth: CommitteeHotAuth ): Certificate; /** - * @param {CommitteeColdResign} committee_hot_key_deregistration + * @param {CommitteeColdResign} committee_cold_resign * @returns {Certificate} */ static new_committee_cold_resign( - committee_hot_key_deregistration: CommitteeColdResign + committee_cold_resign: CommitteeColdResign ): Certificate; /** @@ -1958,12 +1943,12 @@ declare export class Certificate { /** * @returns {CommitteeHotAuth | void} */ - as_committee_hot_key_registration(): CommitteeHotAuth | void; + as_committee_hot_auth(): CommitteeHotAuth | void; /** * @returns {CommitteeColdResign | void} */ - as_committee_hot_key_deregistration(): CommitteeColdResign | void; + as_committee_cold_resign(): CommitteeColdResign | void; /** * @returns {DrepDeregistration | void} @@ -2948,14 +2933,6 @@ declare export class DRep { declare export class DataCost { free(): void; - /** - * !!! DEPRECATED !!! - * Since babbage era we should use coins per byte. Use `.new_coins_per_byte` instead. - * @param {BigNum} coins_per_word - * @returns {DataCost} - */ - static new_coins_per_word(coins_per_word: BigNum): DataCost; - /** * @param {BigNum} coins_per_byte * @returns {DataCost} @@ -4663,62 +4640,6 @@ declare export class InfoAction { */ static new(): InfoAction; } -/** - */ -declare export class InputWithScriptWitness { - free(): void; - - /** - * @param {TransactionInput} input - * @param {NativeScript} witness - * @returns {InputWithScriptWitness} - */ - static new_with_native_script_witness( - input: TransactionInput, - witness: NativeScript - ): InputWithScriptWitness; - - /** - * @param {TransactionInput} input - * @param {PlutusWitness} witness - * @returns {InputWithScriptWitness} - */ - static new_with_plutus_witness( - input: TransactionInput, - witness: PlutusWitness - ): InputWithScriptWitness; - - /** - * @returns {TransactionInput} - */ - input(): TransactionInput; -} -/** - */ -declare export class InputsWithScriptWitness { - free(): void; - - /** - * @returns {InputsWithScriptWitness} - */ - static new(): InputsWithScriptWitness; - - /** - * @param {InputWithScriptWitness} input - */ - add(input: InputWithScriptWitness): void; - - /** - * @param {number} index - * @returns {InputWithScriptWitness} - */ - get(index: number): InputWithScriptWitness; - - /** - * @returns {number} - */ - len(): number; -} /** */ declare export class Int { @@ -5424,20 +5345,11 @@ declare export class Mint { */ insert(key: ScriptHash, value: MintAssets): MintAssets | void; - /** - * !!! DEPRECATED !!! - * Mint can store multiple entries for the same policy id. - * Use `.get_all` instead. - * @param {ScriptHash} key - * @returns {MintAssets | void} - */ - get(key: ScriptHash): MintAssets | void; - /** * @param {ScriptHash} key * @returns {MintsAssets | void} */ - get_all(key: ScriptHash): MintsAssets | void; + get(key: ScriptHash): MintsAssets | void; /** * @returns {ScriptHashes} @@ -6143,13 +6055,6 @@ declare export class NetworkInfo { */ static testnet_preprod(): NetworkInfo; - /** - * !!! DEPRECATED !!! - * This network does not exist anymore. Use `.testnet_preview()` or `.testnet_preprod()` - * @returns {NetworkInfo} - */ - static testnet(): NetworkInfo; - /** * @returns {NetworkInfo} */ @@ -6880,27 +6785,13 @@ declare export class PlutusScriptSource { */ static new(script: PlutusScript): PlutusScriptSource; - /** - * !!! DEPRECATED !!! - * This constructor has missed information about plutus script language vesrion. That can affect - * the script data hash calculation. - * Use `.new_ref_input_with_lang_ver` instead - * @param {ScriptHash} script_hash - * @param {TransactionInput} input - * @returns {PlutusScriptSource} - */ - static new_ref_input( - script_hash: ScriptHash, - input: TransactionInput - ): PlutusScriptSource; - /** * @param {ScriptHash} script_hash * @param {TransactionInput} input * @param {Language} lang_ver * @returns {PlutusScriptSource} */ - static new_ref_input_with_lang_ver( + static new_ref_input( script_hash: ScriptHash, input: TransactionInput, lang_ver: Language @@ -10188,13 +10079,6 @@ declare export class TransactionBody { */ mint(): Mint | void; - /** - * This function returns the mint value of the transaction - * Use `.mint()` instead. - * @returns {Mint | void} - */ - multiassets(): Mint | void; - /** * @param {TransactionInputs} reference_inputs */ @@ -10414,24 +10298,6 @@ declare export class TransactionBuilder { amount: Value ): void; - /** - * This method adds the input to the builder BUT leaves a missing spot for the witness native script - * - * After adding the input with this method, use `.add_required_native_input_scripts` - * and `.add_required_plutus_input_scripts` to add the witness scripts - * - * Or instead use `.add_native_script_input` and `.add_plutus_script_input` - * to add inputs right along with the script, instead of the script hash - * @param {ScriptHash} hash - * @param {TransactionInput} input - * @param {Value} amount - */ - add_script_input( - hash: ScriptHash, - input: TransactionInput, - amount: Value - ): void; - /** * This method will add the input to the builder and also register the required native script witness * @param {NativeScript} script @@ -10468,41 +10334,19 @@ declare export class TransactionBuilder { ): void; /** - * Note that for script inputs this method will use underlying generic `.add_script_input` - * which leaves a required empty spot for the script witness (or witnesses in case of Plutus). - * You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness. + * This function is replace for previous one add_input. + * The functions adds a non script input, if it is a script input it returns an error. + * To add script input you need to use add_native_script_input or add_plutus_script_input. + * Also we recommend to use TxInputsBuilder and .set_inputs, because all add_*_input functions might be removed from transaction builder. * @param {Address} address * @param {TransactionInput} input * @param {Value} amount */ - add_input(address: Address, input: TransactionInput, amount: Value): void; - - /** - * Returns the number of still missing input scripts (either native or plutus) - * Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts - * @returns {number} - */ - count_missing_input_scripts(): number; - - /** - * Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - * Any scripts that don't match any of the previously added inputs will be ignored - * Returns the number of remaining required missing witness scripts - * Use `.count_missing_input_scripts` to find the number of still missing scripts - * @param {NativeScripts} scripts - * @returns {number} - */ - add_required_native_input_scripts(scripts: NativeScripts): number; - - /** - * Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - * Any scripts that don't match any of the previously added inputs will be ignored - * Returns the number of remaining required missing witness scripts - * Use `.count_missing_input_scripts` to find the number of still missing scripts - * @param {PlutusWitnesses} scripts - * @returns {number} - */ - add_required_plutus_input_scripts(scripts: PlutusWitnesses): number; + add_regular_input( + address: Address, + input: TransactionInput, + amount: Value + ): void; /** * Returns a copy of the current script input witness scripts in the builder @@ -10957,16 +10801,6 @@ declare export class TransactionBuilderConfigBuilder { */ fee_algo(fee_algo: LinearFee): TransactionBuilderConfigBuilder; - /** - * !!! DEPRECATED !!! - * Since babbage era cardano nodes use coins per byte. Use '.coins_per_utxo_byte' instead. - * @param {BigNum} coins_per_utxo_word - * @returns {TransactionBuilderConfigBuilder} - */ - coins_per_utxo_word( - coins_per_utxo_word: BigNum - ): TransactionBuilderConfigBuilder; - /** * @param {BigNum} coins_per_utxo_byte * @returns {TransactionBuilderConfigBuilder} @@ -11458,18 +11292,6 @@ declare export class TransactionOutputAmountBuilder { multiasset: MultiAsset ): TransactionOutputAmountBuilder; - /** - * !!! DEPRECATED !!! - * Since babbage era cardano nodes use coins per byte. Use '.with_asset_and_min_required_coin_by_utxo_cost' instead. - * @param {MultiAsset} multiasset - * @param {BigNum} coins_per_utxo_word - * @returns {TransactionOutputAmountBuilder} - */ - with_asset_and_min_required_coin( - multiasset: MultiAsset, - coins_per_utxo_word: BigNum - ): TransactionOutputAmountBuilder; - /** * @param {MultiAsset} multiasset * @param {DataCost} data_cost @@ -12016,26 +11838,6 @@ declare export class TxInputsBuilder { amount: Value ): void; - /** - * !!! DEPRECATED !!! - * This function can make a mistake in choosing right input index. Use `.add_native_script_input` or `.add_plutus_script_input` instead. - * This method adds the input to the builder BUT leaves a missing spot for the witness native script - * - * After adding the input with this method, use `.add_required_native_input_scripts` - * and `.add_required_plutus_input_scripts` to add the witness scripts - * - * Or instead use `.add_native_script_input` and `.add_plutus_script_input` - * to add inputs right along with the script, instead of the script hash - * @param {ScriptHash} hash - * @param {TransactionInput} input - * @param {Value} amount - */ - add_script_input( - hash: ScriptHash, - input: TransactionInput, - amount: Value - ): void; - /** * This method will add the input to the builder and also register the required native script witness * @param {NativeScript} script @@ -12072,55 +11874,16 @@ declare export class TxInputsBuilder { ): void; /** - * Note that for script inputs this method will use underlying generic `.add_script_input` - * which leaves a required empty spot for the script witness (or witnesses in case of Plutus). - * You can use `.add_native_script_input` or `.add_plutus_script_input` directly to register the input along with the witness. + * Adds non script input, in case of script or reward address input it will return an error * @param {Address} address * @param {TransactionInput} input * @param {Value} amount */ - add_input(address: Address, input: TransactionInput, amount: Value): void; - - /** - * Returns the number of still missing input scripts (either native or plutus) - * Use `.add_required_native_input_scripts` or `.add_required_plutus_input_scripts` to add the missing scripts - * @returns {number} - */ - count_missing_input_scripts(): number; - - /** - * Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - * Any scripts that don't match any of the previously added inputs will be ignored - * Returns the number of remaining required missing witness scripts - * Use `.count_missing_input_scripts` to find the number of still missing scripts - * @param {NativeScripts} scripts - * @returns {number} - */ - add_required_native_input_scripts(scripts: NativeScripts): number; - - /** - * !!! DEPRECATED !!! - * This function can make a mistake in choosing right input index. Use `.add_required_script_input_witnesses` instead. - * Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - * Any scripts that don't match any of the previously added inputs will be ignored - * Returns the number of remaining required missing witness scripts - * Use `.count_missing_input_scripts` to find the number of still missing scripts - * @param {PlutusWitnesses} scripts - * @returns {number} - */ - add_required_plutus_input_scripts(scripts: PlutusWitnesses): number; - - /** - * Try adding the specified scripts as witnesses for ALREADY ADDED script inputs - * Any scripts that don't match any of the previously added inputs will be ignored - * Returns the number of remaining required missing witness scripts - * Use `.count_missing_input_scripts` to find the number of still missing scripts - * @param {InputsWithScriptWitness} inputs_with_wit - * @returns {number} - */ - add_required_script_input_witnesses( - inputs_with_wit: InputsWithScriptWitness - ): number; + add_regular_input( + address: Address, + input: TransactionInput, + amount: Value + ): void; /** * @returns {TransactionInputs}