Skip to content

Commit ed71d34

Browse files
gnd: add file data source tests and split fixture subgraphs
Add IPFS and Arweave file data source test fixtures and split the monolithic gnd_test fixture into four focused subgraphs: - token/ ERC20 events, eth_call mocking, dynamic templates - blocks/ Block handlers (every, once, polling filters) - receipts/ Transaction receipts (receipt: true handlers) - file-data-sources/ IPFS and Arweave file data sources Each fixture is a standalone subgraph with its own schema, mappings, ABIs, and test JSON files. The Rust test harness is updated to use a generic setup_fixture(name) helper, with one test function per fixture.
1 parent 5c84368 commit ed71d34

33 files changed

Lines changed: 986 additions & 263 deletions
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "gnd-test-blocks",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"@graphprotocol/graph-cli": "0.98.1",
7+
"@graphprotocol/graph-ts": "0.38.2",
8+
"assemblyscript": "0.19.23"
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type Block @entity(immutable: true) {
2+
id: Bytes!
3+
number: BigInt!
4+
}
5+
6+
type OnceBlock @entity(immutable: true) {
7+
id: Bytes!
8+
msg: String!
9+
}
10+
11+
type PollingBlock @entity(immutable: true) {
12+
id: Bytes!
13+
number: BigInt!
14+
}
File renamed without changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
specVersion: 1.3.0
2+
schema:
3+
file: ./schema.graphql
4+
dataSources:
5+
- name: EveryBlock
6+
kind: ethereum
7+
network: arbitrum
8+
source:
9+
abi: ERC20
10+
address: "0x0000000000000000000000000000000000000000"
11+
mapping:
12+
kind: ethereum/events
13+
apiVersion: 0.0.9
14+
language: wasm/assemblyscript
15+
file: ./src/blocks.ts
16+
entities:
17+
- Block
18+
abis:
19+
- name: ERC20
20+
file: ./abis/ERC20.json
21+
blockHandlers:
22+
- handler: handleEveryBlock
23+
- name: BlockOnce
24+
kind: ethereum
25+
network: arbitrum
26+
source:
27+
abi: ERC20
28+
address: "0x0000000000000000000000000000000000000000"
29+
startBlock: 1000
30+
mapping:
31+
kind: ethereum/events
32+
apiVersion: 0.0.9
33+
language: wasm/assemblyscript
34+
file: ./src/blocks.ts
35+
entities:
36+
- OnceBlock
37+
abis:
38+
- name: ERC20
39+
file: ./abis/ERC20.json
40+
blockHandlers:
41+
- handler: handleOnce
42+
filter:
43+
kind: once
44+
- name: BlockPolling
45+
kind: ethereum
46+
network: arbitrum
47+
source:
48+
abi: ERC20
49+
address: "0x0000000000000000000000000000000000000000"
50+
mapping:
51+
kind: ethereum/events
52+
apiVersion: 0.0.9
53+
language: wasm/assemblyscript
54+
file: ./src/blocks.ts
55+
entities:
56+
- PollingBlock
57+
abis:
58+
- name: ERC20
59+
file: ./abis/ERC20.json
60+
blockHandlers:
61+
- handler: handlePolling
62+
filter:
63+
kind: polling
64+
every: 5
File renamed without changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"anonymous": false,
4+
"inputs": [
5+
{
6+
"indexed": false,
7+
"internalType": "string",
8+
"name": "cid",
9+
"type": "string"
10+
}
11+
],
12+
"name": "IpfsFileCreated",
13+
"type": "event"
14+
},
15+
{
16+
"anonymous": false,
17+
"inputs": [
18+
{
19+
"indexed": false,
20+
"internalType": "string",
21+
"name": "txId",
22+
"type": "string"
23+
}
24+
],
25+
"name": "ArweaveFileCreated",
26+
"type": "event"
27+
}
28+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "gnd-test-file-data-sources",
3+
"version": "0.1.0",
4+
"private": true,
5+
"devDependencies": {
6+
"@graphprotocol/graph-cli": "0.98.1",
7+
"@graphprotocol/graph-ts": "0.38.2",
8+
"assemblyscript": "0.19.23"
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type IpfsFile @entity {
2+
id: ID!
3+
content: String!
4+
}
5+
6+
type ArweaveFile @entity {
7+
id: ID!
8+
content: String!
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { dataSource, Bytes } from "@graphprotocol/graph-ts";
2+
import {
3+
IpfsFileCreated,
4+
ArweaveFileCreated,
5+
} from "../generated/FileEvents/FileEvents";
6+
import { IpfsFile, ArweaveFile } from "../generated/schema";
7+
8+
export function handleIpfsFileCreated(event: IpfsFileCreated): void {
9+
dataSource.create("IpfsFile", [event.params.cid]);
10+
}
11+
12+
export function handleArweaveFileCreated(event: ArweaveFileCreated): void {
13+
dataSource.create("ArweaveFile", [event.params.txId]);
14+
}
15+
16+
export function handleIpfsFile(data: Bytes): void {
17+
let entity = new IpfsFile(dataSource.stringParam());
18+
entity.content = data.toString();
19+
entity.save();
20+
}
21+
22+
export function handleArweaveFile(data: Bytes): void {
23+
let entity = new ArweaveFile(dataSource.stringParam());
24+
entity.content = data.toString();
25+
entity.save();
26+
}

0 commit comments

Comments
 (0)