Skip to content

Commit

Permalink
Simplify once_prepare_addr_with_iota_and_custom_coins, reorder modu…
Browse files Browse the repository at this point in the history
…les in main.rs
  • Loading branch information
tomxey committed Oct 28, 2024
1 parent 447e7ad commit df6b53c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
59 changes: 29 additions & 30 deletions crates/iota-indexer/tests/rpc-tests/coin_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::{path::PathBuf, str::FromStr, sync::OnceLock};
use std::{path::PathBuf, str::FromStr};

use iota_indexer::store::PgIndexerStore;
use iota_json::{call_args, type_args};
Expand All @@ -24,44 +24,43 @@ use iota_types::{
};
use jsonrpsee::http_client::HttpClient;
use test_cluster::TestCluster;
use tokio::sync::Mutex;
use tokio::sync::OnceCell;

use crate::common::{ApiTestSetup, indexer_wait_for_object};

static COMMON_TESTING_ADDR_AND_CUSTOM_COIN_NAME: OnceLock<Mutex<Option<(IotaAddress, String)>>> =
OnceLock::new();
static COMMON_TESTING_ADDR_AND_CUSTOM_COIN_NAME: OnceCell<(IotaAddress, String)> =
OnceCell::const_new();

async fn once_prepare_addr_with_iota_and_custom_coins(
cluster: &TestCluster,
store: &PgIndexerStore,
) -> (IotaAddress, String) {
let addr_and_coin_mutex =
COMMON_TESTING_ADDR_AND_CUSTOM_COIN_NAME.get_or_init(|| Mutex::new(None));
let mut addr_and_coin = addr_and_coin_mutex.lock().await;

if addr_and_coin.is_none() {
let (address, keypair): (_, AccountKeyPair) = get_key_pair();

for _ in 0..5 {
cluster
.fund_address_and_return_gas(
cluster.get_reference_gas_price().await,
Some(500_000_000),
address,
)
COMMON_TESTING_ADDR_AND_CUSTOM_COIN_NAME
.get_or_init(|| async {
let (address, keypair): (_, AccountKeyPair) = get_key_pair();

for _ in 0..5 {
cluster
.fund_address_and_return_gas(
cluster.get_reference_gas_price().await,
Some(500_000_000),
address,
)
.await;
}

let (coin_name, coin_object_ref) =
create_and_mint_trusted_coin(cluster, address, keypair, 100_000)
.await
.unwrap();

indexer_wait_for_object(store, coin_object_ref.object_id, coin_object_ref.version)
.await;
}

let (coin_name, coin_object_ref) = create_and_mint_coin(cluster, address, keypair, 100_000)
.await
.unwrap();

indexer_wait_for_object(store, coin_object_ref.object_id, coin_object_ref.version).await;

*addr_and_coin = Some((address, coin_name));
}

addr_and_coin.clone().unwrap()
(address, coin_name)
})
.await
.clone()
}

#[test]
Expand Down Expand Up @@ -405,7 +404,7 @@ async fn call_get_total_supply_fullnode_indexer(
(result_fullnode, result_indexer)
}

async fn create_and_mint_coin(
async fn create_and_mint_trusted_coin(
cluster: &TestCluster,
address: IotaAddress,
account_keypair: AccountKeyPair,
Expand Down
6 changes: 3 additions & 3 deletions crates/iota-indexer/tests/rpc-tests/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[cfg(feature = "shared_test_runtime")]
mod coin_api;

#[allow(dead_code)]
#[path = "../common/mod.rs"]
mod common;
Expand All @@ -14,8 +17,5 @@ mod indexer_api;
#[cfg(feature = "shared_test_runtime")]
mod read_api;

#[cfg(feature = "shared_test_runtime")]
mod coin_api;

#[cfg(feature = "shared_test_runtime")]
mod write_api;

0 comments on commit df6b53c

Please sign in to comment.