Skip to content

Commit

Permalink
add a test case for the indexmetadataentity trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
lostman committed Aug 29, 2023
1 parent bad76f5 commit badf8c3
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions packages/fuel-indexer-tests/tests/web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::time::{SystemTime, UNIX_EPOCH};

use fuel_indexer_database::queries::last_block_height_for_indexer;
use fuel_indexer_database::IndexerConnection;
use fuel_indexer_tests::fixtures::{
mock_request, setup_indexing_test_components, IndexingTestComponents,
};

const SIGNATURE: &str = "cb19384361af5dd7fec2a0052ca49d289f997238ea90590baf47f16ff0a33fb20170a43bd20208ce16daf443bad06dd66c1d1bf73f48b5ae53de682a5731d7d9";
const NONCE: &str = "ea35be0c98764e7ca06d02067982e3b4";

Expand Down Expand Up @@ -296,3 +302,82 @@ async fn test_querying_sql_endpoint_when_sql_is_enabled_returns_error_for_non_su

server.abort();
}

#[actix_web::test]
async fn test_ensure_no_missing_blocks() {
let config = IndexerConfig {
replace_indexer: true,
..IndexerConfig::default()
};

let IndexingTestComponents {
node,
manifest,
db,
..
} = setup_indexing_test_components(Some(config)).await;

node.abort();

let mut conn =
IndexerConnection::Postgres(Box::new(db.pool.acquire().await.unwrap()));

// Allow the indexer to start and process blocks.
tokio::time::sleep(std::time::Duration::from_secs(2)).await;

let last = last_block_height_for_indexer(
&mut conn,
manifest.namespace(),
manifest.identifier(),
)
.await
.unwrap();

assert_eq!(last, 1);

// Add three more blocks.
mock_request("/block").await;
mock_request("/block").await;
mock_request("/block").await;

let last = last_block_height_for_indexer(
&mut conn,
manifest.namespace(),
manifest.identifier(),
)
.await
.unwrap();

assert_eq!(last, 4);

let mut conn2 = db.pool.acquire().await.unwrap();

// Remove the last entry in the indexmetadataentity table. This will cause a
// gap in block heights and when the indexer tries to insert the entry for
// the next block, the trigger will raise an exception.
postgres::execute_query(
&mut conn2,
format!(
"DELETE FROM {}_{}.indexmetadataentity WHERE block_height = {}",
manifest.namespace(),
manifest.identifier(),
4
),
)
.await.unwrap();

// Trigger the next block #5.
mock_request("/block").await;

let last = last_block_height_for_indexer(
&mut conn,
manifest.namespace(),
manifest.identifier(),
)
.await
.unwrap();

// The indexer did not process block #5 and we save removed the entry for
// block #4, so the last height is #3.
assert_eq!(last, 3);
}

0 comments on commit badf8c3

Please sign in to comment.