Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed Feb 25, 2025
1 parent 3c448de commit 54dda3a
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/integration-tests/load-save/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/load-save/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "load-save",
"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/load-save --node $GRAPH_NODE_ADMIN_URI",
"deploy:test": "graph deploy test/load-save --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/load-save/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type LSData @entity {
id: ID!
data: String!
blockNumber: BigInt!
}
17 changes: 17 additions & 0 deletions tests/integration-tests/load-save/src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BigInt, ethereum } from '@graphprotocol/graph-ts'
import { LSData } from '../generated/schema'

export function handleBlock(block: ethereum.Block): void {
let diff = 1
let entity = new LSData(block.number.toString())
entity.data = 'original entity'
entity.blockNumber = block.number
entity.save()
let block_number = block.number
if (block_number.gt(BigInt.fromI32(diff))) {
let bn = block_number.minus(BigInt.fromI32(diff)).toString()
let entity2 = LSData.load(bn)!
entity2.data = 'modified entity'
entity2.save()
}
}
25 changes: 25 additions & 0 deletions tests/integration-tests/load-save/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
specVersion: 1.2.0
description: Source Subgraph A
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:
- LSData
abis:
- name: SimpleContract
file: ./abis/Contract.abi
blockHandlers:
- handler: handleBlock
file: ./src/mapping.ts
14 changes: 14 additions & 0 deletions tests/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,19 @@ async fn subgraph_data_sources(ctx: TestContext) -> anyhow::Result<()> {
Ok(())
}

async fn load_save(ctx: TestContext) -> anyhow::Result<()> {
let subgraph = ctx.subgraph;
assert!(subgraph.healthy);

let _contract = ctx
.contracts
.iter()
.find(|x| x.name == "SimpleContract")
.unwrap();

Ok(())
}

async fn test_topic_filters(ctx: TestContext) -> anyhow::Result<()> {
let subgraph = ctx.subgraph;
assert!(subgraph.healthy);
Expand Down Expand Up @@ -980,6 +993,7 @@ async fn integration_tests() -> anyhow::Result<()> {
TestCase::new("block-handlers", test_block_handlers),
TestCase::new("timestamp", test_timestamp),
TestCase::new("ethereum-api-tests", test_eth_api),
TestCase::new("load-save", load_save),
TestCase::new("topic-filter", test_topic_filters),
TestCase::new_with_source_subgraph(
"subgraph-data-sources",
Expand Down

0 comments on commit 54dda3a

Please sign in to comment.