diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..e8882ee --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,28 @@ +name: Tests (L1) + +on: + pull_request: + types: [opened, reopened, synchronize] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + # Install commands + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '20' + registry-url: https://registry.npmjs.org + - name: yarn add ts-node + run: yarn add ts-node + - name: yarn install + run: yarn install + + # Run scripts + - name: Test + run: ./node_modules/@graphprotocol/graph-cli/bin/run test -v 0.6.0-rc.2 diff --git a/tests/subgraph-availability-manager.test.ts b/tests/subgraph-availability-manager.test.ts index d2d2b54..20fd16e 100644 --- a/tests/subgraph-availability-manager.test.ts +++ b/tests/subgraph-availability-manager.test.ts @@ -6,48 +6,92 @@ import { beforeAll, afterAll } from "matchstick-as/assembly/index" -import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts" -import { NewOwnership } from "../generated/schema" -import { NewOwnership as NewOwnershipEvent } from "../generated/SubgraphAvailabilityManager/SubgraphAvailabilityManager" -import { handleNewOwnership } from "../src/subgraph-availability-manager" -import { createNewOwnershipEvent } from "./subgraph-availability-manager-utils" +import { Address, BigInt } from "@graphprotocol/graph-ts" +import { handleNewOwnership, handleNewPendingOwnership, handleOracleSet, handleOracleVote, handleVoteTimeLimitSet } from "../src/subgraph-availability-manager" +import { createNewOwnershipEvent, createNewPendingOwnershipEvent, createOracleSetEvent, createOracleVoteEvent, createVoteTimeLimitSetEvent } from "./subgraph-availability-manager-utils" + +import { logStore } from 'matchstick-as/assembly/store' // Tests structure (matchstick-as >=0.5.0) // https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 -describe("Describe entity assertions", () => { - beforeAll(() => { - let from = Address.fromString("0x0000000000000000000000000000000000000001") - let to = Address.fromString("0x0000000000000000000000000000000000000001") - let newNewOwnershipEvent = createNewOwnershipEvent(from, to) - handleNewOwnership(newNewOwnershipEvent) - }) +const defaultID = "0xa16081f360e3847006db660bae1c6d1b2e17ec2a01000000" +const samID = "0x0000000000000000000000000000000000000001" +const samAddress = Address.fromString(samID) +const governorID = "0x0000000000000000000000000000000000000002" +const governorAddress = Address.fromString(governorID) +const pendingGovernorID = "0x0000000000000000000000000000000000000003" +const pendingGovernorAddress = Address.fromString(pendingGovernorID) +const oracleID = "0x0000000000000000000000000000000000000004" +const oracleAddress = Address.fromString(oracleID) +const subgraphDeploymentID = "0x0000000000000000000000000000000000000005" +const subgraphDeploymentAddress = Address.fromString(subgraphDeploymentID) +describe("OWNERSHIP", () => { afterAll(() => { clearStore() }) - // For more test scenarios, see: - // https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test + test("NewPendingOwnership created and stored", () => { + let newPendingOwnershipEvent = createNewPendingOwnershipEvent(governorAddress, pendingGovernorAddress) + handleNewPendingOwnership(newPendingOwnershipEvent) + + assert.entityCount("NewPendingOwnership", 1) + assert.fieldEquals("NewPendingOwnership", defaultID, "from", governorID) + assert.fieldEquals("NewPendingOwnership", defaultID, "to", pendingGovernorID) + }) test("NewOwnership created and stored", () => { + let newNewOwnershipEvent = createNewOwnershipEvent(governorAddress, pendingGovernorAddress) + handleNewOwnership(newNewOwnershipEvent) + assert.entityCount("NewOwnership", 1) + assert.fieldEquals("NewOwnership", defaultID, "from", governorID) + assert.fieldEquals("NewOwnership", defaultID, "to", pendingGovernorID) + }) +}) - // 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function - assert.fieldEquals( - "NewOwnership", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", - "from", - "0x0000000000000000000000000000000000000001" - ) - assert.fieldEquals( - "NewOwnership", - "0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", - "to", - "0x0000000000000000000000000000000000000001" +describe("ORACLE", () => { + afterAll(() => { + clearStore() + }) + + test("OracleSet created and stored", () => { + let newOracleSetEvent = createOracleSetEvent(BigInt.fromI32(0), oracleAddress) + handleOracleSet(newOracleSetEvent) + + assert.entityCount("OracleSet", 1) + assert.fieldEquals("OracleSet", defaultID, "index", "0") + assert.fieldEquals("OracleSet", defaultID, "oracle", oracleID) + }) + + test("OracleVote created and stored", () => { + let newOracleVoteEvent = createOracleVoteEvent( + subgraphDeploymentAddress, + true, + BigInt.fromI32(0), + BigInt.fromI32(300) ) + handleOracleVote(newOracleVoteEvent) + + assert.entityCount("OracleVote", 1) + assert.fieldEquals("OracleVote", defaultID, "subgraphDeploymentID", subgraphDeploymentID) + assert.fieldEquals("OracleVote", defaultID, "deny", "true") + assert.fieldEquals("OracleVote", defaultID, "oracleIndex", "0") + assert.fieldEquals("OracleVote", defaultID, "timestamp", "300") + }) +}) + +describe("VOTE_TIME_LIMIT", () => { + afterAll(() => { + clearStore() + }) + + test("VoteTimeLimit created and stored", () => { + let newVoteTimeLimitEvent = createVoteTimeLimitSetEvent(BigInt.fromI32(300)) + handleVoteTimeLimitSet(newVoteTimeLimitEvent) - // More assert options: - // https://thegraph.com/docs/en/developer/matchstick/#asserts + assert.entityCount("VoteTimeLimitSet", 1) + assert.fieldEquals("VoteTimeLimitSet", defaultID, "voteTimeLimit", "300") }) })