diff --git a/tests/integration-tests/load-save/abis/Contract.abi b/tests/integration-tests/load-save/abis/Contract.abi new file mode 100644 index 00000000000..02da1a9e7f3 --- /dev/null +++ b/tests/integration-tests/load-save/abis/Contract.abi @@ -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" + } +] diff --git a/tests/integration-tests/load-save/package.json b/tests/integration-tests/load-save/package.json new file mode 100644 index 00000000000..41504e2323e --- /dev/null +++ b/tests/integration-tests/load-save/package.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/integration-tests/load-save/schema.graphql b/tests/integration-tests/load-save/schema.graphql new file mode 100644 index 00000000000..5ae77bda7f9 --- /dev/null +++ b/tests/integration-tests/load-save/schema.graphql @@ -0,0 +1,5 @@ +type LSData @entity { + id: ID! + data: String! + blockNumber: BigInt! +} \ No newline at end of file diff --git a/tests/integration-tests/load-save/src/mapping.ts b/tests/integration-tests/load-save/src/mapping.ts new file mode 100644 index 00000000000..f703953f628 --- /dev/null +++ b/tests/integration-tests/load-save/src/mapping.ts @@ -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() + } +} diff --git a/tests/integration-tests/load-save/subgraph.yaml b/tests/integration-tests/load-save/subgraph.yaml new file mode 100644 index 00000000000..fa2e74c2646 --- /dev/null +++ b/tests/integration-tests/load-save/subgraph.yaml @@ -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 \ No newline at end of file diff --git a/tests/tests/integration_tests.rs b/tests/tests/integration_tests.rs index d10df25698b..8d7124bc8b1 100644 --- a/tests/tests/integration_tests.rs +++ b/tests/tests/integration_tests.rs @@ -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); @@ -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",