diff --git a/.github/workflows/subgraph.yml b/.github/workflows/subgraph.yml new file mode 100644 index 00000000..3ea20e8c --- /dev/null +++ b/.github/workflows/subgraph.yml @@ -0,0 +1,64 @@ +name: Subgraph + +on: + pull_request: + branches: + - main + - dev + - release/* + push: + branches: + - main + - dev + - release/* + +jobs: + test: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: subgraph + + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Install Pnpm + uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm + + - name: Get pnpm store directory + shell: bash + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build the subgraph + run: pnpm run build:goerli + + - name: Run the unit tests + run: pnpm run test + + - name: Add test summary + run: | + echo "## Unit tests result" >> $GITHUB_STEP_SUMMARY + echo "✅ Passed" >> $GITHUB_STEP_SUMMARY diff --git a/.gitignore b/.gitignore index 157884c0..e235ddc9 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ typechain-types build generated subgraph.yaml +.bin +.latest.json # Misc .DS_Store diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3e500158..5e73b557 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,11 +95,17 @@ importers: subgraph: devDependencies: '@graphprotocol/graph-cli': - specifier: 0.58.0 - version: 0.58.0(@types/node@20.8.0)(node-fetch@3.3.2)(typescript@5.2.2) + specifier: 0.59.0 + version: 0.59.0(@types/node@20.8.0)(node-fetch@3.3.2)(typescript@5.2.2) '@graphprotocol/graph-ts': - specifier: 0.31.0 - version: 0.31.0 + specifier: 0.30.0 + version: 0.30.0 + assemblyscript: + specifier: 0.19.10 + version: 0.19.10 + matchstick-as: + specifier: 0.5.2 + version: 0.5.2 packages: @@ -1154,8 +1160,8 @@ packages: js-yaml: 4.1.0 dev: true - /@graphprotocol/graph-cli@0.58.0(@types/node@20.8.0)(node-fetch@3.3.2)(typescript@5.2.2): - resolution: {integrity: sha512-EbdL5LZFmIMAuItQXv7LXgd7cqYQ3BdIJR2jxNr+LRL0juBAxmEz6zVvYnIUmgXoa5SB5rxE9ZT6pfe+fhbD6Q==} + /@graphprotocol/graph-cli@0.59.0(@types/node@20.8.0)(node-fetch@3.3.2)(typescript@5.2.2): + resolution: {integrity: sha512-uddsyUootdhQgMqQXkrD0INn/nNkQB+3t5luRzjY0pxA4O9hidXjYZNScjvSgf3eiaN0rcEs/s56qa/dsy4LwA==} engines: {node: '>=14'} hasBin: true dependencies: @@ -1199,8 +1205,8 @@ packages: - utf-8-validate dev: true - /@graphprotocol/graph-ts@0.31.0: - resolution: {integrity: sha512-xreRVM6ho2BtolyOh2flDkNoGZximybnzUnF53zJVp0+Ed0KnAlO1/KOCUYw06euVI9tk0c9nA2Z/D5SIQV2Rg==} + /@graphprotocol/graph-ts@0.30.0: + resolution: {integrity: sha512-h5tJqlsZXglGYM0PcBsBOqof4PT0Fr4Z3QBTYN/IjMF3VvRX2A8/bdpqaAnva+2N0uAfXXwRcwcOcW5O35yzXw==} dependencies: assemblyscript: 0.19.10 dev: true @@ -2473,7 +2479,7 @@ packages: /@types/cli-progress@3.11.2: resolution: {integrity: sha512-Yt/8rEJalfa9ve2SbfQnwFHrc9QF52JIZYHW3FDaTMpkCvnns26ueKiPHDxyJ0CS//IqjMINTx7R5Xa7k7uFHQ==} dependencies: - '@types/node': 20.5.7 + '@types/node': 20.8.0 dev: true /@types/concat-stream@1.6.1: @@ -2485,7 +2491,7 @@ packages: /@types/connect@3.4.36: resolution: {integrity: sha512-P63Zd/JUGq+PdrM1lv0Wv5SBYeA2+CORvbrXbngriYY0jzLUWfQMQQxOhjONEz/wlHOAxOdY7CY65rgQdTjq2w==} dependencies: - '@types/node': 20.5.7 + '@types/node': 20.8.0 dev: true /@types/form-data@0.0.33: @@ -2619,7 +2625,7 @@ packages: /@types/ws@7.4.7: resolution: {integrity: sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==} dependencies: - '@types/node': 20.5.7 + '@types/node': 20.8.0 dev: true /@types/ws@8.5.6: @@ -3211,7 +3217,7 @@ packages: /axios@0.21.4(debug@4.3.4): resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2(debug@4.3.4) + follow-redirects: 1.15.3(debug@4.3.4) transitivePeerDependencies: - debug dev: true @@ -3229,7 +3235,7 @@ packages: /axios@1.5.1: resolution: {integrity: sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==} dependencies: - follow-redirects: 1.15.3 + follow-redirects: 1.15.3(debug@4.3.4) form-data: 4.0.0 proxy-from-env: 1.1.0 transitivePeerDependencies: @@ -4919,7 +4925,7 @@ packages: debug: 4.3.4(supports-color@8.1.1) dev: true - /follow-redirects@1.15.3: + /follow-redirects@1.15.3(debug@4.3.4): resolution: {integrity: sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==} engines: {node: '>=4.0'} peerDependencies: @@ -4927,6 +4933,8 @@ packages: peerDependenciesMeta: debug: optional: true + dependencies: + debug: 4.3.4(supports-color@8.1.1) dev: true /for-each@0.3.3: @@ -5022,7 +5030,7 @@ packages: /fs-jetpack@4.3.1: resolution: {integrity: sha512-dbeOK84F6BiQzk2yqqCVwCPWTxAvVGJ3fMQc6E2wuEohS28mR6yHngbrKuVCK1KHRx/ccByDylqu4H5PCP2urQ==} dependencies: - minimatch: 3.1.2 + minimatch: 8.0.4 rimraf: 2.7.1 dev: true @@ -5154,7 +5162,7 @@ packages: dependencies: inflight: 1.0.6 inherits: 2.0.4 - minimatch: 3.1.2 + minimatch: 8.0.4 once: 1.4.0 path-is-absolute: 1.0.1 dev: true @@ -5165,7 +5173,7 @@ packages: fs.realpath: 1.0.0 inflight: 1.0.6 inherits: 2.0.4 - minimatch: 3.1.2 + minimatch: 8.0.4 once: 1.4.0 path-is-absolute: 1.0.1 dev: true @@ -5695,7 +5703,7 @@ packages: resolution: {integrity: sha512-AmCS+9CT34pp2u0QQVXjKztkuq3y5T+BIciuiHDDtDZucZD8VudosnSdUyXJV6IsRkN5jc4RFDhCk1O6Q3Gxjg==} dependencies: interface-store: 2.0.2 - nanoid: 3.3.3 + nanoid: 3.3.6 uint8arrays: 3.1.1 dev: true @@ -5760,7 +5768,7 @@ packages: multiaddr: 10.0.1(node-fetch@3.3.2) multiaddr-to-uri: 8.0.0(node-fetch@3.3.2) multiformats: 9.9.0 - nanoid: 3.3.3 + nanoid: 3.3.6 parse-duration: 1.1.0 timeout-abort-controller: 2.0.0 uint8arrays: 3.1.1 @@ -5823,7 +5831,7 @@ packages: it-glob: 1.0.2 it-to-stream: 1.0.0 merge-options: 3.0.4 - nanoid: 3.3.3 + nanoid: 3.3.6 native-fetch: 3.0.0(node-fetch@2.7.0) node-fetch: 2.7.0 react-native-fetch-api: 3.0.0 @@ -6152,7 +6160,7 @@ packages: resolution: {integrity: sha512-Ch2Dzhw4URfB9L/0ZHyY+uqOnKvBNeS/SMcRiPmJfpHiM0TsUZn+GkpcZxAoF3dJVdPm/PuIk3A4wlV7SUo23Q==} dependencies: '@types/minimatch': 3.0.5 - minimatch: 3.1.2 + minimatch: 8.0.4 dev: true /it-last@1.0.6: @@ -6998,6 +7006,12 @@ packages: resolution: {integrity: sha512-1RUZVgQlpJSPWYbFSpmudq5nHY1doEIv89gBtF0s4gW1GF2XorxcA/70M5vq7rLv0a6mhOUccRsqkwhwLCIQ2Q==} dev: true + /matchstick-as@0.5.2: + resolution: {integrity: sha512-fb1OVphDKEvJY06Ue02Eh1CNncuW95vp6b8tNAP7UIqplICSLoU/zgN6U7ge7R0upsoO78C7CRi4EyK/7Jxz7g==} + dependencies: + wabt: 1.0.24 + dev: true + /mcl-wasm@0.7.9: resolution: {integrity: sha512-iJIUcQWA88IJB/5L15GnJVnSQJmf/YaxxV6zRavv83HILHaJQb6y0iFyDMdDO0gN8X37tdxmAOrH/P8B6RB8sQ==} engines: {node: '>=8.9.0'} @@ -8699,7 +8713,7 @@ packages: dependencies: '@istanbuljs/schema': 0.1.3 glob: 7.2.3 - minimatch: 3.1.2 + minimatch: 8.0.4 dev: true /text-table@0.2.0: @@ -9232,6 +9246,11 @@ packages: fsevents: 2.3.3 dev: true + /wabt@1.0.24: + resolution: {integrity: sha512-8l7sIOd3i5GWfTWciPL0+ff/FK/deVK2Q6FN+MPz4vfUcD78i2M/49XJTwF6aml91uIiuXJEsLKWMB2cw/mtKg==} + hasBin: true + dev: true + /walker@1.0.8: resolution: {integrity: sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==} dependencies: diff --git a/subgraph/package.json b/subgraph/package.json index 0b35af66..502e6710 100644 --- a/subgraph/package.json +++ b/subgraph/package.json @@ -24,10 +24,13 @@ "deploy": "source .env && cp subgraph.mainnet.yaml subgraph.yaml && pnpm run build && graph deploy --network linea-mainnet --node $DEPLOY_ENDPOINT_MAINNET --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.1 Consensys/linea-attestation-registry", "deploy:goerli": "source .env && cp subgraph.goerli.yaml subgraph.yaml && pnpm run build:goerli && graph deploy --network linea-goerli --node $DEPLOY_ENDPOINT_GOERLI --headers \"{\\\"Authorization\\\": \\\"Basic $IPFS_IDENTIFIERS\\\"}\" --ipfs $IPFS_ENDPOINT --version-label v0.0.5 Consensys/linea-attestation-registry", "remove": "source .env && graph remove --node $DEPLOY_ENDPOINT_MAINNET Consensys/linea-attestation-registry", - "remove:goerli": "source .env && graph remove --node $DEPLOY_ENDPOINT_GOERLI Consensys/linea-attestation-registry" + "remove:goerli": "source .env && graph remove --node $DEPLOY_ENDPOINT_GOERLI Consensys/linea-attestation-registry", + "test": "graph test -v 0.5.2" }, "devDependencies": { - "@graphprotocol/graph-cli": "0.58.0", - "@graphprotocol/graph-ts": "0.31.0" + "@graphprotocol/graph-cli": "0.59.0", + "@graphprotocol/graph-ts": "0.30.0", + "matchstick-as": "0.5.2", + "assemblyscript": "0.19.10" } } diff --git a/subgraph/tests/module-registry.test.ts b/subgraph/tests/module-registry.test.ts new file mode 100644 index 00000000..418867e7 --- /dev/null +++ b/subgraph/tests/module-registry.test.ts @@ -0,0 +1,55 @@ +import { afterEach, assert, clearStore, describe, newMockEvent, test } from "matchstick-as"; +import { ModuleRegistered } from "../generated/ModuleRegistry/ModuleRegistry"; +import { Address, ethereum } from "@graphprotocol/graph-ts"; +import { Module } from "../generated/schema"; + +describe("handleModuleRegistered()", () => { + const moduleAddress = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7"; + const moduleName = "module name"; + const moduleDescription = "module description"; + + afterEach(() => { + clearStore(); + }); + + test("Should create a new Module entity", () => { + assert.entityCount("Module", 0); + + /*const moduleRegisteredEvent = createModuleRegisteredEvent(moduleAddress, moduleName, moduleDescription); + + handleModuleRegistered(moduleRegisteredEvent);*/ + + const module = new Module(moduleAddress); + //module.name = moduleName; + //module.description = moduleDescription; + //module.moduleAddress=moduleAddress; + module.save(); + + assert.entityCount("Module", 1); + /*assert.fieldEquals("Module", moduleAddress, "id", moduleAddress); + assert.fieldEquals("Module", moduleAddress, "name", moduleName); + assert.fieldEquals("Module", moduleAddress, "description", moduleName); + assert.fieldEquals("Module", moduleAddress, "moduleAddress", moduleAddress);*/ + }); +}); + +function createModuleRegisteredEvent( + moduleAddress: string, + moduleName: string, + moduleDescription: string, +): ModuleRegistered { + const moduleRegisteredEvent = changetype(newMockEvent()); + moduleRegisteredEvent.parameters = []; + const moduleAddressParam = new ethereum.EventParam( + "moduleAddress", + ethereum.Value.fromAddress(Address.fromString(moduleAddress)), + ); + const nameParam = new ethereum.EventParam("moduleName", ethereum.Value.fromString(moduleName)); + const descriptionParam = new ethereum.EventParam("moduleDescription", ethereum.Value.fromString(moduleDescription)); + + moduleRegisteredEvent.parameters.push(moduleAddressParam); + moduleRegisteredEvent.parameters.push(nameParam); + moduleRegisteredEvent.parameters.push(descriptionParam); + + return moduleRegisteredEvent; +} diff --git a/subgraph/tsconfig.json b/subgraph/tsconfig.json index a6d2ae82..4e866720 100644 --- a/subgraph/tsconfig.json +++ b/subgraph/tsconfig.json @@ -1,3 +1,4 @@ { - "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json" + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src", "tests"] }