diff --git a/integration_tests/tests/pinata.rs b/integration_tests/tests/pinata.rs index fa4c3d98..0c17e40f 100644 --- a/integration_tests/tests/pinata.rs +++ b/integration_tests/tests/pinata.rs @@ -9,7 +9,7 @@ use std::time::Duration; use anyhow::{Context as _, Result}; use integration_tests::{ TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, private_mention, public_mention, - verify_commitment_is_in_state, + verify_commitment_is_in_state, wait_for_indexer_to_catch_up, }; use log::info; use sequencer_service_rpc::RpcClient as _; @@ -164,6 +164,41 @@ async fn claim_pinata_to_existing_public_account() -> Result<()> { Ok(()) } +#[test] +async fn claim_pinata_indexer_keeps_up() -> Result<()> { + let mut ctx = TestContext::new().await?; + + let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim { + to: public_mention(ctx.existing_public_accounts()[0]), + }); + + wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?; + + info!("Waiting for next block creation"); + tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await; + + info!("Waiting for indexer to parse blocks"); + wait_for_indexer_to_catch_up(&ctx).await?; + + let winner_ind_state = indexer_service_rpc::RpcClient::get_account( + &**ctx.indexer_client(), + ctx.existing_public_accounts()[0].into(), + ) + .await + .unwrap(); + let winner_seq_state = sequencer_service_rpc::RpcClient::get_account( + ctx.sequencer_client(), + ctx.existing_public_accounts()[0], + ) + .await?; + + assert_eq!(winner_ind_state, winner_seq_state.into()); + + info!("Indexer correctly indexed the pinata claim"); + + Ok(()) +} + #[test] async fn claim_pinata_to_existing_private_account() -> Result<()> { let mut ctx = TestContext::new().await?; diff --git a/lez/indexer/core/Cargo.toml b/lez/indexer/core/Cargo.toml index 758acdd6..2ae2d9c0 100644 --- a/lez/indexer/core/Cargo.toml +++ b/lez/indexer/core/Cargo.toml @@ -7,6 +7,10 @@ license = { workspace = true } [lints] workspace = true +[features] +default = [] +testnet = [] + [dependencies] common.workspace = true logos-blockchain-zone-sdk.workspace = true diff --git a/lez/indexer/core/src/block_store.rs b/lez/indexer/core/src/block_store.rs index f00c94c5..9d17109c 100644 --- a/lez/indexer/core/src/block_store.rs +++ b/lez/indexer/core/src/block_store.rs @@ -23,7 +23,12 @@ impl IndexerStore { /// Starting database at the start of new chain. /// Creates files if necessary. pub fn open_db(location: &Path) -> Result { + #[cfg(not(feature = "testnet"))] let initial_state = testnet_initial_state::initial_state(); + + #[cfg(feature = "testnet")] + let initial_state = testnet_initial_state::initial_state_testnet(); + let dbio = RocksDBIO::open_or_create(location, &initial_state)?; let current_state = dbio.final_state()?; diff --git a/lez/indexer/ffi/Cargo.toml b/lez/indexer/ffi/Cargo.toml index a1615b75..6b74ab8b 100644 --- a/lez/indexer/ffi/Cargo.toml +++ b/lez/indexer/ffi/Cargo.toml @@ -6,7 +6,7 @@ version = "0.1.0" [dependencies] lee.workspace = true -indexer_core.workspace = true +indexer_core = { workspace = true, features = ["testnet"] } indexer_service_protocol = { workspace = true, features = ["convert"] } env_logger.workspace = true diff --git a/lez/indexer/service/Cargo.toml b/lez/indexer/service/Cargo.toml index a07a2285..44ab7068 100644 --- a/lez/indexer/service/Cargo.toml +++ b/lez/indexer/service/Cargo.toml @@ -10,7 +10,7 @@ workspace = true [dependencies] indexer_service_protocol = { workspace = true, features = ["convert"] } indexer_service_rpc = { workspace = true, features = ["server"] } -indexer_core.workspace = true +indexer_core = { workspace = true, features = ["testnet"] } clap = { workspace = true, features = ["derive"] } anyhow.workspace = true