Skip to content

Commit

Permalink
tests: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
incrypto32 committed Jan 13, 2025
1 parent a090a95 commit f43bf1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 6 additions & 2 deletions graph/src/blockchain/block_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,14 @@ impl<C: Blockchain> TriggersAdapterWrapper<C> {
SubgraphTriggerScanRange::Range(from, to) => {
let hash_to_entities = self.fetch_entities_for_filters(filters, from, to).await?;

let block_numbers = hash_to_entities
// Get block numbers that have entities
let mut block_numbers: BTreeSet<_> = hash_to_entities
.iter()
.flat_map(|(_, entities, _)| entities.keys().copied())
.collect::<BTreeSet<_>>();
.collect();

// Always include the last block in the range
block_numbers.insert(to);

let blocks = self
.adapter
Expand Down
15 changes: 14 additions & 1 deletion graph/tests/subgraph_datasource_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ async fn test_triggers_adapter_with_entities() {
assert!(result.is_ok(), "Failed to get triggers: {:?}", result.err());
let blocks = result.unwrap();

assert_eq!(blocks.len(), 3, "Should have found three blocks");
assert_eq!(
blocks.len(),
3,
"Should have found blocks with entities plus the last block"
);

let block1 = &blocks[0];
assert_eq!(block1.block.number(), 1, "First block should be number 1");
Expand Down Expand Up @@ -248,4 +252,13 @@ async fn test_triggers_adapter_with_entities() {
} else {
panic!("Expected subgraph trigger");
}

let block3 = &blocks[2];
assert_eq!(block3.block.number(), 3, "Third block should be number 3");
let triggers3 = &block3.trigger_data;
assert_eq!(
triggers3.len(),
0,
"Block 3 should have no triggers but be included as it's the last block"
);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Entity, log, store, BigInt, EntityTrigger, EntityOp } from '@graphprotocol/graph-ts';
import { Block } from '../generated/subgraph-Qmaqf8cRxfxbduZppSHKG9DMuX5JZPMoGuwGb2DQuo48sq';
import { Block } from '../generated/subgraph-QmQCiSBooPHZTrqxJknG9W1YJ8EZXj8c8baFs24eY9pXM8';
import { MirrorBlock } from '../generated/schema';

export function handleEntity(trigger: EntityTrigger<Block>): void {
Expand Down

0 comments on commit f43bf1b

Please sign in to comment.