Skip to content

Commit

Permalink
Fix StructTag conversion for iotax_queryEvents Indexer-RPC method (
Browse files Browse the repository at this point in the history
…#4289)

* fix: convert the struct tag into a complete canonical string in order for the indexer's `MoveEventType` filter to work

* fix: clippy
  • Loading branch information
samuel-rufi authored Nov 28, 2024
1 parent 3ff8bf8 commit b627c88
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/iota-indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,8 @@ impl<U: R2D2Connection> IndexerReader<U> {
)
}
EventFilter::MoveEventType(struct_tag) => {
format!("event_type = '{}'", struct_tag)
let formatted_struct_tag = struct_tag.to_canonical_string(true);
format!("event_type = '{formatted_struct_tag}'")
}
EventFilter::MoveEventModule { package, module } => {
let package_module_prefix = format!("{}::{}", package.to_hex_literal(), module);
Expand Down
32 changes: 32 additions & 0 deletions crates/iota-indexer/tests/rpc-tests/indexer_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,38 @@ fn query_events_supported_events() {
});
}

#[test]
fn query_validator_epoch_info_event() {
let ApiTestSetup {
runtime,
store,
client,
cluster,
} = ApiTestSetup::get_or_init();

runtime.block_on(async move {
indexer_wait_for_checkpoint(store, 1).await;

cluster.force_new_epoch().await;

let result = client.query_events(EventFilter::MoveEventType("0x0000000000000000000000000000000000000000000000000000000000000003::validator_set::ValidatorEpochInfoEventV1".parse().unwrap()), None, None, None).await;
assert!(result.is_ok());
assert!(!result.unwrap().data.is_empty());

let result = client.query_events(EventFilter::MoveEventType("0x3::validator_set::ValidatorEpochInfoEventV1".parse().unwrap()), None, None, None).await;
assert!(result.is_ok());
assert!(!result.unwrap().data.is_empty());

let result = client.query_events(EventFilter::MoveEventType("0x0003::validator_set::ValidatorEpochInfoEventV1".parse().unwrap()), None, None, None).await;
assert!(result.is_ok());
assert!(!result.unwrap().data.is_empty());

let result = client.query_events(EventFilter::MoveEventType("0x1::validator_set::ValidatorEpochInfoEventV1".parse().unwrap()), None, None, None).await;
assert!(result.is_ok());
assert!(result.unwrap().data.is_empty());
});
}

#[test]
fn test_get_owned_objects() -> Result<(), anyhow::Error> {
let ApiTestSetup {
Expand Down

0 comments on commit b627c88

Please sign in to comment.