Skip to content

Commit 1a171a7

Browse files
committed
tests: Include test of catching incompatible block handler functions
1 parent a9b4b15 commit 1a171a7

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed

tests/cli/validation.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,13 @@ describe('Validation', () => {
197197
exitCode: 1,
198198
},
199199
)
200+
201+
cliTest(
202+
'Block handler with incompatible mapping function',
203+
['codegen', '--skip-migrations'],
204+
'validation/block-handler-with-incompatible-mapping-function',
205+
{
206+
exitCode: 1,
207+
},
208+
)
200209
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
- Load subgraph from subgraph.yaml
2+
✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml:
3+
4+
Path: dataSources > 0 > blockHandlers > 0
5+
Matching mapping handler not found in './mapping.ts' for blockHandler: 'handleBlock'.
6+
Signature:
7+
handleBlock(block: ethereum.BlockWithTransactions): void
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"type": "event",
4+
"name": "ExampleEvent",
5+
"inputs": [{ "type": "string" }]
6+
}
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ethereum } from '@graphprotocol/graph-ts'
2+
import { ExampleBlockEntity } from './generated/schema'
3+
4+
export function handleBlock(block: ethereum.BlockWithReceipts): void {
5+
let entity = new ExampleBlockEntity(block.hash.toHexString())
6+
entity.number = block.number
7+
entity.hash = block.hash
8+
entity.save()
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type ExampleBlockEntity @entity {
2+
id: ID!
3+
number: BigInt!
4+
hash: Bytes!
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
specVersion: 0.0.1
2+
schema:
3+
file: ./schema.graphql
4+
dataSources:
5+
- kind: ethereum/contract
6+
name: ExampleSubgraph
7+
network: mainnet
8+
source:
9+
abi: ExampleContract
10+
mapping:
11+
kind: ethereum/events
12+
apiVersion: 0.0.1
13+
language: wasm/assemblyscript
14+
file: ./mapping.ts
15+
entities:
16+
- ExampleBlockEntity
17+
abis:
18+
- name: ExampleContract
19+
file: ./Abi.json
20+
blockHandlers:
21+
- handler: handleBlock
22+
blockFormat: block-with-transactions

0 commit comments

Comments
 (0)