Skip to content

Check grafting from pre 0.0.6 to 0.0.6 and later #5929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Start anvil
run: anvil --gas-limit 100000000000 --base-fee 1 --block-time 2 --port 3021 &
run: anvil --gas-limit 100000000000 --base-fee 1 --block-time 2 --timestamp 1743944919 --port 3021 &

- name: Install graph CLI
run: curl -sSL http://cli.thegraph.com/install.sh | sudo bash
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ services:
image: ghcr.io/foundry-rs/foundry:stable
ports:
- '3021:8545'
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\"'"
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\"'"

# graph-node ports:
# json-rpc: 8020
Expand Down
33 changes: 33 additions & 0 deletions tests/integration-tests/base/abis/Contract.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "x",
"type": "uint16"
}
],
"name": "Trigger",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "x",
"type": "uint16"
}
],
"name": "emitTrigger",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
25 changes: 25 additions & 0 deletions tests/integration-tests/base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "base-subgraph",
"version": "0.1.0",
"scripts": {
"build-contracts": "../../common/build-contracts.sh",
"codegen": "graph codegen --skip-migrations",
"test": "yarn build-contracts && truffle test --compile-none --network test",
"create:test": "graph create test/base-subgraph --node $GRAPH_NODE_ADMIN_URI",
"deploy:test": "graph deploy test/base-subgraph --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.69.0",
"@graphprotocol/graph-ts": "0.34.0",
"solc": "^0.8.2"
},
"dependencies": {
"@truffle/contract": "^4.3",
"@truffle/hdwallet-provider": "^1.2",
"apollo-fetch": "^0.7.0",
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"gluegun": "^4.6.1",
"truffle": "^5.2"
}
}
5 changes: 5 additions & 0 deletions tests/integration-tests/base/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type BaseData @entity(immutable: true) {
id: ID!
data: String!
blockNumber: BigInt!
}
9 changes: 9 additions & 0 deletions tests/integration-tests/base/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ethereum } from '@graphprotocol/graph-ts'
import { BaseData } from '../generated/schema'

export function handleBlock(block: ethereum.Block): void {
let entity = new BaseData(block.number.toString())
entity.data = 'from base'
entity.blockNumber = block.number
entity.save()
}
25 changes: 25 additions & 0 deletions tests/integration-tests/base/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
specVersion: 0.0.5
description: Base Subgraph
repository: https://github.com/graphprotocol/graph-node
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: SimpleContract
network: test
source:
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
abi: SimpleContract
startBlock: 0
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- BaseData
abis:
- name: SimpleContract
file: ./abis/Contract.abi
blockHandlers:
- handler: handleBlock
file: ./src/mapping.ts
33 changes: 33 additions & 0 deletions tests/integration-tests/grafted/abis/Contract.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "x",
"type": "uint16"
}
],
"name": "Trigger",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint16",
"name": "x",
"type": "uint16"
}
],
"name": "emitTrigger",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
25 changes: 25 additions & 0 deletions tests/integration-tests/grafted/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "grafted-subgraph",
"version": "0.1.0",
"scripts": {
"build-contracts": "../../common/build-contracts.sh",
"codegen": "graph codegen --skip-migrations",
"test": "yarn build-contracts && truffle test --compile-none --network test",
"create:test": "graph create test/grafted-subgraph --node $GRAPH_NODE_ADMIN_URI",
"deploy:test": "graph deploy test/grafted-subgraph --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
},
"devDependencies": {
"@graphprotocol/graph-cli": "0.69.0",
"@graphprotocol/graph-ts": "0.34.0",
"solc": "^0.8.2"
},
"dependencies": {
"@truffle/contract": "^4.3",
"@truffle/hdwallet-provider": "^1.2",
"apollo-fetch": "^0.7.0",
"babel-polyfill": "^6.26.0",
"babel-register": "^6.26.0",
"gluegun": "^4.6.1",
"truffle": "^5.2"
}
}
5 changes: 5 additions & 0 deletions tests/integration-tests/grafted/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type GraftedData @entity(immutable: true) {
id: ID!
data: String!
blockNumber: BigInt!
}
9 changes: 9 additions & 0 deletions tests/integration-tests/grafted/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ethereum } from '@graphprotocol/graph-ts'
import { GraftedData } from '../generated/schema'

export function handleBlock(block: ethereum.Block): void {
let entity = new GraftedData(block.number.toString())
entity.data = 'to grafted'
entity.blockNumber = block.number
entity.save()
}
30 changes: 30 additions & 0 deletions tests/integration-tests/grafted/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
specVersion: 0.0.6
description: Grafted Subgraph
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this naming confusing - 'grafted subgraph' implies that this subgraph is grafted onto something else. Maybe just calling it 'base subgraph' would be better. And what's currently called 'grafting subgraph' could then be called 'grafted subgraph', but leaving that as 'grafting subgraph' is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, those names are more intuitive.

repository: https://github.com/graphprotocol/graph-node
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: SimpleContract
network: test
source:
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
abi: SimpleContract
startBlock: 0
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- GraftedData
abis:
- name: SimpleContract
file: ./abis/Contract.abi
blockHandlers:
- handler: handleBlock
file: ./src/mapping.ts
features:
- grafting
graft:
base: QmQpiC9bJGFssQfeZippfQ7rcTv7QA67X7jUejc8nV125F
block: 2
11 changes: 10 additions & 1 deletion tests/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use graph::prelude::{
api::{Eth, Namespace},
contract::{tokens::Tokenize, Contract as Web3Contract, Options},
transports::Http,
types::{Address, Bytes, TransactionReceipt},
types::{Address, Block, BlockId, BlockNumber, Bytes, TransactionReceipt, H256},
},
};
// web3 version 0.18 does not expose this; once the graph crate updates to
Expand Down Expand Up @@ -165,4 +165,13 @@ impl Contract {
}
Ok(contracts)
}

pub async fn latest_block() -> Option<Block<H256>> {
let eth = Self::eth();
let block = eth
.block(BlockId::Number(BlockNumber::Latest))
.await
.unwrap_or_default();
block
}
}
2 changes: 1 addition & 1 deletion tests/src/subgraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Subgraph {
}

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