Skip to content

Commit

Permalink
Fix more tests, don't select inputs for mana when they don't add anyt…
Browse files Browse the repository at this point in the history
…hing
  • Loading branch information
Thoralf-M committed Mar 19, 2024
1 parent 4299672 commit 784c841
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
1 change: 0 additions & 1 deletion sdk/examples/wallet/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use iota_sdk::{
client::{
api::GetAddressesOptions,
constants::SHIMMER_COIN_TYPE,
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
Expand Down
8 changes: 2 additions & 6 deletions sdk/examples/wallet/spammer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
request_funds_from_faucet,
secret::{mnemonic::MnemonicSecretManager, SecretManage, SecretManager},
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
crypto::keys::bip44::Bip44,
types::block::{
address::{Address, Bech32Address, Hrp},
output::BasicOutput,
payload::signed_transaction::TransactionId,
},
types::block::{address::Bech32Address, output::BasicOutput, payload::signed_transaction::TransactionId},
wallet::{ClientOptions, FilterOptions, SendParams, Wallet},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ impl TransactionBuilder {
let Some(input) = priority_map.next(required_mana - selected_mana) else {
break;
};
// Don't select input with 0 available mana
if input.output.available_mana(
&self.protocol_parameters,
input.output_id().transaction_id().slot_index(),
self.creation_slot,
)? == 0
{
continue;
}
selected_mana += self.total_mana(&input, include_generated)?;
if let Some(output) = self.select_input(input)? {
required_mana += output.mana();
Expand Down
19 changes: 14 additions & 5 deletions sdk/tests/wallet/burn_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ async fn create_and_melt_native_token() -> Result<(), Box<dyn std::error::Error>
// First create an account output, this needs to be done only once, because an account can have many foundry outputs
let transaction = wallet.create_account_output(None, None).await?;

let account_id = AccountId::from(&OutputId::new(transaction.transaction_id, 0));
wallet
.wait_for_transaction_acceptance(&transaction.transaction_id, None, None)
.await?;
wallet.sync(None).await?;

let circulating_supply = U256::from(60i32);
let params = CreateNativeTokenParams {
account_id: None,
account_id: Some(account_id),
circulating_supply,
maximum_supply: U256::from(100i32),
foundry_metadata: None,
Expand Down Expand Up @@ -175,7 +176,7 @@ async fn create_and_melt_native_token() -> Result<(), Box<dyn std::error::Error>

// Call to run tests in sequence
destroy_foundry(&wallet).await?;
destroy_account(&wallet).await?;
destroy_account(&wallet, account_id).await?;

tear_down(storage_path)
}
Expand Down Expand Up @@ -203,12 +204,10 @@ async fn destroy_foundry(wallet: &Wallet) -> Result<(), Box<dyn std::error::Erro
Ok(())
}

async fn destroy_account(wallet: &Wallet) -> Result<(), Box<dyn std::error::Error>> {
async fn destroy_account(wallet: &Wallet, account_id: AccountId) -> Result<(), Box<dyn std::error::Error>> {
let balance = wallet.sync(None).await.unwrap();
println!("account balance -> {}", serde_json::to_string(&balance).unwrap());

// Let's destroy the first account we can find
let account_id = *balance.accounts().first().unwrap();
println!("account_id -> {account_id}");
let transaction = wallet.burn(account_id, None).await.unwrap();
wallet
Expand All @@ -228,6 +227,16 @@ async fn destroy_account(wallet: &Wallet) -> Result<(), Box<dyn std::error::Erro
#[ignore]
#[tokio::test]
async fn create_and_burn_native_tokens() -> Result<(), Box<dyn std::error::Error>> {
let logger_output_config = fern_logger::LoggerOutputConfigBuilder::new()
.name("client.log")
.target_exclusions(&["h2", "hyper", "rustls"])
.level_filter(log::LevelFilter::Debug);

let config = fern_logger::LoggerConfig::build()
.with_output(logger_output_config)
.finish();

fern_logger::logger_init(config).unwrap();
let storage_path = "test-storage/create_and_burn_native_tokens";
setup(storage_path)?;

Expand Down
53 changes: 45 additions & 8 deletions sdk/tests/wallet/claim_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,41 @@ async fn claim_1_of_2_basic_outputs() -> Result<(), Box<dyn std::error::Error>>

#[ignore]
#[tokio::test]
async fn claim_2_basic_outputs_no_outputs_in_claim_account() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_0 = "test-storage/claim_2_basic_outputs_no_outputs_in_claim_account_0";
let storage_path_1 = "test-storage/claim_2_basic_outputs_no_outputs_in_claim_account_1";
async fn claim_2_basic_outputs_no_available_in_claim_account() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_0 = "test-storage/claim_2_basic_outputs_no_available_in_claim_account_0";
let storage_path_1 = "test-storage/claim_2_basic_outputs_no_available_in_claim_account_1";
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;

// Send all available from wallet 1 away
let balance = wallet_1.sync(None).await?;
let tx = wallet_1
.send_with_params(
[SendParams::new(
balance.base_coin().available(),
wallet_0.address().await,
)?],
None,
)
.await?;
wallet_1
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
.await?;

let storage_score_params = wallet_0.client().get_storage_score_parameters().await?;
// TODO more fitting value
let expiration_slot = wallet_0.client().get_slot_index().await? + 86400;
let slot_duration_in_seconds = wallet_0
.client()
.get_protocol_parameters()
.await?
.slot_duration_in_seconds();

let expiration_slot = wallet_0.client().get_slot_index().await? + (86400 / slot_duration_in_seconds as u32);

let output = BasicOutputBuilder::new_with_minimum_amount(storage_score_params)
.add_unlock_condition(AddressUnlockCondition::new(wallet_1.address().await))
Expand Down Expand Up @@ -281,16 +302,32 @@ async fn claim_2_native_tokens() -> Result<(), Box<dyn std::error::Error>> {

#[ignore]
#[tokio::test]
async fn claim_2_native_tokens_no_outputs_in_claim_account() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_0 = "test-storage/claim_2_native_tokens_no_outputs_in_claim_account_0";
let storage_path_1 = "test-storage/claim_2_native_tokens_no_outputs_in_claim_account_1";
async fn claim_2_native_tokens_no_available_balance_in_claim_account() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_0 = "test-storage/claim_2_native_tokens_no_available_balance_in_claim_account_0";
let storage_path_1 = "test-storage/claim_2_native_tokens_no_available_balance_in_claim_account_1";
setup(storage_path_0)?;
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, None, None).await?;
let wallet_1 = make_wallet(storage_path_1, None, None).await?;

request_funds(&wallet_0).await?;
request_funds(&wallet_1).await?;

// Send all available from wallet 1 away
let balance = wallet_1.sync(None).await?;
let tx = wallet_1
.send_with_params(
[SendParams::new(
balance.base_coin().available(),
wallet_0.address().await,
)?],
None,
)
.await?;
wallet_1
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
.await?;

let native_token_amount = U256::from(100);

Expand Down
4 changes: 2 additions & 2 deletions sdk/tests/wallet/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use iota_sdk::{client::generate_mnemonic, wallet::SendParams};
use iota_sdk::wallet::SendParams;
use pretty_assertions::assert_eq;

use crate::wallet::common::{make_wallet, request_funds, setup, tear_down};
Expand All @@ -13,7 +13,7 @@ async fn send_amount() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_1 = "test-storage/send_amount_1";
setup(storage_path_1)?;

let wallet_0 = make_wallet(storage_path_0, Some(generate_mnemonic()?), None).await?;
let wallet_0 = make_wallet(storage_path_0, None, None).await?;
request_funds(&wallet_0).await?;

let wallet_1 = make_wallet(storage_path_1, None, None).await?;
Expand Down

0 comments on commit 784c841

Please sign in to comment.