From b627c887c0a23ae6dacbcd42b4a00d2a2f2c724d Mon Sep 17 00:00:00 2001 From: Samuel Rufinatscha Date: Thu, 28 Nov 2024 15:09:18 +0100 Subject: [PATCH] Fix `StructTag` conversion for `iotax_queryEvents` Indexer-RPC method (#4289) * fix: convert the struct tag into a complete canonical string in order for the indexer's `MoveEventType` filter to work * fix: clippy --- crates/iota-indexer/src/indexer_reader.rs | 3 +- .../tests/rpc-tests/indexer_api.rs | 32 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/iota-indexer/src/indexer_reader.rs b/crates/iota-indexer/src/indexer_reader.rs index 3915588184f..1fa26c1969c 100644 --- a/crates/iota-indexer/src/indexer_reader.rs +++ b/crates/iota-indexer/src/indexer_reader.rs @@ -1161,7 +1161,8 @@ impl IndexerReader { ) } 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); diff --git a/crates/iota-indexer/tests/rpc-tests/indexer_api.rs b/crates/iota-indexer/tests/rpc-tests/indexer_api.rs index c830f7ae7a7..49f4e35ff80 100644 --- a/crates/iota-indexer/tests/rpc-tests/indexer_api.rs +++ b/crates/iota-indexer/tests/rpc-tests/indexer_api.rs @@ -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 {