Skip to content

Commit 78c451c

Browse files
committed
tests: runner test for skipDuplicates immutable entities
Add end-to-end runner test exercising @entity(immutable: true, skipDuplicates: true) with duplicate entity inserts across blocks. - tests/runner-tests/skip-duplicates/: subgraph with Ping entity using skipDuplicates, block handler that saves same ID every block - tests/tests/runner_tests.rs: skip_duplicates() test syncs 4 blocks and verifies entity is queryable (indexing did not fail)
1 parent 195848b commit 78c451c

File tree

7 files changed

+119
-17
lines changed

7 files changed

+119
-17
lines changed

pnpm-lock.yaml

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"anonymous": false,
4+
"inputs": [
5+
{
6+
"indexed": false,
7+
"internalType": "string",
8+
"name": "testCommand",
9+
"type": "string"
10+
}
11+
],
12+
"name": "TestEvent",
13+
"type": "event"
14+
}
15+
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "skip-duplicates",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"codegen": "graph codegen --skip-migrations",
7+
"deploy:test": "graph deploy test/skip-duplicates --version-label v0.0.1 --ipfs $IPFS_URI --node $GRAPH_NODE_ADMIN_URI"
8+
},
9+
"devDependencies": {
10+
"@graphprotocol/graph-cli": "0.60.0",
11+
"@graphprotocol/graph-ts": "0.31.0"
12+
}
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type Ping @entity(immutable: true, skipDuplicates: true) {
2+
id: ID!
3+
value: String!
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ethereum } from "@graphprotocol/graph-ts";
2+
import { Ping } from "../generated/schema";
3+
4+
export function handleBlock(block: ethereum.Block): void {
5+
let entity = new Ping("duplicate-entity");
6+
entity.value = "ping";
7+
entity.save();
8+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
specVersion: 0.0.8
2+
schema:
3+
file: ./schema.graphql
4+
dataSources:
5+
- kind: ethereum/contract
6+
name: Contract
7+
network: test
8+
source:
9+
address: "0x0000000000000000000000000000000000000000"
10+
abi: Contract
11+
mapping:
12+
kind: ethereum/events
13+
apiVersion: 0.0.7
14+
language: wasm/assemblyscript
15+
entities:
16+
- Ping
17+
abis:
18+
- name: Contract
19+
file: ./abis/Contract.abi
20+
blockHandlers:
21+
- handler: handleBlock
22+
filter:
23+
kind: polling
24+
every: 1
25+
file: ./src/mapping.ts

tests/tests/runner_tests.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,3 +1381,40 @@ async fn aggregation_current_bucket() {
13811381
})
13821382
);
13831383
}
1384+
1385+
#[graph::test]
1386+
async fn skip_duplicates() {
1387+
let RunnerTestRecipe { stores, test_info } =
1388+
RunnerTestRecipe::new("skip_duplicates", "skip-duplicates").await;
1389+
1390+
let blocks = {
1391+
let block_0 = genesis();
1392+
let mut block_1 = empty_block(block_0.ptr(), test_ptr(1));
1393+
push_test_polling_trigger(&mut block_1);
1394+
let mut block_2 = empty_block(block_1.ptr(), test_ptr(2));
1395+
push_test_polling_trigger(&mut block_2);
1396+
let mut block_3 = empty_block(block_2.ptr(), test_ptr(3));
1397+
push_test_polling_trigger(&mut block_3);
1398+
let mut block_4 = empty_block(block_3.ptr(), test_ptr(4));
1399+
push_test_polling_trigger(&mut block_4);
1400+
vec![block_0, block_1, block_2, block_3, block_4]
1401+
};
1402+
1403+
let stop_block = blocks.last().unwrap().block.ptr();
1404+
let chain = chain(&test_info.test_name, blocks, &stores, None).await;
1405+
let ctx = fixture::setup(&test_info, &stores, &chain, None, None).await;
1406+
1407+
ctx.start_and_sync_to(stop_block).await;
1408+
1409+
let query_res = ctx
1410+
.query(r#"{ ping(id: "duplicate-entity") { id, value } }"#)
1411+
.await
1412+
.unwrap();
1413+
1414+
assert_eq!(
1415+
query_res,
1416+
Some(object! {
1417+
ping: object! { id: "duplicate-entity", value: "ping" }
1418+
})
1419+
);
1420+
}

0 commit comments

Comments
 (0)