-
Notifications
You must be signed in to change notification settings - Fork 969
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding runner_test for auto-graft-sync
- Loading branch information
Showing
9 changed files
with
348 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[general] | ||
|
||
# This is the config flag for enabling auto-graft-sync, which is the target of this test. | ||
auto_graft_sync = true | ||
|
||
[store] | ||
[store.primary] | ||
connection = "$THEGRAPH_STORE_POSTGRES_DIESEL_URL" | ||
pool_size = 10 | ||
|
||
[deployment] | ||
[[deployment.rule]] | ||
store = "primary" | ||
indexers = ["default"] | ||
|
||
[chains] | ||
ingestor = "default" | ||
|
||
# The tests do not talk to ethereum clients | ||
[chains.test] | ||
shard = "primary" | ||
provider = [{ label = "penguin", url = "http://localhost:1/", features = [] }] |
19 changes: 19 additions & 0 deletions
19
tests/runner-tests/auto-graft-sync/generateAndPublishManifestFromTemplate.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
const fs = require('fs'); | ||
const { execSync } = require('child_process'); | ||
|
||
// This takes a subgraphName, outPath, and Qm.. hash as a CLI input, which is the graft base. | ||
const outPath = process.argv[2]; | ||
const graftBase = process.argv[3]; | ||
|
||
const yamlPath = './template.yaml'; | ||
let yamlContent = fs.readFileSync(yamlPath, 'utf-8'); | ||
yamlContent = yamlContent.replace(/base: .+/, `base: ${graftBase}`); | ||
fs.writeFileSync(outPath, yamlContent); | ||
console.log("fuzzba") | ||
|
||
// Assuming you have your IPFS_URI exported as environment variables. | ||
// Instead of deploy, run graph build to -only upload to ipfs-. | ||
execSync('graph build ' + outPath + ' --ipfs $IPFS_URI', { | ||
stdio: 'inherit' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# for this test, this is the lowest level of the grafting hierarchy | ||
specVersion: 0.0.4 | ||
features: | ||
- grafting | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: Contract | ||
network: test | ||
source: | ||
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601" | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlock | ||
file: ./src/mapping.ts | ||
# Tests that adding a data source is possible in a graft | ||
- kind: ethereum/contract | ||
name: Contract2 | ||
network: test | ||
source: | ||
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601" | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
callHandlers: | ||
- handler: handleBlock | ||
function: emitTrigger(uint16) | ||
file: ./src/mapping.ts | ||
templates: | ||
- kind: ethereum/contract | ||
name: Template | ||
network: test | ||
source: | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlockTemplate | ||
file: ./src/mapping.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "auto-graft-sync", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"codegen": "graph codegen --skip-migrations", | ||
"build-graft-root": "graph build graft-base.yaml --ipfs $IPFS_URI", | ||
"build:test-auto-graft-sync": "node generateManifestFromTemplate.js" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.60.0", | ||
"@graphprotocol/graph-ts": "0.31.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The `id` is the block number and `count` the handler invocations at that block. | ||
type DataSourceCount @entity { | ||
id: ID! | ||
count: Int! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
ethereum, | ||
DataSourceContext, | ||
dataSource, | ||
Address, | ||
BigInt, | ||
} from "@graphprotocol/graph-ts"; | ||
import { Template } from "../generated/templates"; | ||
import { DataSourceCount } from "../generated/schema"; | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
let context = new DataSourceContext(); | ||
context.setBigInt("number", block.number); | ||
context.setBytes("hash", block.hash); | ||
|
||
Template.createWithContext( | ||
changetype<Address>(Address.fromHexString( | ||
"0x2E645469f354BB4F5c8a05B3b30A929361cf77eC" | ||
)), | ||
context | ||
); | ||
} | ||
|
||
export function handleBlockTemplate(block: ethereum.Block): void { | ||
let count = DataSourceCount.load(block.number.toString()); | ||
if (count == null) { | ||
count = new DataSourceCount(block.number.toString()); | ||
count.count = 0; | ||
} | ||
|
||
let ctx = dataSource.context(); | ||
let number = ctx.getBigInt("number"); | ||
assert( | ||
count.count == number.toI32(), | ||
"wrong count, found " + BigInt.fromI32(count.count).toString() | ||
); | ||
count.count += 1; | ||
count.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
specVersion: 0.0.4 | ||
features: | ||
- grafting | ||
schema: | ||
file: ./schema.graphql | ||
graft: | ||
# This value will be overwritten by the templates | ||
base: QmcAL39QSKZvRssr2ToCJrav7XK9ggajxvBR7M1NNUCqdh | ||
block: 3 | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: Contract | ||
network: test | ||
source: | ||
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601" | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlock | ||
file: ./src/mapping.ts | ||
# Tests that adding a data source is possible in a graft | ||
- kind: ethereum/contract | ||
name: Contract2 | ||
network: test | ||
source: | ||
address: "0xCfEB869F69431e42cdB54A4F4f105C19C080A601" | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
callHandlers: | ||
- handler: handleBlock | ||
function: emitTrigger(uint16) | ||
file: ./src/mapping.ts | ||
templates: | ||
- kind: ethereum/contract | ||
name: Template | ||
network: test | ||
source: | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlockTemplate | ||
file: ./src/mapping.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters