Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sui-indexer): Fix StructTag conversion for suix_queryEvents Indexer-RPC method #20467

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion crates/sui-indexer/src/indexer_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,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}'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small tweak here -- we can use to_canonical_display to avoid materializing to an intermediate string.

Suggested change
let formatted_struct_tag = struct_tag.to_canonical_string(true);
format!("event_type = '{formatted_struct_tag}'")
format!(
"event_type = '{}'",
struct_tag.to_canonical_display(/* with_prefix */ true),
)

Copy link
Contributor Author

@samuel-rufi samuel-rufi Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @amnn thanks very much for your response and suggestion, will keep this in mind! 🙏

}
EventFilter::MoveEventModule { package, module } => {
let package_module_prefix = format!("{}::{}", package.to_hex_literal(), module);
Expand Down
58 changes: 58 additions & 0 deletions crates/sui-indexer/tests/json_rpc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,61 @@ async fn test_events() -> Result<(), anyhow::Error> {

Ok(())
}

#[tokio::test]
async fn test_event_type_filter() {
let cluster = TestClusterBuilder::new()
.with_indexer_backed_rpc()
.build()
.await;

let client = cluster.rpc_client();

cluster.trigger_reconfiguration().await;

let result = client.query_events(EventFilter::MoveEventType("0x0000000000000000000000000000000000000000000000000000000000000003::validator_set::ValidatorEpochInfoEventV2".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::ValidatorEpochInfoEventV2"
.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::ValidatorEpochInfoEventV2"
.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::ValidatorEpochInfoEventV2"
.parse()
.unwrap(),
),
None,
None,
None,
)
.await;
assert!(result.is_ok());
assert!(result.unwrap().data.is_empty());
}
Loading