Skip to content

Commit 1ff44c6

Browse files
committed
tests: fix failing tests
1 parent 653eee5 commit 1ff44c6

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

graph/src/blockchain/block_stream.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,14 @@ impl<C: Blockchain> TriggersAdapterWrapper<C> {
357357
SubgraphTriggerScanRange::Range(from, to) => {
358358
let hash_to_entities = self.fetch_entities_for_filters(filters, from, to).await?;
359359

360-
let block_numbers = hash_to_entities
360+
// Get block numbers that have entities
361+
let mut block_numbers: BTreeSet<_> = hash_to_entities
361362
.iter()
362363
.flat_map(|(_, entities, _)| entities.keys().copied())
363-
.collect::<BTreeSet<_>>();
364+
.collect();
365+
366+
// Always include the last block in the range
367+
block_numbers.insert(to);
364368

365369
let blocks = self
366370
.adapter

graph/tests/subgraph_datasource_tests.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ async fn test_triggers_adapter_with_entities() {
201201
assert!(result.is_ok(), "Failed to get triggers: {:?}", result.err());
202202
let blocks = result.unwrap();
203203

204-
assert_eq!(blocks.len(), 3, "Should have found three blocks");
204+
assert_eq!(
205+
blocks.len(),
206+
3,
207+
"Should have found blocks with entities plus the last block"
208+
);
205209

206210
let block1 = &blocks[0];
207211
assert_eq!(block1.block.number(), 1, "First block should be number 1");
@@ -248,4 +252,13 @@ async fn test_triggers_adapter_with_entities() {
248252
} else {
249253
panic!("Expected subgraph trigger");
250254
}
255+
256+
let block3 = &blocks[2];
257+
assert_eq!(block3.block.number(), 3, "Third block should be number 3");
258+
let triggers3 = &block3.trigger_data;
259+
assert_eq!(
260+
triggers3.len(),
261+
0,
262+
"Block 3 should have no triggers but be included as it's the last block"
263+
);
251264
}

tests/integration-tests/subgraph-data-sources/src/mapping.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Entity, log, store, BigInt, EntityTrigger, EntityOp } from '@graphprotocol/graph-ts';
2-
import { Block } from '../generated/subgraph-Qmaqf8cRxfxbduZppSHKG9DMuX5JZPMoGuwGb2DQuo48sq';
2+
import { Block } from '../generated/subgraph-QmQCiSBooPHZTrqxJknG9W1YJ8EZXj8c8baFs24eY9pXM8';
33
import { MirrorBlock } from '../generated/schema';
44

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

0 commit comments

Comments
 (0)