Skip to content

Commit

Permalink
tests: Include test of catching incompatible block handler functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fordN committed Jul 16, 2020
1 parent a9b4b15 commit 1a171a7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/cli/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,13 @@ describe('Validation', () => {
exitCode: 1,
},
)

cliTest(
'Block handler with incompatible mapping function',
['codegen', '--skip-migrations'],
'validation/block-handler-with-incompatible-mapping-function',
{
exitCode: 1,
},
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Load subgraph from subgraph.yaml
✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml:

Path: dataSources > 0 > blockHandlers > 0
Matching mapping handler not found in './mapping.ts' for blockHandler: 'handleBlock'.
Signature:
handleBlock(block: ethereum.BlockWithTransactions): void
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "event",
"name": "ExampleEvent",
"inputs": [{ "type": "string" }]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ethereum } from '@graphprotocol/graph-ts'
import { ExampleBlockEntity } from './generated/schema'

export function handleBlock(block: ethereum.BlockWithReceipts): void {
let entity = new ExampleBlockEntity(block.hash.toHexString())
entity.number = block.number
entity.hash = block.hash
entity.save()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type ExampleBlockEntity @entity {
id: ID!
number: BigInt!
hash: Bytes!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
specVersion: 0.0.1
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: ExampleSubgraph
network: mainnet
source:
abi: ExampleContract
mapping:
kind: ethereum/events
apiVersion: 0.0.1
language: wasm/assemblyscript
file: ./mapping.ts
entities:
- ExampleBlockEntity
abis:
- name: ExampleContract
file: ./Abi.json
blockHandlers:
- handler: handleBlock
blockFormat: block-with-transactions

0 comments on commit 1a171a7

Please sign in to comment.