Skip to content

Commit

Permalink
Move the subgraph out of the monorepo so it works with graph test
Browse files Browse the repository at this point in the history
  • Loading branch information
sembrestels committed Sep 19, 2024
1 parent 0fdd6a1 commit 3bd5735
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ logs
# Misc
.DS_Store
*.pem
.bin
.latest.json
.docker
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"overrides": [
{
"include": ["contracts/councilhaus-subgraph/**"],
"include": ["contracts/**/subgraph/**"],
"linter": {
"rules": {
"suspicious": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
File renamed without changes.
22 changes: 22 additions & 0 deletions contracts/councilhaus/subgraph/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM --platform=linux/x86_64 ubuntu:22.04

ARG DEBIAN_FRONTEND=noninteractive

ENV ARGS=""

RUN apt update \
&& apt install -y sudo curl postgresql postgresql-contrib

RUN curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - \
&& sudo apt-get install -y nodejs

RUN curl -OL https://github.com/LimeChain/matchstick/releases/download/0.6.0/binary-linux-22 \
&& chmod a+x binary-linux-22

RUN mkdir matchstick
WORKDIR /matchstick

# Commenting out for now as it seems there's no need to copy when using bind mount
# COPY ./ .

CMD ../binary-linux-22 ${ARGS}
Binary file added contracts/councilhaus/subgraph/bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"create-local": "graph create --node http://localhost:8020/ councilhaus-optimism",
"remove-local": "graph remove --node http://localhost:8020/ councilhaus-optimism",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 councilhaus-optimism",
"test": "graph test"
"test": "graph test",
"test:coverage": "graph test --coverage"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.82.0",
Expand All @@ -18,5 +19,8 @@
"devDependencies": {
"matchstick-as": "0.5.0",
"mustache": "^4.0.1"
},
"resolutions": {
"@graphprotocol/graph-ts": "0.35.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type Council @entity {
id: ID!
councilName: String!
councilSymbol: String!
pool: Bytes!
distributionToken: Bytes!
councilMembers: [CouncilMember!]! @derivedFrom(field: "council")
grantees: [Grantee!]! @derivedFrom(field: "council")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CouncilCreated as CouncilCreatedEvent } from "../generated/CouncilFactory/CouncilFactory";
import { CouncilCreated as CouncilCreatedEvent } from "../generated/CouncilFactory/CouncilFactory";
import { Council } from "../generated/schema";
import { Council as CouncilTemplate } from "../generated/templates";
import { Council as CouncilContract } from "../generated/templates/Council/Council";
Expand All @@ -11,6 +11,7 @@ export function handleCouncilCreated(event: CouncilCreatedEvent): void {

entity.councilName = councilContract.name();
entity.councilSymbol = councilContract.symbol();
entity.pool = event.params.pool;
entity.distributionToken = councilContract.distributionToken();
entity.createdAt = event.block.timestamp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigInt } from "@graphprotocol/graph-ts";
import { log } from "@graphprotocol/graph-ts";
import { Allocation, CouncilMember, Grantee } from "../generated/schema";
import type {
import {
BudgetAllocated,
CouncilMemberAdded,
CouncilMemberRemoved,
Expand Down
21 changes: 21 additions & 0 deletions contracts/councilhaus/subgraph/tests/council-factory-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Address, ethereum } from "@graphprotocol/graph-ts";
import { newMockEvent } from "matchstick-as";
import { CouncilCreated } from "../generated/CouncilFactory/CouncilFactory";

export function createCouncilCreatedEvent(
council: Address,
pool: Address,
): CouncilCreated {
const councilCreatedEvent = changetype<CouncilCreated>(newMockEvent());

councilCreatedEvent.parameters = new Array();

councilCreatedEvent.parameters.push(
new ethereum.EventParam("council", ethereum.Value.fromAddress(council)),
);
councilCreatedEvent.parameters.push(
new ethereum.EventParam("pool", ethereum.Value.fromAddress(pool)),
);

return councilCreatedEvent;
}
83 changes: 83 additions & 0 deletions contracts/councilhaus/subgraph/tests/council-factory.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Address, ethereum } from "@graphprotocol/graph-ts";
import {
assert,
afterAll,
beforeAll,
clearStore,
describe,
mockFunction,
test,
} from "matchstick-as/assembly/index";
import { handleCouncilCreated } from "../src/council-factory";
import { createCouncilCreatedEvent } from "./council-factory-utils";

describe("Describe entity assertions", () => {
beforeAll(() => {
const councilAddress = Address.fromString(
"0x0000000000000000000000000000000000000001",
);
const pool = Address.fromString(
"0x0000000000000000000000000000000000000002",
);
const newCouncilCreatedEvent = createCouncilCreatedEvent(
councilAddress,
pool,
);

mockFunction(
councilAddress,
"name",
"name():(string)",
[],
[ethereum.Value.fromString("Test Council")],
false,
);
mockFunction(
councilAddress,
"symbol",
"symbol():(string)",
[],
[ethereum.Value.fromString("TST")],
false,
);
mockFunction(
councilAddress,
"distributionToken",
"distributionToken():(address)",
[],
[
ethereum.Value.fromAddress(
Address.fromString("0x0000000000000000000000000000000000000003"),
),
],
false,
);

handleCouncilCreated(newCouncilCreatedEvent);
});

afterAll(() => {
clearStore();
});

test("Council created and stored", () => {
assert.entityCount("Council", 1);

const councilId = "0x0000000000000000000000000000000000000001";

assert.fieldEquals("Council", councilId, "councilName", "Test Council");
assert.fieldEquals("Council", councilId, "councilSymbol", "TST");
assert.fieldEquals(
"Council",
councilId,
"pool",
"0x0000000000000000000000000000000000000002",
);
assert.fieldEquals(
"Council",
councilId,
"distributionToken",
"0x0000000000000000000000000000000000000003",
);
});
});
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@
"node": ">=18"
},
"packageManager": "bun@1.1.4",
"workspaces": ["apps/*", "contracts/*", "packages/*"],
"dependencies": {
"graphql": "^16.9.0",
"graphql-request": "^7.1.0"
}
"workspaces": ["apps/*", "contracts/*", "packages/*"]
}

0 comments on commit 3bd5735

Please sign in to comment.