-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add unit test to the subgraph
- Loading branch information
Showing
9 changed files
with
227 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ typechain-types | |
build | ||
generated | ||
subgraph.yaml | ||
.bin | ||
.latest.json | ||
|
||
# Misc | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { afterEach, assert, clearStore, describe, log, test } from "matchstick-as"; | ||
import { | ||
ModuleRegistered as ModuleRegisteredEvent, | ||
ModuleRegistered, | ||
} from "../generated/ModuleRegistry/ModuleRegistry"; | ||
import { Address, ethereum } from "@graphprotocol/graph-ts"; | ||
import { newTypedMockEvent } from "matchstick-as/assembly/defaults"; | ||
import { handleModuleRegistered } from "../src/module-registry"; | ||
|
||
describe("handleModuleRegistered()", () => { | ||
const moduleAddress = "0xF75BE6f9418710fd516fA82Afb3AAD07e11a0f1b"; | ||
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); | ||
|
||
assert.entityCount("Module", 1); | ||
|
||
assert.fieldEquals("Module", moduleAddress, "id", moduleAddress); | ||
assert.fieldEquals("Module", moduleAddress, "name", moduleName); | ||
assert.fieldEquals("Module", moduleAddress, "description", moduleDescription); | ||
assert.fieldEquals("Module", moduleAddress, "moduleAddress", moduleAddress); | ||
}); | ||
}); | ||
|
||
function createModuleRegisteredEvent( | ||
moduleAddress: string, | ||
moduleName: string, | ||
moduleDescription: string, | ||
): ModuleRegistered { | ||
const moduleRegisteredEvent = newTypedMockEvent<ModuleRegisteredEvent>(); | ||
|
||
moduleRegisteredEvent.parameters.push( | ||
new ethereum.EventParam("moduleAddress", ethereum.Value.fromAddress(Address.fromString(moduleAddress))), | ||
); | ||
moduleRegisteredEvent.parameters.push(new ethereum.EventParam("moduleName", ethereum.Value.fromString(moduleName))); | ||
moduleRegisteredEvent.parameters.push( | ||
new ethereum.EventParam("moduleDescription", ethereum.Value.fromString(moduleDescription)), | ||
); | ||
|
||
return moduleRegisteredEvent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { afterEach, assert, clearStore, describe, test } from "matchstick-as"; | ||
import { BigInt, ethereum } from "@graphprotocol/graph-ts"; | ||
import { newTypedMockEvent } from "matchstick-as/assembly/defaults"; | ||
import { handleSchemaCreated } from "../src/schema-registry"; | ||
import { SchemaCreated, SchemaCreated as SchemaCreatedEvent } from "../generated/SchemaRegistry/SchemaRegistry"; | ||
|
||
describe("handleSchemaCreated()", () => { | ||
const schemaId = "0x7930a5ebfabdd4ef76bbb8cdcbc2225b6256d9511d9cf5ff0d6514c1bdb4d7dc"; | ||
const schemaName = "module name"; | ||
const schemaDescription = "module description"; | ||
const schemaContext = "schema context"; | ||
const schemaString = "(bool isBuilder)"; | ||
|
||
afterEach(() => { | ||
clearStore(); | ||
}); | ||
|
||
test("Should create a new Schema entity", () => { | ||
assert.entityCount("Schema", 0); | ||
|
||
const schemaCreatedEvent = createSchemaCreatedEvent( | ||
schemaId, | ||
schemaName, | ||
schemaDescription, | ||
schemaContext, | ||
schemaString, | ||
); | ||
|
||
handleSchemaCreated(schemaCreatedEvent); | ||
|
||
assert.entityCount("Schema", 1); | ||
|
||
assert.fieldEquals("Schema", schemaId, "id", schemaId); | ||
assert.fieldEquals("Schema", schemaId, "name", schemaName); | ||
assert.fieldEquals("Schema", schemaId, "description", schemaDescription); | ||
assert.fieldEquals("Schema", schemaId, "context", schemaContext); | ||
assert.fieldEquals("Schema", schemaId, "schema", schemaString); | ||
}); | ||
}); | ||
|
||
function createSchemaCreatedEvent( | ||
schemaId: string, | ||
schemaName: string, | ||
schemaDescription: string, | ||
schemaContext: string, | ||
schemaString: string, | ||
): SchemaCreated { | ||
const schemaCreatedEvent = newTypedMockEvent<SchemaCreatedEvent>(); | ||
|
||
schemaCreatedEvent.parameters.push( | ||
new ethereum.EventParam("id", ethereum.Value.fromI32(BigInt.fromString(schemaId).toI32())), | ||
); | ||
schemaCreatedEvent.parameters.push(new ethereum.EventParam("name", ethereum.Value.fromString(schemaName))); | ||
schemaCreatedEvent.parameters.push( | ||
new ethereum.EventParam("description", ethereum.Value.fromString(schemaDescription)), | ||
); | ||
schemaCreatedEvent.parameters.push(new ethereum.EventParam("context", ethereum.Value.fromString(schemaContext))); | ||
schemaCreatedEvent.parameters.push(new ethereum.EventParam("schemaString", ethereum.Value.fromString(schemaString))); | ||
|
||
return schemaCreatedEvent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"extends": "@graphprotocol/graph-ts/types/tsconfig.base.json" | ||
"extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", | ||
"include": ["src", "tests"] | ||
} |