From e16edb5d8c0e17f6f175fc2322f29bca38434d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thoralf=20M=C3=BCller?= Date: Thu, 21 Mar 2024 13:28:58 +0100 Subject: [PATCH] Add send_amount_from_block_issuer_account_with_generated_mana test --- .../transaction_builder/account_outputs.rs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/sdk/tests/client/transaction_builder/account_outputs.rs b/sdk/tests/client/transaction_builder/account_outputs.rs index 38611fac17..86533dd7c5 100644 --- a/sdk/tests/client/transaction_builder/account_outputs.rs +++ b/sdk/tests/client/transaction_builder/account_outputs.rs @@ -19,6 +19,7 @@ use iota_sdk::{ payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag}, protocol::iota_mainnet_protocol_parameters, rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id}, + slot::SlotIndex, }, }; use pretty_assertions::{assert_eq, assert_ne}; @@ -2406,3 +2407,66 @@ fn account_transition_with_required_context_inputs() { 1 ); } + +#[test] +fn send_amount_from_block_issuer_account_with_generated_mana() { + let protocol_parameters = iota_mainnet_protocol_parameters().clone(); + let account_id_1 = AccountId::from_str(ACCOUNT_ID_1).unwrap(); + let ed25519_address = Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(); + + let inputs = [AccountOutputBuilder::new_with_amount(10_000_000, account_id_1) + .with_mana(20000) + .add_unlock_condition(AddressUnlockCondition::new( + Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(), + )) + .with_features([BlockIssuerFeature::new( + u32::MAX, + BlockIssuerKeys::from_vec(vec![ + Ed25519PublicKeyHashBlockIssuerKey::new(**ed25519_address.as_ed25519()).into(), + ]) + .unwrap(), + ) + .unwrap()]) + .finish_output() + .unwrap()]; + let inputs = inputs + .into_iter() + .map(|input| InputSigningData { + output: input, + output_metadata: rand_output_metadata_with_id(rand_output_id_with_slot_index(SlotIndex(5))), + chain: None, + }) + .collect::>(); + + let outputs = vec![ + BasicOutputBuilder::new_with_amount(1_000_000) + .add_unlock_condition(AddressUnlockCondition::new(ed25519_address.clone())) + .finish_output() + .unwrap(), + ]; + + let selected = TransactionBuilder::new( + inputs.clone(), + outputs.clone(), + [Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()], + SLOT_INDEX, + SLOT_COMMITMENT_ID, + protocol_parameters, + ) + .with_min_mana_allotment(account_id_1, 2) + .with_remainder_address(Address::Account(account_id_1.into())) + .finish() + .unwrap(); + + assert!(unsorted_eq(&selected.inputs_data, &inputs)); + assert_eq!(selected.transaction.outputs().len(), 2); + assert!(selected.transaction.outputs()[1].is_account()); + assert_eq!(selected.transaction.allotments().len(), 1); + // Required context inputs are added when the account is transitioned + assert_eq!(selected.transaction.context_inputs().len(), 2); + assert!(selected.transaction.context_inputs().commitment().is_some()); + assert_eq!( + selected.transaction.context_inputs().block_issuance_credits().count(), + 1 + ); +}