Skip to content

Instantly share code, notes, and snippets.

View axiomatic-aardvark's full-sized avatar
:octocat:
Keep buidling

Petko Pavlovski axiomatic-aardvark

:octocat:
Keep buidling
View GitHub Profile
import { test } from "matchstick-as/assembly/index";
import { log } from "matchstick-as/assembly/log";
export function runTests(): void {
test("Success", () => {
log.success("Success!");
});
test("Error", () => {
log.error("Error :( ");
});
import { assert } from "matchstick-as/assembly/index";
import { ethereum } from "@graphprotocol/graph-ts";
assert.equals(ethereum.Value.fromString("hello"), ethereum.Value.fromString("hello"));
import { newMockEvent } from "matchstick-as/assembly/index";
import { ethereum, Address } from "@graphprotocol/graph-ts";
import { NewCustomEntity } from "../generated/MyDataSource/Example";
let newEntityEvent = newMockEvent(new NewCustomEntity()) as NewCustomEntity;
// Read
let logType = newEntityEvent.logType;
// Write
import { addMetadata } from "matchstick-as/assembly/index";
import { ethereum } from "@graphprotocol/graph-ts";
import { NewCustomEntity } from "../generated/MyDataSource/Example";
let base: ethereum.Event = new NewCustomEntity();
let newEntityEvent: NewCustomEntity = addMetadata(base);
import { assert, createMockedFunction } from "matchstick-as/assembly/index";
import { Contract } from "../../generated/MyDataSource/Example";
import { Address, ethereum } from "@graphprotocol/graph-ts";
let contractAddress = Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7");
let arg = ethereum.Value.fromString("example string arg");
createMockedFunction(contractAddress, "functionName", "functionName(string):(string)")
.withArgs([arg])
.reverts();
import { assert, createMockedFunction } from "matchstick-as/assembly/index";
import { Contract } from "../../generated/MyDataSource/Example";
import { Address, ethereum } from "@graphprotocol/graph-ts";
let contractAddress = Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7");
let arg = ethereum.Value.fromString("example string arg");
createMockedFunction(contractAddress, "functionName", "functionName(string):(string)")
.withArgs([arg])
.returns([ethereum.Value.fromString("result")]);
import { test, assert } from "matchstick-as/assembly/index";
import { CustomEntity } from '../../generated/schema';
import { Value } from "@graphprotocol/graph-ts";
export function runTests(): void {
test("Next test", () => {
let customEntity = new CustomEntity("434");
customEntity.set("name", Value.fromString("Frederick"));
customEntity.save();
import { clearStore, test, assert, newMockEvent } from "matchstick-as/assembly/index";
import { ethereum } from "@graphprotocol/graph-ts";
import { NewCustomEntity } from "../generated/MyDataSource/Example";
import { handleNewCustomEntity } from "../mapping";
export function runTests(): void {
test("Example", () => {
// Initialise event (this can be generalised into a separate function)
let newEntityEvent = newMockEvent(new NewCustomEntity()) as NewCustomEntity;
newEntityEvent.parameters = [];
import { NewCustomEntity } from "../generated/MyDataSource/Example";
import { CustomEntity } from '../generated/schema';
export function handleNewCustomEntity(event: NewCustomEntity): void {
let customEntity = new CustomEntity(event.params.id.toString());
customEntity.name = event.params.name;
customEntity.save();
}
import { NewEntity } from "../generated/Example/Example";
import { CustomEntity } from '../../generated/schema';
export function handleNewEntity(event: NewEntity): void {
let customEntity = new CustomEntity(event.params.id.toHex());
customEntity.name = event.params.displayName;
customEntity.save();
}