Skip to content

Commit

Permalink
Add debug logs and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Mar 26, 2024
1 parent 91e2eb4 commit db04a13
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 41 deletions.
14 changes: 14 additions & 0 deletions sdk/src/wallet/operations/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ where
.await;

log::debug!("submitting block {}", block.id(&protocol_parameters));
log::debug!(
"submitting block alloted {}/{} max burned mana",
block
.as_basic()
.payload()
.unwrap()
.as_signed_transaction()
.transaction()
.allotments()
.first()
.unwrap()
.mana(),
block.as_basic().max_burned_mana(),
);
log::debug!("submitting block {:?}", block);
for attempt in 1..MAX_POST_BLOCK_ATTEMPTS {
if let Ok(block_id) = self.client().post_block(&block).await {
Expand Down
110 changes: 69 additions & 41 deletions sdk/tests/client/transaction_builder/account_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,37 @@

use std::str::FromStr;

use crypto::keys::bip44::Bip44;
use iota_sdk::{
client::{
api::transaction_builder::{Burn, Requirement, TransactionBuilder, TransactionBuilderError, Transitions},
secret::types::InputSigningData,
api::{
transaction_builder::{Burn, Requirement, TransactionBuilder, TransactionBuilderError, Transitions},
GetAddressesOptions,
},
constants::SHIMMER_COIN_TYPE,
secret::{mnemonic::MnemonicSecretManager, types::InputSigningData, SecretManage, SecretManager},
Client,
},
types::block::{
address::{Address, ImplicitAccountCreationAddress},
core::{
basic::{MaxBurnedManaAmount, StrongParents},
BlockHeader,
},
mana::ManaAllotment,
output::{
feature::{BlockIssuerFeature, BlockIssuerKeys, Ed25519PublicKeyHashBlockIssuerKey},
unlock_condition::AddressUnlockCondition,
AccountId, AccountOutputBuilder, BasicOutputBuilder, Output,
},
payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
protocol::iota_mainnet_protocol_parameters,
payload::{
signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
Payload, SignedTransactionPayload,
},
protocol::{iota_mainnet_protocol_parameters, WorkScore},
rand::output::{rand_output_id_with_slot_index, rand_output_metadata_with_id},
slot::SlotIndex,
slot::{SlotCommitmentId, SlotIndex},
BlockBody, BlockId, UnsignedBlock,
},
};
use pretty_assertions::{assert_eq, assert_ne};
Expand Down Expand Up @@ -2408,35 +2422,38 @@ fn account_transition_with_required_context_inputs() {
);
}

#[test]
fn send_amount_from_block_issuer_account_with_generated_mana() {
#[tokio::test]
async fn basic_input_automatic_allotment() {
let secret_manager = SecretManager::try_from_mnemonic(Client::generate_mnemonic().unwrap()).unwrap();

let ed25519_address = secret_manager
.generate_ed25519_addresses(GetAddressesOptions::default().with_range(0..1))
.await
.unwrap()[0]
.clone()
.into_inner();

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::<Vec<_>>();
let reference_mana_cost = 1;

let inputs = build_inputs(
[(
Basic {
amount: 10_000_000,
mana: 10_000,
address: ed25519_address.clone(),
native_token: None,
sender: None,
sdruc: None,
timelock: None,
expiration: None,
},
Some(Bip44::new(SHIMMER_COIN_TYPE)),
)],
Some(SLOT_INDEX),
);

let outputs = vec![
BasicOutputBuilder::new_with_amount(1_000_000)
Expand All @@ -2448,25 +2465,36 @@ fn send_amount_from_block_issuer_account_with_generated_mana() {
let selected = TransactionBuilder::new(
inputs.clone(),
outputs.clone(),
[Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap()],
[ed25519_address],
SLOT_INDEX,
SLOT_COMMITMENT_ID,
protocol_parameters,
protocol_parameters.clone(),
)
.with_min_mana_allotment(account_id_1, 2)
.with_remainder_address(Address::Account(account_id_1.into()))
.with_min_mana_allotment(account_id_1, reference_mana_cost)
.finish()
.unwrap();

let unlocks = secret_manager
.transaction_unlocks(&selected, &protocol_parameters)
.await
.unwrap();

let signed_transaction_payload = SignedTransactionPayload::new(selected.transaction.clone(), unlocks).unwrap();

let basic_block_body = BlockBody::build_basic(
StrongParents::from_vec(vec![BlockId::new([0; 36])]).unwrap(),
(protocol_parameters.work_score_parameters(), reference_mana_cost),
)
.with_payload(Payload::from(signed_transaction_payload))
.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
// 73 less than it should be?
selected.transaction.allotments().first().unwrap().mana(),
basic_block_body.max_burned_mana(),
);
}

0 comments on commit db04a13

Please sign in to comment.