Skip to content

Commit

Permalink
iota-indexer: Add staking tests for TransactionBuilder API (#3836)
Browse files Browse the repository at this point in the history
* iota-indexer: Add staking tests for TransactionBuilder API

* Add comment for `stake_amount`, rename `cluster_builder_modifier`, test the Active status of stakes
  • Loading branch information
tomxey authored Nov 7, 2024
1 parent bfc8a32 commit 543cdf8
Show file tree
Hide file tree
Showing 3 changed files with 458 additions and 42 deletions.
29 changes: 7 additions & 22 deletions crates/iota-indexer/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use std::{
};

use diesel::PgConnection;
use iota_config::{
local_ip_utils::{get_available_port, new_local_tcp_socket_for_testing},
node::RunWithRange,
};
use iota_config::local_ip_utils::{get_available_port, new_local_tcp_socket_for_testing};
use iota_indexer::{
IndexerConfig,
errors::IndexerError,
Expand All @@ -26,7 +23,6 @@ use iota_metrics::init_metrics;
use iota_types::{
base_types::{ObjectID, SequenceNumber},
digests::TransactionDigest,
object::Object,
};
use jsonrpsee::{
http_client::{HttpClient, HttpClientBuilder},
Expand Down Expand Up @@ -58,12 +54,9 @@ impl ApiTestSetup {
GLOBAL_API_TEST_SETUP.get_or_init(|| {
let runtime = tokio::runtime::Runtime::new().unwrap();

let (cluster, store, client) =
runtime.block_on(start_test_cluster_with_read_write_indexer(
None,
Some("shared_test_indexer_db"),
None,
));
let (cluster, store, client) = runtime.block_on(
start_test_cluster_with_read_write_indexer(Some("shared_test_indexer_db"), None),
);

Self {
runtime,
Expand Down Expand Up @@ -117,24 +110,16 @@ impl SimulacrumTestSetup {
/// Start a [`TestCluster`][`test_cluster::TestCluster`] with a `Read` &
/// `Write` indexer
pub async fn start_test_cluster_with_read_write_indexer(
stop_cluster_after_checkpoint_seq: Option<u64>,
database_name: Option<&str>,
objects: Option<Vec<Object>>,
builder_modifier: Option<Box<dyn FnOnce(TestClusterBuilder) -> TestClusterBuilder>>,
) -> (TestCluster, PgIndexerStore<PgConnection>, HttpClient) {
let temp = tempdir().unwrap().into_path();
let mut builder = TestClusterBuilder::new().with_data_ingestion_dir(temp.clone());

// run the cluster until the declared checkpoint sequence number
if let Some(stop_cluster_after_checkpoint_seq) = stop_cluster_after_checkpoint_seq {
builder = builder.with_fullnode_run_with_range(Some(RunWithRange::Checkpoint(
stop_cluster_after_checkpoint_seq,
)));
if let Some(builder_modifier) = builder_modifier {
builder = builder_modifier(builder);
};

if let Some(objects) = objects {
builder = builder.with_objects(objects);
}

let cluster = builder.build().await;

// start indexer in write mode
Expand Down
22 changes: 8 additions & 14 deletions crates/iota-indexer/tests/rpc-tests/governance_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn test_staking() {

runtime.block_on(async move {
let (cluster, store, client) =
&start_test_cluster_with_read_write_indexer(None, Some("test_staking"), None).await;
&start_test_cluster_with_read_write_indexer(Some("test_staking"), None).await;

indexer_wait_for_checkpoint(store, 1).await;

Expand Down Expand Up @@ -107,7 +107,7 @@ fn test_unstaking() {

runtime.block_on(async move {
let (cluster, store, client) =
&start_test_cluster_with_read_write_indexer(None, Some("test_unstaking"), None).await;
&start_test_cluster_with_read_write_indexer(Some("test_unstaking"), None).await;

indexer_wait_for_checkpoint(store, 1).await;

Expand Down Expand Up @@ -210,12 +210,9 @@ fn test_timelocked_staking() {
let ApiTestSetup { runtime, .. } = ApiTestSetup::get_or_init();

runtime.block_on(async move {
let (cluster, store, client) = &start_test_cluster_with_read_write_indexer(
None,
Some("test_timelocked_staking"),
None,
)
.await;
let (cluster, store, client) =
&start_test_cluster_with_read_write_indexer(Some("test_timelocked_staking"), None)
.await;

indexer_wait_for_checkpoint(store, 1).await;

Expand Down Expand Up @@ -322,12 +319,9 @@ fn test_timelocked_unstaking() {
let ApiTestSetup { runtime, .. } = ApiTestSetup::get_or_init();

runtime.block_on(async move {
let (cluster, store, client) = &start_test_cluster_with_read_write_indexer(
None,
Some("test_timelocked_unstaking"),
None,
)
.await;
let (cluster, store, client) =
&start_test_cluster_with_read_write_indexer(Some("test_timelocked_unstaking"), None)
.await;

indexer_wait_for_checkpoint(store, 1).await;

Expand Down
Loading

0 comments on commit 543cdf8

Please sign in to comment.