Skip to content

Commit 4175720

Browse files
committed
ethereum: Test for eth_get_logs_filters
1 parent d5a03f4 commit 4175720

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

chain/ethereum/src/adapter.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,3 +741,59 @@ mod tests {
741741
);
742742
}
743743
}
744+
745+
// Tests `eth_get_logs_filters` in instances where all events are filtered on by all contracts.
746+
// This represents, for example, the relationship between dynamic data sources and their events.
747+
#[test]
748+
fn complete_log_filter() {
749+
use std::collections::BTreeSet;
750+
751+
// Test a few combinations of complete graphs.
752+
for i in [1, 2] {
753+
let events: BTreeSet<_> = (0..i).map(H256::from_low_u64_le).collect();
754+
755+
for j in [1, 1000, 2000, 3000] {
756+
let contracts: BTreeSet<_> = (0..j).map(Address::from_low_u64_le).collect();
757+
758+
// Construct the complete bipartite graph with i events and j contracts.
759+
let mut contracts_and_events_graph = GraphMap::new();
760+
for &contract in &contracts {
761+
for &event in &events {
762+
contracts_and_events_graph.add_edge(
763+
LogFilterNode::Contract(contract),
764+
LogFilterNode::Event(event),
765+
(),
766+
);
767+
}
768+
}
769+
770+
// Run `eth_get_logs_filters`, which is what we want to test.
771+
let logs_filters: Vec<_> = EthereumLogFilter {
772+
contracts_and_events_graph,
773+
wildcard_events: HashSet::new(),
774+
}
775+
.eth_get_logs_filters()
776+
.collect();
777+
778+
// Assert that a contract or event is filtered on iff it was present in the graph.
779+
assert_eq!(
780+
logs_filters
781+
.iter()
782+
.map(|l| l.contracts.iter())
783+
.flatten()
784+
.copied()
785+
.collect::<BTreeSet<_>>(),
786+
contracts
787+
);
788+
assert_eq!(
789+
logs_filters
790+
.iter()
791+
.map(|l| l.event_signatures.iter())
792+
.flatten()
793+
.copied()
794+
.collect::<BTreeSet<_>>(),
795+
events
796+
);
797+
}
798+
}
799+
}

0 commit comments

Comments
 (0)