Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test with custom input #749

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions sdk/tests/client/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use iota_sdk::{
client::{api::GetAddressesOptions, node_api::indexer::query_parameters::QueryParameter, Result},
types::block::{
address::ToBech32Ext,
input::{Input, UtxoInput},
output::{unlock_condition::AddressUnlockCondition, BasicOutputBuilder, OutputId},
payload::{transaction::TransactionEssence, Payload},
},
Expand Down Expand Up @@ -68,3 +69,69 @@ async fn send_basic_output() -> Result<()> {

Ok(())
}

#[ignore]
#[tokio::test]
async fn custom_input() -> Result<()> {
let (client, secret_manager) = create_client_and_secret_manager_with_funds(None).await?;

let token_supply = client.get_token_supply().await?;

let address = secret_manager
.generate_ed25519_addresses(GetAddressesOptions::from_client(&client).await?.with_range(0..1))
.await?[0];

let bech32_hrp = client.get_bech32_hrp().await?;

// First create multiple outputs on our address, so there is even the possibility to select another input
let output = BasicOutputBuilder::new_with_amount(1_000_000)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(token_supply)?;
let block = client
.block()
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
.with_secret_manager(&secret_manager)
.with_outputs(vec![output; 10])?
.finish()
.await?;
client.retry_until_included(&block.id(), None, None).await?;

let output_ids_response = client
.basic_output_ids([
QueryParameter::Address(address.to_bech32(bech32_hrp)),
QueryParameter::HasExpiration(false),
QueryParameter::HasTimelock(false),
QueryParameter::HasStorageDepositReturn(false),
])
.await?;

// The first output would be picked when using automatic input selection, so use the second one instead
let input_id = output_ids_response.items[1];

let input_amount = client.get_output(&input_id).await?.output().amount();

let output = BasicOutputBuilder::new_with_amount(input_amount)
.add_unlock_condition(AddressUnlockCondition::new(address))
.finish_output(token_supply)?;

let utxo_input = UtxoInput::from(input_id);
let block = client
.block()
.with_secret_manager(&secret_manager)
.with_outputs([output.clone()])?
.with_input(utxo_input)?
.finish()
.await?;

client.retry_until_included(&block.id(), None, None).await?;

if let Payload::Transaction(tx_payload) = block.payload().unwrap() {
let TransactionEssence::Regular(essence) = tx_payload.essence();
// only the provided input is used
assert_eq!(essence.inputs().len(), 1);
assert_eq!(essence.inputs()[0], Input::Utxo(utxo_input));
} else {
panic!("missing transaction payload")
};

Ok(())
}
Loading