diff --git a/.github/workflows/subgraph.yml b/.github/workflows/subgraph.yml new file mode 100644 index 00000000..f5c6e0c3 --- /dev/null +++ b/.github/workflows/subgraph.yml @@ -0,0 +1,45 @@ +name: Subgraph + +on: + pull_request: + paths: + - '.github/workflows/subgraph.yml' + - 'apps/subgraph/**' + - 'biome.json' + - 'package.json' + - 'pnpm-lock.yaml' + - 'pnpm-workspace.yaml' + +jobs: + test-and-build: + name: Codegen, test, build + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Setup pnpm + uses: pnpm/action-setup@v6 + with: + version: 9.15.2 + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: 'lts/*' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests + run: pnpm --filter @dealbot/subgraph test + + - name: Build calibration + run: pnpm --filter @dealbot/subgraph run build:calibration + + - name: Build mainnet + run: pnpm --filter @dealbot/subgraph run build:mainnet diff --git a/apps/subgraph/biome.json b/apps/subgraph/biome.json new file mode 100644 index 00000000..62311210 --- /dev/null +++ b/apps/subgraph/biome.json @@ -0,0 +1,34 @@ +{ + "root": false, + "$schema": "https://biomejs.dev/schemas/2.3.14/schema.json", + "extends": "//", + "overrides": [ + { + "includes": ["**/*.spec.ts", "**/*.test.ts", "tests/**/*.ts"], + "linter": { + "rules": { + "suspicious": { + "noExplicitAny": "off" + } + } + } + }, + { + "includes": ["src/**", "tests/**"], + "linter": { + "rules": { + "style": { + "useImportType": "off" + }, + "suspicious": { + "noShadowRestrictedNames": "off", + "noDoubleEquals": "off" + }, + "complexity": { + "noStaticOnlyClass": "off" + } + } + } + } + ] +} diff --git a/apps/subgraph/package.json b/apps/subgraph/package.json index 8c421738..7d52ce63 100644 --- a/apps/subgraph/package.json +++ b/apps/subgraph/package.json @@ -10,7 +10,14 @@ "build:calibration": "pnpm run codegen && graph build --network filecoin-testnet", "deploy:mainnet": "goldsky subgraph deploy dealbot-mainnet/$VERSION --path ./build", "deploy:calibration": "goldsky subgraph deploy dealbot-calibration/$VERSION --path ./build", - "test": "graph test && node --test scripts/check-networks.test.mjs" + "pretest": "pnpm run codegen", + "test": "graph test && node --test scripts/check-networks.test.mjs", + "format": "biome format --write .", + "format:check": "biome format .", + "lint": "biome lint --write .", + "lint:check": "biome lint .", + "check": "biome check --write .", + "check:ci": "biome ci ." }, "dependencies": { "@filoz/synapse-core": "0.3.3", @@ -18,6 +25,7 @@ "@graphprotocol/graph-ts": "0.38.2" }, "devDependencies": { + "@biomejs/biome": "catalog:", "assemblyscript": "0.19.23", "matchstick-as": "0.6.0" } diff --git a/apps/subgraph/scripts/check-networks.test.mjs b/apps/subgraph/scripts/check-networks.test.mjs index 59699e72..aaea084f 100644 --- a/apps/subgraph/scripts/check-networks.test.mjs +++ b/apps/subgraph/scripts/check-networks.test.mjs @@ -3,11 +3,11 @@ // FilOzone/filecoin-services). Bumping synapse-core is the trigger for any // address change; this test fails fast if networks.json drifts. +import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { dirname, join } from "node:path"; -import { fileURLToPath } from "node:url"; import { test } from "node:test"; -import assert from "node:assert/strict"; +import { fileURLToPath } from "node:url"; import { generated } from "@filoz/synapse-core/abis"; const { filecoinWarmStorageServiceAddress, pdpVerifierAddress } = generated; @@ -17,7 +17,7 @@ const networksPath = join(here, "..", "networks.json"); const networks = JSON.parse(await readFile(networksPath, "utf8")); const cases = { - "filecoin": 314, + filecoin: 314, "filecoin-testnet": 314159, }; @@ -25,12 +25,16 @@ for (const [network, chainId] of Object.entries(cases)) { test(`${network} PDPVerifier address matches synapse-core[${chainId}]`, () => { const actual = networks[network]?.PDPVerifier?.address; const expected = pdpVerifierAddress[chainId]; - assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.PDPVerifier.address`) + assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.PDPVerifier.address`); }); test(`${network} FilecoinWarmStorageService address matches synapse-core[${chainId}]`, () => { const actual = networks[network]?.FilecoinWarmStorageService?.address; const expected = filecoinWarmStorageServiceAddress[chainId]; - assert.equal(actual, expected, `expected ${expected}, got ${actual} for ${network}.FilecoinWarmStorageService.address`); + assert.equal( + actual, + expected, + `expected ${expected}, got ${actual} for ${network}.FilecoinWarmStorageService.address`, + ); }); -} \ No newline at end of file +} diff --git a/apps/subgraph/scripts/sync-abis.mjs b/apps/subgraph/scripts/sync-abis.mjs index 7a54dc41..c13480e1 100644 --- a/apps/subgraph/scripts/sync-abis.mjs +++ b/apps/subgraph/scripts/sync-abis.mjs @@ -5,7 +5,7 @@ // truth; bumping the synapse-core version is all that's needed to pick up // ABI changes. -import { writeFile, mkdir } from "node:fs/promises"; +import { mkdir, writeFile } from "node:fs/promises"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { fwss, pdp } from "@filoz/synapse-core/abis"; diff --git a/apps/subgraph/src/fwss.ts b/apps/subgraph/src/fwss.ts index 2e739b36..710f12a9 100644 --- a/apps/subgraph/src/fwss.ts +++ b/apps/subgraph/src/fwss.ts @@ -80,9 +80,7 @@ export function handleFwssPdpPaymentTerminated(event: PDPPaymentTerminatedEvent) export function handleFwssDataSetServiceProviderChanged(event: DataSetServiceProviderChangedEvent): void { const ds = DataSet.load(getProofSetEntityId(event.params.dataSetId)); if (ds == null) { - log.warning("FWSS DataSetServiceProviderChanged for unknown dataSet {}", [ - event.params.dataSetId.toString(), - ]); + log.warning("FWSS DataSetServiceProviderChanged for unknown dataSet {}", [event.params.dataSetId.toString()]); return; } diff --git a/apps/subgraph/src/helpers.ts b/apps/subgraph/src/helpers.ts index e3350bdb..e93430b1 100644 --- a/apps/subgraph/src/helpers.ts +++ b/apps/subgraph/src/helpers.ts @@ -7,7 +7,7 @@ export function getProofSetEntityId(setId: BigInt): Bytes { } export function getRootEntityId(setId: BigInt, rootId: BigInt): Bytes { - return Bytes.fromUTF8(setId.toString() + "-" + rootId.toString()); + return Bytes.fromUTF8(`${setId.toString()}-${rootId.toString()}`); } // Uniform pseudorandom sort key for Root entities. Used by dealbot to draw @@ -77,7 +77,7 @@ export class UvarintResult { } export function readUvarint(data: Bytes, offset: BigInt): UvarintResult { - let offsetU32 = offset.toU32(); + const offsetU32 = offset.toU32(); if (offsetU32 >= u32(data.length)) { return new UvarintResult(false); @@ -97,7 +97,7 @@ export function readUvarint(data: Bytes, offset: BigInt): UvarintResult { return new UvarintResult(false); } - let nextByte = u64(data[offsetU32 + i] & 0x7f); + const nextByte = u64(data[offsetU32 + i] & 0x7f); value = value | (nextByte << (i * 7)); } @@ -122,12 +122,12 @@ export function validateCommPv2(cidData: Bytes): CommPv2ValidationResult { return new CommPv2ValidationResult(false); } - let mhLengthResult = readUvarint(cidData, offset); + const mhLengthResult = readUvarint(cidData, offset); if (!mhLengthResult.isValid) { return new CommPv2ValidationResult(false); } - let mhLength = mhLengthResult.value; + const mhLength = mhLengthResult.value; offset = mhLengthResult.offset; if (mhLength.lt(BigInt.fromU32(34))) { @@ -142,19 +142,19 @@ export function validateCommPv2(cidData: Bytes): CommPv2ValidationResult { return new CommPv2ValidationResult(false); } - let paddingResult = readUvarint(cidData, offset); + const paddingResult = readUvarint(cidData, offset); if (!paddingResult.isValid) { return new CommPv2ValidationResult(false); } - let padding = paddingResult.value; + const padding = paddingResult.value; offset = paddingResult.offset; if (offset.toU32() >= u32(cidData.length)) { return new CommPv2ValidationResult(false); } - let height = cidData[offset.toU32()]; + const height = cidData[offset.toU32()]; offset = offset.plus(BigInt.fromU32(1)); return new CommPv2ValidationResult(true, padding, height, offset); diff --git a/apps/subgraph/src/types.ts b/apps/subgraph/src/types.ts index 935ffdea..6eac775a 100644 --- a/apps/subgraph/src/types.ts +++ b/apps/subgraph/src/types.ts @@ -1,6 +1,6 @@ -export class DataSetStatus { - static readonly EMPTY: string = "EMPTY"; - static readonly READY: string = "READY"; - static readonly PROVING: string = "PROVING"; - static readonly DELETED: string = "DELETED"; +export namespace DataSetStatus { + export const EMPTY: string = "EMPTY"; + export const READY: string = "READY"; + export const PROVING: string = "PROVING"; + export const DELETED: string = "DELETED"; } diff --git a/apps/subgraph/tests/dataset-status.test.ts b/apps/subgraph/tests/dataset-status.test.ts index e3a67d63..df665263 100644 --- a/apps/subgraph/tests/dataset-status.test.ts +++ b/apps/subgraph/tests/dataset-status.test.ts @@ -1,5 +1,5 @@ -import { afterEach, assert, clearStore, describe, test } from "matchstick-as/assembly/index"; import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { afterEach, assert, clearStore, describe, test } from "matchstick-as/assembly/index"; import { handleDataSetCreated, handleDataSetDeleted, diff --git a/apps/subgraph/tests/fwss-utils.ts b/apps/subgraph/tests/fwss-utils.ts index e5db3137..36716e7d 100644 --- a/apps/subgraph/tests/fwss-utils.ts +++ b/apps/subgraph/tests/fwss-utils.ts @@ -1,11 +1,11 @@ +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; import { newMockEvent } from "matchstick-as"; -import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts"; import { DataSetCreated as FwssDataSetCreated, + DataSetServiceProviderChanged as FwssDataSetServiceProviderChanged, + PDPPaymentTerminated as FwssPdpPaymentTerminated, PieceAdded as FwssPieceAdded, ServiceTerminated as FwssServiceTerminated, - PDPPaymentTerminated as FwssPdpPaymentTerminated, - DataSetServiceProviderChanged as FwssDataSetServiceProviderChanged, } from "../generated/FilecoinWarmStorageService/FilecoinWarmStorageService"; // FWSS DataSetCreated: @@ -20,68 +20,21 @@ export function createFwssDataSetCreatedEvent( metadataKeys: string[], metadataValues: string[], blockNumber: BigInt = BigInt.fromI32(1), - timestamp: BigInt = BigInt.fromI32(1) + timestamp: BigInt = BigInt.fromI32(1), ): FwssDataSetCreated { - let ev = changetype(newMockEvent()); - ev.parameters = new Array(); - - ev.parameters.push( - new ethereum.EventParam( - "dataSetId", - ethereum.Value.fromUnsignedBigInt(dataSetId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "providerId", - ethereum.Value.fromUnsignedBigInt(providerId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "pdpRailId", - ethereum.Value.fromUnsignedBigInt(pdpRailId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "cacheMissRailId", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "cdnRailId", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)) - ) - ); - ev.parameters.push( - new ethereum.EventParam("payer", ethereum.Value.fromAddress(payer)) - ); - ev.parameters.push( - new ethereum.EventParam( - "serviceProvider", - ethereum.Value.fromAddress(serviceProvider) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "payee", - ethereum.Value.fromAddress(serviceProvider) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "metadataKeys", - ethereum.Value.fromStringArray(metadataKeys) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "metadataValues", - ethereum.Value.fromStringArray(metadataValues) - ) - ); + const ev = changetype(newMockEvent()); + ev.parameters = []; + + ev.parameters.push(new ethereum.EventParam("dataSetId", ethereum.Value.fromUnsignedBigInt(dataSetId))); + ev.parameters.push(new ethereum.EventParam("providerId", ethereum.Value.fromUnsignedBigInt(providerId))); + ev.parameters.push(new ethereum.EventParam("pdpRailId", ethereum.Value.fromUnsignedBigInt(pdpRailId))); + ev.parameters.push(new ethereum.EventParam("cacheMissRailId", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)))); + ev.parameters.push(new ethereum.EventParam("cdnRailId", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)))); + ev.parameters.push(new ethereum.EventParam("payer", ethereum.Value.fromAddress(payer))); + ev.parameters.push(new ethereum.EventParam("serviceProvider", ethereum.Value.fromAddress(serviceProvider))); + ev.parameters.push(new ethereum.EventParam("payee", ethereum.Value.fromAddress(serviceProvider))); + ev.parameters.push(new ethereum.EventParam("metadataKeys", ethereum.Value.fromStringArray(metadataKeys))); + ev.parameters.push(new ethereum.EventParam("metadataValues", ethereum.Value.fromStringArray(metadataValues))); ev.block.number = blockNumber; ev.block.timestamp = timestamp; @@ -96,36 +49,20 @@ export function createFwssPieceAddedEvent( keys: string[], values: string[], blockNumber: BigInt = BigInt.fromI32(1), - timestamp: BigInt = BigInt.fromI32(1) + timestamp: BigInt = BigInt.fromI32(1), ): FwssPieceAdded { - let ev = changetype(newMockEvent()); - ev.parameters = new Array(); - - ev.parameters.push( - new ethereum.EventParam( - "dataSetId", - ethereum.Value.fromUnsignedBigInt(dataSetId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "pieceId", - ethereum.Value.fromUnsignedBigInt(pieceId) - ) - ); - - let cidTuple = new ethereum.Tuple(); + const ev = changetype(newMockEvent()); + ev.parameters = []; + + ev.parameters.push(new ethereum.EventParam("dataSetId", ethereum.Value.fromUnsignedBigInt(dataSetId))); + ev.parameters.push(new ethereum.EventParam("pieceId", ethereum.Value.fromUnsignedBigInt(pieceId))); + + const cidTuple = new ethereum.Tuple(); cidTuple.push(ethereum.Value.fromBytes(pieceCidBytes)); - ev.parameters.push( - new ethereum.EventParam("pieceCid", ethereum.Value.fromTuple(cidTuple)) - ); + ev.parameters.push(new ethereum.EventParam("pieceCid", ethereum.Value.fromTuple(cidTuple))); - ev.parameters.push( - new ethereum.EventParam("keys", ethereum.Value.fromStringArray(keys)) - ); - ev.parameters.push( - new ethereum.EventParam("values", ethereum.Value.fromStringArray(values)) - ); + ev.parameters.push(new ethereum.EventParam("keys", ethereum.Value.fromStringArray(keys))); + ev.parameters.push(new ethereum.EventParam("values", ethereum.Value.fromStringArray(values))); ev.block.number = blockNumber; ev.block.timestamp = timestamp; @@ -137,38 +74,16 @@ export function createFwssServiceTerminatedEvent( dataSetId: BigInt, caller: Address, blockNumber: BigInt = BigInt.fromI32(1), - timestamp: BigInt = BigInt.fromI32(1) + timestamp: BigInt = BigInt.fromI32(1), ): FwssServiceTerminated { - let ev = changetype(newMockEvent()); - ev.parameters = new Array(); - - ev.parameters.push( - new ethereum.EventParam("caller", ethereum.Value.fromAddress(caller)) - ); - ev.parameters.push( - new ethereum.EventParam( - "dataSetId", - ethereum.Value.fromUnsignedBigInt(dataSetId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "pdpRailId", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "cacheMissRailId", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "cdnRailId", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)) - ) - ); + const ev = changetype(newMockEvent()); + ev.parameters = []; + + ev.parameters.push(new ethereum.EventParam("caller", ethereum.Value.fromAddress(caller))); + ev.parameters.push(new ethereum.EventParam("dataSetId", ethereum.Value.fromUnsignedBigInt(dataSetId))); + ev.parameters.push(new ethereum.EventParam("pdpRailId", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)))); + ev.parameters.push(new ethereum.EventParam("cacheMissRailId", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)))); + ev.parameters.push(new ethereum.EventParam("cdnRailId", ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(0)))); ev.block.number = blockNumber; ev.block.timestamp = timestamp; @@ -181,29 +96,14 @@ export function createFwssPdpPaymentTerminatedEvent( endEpoch: BigInt, pdpRailId: BigInt, blockNumber: BigInt = BigInt.fromI32(1), - timestamp: BigInt = BigInt.fromI32(1) + timestamp: BigInt = BigInt.fromI32(1), ): FwssPdpPaymentTerminated { - let ev = changetype(newMockEvent()); - ev.parameters = new Array(); - - ev.parameters.push( - new ethereum.EventParam( - "dataSetId", - ethereum.Value.fromUnsignedBigInt(dataSetId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "endEpoch", - ethereum.Value.fromUnsignedBigInt(endEpoch) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "pdpRailId", - ethereum.Value.fromUnsignedBigInt(pdpRailId) - ) - ); + const ev = changetype(newMockEvent()); + ev.parameters = []; + + ev.parameters.push(new ethereum.EventParam("dataSetId", ethereum.Value.fromUnsignedBigInt(dataSetId))); + ev.parameters.push(new ethereum.EventParam("endEpoch", ethereum.Value.fromUnsignedBigInt(endEpoch))); + ev.parameters.push(new ethereum.EventParam("pdpRailId", ethereum.Value.fromUnsignedBigInt(pdpRailId))); ev.block.number = blockNumber; ev.block.timestamp = timestamp; @@ -216,29 +116,14 @@ export function createFwssDataSetServiceProviderChangedEvent( oldServiceProvider: Address, newServiceProvider: Address, blockNumber: BigInt = BigInt.fromI32(1), - timestamp: BigInt = BigInt.fromI32(1) + timestamp: BigInt = BigInt.fromI32(1), ): FwssDataSetServiceProviderChanged { - let ev = changetype(newMockEvent()); - ev.parameters = new Array(); - - ev.parameters.push( - new ethereum.EventParam( - "dataSetId", - ethereum.Value.fromUnsignedBigInt(dataSetId) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "oldServiceProvider", - ethereum.Value.fromAddress(oldServiceProvider) - ) - ); - ev.parameters.push( - new ethereum.EventParam( - "newServiceProvider", - ethereum.Value.fromAddress(newServiceProvider) - ) - ); + const ev = changetype(newMockEvent()); + ev.parameters = []; + + ev.parameters.push(new ethereum.EventParam("dataSetId", ethereum.Value.fromUnsignedBigInt(dataSetId))); + ev.parameters.push(new ethereum.EventParam("oldServiceProvider", ethereum.Value.fromAddress(oldServiceProvider))); + ev.parameters.push(new ethereum.EventParam("newServiceProvider", ethereum.Value.fromAddress(newServiceProvider))); ev.block.number = blockNumber; ev.block.timestamp = timestamp; diff --git a/apps/subgraph/tests/fwss.test.ts b/apps/subgraph/tests/fwss.test.ts index d63d7db4..25e816ce 100644 --- a/apps/subgraph/tests/fwss.test.ts +++ b/apps/subgraph/tests/fwss.test.ts @@ -1,5 +1,5 @@ -import { assert, beforeEach, clearStore, describe, test } from "matchstick-as/assembly/index"; import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { assert, beforeEach, clearStore, describe, test } from "matchstick-as/assembly/index"; import { handleFwssDataSetCreated, handleFwssDataSetServiceProviderChanged, @@ -9,7 +9,6 @@ import { } from "../src/fwss"; import { getRootEntityId } from "../src/helpers"; import { handleDataSetCreated, handlePiecesAdded } from "../src/pdp-verifier"; -import { createDataSetCreatedEvent, createRootsAddedEvent } from "./pdp-verifier-utils"; import { createFwssDataSetCreatedEvent, createFwssDataSetServiceProviderChangedEvent, @@ -17,6 +16,7 @@ import { createFwssPieceAddedEvent, createFwssServiceTerminatedEvent, } from "./fwss-utils"; +import { createDataSetCreatedEvent, createRootsAddedEvent } from "./pdp-verifier-utils"; const SET_ID = BigInt.fromI32(1); const PROVIDER_ID = BigInt.fromI32(42); @@ -264,9 +264,13 @@ describe("FWSS handlers", () => { // FWSS.PieceAdded adds ipfsRootCID. handleFwssPieceAdded( - createFwssPieceAddedEvent(SET_ID, ROOT_ID, Bytes.fromHexString("0xdeadbeef"), ["ipfsRootCID"], [ - "bafybeiexamplecid", - ]), + createFwssPieceAddedEvent( + SET_ID, + ROOT_ID, + Bytes.fromHexString("0xdeadbeef"), + ["ipfsRootCID"], + ["bafybeiexamplecid"], + ), ); const dsId = PROOF_SET_ENTITY_ID.toHexString(); diff --git a/apps/subgraph/tests/pdp-verifier-utils.ts b/apps/subgraph/tests/pdp-verifier-utils.ts index d3e37a29..536b03ea 100644 --- a/apps/subgraph/tests/pdp-verifier-utils.ts +++ b/apps/subgraph/tests/pdp-verifier-utils.ts @@ -1,18 +1,18 @@ +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; import { newMockEvent } from "matchstick-as"; -import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts"; import { DataSetCreated, - PiecesAdded, - NextProvingPeriod, - PossessionProven, DataSetDeleted, DataSetEmpty, + NextProvingPeriod, + PiecesAdded, + PossessionProven, } from "../generated/PDPVerifier/PDPVerifier"; // Helper to generate unique transaction hash from a counter export function generateTxHash(counter: i32): Bytes { const hexCounter = counter.toString(16).padStart(64, "0"); - return Bytes.fromHexString("0x" + hexCounter); + return Bytes.fromHexString(`0x${hexCounter}`); } // Mocks the DataSetCreated event @@ -25,24 +25,15 @@ export function createDataSetCreatedEvent( blockNumber: BigInt = BigInt.fromI32(1), timestamp: BigInt = BigInt.fromI32(1), txHash: Bytes = generateTxHash(1), - logIndex: BigInt = BigInt.fromI32(0) + logIndex: BigInt = BigInt.fromI32(0), ): DataSetCreated { - let DataSetCreatedEvent = changetype(newMockEvent()); + const DataSetCreatedEvent = changetype(newMockEvent()); - DataSetCreatedEvent.parameters = new Array(); + DataSetCreatedEvent.parameters = []; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); - let providerParam = new ethereum.EventParam( - "provider", - ethereum.Value.fromAddress(provider) - ); - let rootParam = new ethereum.EventParam( - "root", - ethereum.Value.fromFixedBytes(root) - ); + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); + const providerParam = new ethereum.EventParam("provider", ethereum.Value.fromAddress(provider)); + const rootParam = new ethereum.EventParam("root", ethereum.Value.fromFixedBytes(root)); DataSetCreatedEvent.parameters.push(setIdParam); DataSetCreatedEvent.parameters.push(providerParam); @@ -64,46 +55,37 @@ export function createRootsAddedEvent( setId: BigInt, pieceIds: BigInt[], sender: Address, - contractAddress: Address + contractAddress: Address, ): PiecesAdded { - let rootsAddedEvent = changetype(newMockEvent()); + const rootsAddedEvent = changetype(newMockEvent()); - rootsAddedEvent.parameters = new Array(); + rootsAddedEvent.parameters = []; rootsAddedEvent.address = contractAddress; rootsAddedEvent.transaction.from = sender; rootsAddedEvent.transaction.to = contractAddress; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); - let rootIdsParam = new ethereum.EventParam( - "pieceIds", - ethereum.Value.fromUnsignedBigIntArray(pieceIds) - ); + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); + const rootIdsParam = new ethereum.EventParam("pieceIds", ethereum.Value.fromUnsignedBigIntArray(pieceIds)); - let pieceCids: Array = []; + const pieceCids: Array = []; for (let i = 0; i < pieceIds.length; i++) { - let cidTuple = new ethereum.Tuple(); - let cidData = Bytes.fromHexString( - "0x01559120258ff7f7021387dcea7164b7d1c4a98bd6f8d3c187e3114795efa391df307c8aa9d5d5cbac03" + const cidTuple = new ethereum.Tuple(); + const cidData = Bytes.fromHexString( + "0x01559120258ff7f7021387dcea7164b7d1c4a98bd6f8d3c187e3114795efa391df307c8aa9d5d5cbac03", ); cidTuple.push(ethereum.Value.fromBytes(cidData)); pieceCids.push(cidTuple); } - let pieceCidsParam = new ethereum.EventParam( - "pieceCids", - ethereum.Value.fromTupleArray(pieceCids) - ); + const pieceCidsParam = new ethereum.EventParam("pieceCids", ethereum.Value.fromTupleArray(pieceCids)); rootsAddedEvent.parameters.push(setIdParam); rootsAddedEvent.parameters.push(rootIdsParam); rootsAddedEvent.parameters.push(pieceCidsParam); - let txInputHex = + const txInputHex = "0x9afd37f20000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002a01559120258ff7f7021387dcea7164b7d1c4a98bd6f8d3c187e3114795efa391df307c8aa9d5d5cbac030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a05f13cbf0c320f1092664967af5de13e4abe964d4f755c0d4cffe18a146f395030000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b69706673526f6f744349440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003b626166796265696537696d32766e766870347a726d6778776c6b336d6133736f736f6e743765367776726f63336134756261707a7a7a3368796a75000000000000000000000000000000000000000000000000000000000000000000000000411b4c7e389fe7383d20d251599c194c9ddb3e71d79c2c1b44fe15b0f505aea92e525239a7e91647c64370054fe8a779486342fafb8971a7eb69101c97368c4bf61b00000000000000000000000000000000000000000000000000000000000000"; - let txInput = Bytes.fromHexString(txInputHex); + const txInput = Bytes.fromHexString(txInputHex); rootsAddedEvent.transaction.input = txInput; rootsAddedEvent.block.number = BigInt.fromI32(1); @@ -120,24 +102,18 @@ export function createNextProvingPeriodEvent( blockNumber: BigInt = BigInt.fromI32(1), timestamp: BigInt = BigInt.fromI32(1), txHash: Bytes = generateTxHash(2), - logIndex: BigInt = BigInt.fromI32(0) + logIndex: BigInt = BigInt.fromI32(0), ): NextProvingPeriod { - let nextProvingPeriodEvent = changetype(newMockEvent()); + const nextProvingPeriodEvent = changetype(newMockEvent()); - nextProvingPeriodEvent.parameters = new Array(); + nextProvingPeriodEvent.parameters = []; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); - let challengeEpochParam = new ethereum.EventParam( + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); + const challengeEpochParam = new ethereum.EventParam( "challengeEpoch", - ethereum.Value.fromUnsignedBigInt(challengeEpoch) - ); - let leafCountParam = new ethereum.EventParam( - "leafCount", - ethereum.Value.fromUnsignedBigInt(leafCount) + ethereum.Value.fromUnsignedBigInt(challengeEpoch), ); + const leafCountParam = new ethereum.EventParam("leafCount", ethereum.Value.fromUnsignedBigInt(leafCount)); nextProvingPeriodEvent.parameters.push(setIdParam); nextProvingPeriodEvent.parameters.push(challengeEpochParam); @@ -160,35 +136,29 @@ export function createPossessionProvenEvent( blockNumber: BigInt = BigInt.fromI32(1), timestamp: BigInt = BigInt.fromI32(1), txHash: Bytes = generateTxHash(3), - logIndex: BigInt = BigInt.fromI32(0) + logIndex: BigInt = BigInt.fromI32(0), ): PossessionProven { if (pieceIds.length !== offsets.length) { throw new Error( - `createPossessionProvenEvent: pieceIds.length (${pieceIds.length}) must equal offsets.length (${offsets.length})` + `createPossessionProvenEvent: pieceIds.length (${pieceIds.length}) must equal offsets.length (${offsets.length})`, ); } - let possessionProvenEvent = changetype(newMockEvent()); + const possessionProvenEvent = changetype(newMockEvent()); - possessionProvenEvent.parameters = new Array(); + possessionProvenEvent.parameters = []; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); - let challenges: Array = []; + const challenges: Array = []; for (let i = 0; i < pieceIds.length; i++) { - let challenge = new ethereum.Tuple(); + const challenge = new ethereum.Tuple(); challenge.push(ethereum.Value.fromUnsignedBigInt(pieceIds[i])); challenge.push(ethereum.Value.fromUnsignedBigInt(offsets[i])); challenges.push(challenge); } - let challengesParam = new ethereum.EventParam( - "challenges", - ethereum.Value.fromTupleArray(challenges) - ); + const challengesParam = new ethereum.EventParam("challenges", ethereum.Value.fromTupleArray(challenges)); possessionProvenEvent.parameters.push(setIdParam); possessionProvenEvent.parameters.push(challengesParam); @@ -209,19 +179,16 @@ export function createDataSetDeletedEvent( blockNumber: BigInt = BigInt.fromI32(1), timestamp: BigInt = BigInt.fromI32(1), txHash: Bytes = generateTxHash(4), - logIndex: BigInt = BigInt.fromI32(0) + logIndex: BigInt = BigInt.fromI32(0), ): DataSetDeleted { - let dataSetDeletedEvent = changetype(newMockEvent()); + const dataSetDeletedEvent = changetype(newMockEvent()); - dataSetDeletedEvent.parameters = new Array(); + dataSetDeletedEvent.parameters = []; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); - let deletedLeafCountParam = new ethereum.EventParam( + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); + const deletedLeafCountParam = new ethereum.EventParam( "deletedLeafCount", - ethereum.Value.fromUnsignedBigInt(deletedLeafCount) + ethereum.Value.fromUnsignedBigInt(deletedLeafCount), ); dataSetDeletedEvent.parameters.push(setIdParam); @@ -232,9 +199,7 @@ export function createDataSetDeletedEvent( dataSetDeletedEvent.block.timestamp = timestamp; dataSetDeletedEvent.transaction.hash = txHash; dataSetDeletedEvent.logIndex = logIndex; - dataSetDeletedEvent.transaction.from = Address.fromString( - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a" - ); + dataSetDeletedEvent.transaction.from = Address.fromString("0xa16081f360e3847006db660bae1c6d1b2e17ec2a"); dataSetDeletedEvent.transaction.to = contractAddress; return dataSetDeletedEvent; @@ -246,16 +211,13 @@ export function createDataSetEmptyEvent( blockNumber: BigInt = BigInt.fromI32(1), timestamp: BigInt = BigInt.fromI32(1), txHash: Bytes = generateTxHash(5), - logIndex: BigInt = BigInt.fromI32(0) + logIndex: BigInt = BigInt.fromI32(0), ): DataSetEmpty { - let dataSetEmptyEvent = changetype(newMockEvent()); + const dataSetEmptyEvent = changetype(newMockEvent()); - dataSetEmptyEvent.parameters = new Array(); + dataSetEmptyEvent.parameters = []; - let setIdParam = new ethereum.EventParam( - "setId", - ethereum.Value.fromUnsignedBigInt(setId) - ); + const setIdParam = new ethereum.EventParam("setId", ethereum.Value.fromUnsignedBigInt(setId)); dataSetEmptyEvent.parameters.push(setIdParam); @@ -264,9 +226,7 @@ export function createDataSetEmptyEvent( dataSetEmptyEvent.block.timestamp = timestamp; dataSetEmptyEvent.transaction.hash = txHash; dataSetEmptyEvent.logIndex = logIndex; - dataSetEmptyEvent.transaction.from = Address.fromString( - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a" - ); + dataSetEmptyEvent.transaction.from = Address.fromString("0xa16081f360e3847006db660bae1c6d1b2e17ec2a"); dataSetEmptyEvent.transaction.to = contractAddress; return dataSetEmptyEvent; diff --git a/apps/subgraph/tests/pdp-verifier.test.ts b/apps/subgraph/tests/pdp-verifier.test.ts index 1c0ece7a..3ff37757 100644 --- a/apps/subgraph/tests/pdp-verifier.test.ts +++ b/apps/subgraph/tests/pdp-verifier.test.ts @@ -1,5 +1,5 @@ -import { afterAll, assert, beforeAll, clearStore, describe, test } from "matchstick-as/assembly/index"; import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { afterAll, assert, beforeAll, clearStore, describe, test } from "matchstick-as/assembly/index"; import { getRootEntityId, getRootSampleKey } from "../src/helpers"; import { handleDataSetCreated, handlePiecesAdded } from "../src/pdp-verifier"; import { createDataSetCreatedEvent, createRootsAddedEvent } from "./pdp-verifier-utils"; @@ -7,8 +7,7 @@ import { createDataSetCreatedEvent, createRootsAddedEvent } from "./pdp-verifier const SET_ID = BigInt.fromI32(1); const ROOT_ID_1 = BigInt.fromI32(101); const RAW_SIZE_1 = BigInt.fromI32(10486897); -const ROOT_CID_1_STR = - "0x01559120258ff7f7021387dcea7164b7d1c4a98bd6f8d3c187e3114795efa391df307c8aa9d5d5cbac03"; +const ROOT_CID_1_STR = "0x01559120258ff7f7021387dcea7164b7d1c4a98bd6f8d3c187e3114795efa391df307c8aa9d5d5cbac03"; const SENDER_ADDRESS = Address.fromString("0xa16081f360e3847006db660bae1c6d1b2e17ec2a"); const CONTRACT_ADDRESS = Address.fromString("0xb16081f360e3847006db660bae1c6d1b2e17ec2b"); const PROOF_SET_ID_BYTES = Bytes.fromBigInt(SET_ID); @@ -29,7 +28,7 @@ describe("handlePiecesAdded Tests", () => { rootsAddedEvent.block.timestamp = BigInt.fromI32(100); rootsAddedEvent.block.number = BigInt.fromI32(50); rootsAddedEvent.logIndex = BigInt.fromI32(1); - rootsAddedEvent.transaction.hash = Bytes.fromHexString("0x" + "c".repeat(64)); + rootsAddedEvent.transaction.hash = Bytes.fromHexString(`0x${"c".repeat(64)}`); handlePiecesAdded(rootsAddedEvent); }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52dfce55..3cee57cc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -211,6 +211,9 @@ importers: specifier: 0.38.2 version: 0.38.2 devDependencies: + '@biomejs/biome': + specifier: 'catalog:' + version: 2.3.14 assemblyscript: specifier: 0.19.23 version: 0.19.23