Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 4299672

Browse files
committed
Update private tangle tests so they work with 2.0
1 parent faafb1a commit 4299672

File tree

17 files changed

+449
-327
lines changed

17 files changed

+449
-327
lines changed

.github/workflows/private-tangle-tests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ jobs:
6565
uses: "./.github/actions/ledger-nano"
6666

6767
- name: Run tests
68-
run: |
69-
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
70-
# TODO: change in the future to run all tests and not only test_get_info
71-
# cargo ci-tangle-test
68+
run: cargo ci-tangle-test
7269

7370
- name: Tear down private tangle
7471
if: always()

bindings/core/tests/combined.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,13 @@ async fn client_from_wallet() -> Result<(), Error> {
9595
.build()
9696
.await?;
9797

98-
// TODO reenable
99-
// // Send ClientMethod via the client from the wallet
100-
// let response = wallet
101-
// .client()
102-
// .call_method(ClientMethod::GetHealth)
103-
// .await;
104-
105-
// match response {
106-
// Response::Bool(_) => {}
107-
// _ => panic!("unexpected response {response:?}"),
108-
// }
98+
// Send ClientMethod via the client from the wallet
99+
let response = wallet.client().call_method(ClientMethod::GetNodeInfo).await;
100+
101+
match response {
102+
Response::NodeInfo(_) => {}
103+
_ => panic!("unexpected response {response:?}"),
104+
}
109105

110106
std::fs::remove_dir_all(storage_path).ok();
111107
Ok(())

sdk/src/types/block/output/basic.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,9 @@ mod tests {
517517

518518
use super::*;
519519
use crate::types::block::{
520-
output::{basic::dto::BasicOutputDto, FoundryId, SimpleTokenScheme, TokenId},
520+
output::basic::dto::BasicOutputDto,
521521
protocol::iota_mainnet_protocol_parameters,
522-
rand::{
523-
address::rand_account_address,
524-
output::{
525-
feature::rand_allowed_features, rand_basic_output, unlock_condition::rand_address_unlock_condition,
526-
},
527-
},
522+
rand::output::{rand_basic_output, unlock_condition::rand_address_unlock_condition},
528523
};
529524

530525
#[test]

sdk/tests/client/common/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

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

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

88
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";

sdk/tests/client/node_api/core.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ async fn test_get_issuance() {
5555
#[ignore]
5656
#[tokio::test]
5757
async fn test_post_block_with_tagged_data() {
58-
let secret_manager = setup_secret_manager();
59-
let block_id = setup_tagged_data_block(&secret_manager).await;
58+
let block_id = setup_tagged_data_block().await.unwrap();
6059
println!("{block_id}");
6160
}
6261

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

77-
let block_id = setup_tagged_data_block(&secret_manager).await;
75+
let block_id = setup_tagged_data_block().await.unwrap();
7876
let r = client.get_block(&block_id).await.unwrap();
7977

8078
println!("{r:#?}");
@@ -83,8 +81,7 @@ async fn test_get_block_data() {
8381
#[ignore]
8482
#[tokio::test]
8583
async fn test_get_block_metadata() {
86-
let secret_manager = setup_secret_manager();
87-
let block_id = setup_tagged_data_block(&secret_manager).await;
84+
let block_id = setup_tagged_data_block().await.unwrap();
8885

8986
let r = setup_client_with_node_health_ignored()
9087
.await
@@ -98,8 +95,7 @@ async fn test_get_block_metadata() {
9895
#[ignore]
9996
#[tokio::test]
10097
async fn test_get_block_raw() {
101-
let secret_manager = setup_secret_manager();
102-
let block_id = setup_tagged_data_block(&secret_manager).await;
98+
let block_id = setup_tagged_data_block().await.unwrap();
10399

104100
let r = setup_client_with_node_health_ignored()
105101
.await
@@ -201,7 +197,7 @@ async fn test_call_plugin_route() {
201197

202198
// we call the "custom" plugin "node info"
203199
let plugin_res: NodeInfoResponse = c
204-
.call_plugin_route("api/core/v2/", "GET", "info", vec![], None)
200+
.call_plugin_route("api/core/v3/", "GET", "info", vec![], None)
205201
.await
206202
.unwrap();
207203

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

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

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

233229
assert_eq!(metadata_response.block_id, block_id);
234-
assert_eq!(metadata_response.block_state, BlockState::Finalized);
230+
match metadata_response.block_state {
231+
BlockState::Accepted | BlockState::Confirmed | BlockState::Finalized => {}
232+
_ => panic!("block state is not accepted/confirmed/finalized"),
233+
}
235234

236235
println!("{metadata_response:#?}");
237236
}

sdk/tests/client/node_api/mod.rs

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ use iota_sdk::{
1111
client::{
1212
api::GetAddressesOptions,
1313
constants::IOTA_COIN_TYPE,
14+
generate_mnemonic,
1415
node_api::indexer::query_parameters::BasicOutputQueryParameters,
1516
request_funds_from_faucet,
16-
secret::{SecretManager, SignBlock},
17+
secret::{mnemonic::MnemonicSecretManager, SecretManager, SignBlock},
1718
Client,
1819
},
1920
types::block::{
21+
address::{Address, Bech32Address, ImplicitAccountCreationAddress},
2022
output::AccountId,
2123
payload::{signed_transaction::TransactionId, tagged_data::TaggedDataPayload, Payload},
2224
BlockId,
@@ -28,25 +30,64 @@ use crate::client::common::{setup_client_with_node_health_ignored, FAUCET_URL};
2830
// THIS SEED SERVES FOR TESTING PURPOSES! DON'T USE THIS SEED IN PRODUCTION!
2931
const DEFAULT_DEVELOPMENT_SEED: &str = "0x256a818b2aac458941f7274985a410e57fb750f3a3a67969ece5bd9ae7eef5b2";
3032

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

35-
let protocol_params = client.get_protocol_parameters().await.unwrap();
37+
let secret_manager = SecretManager::Mnemonic(MnemonicSecretManager::try_from_mnemonic(generate_mnemonic()?)?);
38+
39+
let bech32_hrp = client.get_bech32_hrp().await?;
40+
41+
let address = secret_manager
42+
.generate_ed25519_address(IOTA_COIN_TYPE, 0, 0, bech32_hrp, None)
43+
.await?;
44+
let address =
45+
Address::ImplicitAccountCreation(ImplicitAccountCreationAddress::new(**address.into_inner().as_ed25519()));
46+
let bech32_address = Bech32Address::new(bech32_hrp, address);
47+
48+
request_funds_from_faucet(FAUCET_URL, &bech32_address).await?;
3649

37-
client
50+
let mut account_id = AccountId::null();
51+
// Continue only after funds are received
52+
for i in 0..30 {
53+
let output_ids = client
54+
.basic_output_ids(BasicOutputQueryParameters::only_address_unlock_condition(
55+
bech32_address.clone(),
56+
))
57+
.await?
58+
.items;
59+
if !output_ids.is_empty() {
60+
account_id = AccountId::from(&output_ids[0]);
61+
break;
62+
}
63+
if i == 29 {
64+
panic!("Faucet no longer wants to hand over coins");
65+
}
66+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
67+
}
68+
// Wait until account is read to issue blocks
69+
for _ in 0..60 {
70+
if let Ok(_r) = client.get_account_congestion(&account_id, None).await {
71+
break;
72+
}
73+
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
74+
}
75+
76+
let block = client
3877
.build_basic_block(
39-
AccountId::null(),
78+
account_id,
4079
Some(Payload::TaggedData(Box::new(
4180
TaggedDataPayload::new(b"Hello".to_vec(), b"Tangle".to_vec()).unwrap(),
4281
))),
4382
)
4483
.await
4584
.unwrap()
46-
.sign_ed25519(secret_manager, Bip44::new(IOTA_COIN_TYPE))
47-
.await
48-
.unwrap()
49-
.id(&protocol_params)
85+
.sign_ed25519(&secret_manager, Bip44::new(IOTA_COIN_TYPE))
86+
.await?;
87+
client.post_block(&block).await?;
88+
89+
let protocol_params = client.get_protocol_parameters().await.unwrap();
90+
Ok(block.id(&protocol_params))
5091
}
5192

5293
pub fn setup_secret_manager() -> SecretManager {

sdk/tests/client/secret_manager/address_generation.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@
33

44
#[cfg(feature = "stronghold")]
55
use crypto::keys::bip39::Mnemonic;
6-
use crypto::keys::bip44::Bip44;
6+
#[cfg(feature = "ledger_nano")]
7+
use iota_sdk::client::secret::ledger_nano::LedgerSecretManager;
78
#[cfg(feature = "stronghold")]
89
use iota_sdk::client::secret::stronghold::StrongholdSecretManager;
9-
#[cfg(feature = "ledger_nano")]
10-
use iota_sdk::client::secret::{ledger_nano::LedgerSecretManager, GenerateAddressOptions};
11-
#[cfg(feature = "events")]
12-
use iota_sdk::wallet::events::{WalletEvent, WalletEventType};
1310
use iota_sdk::{
1411
client::{
15-
api::GetAddressesOptions,
1612
constants::{IOTA_COIN_TYPE, SHIMMER_COIN_TYPE},
1713
secret::{mnemonic::MnemonicSecretManager, SecretManager},
1814
ClientError,
1915
},
20-
types::block::address::{Hrp, ToBech32Ext},
21-
wallet::{ClientOptions, Wallet},
16+
types::block::address::ToBech32Ext,
2217
};
2318
use pretty_assertions::assert_eq;
2419

25-
use crate::client::common::{setup, tear_down, DEFAULT_MNEMONIC, NODE_LOCAL};
20+
use crate::client::common::{setup, tear_down, DEFAULT_MNEMONIC};
2621

2722
#[tokio::test]
2823
async fn address_generation_mnemonic() -> Result<(), Box<dyn std::error::Error>> {

sdk/tests/client/secret_manager/mnemonic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use iota_sdk::client::{
5-
api::GetAddressesOptions,
65
constants::{SHIMMER_COIN_TYPE, SHIMMER_TESTNET_BECH32_HRP},
76
secret::SecretManager,
87
ClientError,

sdk/tests/client/secret_manager/stronghold.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
use iota_sdk::client::{
5-
api::GetAddressesOptions,
65
constants::{SHIMMER_COIN_TYPE, SHIMMER_TESTNET_BECH32_HRP},
76
secret::SecretManager,
87
ClientError,

sdk/tests/wallet/balance.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {
141141

142142
request_funds(&wallet_0).await?;
143143

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

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

206-
// It's possible to send the expired output
207-
let outputs = [BasicOutputBuilder::new_with_amount(1_000_000)
208-
// Send to wallet 1 with expiration to wallet 2, both have no amount yet
209-
.with_unlock_conditions([AddressUnlockCondition::new(wallet_1.address().await)])
210-
.finish_output()?];
211-
let _tx = wallet_2.send_outputs(outputs, None).await?;
212-
213206
tear_down(storage_path_0)?;
214207
tear_down(storage_path_1)?;
215208
tear_down(storage_path_2)?;
@@ -218,7 +211,7 @@ async fn balance_expiration() -> Result<(), Box<dyn std::error::Error>> {
218211

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

230223
request_funds(&wallet_0).await?;
231224

232-
let balance_0 = wallet_0.balance().await?;
233-
let balance_0_sync = wallet_0.sync(None).await?;
225+
let balance_0 = wallet_0.sync(None).await?;
234226
let to_send = balance_0.base_coin().available();
235227

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

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

247-
// Balance should update without sync
238+
// Available balance should update without sync
248239
let balance_0 = wallet_0.balance().await?;
249240
let balance_0_sync = wallet_0.sync(None).await?;
250241
assert_eq!(balance_0.base_coin().available(), 0);
251-
assert_eq!(balance_0, balance_0_sync);
242+
assert_eq!(
243+
balance_0.base_coin().available(),
244+
balance_0_sync.base_coin().available()
245+
);
252246

253247
wallet_0
254248
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
255249
.await?;
256250

257-
// Balance should have transferred entirely
258-
let balance_1_sync = wallet_1.sync(None).await?;
251+
// Available balance should have transferred entirely
252+
let balance_1 = wallet_1.sync(None).await?;
259253
assert!(balance_1.base_coin().available() > 0);
260-
assert_eq!(balance_1, balance_1_sync);
261254

262255
tear_down(storage_path_0)?;
263256
tear_down(storage_path_1)?;

0 commit comments

Comments
 (0)