Skip to content

Commit

Permalink
More test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Oct 3, 2023
1 parent de48e04 commit f3607b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,12 @@ impl InputSelection {
// Checks if an available input can unlock a given ED25519 address.
// In case an account input is selected, also tells if it needs to be state or governance transitioned.
fn available_has_ed25519_address(&self, input: &InputSigningData, address: &Address) -> bool {
// TODO remove?
if input.output.is_account() {
// PANIC: safe to unwrap as outputs without unlock conditions have been filtered out already.
let unlock_conditions = input.output.unlock_conditions().unwrap();

// PANIC: safe to unwrap as accounts have a state controller address.
if unlock_conditions.state_controller_address().unwrap().address() == address {
return self.addresses.contains(address);
}

// PANIC: safe to unwrap as accounts have a governor address.
if unlock_conditions.governor_address().unwrap().address() == address {
return self.addresses.contains(address);
}

false
} else {
let (required_address, _) = input
.output
.required_and_unlocked_address(self.slot_index, input.output_id())
.unwrap();
let (required_address, _) = input
.output
.required_and_unlocked_address(self.slot_index, input.output_id())
.unwrap();

&required_address == address
}
&required_address == address
}

/// Fulfills an ed25519 sender requirement by selecting an available input that unlocks its address.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl<S: 'static + SecretManage> Account<S>
where
crate::wallet::Error: From<S::Error>,
{
// TODO
/// Returns output ids of account outputs
pub(crate) async fn get_account_and_foundry_output_ids(
&self,
Expand Down
34 changes: 8 additions & 26 deletions sdk/tests/client/input_selection/foundry_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use iota_sdk::{
types::block::{
address::{AccountAddress, Address},
output::{
unlock_condition::{GovernorAddressUnlockCondition, StateControllerAddressUnlockCondition},
AccountId, AccountOutputBuilder, FoundryId, Output, SimpleTokenScheme, TokenId,
unlock_condition::AddressUnlockCondition, AccountId, AccountOutputBuilder, FoundryId, Output,
SimpleTokenScheme, TokenId,
},
protocol::protocol_parameters,
rand::output::rand_output_metadata,
Expand Down Expand Up @@ -226,10 +226,7 @@ fn melt_native_tokens() {
),
]);
let account_output = AccountOutputBuilder::new_with_amount(1_000_000, account_id_1)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down Expand Up @@ -464,10 +461,7 @@ fn simple_foundry_transition_basic_not_needed() {
),
]);
let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down Expand Up @@ -534,10 +528,7 @@ fn simple_foundry_transition_basic_not_needed_with_remainder() {
),
]);
let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down Expand Up @@ -679,10 +670,7 @@ fn mint_and_burn_at_the_same_time() {
Some(vec![(&token_id.to_string(), 100)]),
)]);
let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down Expand Up @@ -735,10 +723,7 @@ fn take_amount_from_account_and_foundry_to_fund_basic() {
),
]);
let account_output = AccountOutputBuilder::new_with_amount(2_000_000, account_id_1)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down Expand Up @@ -942,10 +927,7 @@ fn foundry_in_outputs_and_required() {
None,
)]);
let account_output = AccountOutputBuilder::new_with_amount(1_251_500, account_id_2)
.add_unlock_condition(StateControllerAddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.add_unlock_condition(GovernorAddressUnlockCondition::new(
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32(BECH32_ADDRESS_ED25519_0).unwrap(),
))
.with_foundry_counter(1)
Expand Down
8 changes: 1 addition & 7 deletions sdk/tests/types/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use iota_sdk::types::{
rand::output::{
feature::{rand_issuer_feature, rand_metadata_feature, rand_sender_feature},
rand_account_id, rand_account_output,
unlock_condition::{
rand_address_unlock_condition_different_from_account_id,
rand_state_controller_address_unlock_condition_different_from,
},
unlock_condition::rand_address_unlock_condition_different_from_account_id,
},
},
ValidationParams,
Expand Down Expand Up @@ -60,9 +57,6 @@ fn builder() {

let output = builder
.with_minimum_storage_deposit(protocol_parameters.rent_structure())
.add_unlock_condition(rand_state_controller_address_unlock_condition_different_from(
&account_id,
))
.add_unlock_condition(rand_address_unlock_condition_different_from_account_id(&account_id))
.with_features([Feature::from(metadata.clone()), sender_1.into()])
.with_immutable_features([Feature::from(metadata.clone()), issuer_1.into()])
Expand Down
10 changes: 2 additions & 8 deletions sdk/tests/wallet/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

use iota_sdk::{
types::block::output::{
unlock_condition::{
AddressUnlockCondition, ExpirationUnlockCondition, GovernorAddressUnlockCondition,
StateControllerAddressUnlockCondition, StorageDepositReturnUnlockCondition,
},
unlock_condition::{AddressUnlockCondition, ExpirationUnlockCondition, StorageDepositReturnUnlockCondition},
AccountId, AccountOutputBuilder, BasicOutputBuilder, NftId, NftOutputBuilder, UnlockCondition,
},
wallet::{account::SyncOptions, Result},
Expand Down Expand Up @@ -107,10 +104,7 @@ async fn sync_only_most_basic_outputs() -> Result<()> {
])
.finish_output(token_supply)?,
AccountOutputBuilder::new_with_amount(1_000_000, AccountId::null())
.with_unlock_conditions([
UnlockCondition::StateControllerAddress(StateControllerAddressUnlockCondition::new(account_1_address)),
UnlockCondition::GovernorAddress(GovernorAddressUnlockCondition::new(account_1_address)),
])
.with_unlock_conditions([UnlockCondition::Address(AddressUnlockCondition::new(account_1_address))])
.finish_output(token_supply)?,
];

Expand Down

0 comments on commit f3607b4

Please sign in to comment.