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

Update private tangle tests so they work with 2.0 #2191

Merged
merged 23 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4299672
Update private tangle tests so they work with 2.0
Thoralf-M Mar 18, 2024
784c841
Fix more tests, don't select inputs for mana when they don't add anyt…
Thoralf-M Mar 19, 2024
0f9b262
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 19, 2024
09f6bc5
Use nova branch for ledger nano simulator
Thoralf-M Mar 19, 2024
168ee5e
Uncomment and update test
Thoralf-M Mar 19, 2024
4a97d12
Update failing tests
Thoralf-M Mar 19, 2024
121fd07
Build ledger simulator with default IOTA coin type
Thoralf-M Mar 20, 2024
fcf7a7e
Update sdk/tests/wallet/common/mod.rs
Thoralf-M Mar 20, 2024
973e39f
Review suggestions
Thoralf-M Mar 20, 2024
53bfbb8
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 20, 2024
ce9ca65
Fix implicit_account break
Thoralf-M Mar 20, 2024
14c69e0
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 20, 2024
72eca57
Add and use slots_in_duration()
Thoralf-M Mar 20, 2024
236de1c
Make instant dep required
Thoralf-M Mar 20, 2024
013bf93
Merge branch '2.0' into wallet-transaction-tests
Mar 20, 2024
df9da41
Add and use ProtocolParameters::duration_of_slots()
Thoralf-M Mar 21, 2024
77f9eb2
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 21, 2024
14c7aa2
no_std
Thoralf-M Mar 21, 2024
1ac81de
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 21, 2024
f56fd17
Merge branch '2.0' into wallet-transaction-tests
Thoralf-M Mar 21, 2024
19ab6c0
comment before attribute, allow_additional_input_selection for consol…
Thoralf-M Mar 21, 2024
50bfb18
Fix inputs ordering
Thoralf-M Mar 21, 2024
97cd421
Merge branch '2.0' into wallet-transaction-tests
thibault-martinez Mar 22, 2024
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
4 changes: 2 additions & 2 deletions .github/actions/ledger-nano/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
uses: actions/checkout@v3
with:
repository: iotaledger/ledger-iota-app
ref: develop
ref: feat/nova
path: ledger-iota-app

- name: Update submodules
Expand All @@ -17,5 +17,5 @@ runs:

- name: Run the simulator
shell: bash
run: ./build.sh -s -v shimmer -b
run: ./build.sh -s -b
working-directory: ledger-iota-app
5 changes: 1 addition & 4 deletions .github/workflows/private-tangle-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ jobs:
uses: "./.github/actions/ledger-nano"

- name: Run tests
run: |
cargo nextest run test_get_info --all-features --run-ignored ignored-only --profile ci --cargo-profile ci -p iota-sdk -p iota-sdk-bindings-core --no-capture
# TODO: change in the future to run all tests and not only test_get_info
# cargo ci-tangle-test
run: cargo ci-tangle-test

- name: Tear down private tangle
if: always()
Expand Down
18 changes: 7 additions & 11 deletions bindings/core/tests/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,13 @@ async fn client_from_wallet() -> Result<(), Error> {
.build()
.await?;

// TODO reenable
// // Send ClientMethod via the client from the wallet
// let response = wallet
// .client()
// .call_method(ClientMethod::GetHealth)
// .await;

// match response {
// Response::Bool(_) => {}
// _ => panic!("unexpected response {response:?}"),
// }
// Send ClientMethod via the client from the wallet
let response = wallet.client().call_method(ClientMethod::GetProtocolParameters).await;

match response {
Response::ProtocolParameters(_) => {}
_ => panic!("unexpected response {response:?}"),
}

std::fs::remove_dir_all(storage_path).ok();
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ std = [
"iota_stronghold?/std",
"iota-crypto/std",
"once_cell?/std",
"dep:instant"
]
storage = ["iota-crypto/chacha", "dep:time", "dep:anymap", "dep:once_cell"]
stronghold = [
Expand All @@ -199,7 +200,6 @@ client = [
"iota-crypto/slip10",
"dep:async-trait",
"dep:futures",
"dep:instant",
"dep:log",
"dep:reqwest",
"dep:thiserror",
Expand Down
9 changes: 2 additions & 7 deletions sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,9 @@ mod tests {

use super::*;
use crate::types::block::{
output::{basic::dto::BasicOutputDto, FoundryId, SimpleTokenScheme, TokenId},
output::basic::dto::BasicOutputDto,
protocol::iota_mainnet_protocol_parameters,
rand::{
address::rand_account_address,
output::{
feature::rand_allowed_features, rand_basic_output, unlock_condition::rand_address_unlock_condition,
},
},
rand::output::{rand_basic_output, unlock_condition::rand_address_unlock_condition},
};

#[test]
Expand Down
14 changes: 14 additions & 0 deletions sdk/src/types/block/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use core::borrow::Borrow;

use crypto::hashes::{blake2b::Blake2b256, Digest};
use getset::{CopyGetters, Getters};
#[cfg(feature = "std")]
use instant::Duration;
use packable::{prefix::StringPrefix, Packable, PackableExt};
#[cfg(feature = "protocol_parameters_samples")]
pub use samples::{iota_mainnet_protocol_parameters, shimmer_mainnet_protocol_parameters};
Expand Down Expand Up @@ -173,6 +175,18 @@ impl ProtocolParameters {
}
}

#[cfg(feature = "std")]
/// Calculates the number of slots in a duration.
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
pub fn slots_in_duration(&self, duration: Duration) -> u32 {
(duration.as_secs() / self.slot_duration_in_seconds() as u64) as u32
}

#[cfg(feature = "std")]
/// Calculates the [`Duration`] of a number of slots.
pub fn duration_of_slots(&self, slots: u32) -> Duration {
Duration::from_secs((slots * self.slot_duration_in_seconds() as u32) as u64)
}

/// Gets the [`EpochIndex`] of a given [`SlotIndex`].
pub fn epoch_index_of(&self, slot_index: impl Into<SlotIndex>) -> EpochIndex {
EpochIndex::from_slot_index(slot_index, self.genesis_slot, self.slots_per_epoch_exponent())
Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/common/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

pub static NODE_LOCAL: &str = "http://localhost:8050";

pub static FAUCET_URL: &str = "http://localhost:8091/api/enqueue";
pub static FAUCET_URL: &str = "http://localhost:8088/api/enqueue";

pub static DEFAULT_MNEMONIC: &str = "inhale gorilla deny three celery song category owner lottery rent author wealth penalty crawl hobby obtain glad warm early rain clutch slab august bleak";
21 changes: 10 additions & 11 deletions sdk/tests/client/node_api/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ async fn test_get_issuance() {
#[ignore]
#[tokio::test]
async fn test_post_block_with_tagged_data() {
let secret_manager = setup_secret_manager();
let block_id = setup_tagged_data_block(&secret_manager).await;
let block_id = setup_tagged_data_block().await.unwrap();
println!("{block_id}");
}

Expand All @@ -72,9 +71,8 @@ async fn test_post_block_with_transaction() {
#[tokio::test]
async fn test_get_block_data() {
let client = setup_client_with_node_health_ignored().await;
let secret_manager = setup_secret_manager();

let block_id = setup_tagged_data_block(&secret_manager).await;
let block_id = setup_tagged_data_block().await.unwrap();
let r = client.get_block(&block_id).await.unwrap();

println!("{r:#?}");
Expand All @@ -83,8 +81,7 @@ async fn test_get_block_data() {
#[ignore]
#[tokio::test]
async fn test_get_block_metadata() {
let secret_manager = setup_secret_manager();
let block_id = setup_tagged_data_block(&secret_manager).await;
let block_id = setup_tagged_data_block().await.unwrap();

let r = setup_client_with_node_health_ignored()
.await
Expand All @@ -98,8 +95,7 @@ async fn test_get_block_metadata() {
#[ignore]
#[tokio::test]
async fn test_get_block_raw() {
let secret_manager = setup_secret_manager();
let block_id = setup_tagged_data_block(&secret_manager).await;
let block_id = setup_tagged_data_block().await.unwrap();

let r = setup_client_with_node_health_ignored()
.await
Expand Down Expand Up @@ -201,7 +197,7 @@ async fn test_call_plugin_route() {

// we call the "custom" plugin "node info"
let plugin_res: NodeInfoResponse = c
.call_plugin_route("api/core/v2/", "GET", "info", vec![], None)
.call_plugin_route("api/core/v3/", "GET", "info", vec![], None)
.await
.unwrap();

Expand All @@ -218,7 +214,7 @@ async fn test_get_routes() {

let routes_response = client.get_routes().await.unwrap();
// At at least one route, which is not created by plugin, is available
assert!(routes_response.routes.contains(&"core/v2".to_string()));
assert!(routes_response.routes.contains(&"core/v3".to_string()));

println!("{routes_response:#?}");
}
Expand All @@ -231,7 +227,10 @@ async fn test_get_included_block_metadata() {
let metadata_response = client.get_included_block_metadata(&transaction_id).await.unwrap();

assert_eq!(metadata_response.block_id, block_id);
assert_eq!(metadata_response.block_state, BlockState::Finalized);
match metadata_response.block_state {
BlockState::Accepted | BlockState::Confirmed | BlockState::Finalized => {}
_ => panic!("block state is not accepted/confirmed/finalized"),
}

println!("{metadata_response:#?}");
}
59 changes: 50 additions & 9 deletions sdk/tests/client/node_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use iota_sdk::{
client::{
api::GetAddressesOptions,
constants::IOTA_COIN_TYPE,
generate_mnemonic,
node_api::indexer::query_parameters::BasicOutputQueryParameters,
request_funds_from_faucet,
secret::{SecretManager, SignBlock},
secret::{mnemonic::MnemonicSecretManager, SecretManager, SignBlock},
Client,
},
types::block::{
address::{Address, Bech32Address, ImplicitAccountCreationAddress},
output::AccountId,
payload::{signed_transaction::TransactionId, tagged_data::TaggedDataPayload, Payload},
BlockId,
Expand All @@ -29,24 +31,63 @@ use crate::client::common::{setup_client_with_node_health_ignored, FAUCET_URL};
const DEFAULT_DEVELOPMENT_SEED: &str = "0x256a818b2aac458941f7274985a410e57fb750f3a3a67969ece5bd9ae7eef5b2";

// Sends a tagged data block to the node to test against it.
async fn setup_tagged_data_block(secret_manager: &SecretManager) -> BlockId {
async fn setup_tagged_data_block() -> Result<BlockId, Box<dyn std::error::Error>> {
let client = setup_client_with_node_health_ignored().await;

let protocol_params = client.get_protocol_parameters().await.unwrap();
let secret_manager = SecretManager::Mnemonic(MnemonicSecretManager::try_from_mnemonic(generate_mnemonic()?)?);

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

let address = secret_manager
.generate_ed25519_address(IOTA_COIN_TYPE, 0, 0, bech32_hrp, None)
.await?;
let address =
Address::ImplicitAccountCreation(ImplicitAccountCreationAddress::new(**address.into_inner().as_ed25519()));
let bech32_address = Bech32Address::new(bech32_hrp, address);

request_funds_from_faucet(FAUCET_URL, &bech32_address).await?;

client
let mut account_id = AccountId::null();
// Continue only after funds are received
for i in 0..30 {
let output_ids = client
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(
bech32_address.clone(),
))
.await?
.items;
if !output_ids.is_empty() {
account_id = AccountId::from(&output_ids[0]);
break;
}
if i == 29 {
panic!("Faucet no longer wants to hand over coins");
}
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
}
// Wait until account is read to issue blocks
for _ in 0..60 {
if client.get_account_congestion(&account_id, None).await.is_ok() {
break;
}
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
}

let block = client
.build_basic_block(
AccountId::null(),
account_id,
Some(Payload::TaggedData(Box::new(
TaggedDataPayload::new(b"Hello".to_vec(), b"Tangle".to_vec()).unwrap(),
))),
)
.await
.unwrap()
.sign_ed25519(secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await
.unwrap()
.id(&protocol_params)
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
.await?;
client.post_block(&block).await?;

let protocol_params = client.get_protocol_parameters().await.unwrap();
Ok(block.id(&protocol_params))
}

pub fn setup_secret_manager() -> SecretManager {
Expand Down
29 changes: 11 additions & 18 deletions sdk/tests/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {

request_funds(&wallet_0).await?;

let slots_until_expired = 20;
let slots_until_expired = 5;
let outputs = [BasicOutputBuilder::new_with_amount(1_000_000)
// Send to account 1 with expiration to account 2, both have no amount yet
.with_unlock_conditions([
Expand All @@ -162,7 +162,7 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {
balance_before_tx.base_coin().total(),
balance_after_tx.base_coin().total()
);
assert_eq!(balance_after_tx.base_coin().available(), 0);
assert_eq!(balance_after_tx.base_coin().available(), 999968300);

wallet_0
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
Expand Down Expand Up @@ -203,13 +203,6 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {
assert_eq!(balance.base_coin().total(), 1_000_000);
assert_eq!(balance.base_coin().available(), 1_000_000);

// It's possible to send the expired output
let outputs = [BasicOutputBuilder::new_with_amount(1_000_000)
// Send to wallet 1 with expiration to wallet 2, both have no amount yet
.with_unlock_conditions([AddressUnlockCondition::new(wallet_1.address().await)])
.finish_output()?];
let _tx = wallet_2.send_outputs(outputs, None).await?;

tear_down(storage_path_0)?;
tear_down(storage_path_1)?;
tear_down(storage_path_2)?;
Expand All @@ -218,7 +211,7 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {

#[ignore]
#[tokio::test]
async fn balance_transfer() -> Result<(), Box<dyn std::error::Error>> {
async fn available_balance_transfer() -> Result<(), Box<dyn std::error::Error>> {
let storage_path_0 = "test-storage/addresses_balance_0";
let storage_path_1 = "test-storage/addresses_balance_1";
setup(storage_path_0)?;
Expand All @@ -229,13 +222,11 @@ async fn balance_transfer() -> Result<(), Box<dyn std::error::Error>> {

request_funds(&wallet_0).await?;

let balance_0 = wallet_0.balance().await?;
let balance_0_sync = wallet_0.sync(None).await?;
let balance_0 = wallet_0.sync(None).await?;
let to_send = balance_0.base_coin().available();

// Check if 0 has balance and sync() and address_balance() match
assert!(to_send > 0);
assert_eq!(balance_0, balance_0_sync);

// Make sure 1 is empty
let balance_1 = wallet_1.sync(None).await?;
Expand All @@ -244,20 +235,22 @@ async fn balance_transfer() -> Result<(), Box<dyn std::error::Error>> {
// Send to 1
let tx = wallet_0.send(to_send, wallet_1.address().await, None).await?;

// Balance should update without sync
// Available balance should update without sync
let balance_0 = wallet_0.balance().await?;
let balance_0_sync = wallet_0.sync(None).await?;
assert_eq!(balance_0.base_coin().available(), 0);
assert_eq!(balance_0, balance_0_sync);
assert_eq!(
balance_0.base_coin().available(),
balance_0_sync.base_coin().available()
);

wallet_0
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
.await?;

// Balance should have transferred entirely
let balance_1_sync = wallet_1.sync(None).await?;
// Available balance should have transferred entirely
let balance_1 = wallet_1.sync(None).await?;
assert!(balance_1.base_coin().available() > 0);
assert_eq!(balance_1, balance_1_sync);

tear_down(storage_path_0)?;
tear_down(storage_path_1)?;
Expand Down
Loading
Loading