Skip to content

Commit bafc3dd

Browse files
authored
test: check grafting from pre 0.0.6 to 0.0.6 and later
1 parent c051672 commit bafc3dd

File tree

15 files changed

+337
-19
lines changed

15 files changed

+337
-19
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
- name: Install Foundry
154154
uses: foundry-rs/foundry-toolchain@v1
155155
- name: Start anvil
156-
run: anvil --gas-limit 100000000000 --base-fee 1 --block-time 2 --port 3021 &
156+
run: anvil --gas-limit 100000000000 --base-fee 1 --block-time 2 --timestamp 1743944919 --port 3021 &
157157

158158
- name: Install graph CLI
159159
run: curl -sSL http://cli.thegraph.com/install.sh | sudo bash

Diff for: tests/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
image: ghcr.io/foundry-rs/foundry:stable
2424
ports:
2525
- '3021:8545'
26-
command: "'anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1 --block-time 5 --mnemonic \"test test test test test test test test test test test junk\"'"
26+
command: "'anvil --host 0.0.0.0 --gas-limit 100000000000 --base-fee 1 --block-time 2 --timestamp 1743944919 --mnemonic \"test test test test test test test test test test test junk\"'"
2727

2828
# graph-node ports:
2929
# json-rpc: 8020

Diff for: tests/integration-tests/base/abis/Contract.abi

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"inputs": [],
4+
"stateMutability": "nonpayable",
5+
"type": "constructor"
6+
},
7+
{
8+
"anonymous": false,
9+
"inputs": [
10+
{
11+
"indexed": false,
12+
"internalType": "uint16",
13+
"name": "x",
14+
"type": "uint16"
15+
}
16+
],
17+
"name": "Trigger",
18+
"type": "event"
19+
},
20+
{
21+
"inputs": [
22+
{
23+
"internalType": "uint16",
24+
"name": "x",
25+
"type": "uint16"
26+
}
27+
],
28+
"name": "emitTrigger",
29+
"outputs": [],
30+
"stateMutability": "nonpayable",
31+
"type": "function"
32+
}
33+
]

Diff for: tests/integration-tests/base/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "base-subgraph",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"build-contracts": "../../common/build-contracts.sh",
6+
"codegen": "graph codegen --skip-migrations",
7+
"test": "yarn build-contracts && truffle test --compile-none --network test",
8+
"create:test": "graph create test/base-subgraph --node $GRAPH_NODE_ADMIN_URI",
9+
"deploy:test": "graph deploy test/base-subgraph --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
10+
},
11+
"devDependencies": {
12+
"@graphprotocol/graph-cli": "0.69.0",
13+
"@graphprotocol/graph-ts": "0.34.0",
14+
"solc": "^0.8.2"
15+
},
16+
"dependencies": {
17+
"@truffle/contract": "^4.3",
18+
"@truffle/hdwallet-provider": "^1.2",
19+
"apollo-fetch": "^0.7.0",
20+
"babel-polyfill": "^6.26.0",
21+
"babel-register": "^6.26.0",
22+
"gluegun": "^4.6.1",
23+
"truffle": "^5.2"
24+
}
25+
}

Diff for: tests/integration-tests/base/schema.graphql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type BaseData @entity(immutable: true) {
2+
id: ID!
3+
data: String!
4+
blockNumber: BigInt!
5+
}

Diff for: tests/integration-tests/base/src/mapping.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ethereum } from '@graphprotocol/graph-ts'
2+
import { BaseData } from '../generated/schema'
3+
4+
export function handleBlock(block: ethereum.Block): void {
5+
let entity = new BaseData(block.number.toString())
6+
entity.data = 'from base'
7+
entity.blockNumber = block.number
8+
entity.save()
9+
}

Diff for: tests/integration-tests/base/subgraph.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
specVersion: 0.0.5
2+
description: Base Subgraph
3+
repository: https://github.com/graphprotocol/graph-node
4+
schema:
5+
file: ./schema.graphql
6+
dataSources:
7+
- kind: ethereum/contract
8+
name: SimpleContract
9+
network: test
10+
source:
11+
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
12+
abi: SimpleContract
13+
startBlock: 0
14+
mapping:
15+
kind: ethereum/events
16+
apiVersion: 0.0.6
17+
language: wasm/assemblyscript
18+
entities:
19+
- BaseData
20+
abis:
21+
- name: SimpleContract
22+
file: ./abis/Contract.abi
23+
blockHandlers:
24+
- handler: handleBlock
25+
file: ./src/mapping.ts

Diff for: tests/integration-tests/grafted/abis/Contract.abi

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[
2+
{
3+
"inputs": [],
4+
"stateMutability": "nonpayable",
5+
"type": "constructor"
6+
},
7+
{
8+
"anonymous": false,
9+
"inputs": [
10+
{
11+
"indexed": false,
12+
"internalType": "uint16",
13+
"name": "x",
14+
"type": "uint16"
15+
}
16+
],
17+
"name": "Trigger",
18+
"type": "event"
19+
},
20+
{
21+
"inputs": [
22+
{
23+
"internalType": "uint16",
24+
"name": "x",
25+
"type": "uint16"
26+
}
27+
],
28+
"name": "emitTrigger",
29+
"outputs": [],
30+
"stateMutability": "nonpayable",
31+
"type": "function"
32+
}
33+
]

Diff for: tests/integration-tests/grafted/package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "grafted-subgraph",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"build-contracts": "../../common/build-contracts.sh",
6+
"codegen": "graph codegen --skip-migrations",
7+
"test": "yarn build-contracts && truffle test --compile-none --network test",
8+
"create:test": "graph create test/grafted-subgraph --node $GRAPH_NODE_ADMIN_URI",
9+
"deploy:test": "graph deploy test/grafted-subgraph --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
10+
},
11+
"devDependencies": {
12+
"@graphprotocol/graph-cli": "0.69.0",
13+
"@graphprotocol/graph-ts": "0.34.0",
14+
"solc": "^0.8.2"
15+
},
16+
"dependencies": {
17+
"@truffle/contract": "^4.3",
18+
"@truffle/hdwallet-provider": "^1.2",
19+
"apollo-fetch": "^0.7.0",
20+
"babel-polyfill": "^6.26.0",
21+
"babel-register": "^6.26.0",
22+
"gluegun": "^4.6.1",
23+
"truffle": "^5.2"
24+
}
25+
}

Diff for: tests/integration-tests/grafted/schema.graphql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type GraftedData @entity(immutable: true) {
2+
id: ID!
3+
data: String!
4+
blockNumber: BigInt!
5+
}

Diff for: tests/integration-tests/grafted/src/mapping.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ethereum } from '@graphprotocol/graph-ts'
2+
import { GraftedData } from '../generated/schema'
3+
4+
export function handleBlock(block: ethereum.Block): void {
5+
let entity = new GraftedData(block.number.toString())
6+
entity.data = 'to grafted'
7+
entity.blockNumber = block.number
8+
entity.save()
9+
}

Diff for: tests/integration-tests/grafted/subgraph.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
specVersion: 0.0.6
2+
description: Grafted Subgraph
3+
repository: https://github.com/graphprotocol/graph-node
4+
schema:
5+
file: ./schema.graphql
6+
dataSources:
7+
- kind: ethereum/contract
8+
name: SimpleContract
9+
network: test
10+
source:
11+
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
12+
abi: SimpleContract
13+
startBlock: 0
14+
mapping:
15+
kind: ethereum/events
16+
apiVersion: 0.0.6
17+
language: wasm/assemblyscript
18+
entities:
19+
- GraftedData
20+
abis:
21+
- name: SimpleContract
22+
file: ./abis/Contract.abi
23+
blockHandlers:
24+
- handler: handleBlock
25+
file: ./src/mapping.ts
26+
features:
27+
- grafting
28+
graft:
29+
base: QmQpiC9bJGFssQfeZippfQ7rcTv7QA67X7jUejc8nV125F
30+
block: 2

Diff for: tests/src/contract.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use graph::prelude::{
77
api::{Eth, Namespace},
88
contract::{tokens::Tokenize, Contract as Web3Contract, Options},
99
transports::Http,
10-
types::{Address, Bytes, TransactionReceipt},
10+
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256},
1111
},
1212
};
1313
// web3 version 0.18 does not expose this; once the graph crate updates to
@@ -165,4 +165,13 @@ impl Contract {
165165
}
166166
Ok(contracts)
167167
}
168+
169+
pub async fn latest_block() -> Option<Block<H256>> {
170+
let eth = Self::eth();
171+
let block = eth
172+
.block(BlockId::Number(BlockNumber::Latest))
173+
.await
174+
.unwrap_or_default();
175+
block
176+
}
168177
}

Diff for: tests/src/subgraph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl Subgraph {
164164
}
165165

166166
/// Make a GraphQL query to the index node API
167-
pub async fn index_with_vars(&self, text: &str, vars: Value) -> anyhow::Result<Value> {
167+
pub async fn query_with_vars(text: &str, vars: Value) -> anyhow::Result<Value> {
168168
let endpoint = CONFIG.graph_node.index_node_uri();
169169
graphql_query_with_vars(&endpoint, text, vars).await
170170
}

0 commit comments

Comments
 (0)