Skip to content

Instantly share code, notes, and snippets.

@axiomatic-aardvark
Last active August 20, 2021 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axiomatic-aardvark/0f04b30602f501bee9c78cfe8f8a9ceb to your computer and use it in GitHub Desktop.
Save axiomatic-aardvark/0f04b30602f501bee9c78cfe8f8a9ceb to your computer and use it in GitHub Desktop.
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 = [];
let idParam = new ethereum.EventParam();
idParam.value = ethereum.Value.fromI32(434);
let nameParam = new ethereum.EventParam();
nameParam.value = ethereum.Value.fromString("Don Draper");
newEntityEvent.parameters.push(idParam);
newEntityEvent.parameters.push(nameParam);
// Call mappings
handleNewCustomEntity(newEntityEvent);
// Assert the state of the store
assert.fieldEquals("CustomEntity", "434", "name", "Don Draper");
// Clear the store before the next test (optional)
clearStore();
});
test("Next test", () => {
//...
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment