Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/metal-lights-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

Fixed entity id format in generated tests
4 changes: 2 additions & 2 deletions examples/ethereum-basic-event-handlers/build/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type NewGravatar @entity {
type NewGravatar @entity(immutable: false) {
id: ID!
owner: Bytes!
displayName: String!
imageUrl: String!
}

type UpdatedGravatar @entity {
type UpdatedGravatar @entity(immutable: false) {
id: ID!
owner: Bytes!
displayName: String!
Expand Down
2 changes: 1 addition & 1 deletion examples/ethereum-basic-event-handlers/build/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dataSources:
name: Gravity
network: test
source:
address: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf"
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
abi: Gravity
mapping:
kind: ethereum/events
Expand Down
26 changes: 21 additions & 5 deletions examples/ethereum-basic-event-handlers/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ services:
- '8545:8545'
graph-node:
image: graphprotocol/graph-node:latest
platform: linux/amd64
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- hardhat
- ipfs
- postgres
hardhat:
condition: service_started
ipfs:
condition: service_started
postgres:
condition: service_healthy
environment:
postgres_host: postgres
postgres_user: graph-node
Expand All @@ -24,24 +28,36 @@ services:
ethereum: 'test:http://hardhat:8545'
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: 1
healthcheck:
test: ['CMD-SHELL', 'nc -z localhost 8030 || exit 1']
interval: 5s
timeout: 5s
retries: 30
start_period: 10s
ipfs:
image: ipfs/kubo:v0.19.1
ports:
- '5001:5001'
volumes:
- ipfs-data:/data/ipfs
postgres:
image: postgres
image: postgres:17
ports:
- '5432:5432'
command: ['postgres', '-cshared_preload_libraries=pg_stat_statements']
command: ['postgres', '-c', 'shared_preload_libraries=pg_stat_statements']
environment:
POSTGRES_USER: graph-node
POSTGRES_PASSWORD: let-me-in
POSTGRES_DB: graph-node
POSTGRES_INITDB_ARGS: '-E UTF8 --locale=C'
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U graph-node']
interval: 5s
timeout: 5s
retries: 30
start_period: 5s

volumes:
ipfs-data:
Expand Down
2 changes: 1 addition & 1 deletion examples/ethereum-basic-event-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"codegen": "graph codegen",
"create-test": "graph create test/basic-event-handlers --node http://localhost:8020/",
"deploy-test": "graph deploy test/basic-event-handlers --version-label v0.0.1 --ipfs http://localhost:5001 --node http://localhost:8020/",
"test": "docker compose up -d && sleep 30 && hardhat test --network localhost && docker compose down",
"test": "docker compose up -d --wait --wait-timeout 50 && hardhat test --network localhost && docker compose down",
"test:hardhat": "hardhat test --network localhost"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/ethereum-basic-event-handlers/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dataSources:
name: Gravity
network: test
source:
address: '0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf'
address: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
abi: Gravity
mapping:
kind: ethereum/events
Expand Down
28 changes: 16 additions & 12 deletions packages/cli/src/scaffold/__snapshots__/ethereum.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -315,34 +315,36 @@ describe("Describe entity assertions", () => {
test("ExampleEvent created and stored", () => {
assert.entityCount("ExampleEvent", 1)

// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"a",
"234"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"b",
"[1234567890]"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"param2",
"Example string value"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"c",
"ethereum.Tuple Not implemented"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"d",
"Example string value"
)
Expand Down Expand Up @@ -482,34 +484,36 @@ describe("Describe entity assertions", () => {
test("ExampleEvent created and stored", () => {
assert.entityCount("ExampleEvent", 1)

// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"a",
"234"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"b",
"[1234567890]"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"param2",
"Example string value"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"c",
"ethereum.Tuple Not implemented"
)
assert.fieldEquals(
"ExampleEvent",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000",
"d",
"Example string value"
)
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/scaffold/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const generateFieldsAssertions = (entity: string, eventInputs: any[], indexEvent
(input, index) =>
`assert.fieldEquals(
"${entity}",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a${indexEvents ? '-1' : ''}",
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a${indexEvents ? '01000000' : ''}",
"${input.name || `param${index}`}",
"${expectedValue(ascTypeForEthereum(input.type))}"
)`,
Expand Down Expand Up @@ -171,7 +171,9 @@ const generateExampleTest = (
test("${entity} created and stored", () => {
assert.entityCount('${entity}', 1)

// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default transaction hash used in newMockEvent() function
// When indexEvents is true, entity ID uses concatI32() which appends log index as little-endian bytes
// Default log index 1 becomes: 01000000 (4 bytes: 0x01 0x00 0x00 0x00)
${generateFieldsAssertions(entity, eventInputs, indexEvents)}

// More assert options:
Expand Down