Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions integration_tests/tests/features/indexer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Feature: Indexer node
Then I wait for the indexer INDEXER to sync with the network

# Scan the network for the event emitted on ACC creation
When indexer INDEXER scans the network events for account ACC with topics std.component.created,std.vault.pay_fee,std.component.updated
When indexer INDEXER scans the network events for account ACC with topics std.component.created,Account.pay_fee,std.component.updated

Scenario: Indexer GraphQL requests work
# Initialize a base node, wallet, miner and VN
Expand All @@ -75,10 +75,10 @@ Feature: Indexer node
Then I wait for the indexer INDEXER to sync with the network
##### Scenario
# Scan the network for the event emitted on ACC_1 creation
When indexer INDEXER scans the network events for account ACC_1 with topics std.component.created,std.vault.pay_fee
When indexer INDEXER scans the network events for account ACC_1 with topics std.component.created,Account.pay_fee

# Scan the network for the event emitted on ACC_2 creation
When indexer INDEXER scans the network events for account ACC_2 with topics std.component.created,std.vault.pay_fee
When indexer INDEXER scans the network events for account ACC_2 with topics std.component.created,Account.pay_fee

Scenario: Indexer GraphQL filtering and pagination of events
Given a network with registered validator VN and wallet daemon WALLET_D
Expand Down
62 changes: 39 additions & 23 deletions integration_tests/tests/steps/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,30 +109,46 @@ async fn indexer_scans_network_events(
let account = world.wallet_accounts.get(&account_name).unwrap_or_else(|| {
panic!("No wallet account found with name {}", account_name);
});
let mut graphql_client = indexer.get_graphql_indexer_client().await;
let query = r#"{ getEvents { substateId, templateAddress, txHash, topic, payload } }"#.to_string();
let res = graphql_client
.send_request::<HashMap<String, Vec<tari_indexer::graphql::model::events::Event>>>(&query, None, None)
.await
.expect("Failed to obtain getEvents query result");
let component_address = account.component_address().to_string();
let expected_topics: Vec<&str> = topics_str.split(',').collect();

let events = res.get("getEvents").unwrap();
let topics_for_component = events
.iter()
.filter(|e| e.substate_id == Some(account.component_address().to_string()))
.map(|e| e.topic.as_str())
.collect::<HashSet<_>>();

let expected_topics = topics_str.split(',');
for (ind, topic) in expected_topics.enumerate() {
assert!(
topics_for_component.contains(topic),
"Unexpected topic at index {}. Events emitted were {}. Expected topic {} (ALL {:?})",
ind,
topics_for_component.display(),
topic,
events
);
let mut remaining = 30;
loop {
let mut graphql_client = indexer.get_graphql_indexer_client().await;
let query = r#"{ getEvents { substateId, templateAddress, txHash, topic, payload } }"#.to_string();
let res = graphql_client
.send_request::<HashMap<String, Vec<tari_indexer::graphql::model::events::Event>>>(&query, None, None)
.await
.expect("Failed to obtain getEvents query result");

let events = res.get("getEvents").unwrap();
let topics_for_component = events
.iter()
.filter(|e| e.substate_id == Some(component_address.clone()))
.map(|e| e.topic.as_str())
.collect::<HashSet<_>>();

let all_found = expected_topics.iter().all(|topic| topics_for_component.contains(topic));
if all_found {
return;
}

if remaining == 0 {
// Report which topics were missing
for (ind, topic) in expected_topics.iter().enumerate() {
assert!(
topics_for_component.contains(topic),
"Unexpected topic at index {}. Events emitted were {}. Expected topic {} (ALL {:?})",
ind,
topics_for_component.display(),
topic,
events
);
}
unreachable!();
}
remaining -= 1;
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
}

Expand Down