• Stars
    star
    207
  • Rank 189,769 (Top 4 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 3 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️

GitHub Banner-1

License: MIT

👋 Welcome to Matchstick - a unit testing framework for The Graph protocol. Try out your mapping logic in a sandboxed environment and ensure your handlers run correctly when deploying your awesome subgraph!

Quick Start 🚀

Configuration ⚙️

Matchstick can be configured to use a custom tests and libs folder via matchstick.yaml config file:

  • To change the default tests location (./tests), add testsFolder: path/to/tests_folder

  • To change the default libs location (./node_modules), add libsFolder: path/to/node_modules

  • To change the default manifest location (./subgraph.yaml), add manifestPath: path/to/subgraph.yaml

Docker 🐳

The quickest way to use Matchstick "out of the box" is to build and run an ubuntu-based Docker container with a Matchstick image. Steps:

  • Install Docker if you don't have it already.

  • Create a file named Dockerfile in the root folder of your subgraph project, and paste the contents of this file there. Replace <MATCHSTICK_VERSION> placeholder with the desired matchstick version. You can find all available versions here

  • Build a Matchstick image using the following command:

docker build -t matchstick .
  • The build step might take a while, but once that's done we can quickly run our tests like this:
docker run -it --rm --mount type=bind,source=<absolute/path/to/project>,target=/matchstick matchstick

❗ If you want to pass arguments to Matchstick (for instance to test only a specific datasource or to generate a test coverage report) you can do so like this:

docker run -e ARGS="gravity" -it --rm --mount type=bind,source=<absolute/path/to/project>,target=/matchstick matchstick

Note: The command will mount the project folder in the container, so you don't need to rebuild the image after every change to your code. Also any changes that happen to files during the run will persist on the host machine as well. More info about docker bind mounts

After that you can go straight to the final setup step and you'll be all set to start writing your first unit test.

❗ If you have previously ran graph test you may encounter the following error during docker build: error from sender: failed to xattr node_modules/binary-install-raw/bin/binary-<platform>: permission denied. In this case create a file named .dockerignore in the root folder and add node_modules/binary-install-raw/bin

❗ Although using the Docker approach is easy, we highly recommend using Matchstick via OS-specific binary (which is downloaded automatically when you run graph test). The Docker approach should only be considered if for some reason you cannot get graph test to work, or if you just want to quickly try something out.

OS-specific release binaries ⚙️

The release binary comes in two flavours - for МacOS and Linux. To add Matchstick to your subgraph project just open up a terminal, navigate to the root folder of your project and simply run graph test - it downloads the latest Matchstick binary and runs the specified test or all tests in a test folder (or all existing tests if no datasource flag is specified). Example usage: graph test gravity.

❗ If you don't have Postgres installed, you will need to install it. Instructions for that below: ❗❗❗ Since graph-node depends on diesel (and diesel requires a local postgres installation) we highly advise using the commands below as adding it in any other way may cause unexpected errors!

MacOS 

❗ Postgres installation command:

brew install postgresql@14

Then create new symlink to the lib:

ln -sf /usr/local/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/opt/postgresql/lib/libpq.5.dylib

Linux 🐧

❗ Postgres installation command (depends on your distro):

sudo apt install postgresql

WSL (Windows Subsystem for Linux) 🤖

You can use Matchstick on WSL both using the Docker approach and the binary approach. As WSL can be a bit tricky, here's a few tips in case you encounter issues like static BYTES = Symbol("Bytes") SyntaxError: Unexpected token = or <PROJECT_PATH>/node_modules/gluegun/build/index.js:13 throw up;, or anything else that looks off:

Please make sure you're on a newer version of Node.js (graph-cli doesn't support v10.19.0 anymore, and that is still the default version for new Ubuntu images on WSL. For instance Matchstick is confirmed to be working on WSL with v18.1.0, you can switch to it either via nvm or if you update your global Node.js). Don't forget to delete node_modules and to run npm install again after updating you nodejs! Then, make sure you have libpq installed, you can do that by running sudo apt-get install libpq-dev. And finally, do not use graph test (which uses your global installation of graph-cli and for some reason that looks like it's broken on WSL currently), instead use yarn test or npm run test (that will use the local, project-level instance of graph-cli, which works like a charm. For that you would of course need to have a "test" script in your package.json file which can be something as simple as "test": "graph test").

Install dependencies

In order to use the test helper methods and run the tests, you will need to install the following dependencies:

yarn add --dev matchstick-as

Now you can jump straight to the examples in our demo-subgraph and start your journey in Subgraph unit testing!

Building from source

Prerequisites

To build and run Matchstick you need to have the following installed on your system:

Setup

Clone this repository and run cargo build. If that executes successfully congratulations 🎉 you're all set.

NOTE: You may encounter an error, related to missing libpq dependencies on your system. In that case - install the missing dependencies (listed in the error log) with your package manager.

Next steps 🎯

There is a lot of room for improvements to Matchstick. We're trying to gather as much feedback from subgraph developers as we can, to understand how we can solve the problems they face when building subgraphs, as well as how we can make the overall testing process as smooth and streamlined as possible.

There's a GitHub project board where we keep track of day to day work which you can check out here.

You can check out the full list of tasks here.

Technologies used 💻

diagram-resized

The Matchstick framework is built in Rust and acts as a wrapper for the generated WebAssembly module that contains the mappings and the unit tests. It passes the host function implementations down to the module, to be used in the tests (and in the mappings if needed). The framework also acts as a proxy for structs defined in the graph-node repo, because it needs to pass down all the usual imports, as well as a few bonus/mocked ones glued on top.

Matchstick also relies on a helper library - matchstick-as, written in AssemblyScript and used as an import in the unit tests.

More Repositories

1

etherlime

Dapp Development framework based on ethers.js
JavaScript
185
star
2

RollupCodes

Interactive Specification of Ethereum Rollups
MDX
87
star
3

demo-subgraph

Demo Subgraph (The Graph) showcasing unit testing with Matchstick!
TypeScript
45
star
4

eoslime

Complete EOSIO framework for development, testing, and deployment in JavaScript
JavaScript
38
star
5

extractoor-contracts

EVM contracts that can prove storage slots of Ethereum Rollups using MPT Inclusion proofs
Solidity
32
star
6

subsembly

Framework for building AssemblyScript Substrate Runtimes
TypeScript
31
star
7

Fruzhin

Java implementation of the Polkadot Host
Java
30
star
8

hashport-validator

Official repository containing the source code of the Hashport validators
Go
23
star
9

matchstick-as

Helper library for writing subgraph unit tests in Assemblyscript
TypeScript
20
star
10

as-scale-codec

AssemblyScript implementation of the SCALE codec used in the Parity Substrate framework.
TypeScript
19
star
11

as-substrate-runtime

This is a Substrate PoC Account-Based Runtime written in AssemblyScript.
TypeScript
14
star
12

react-web3-boilerplate

TypeScript
13
star
13

gosemble

Go-based framework for building Polkadot/Substrate-compatible runtimes. 🧱
Go
11
star
14

batched-transactions

JavaScript
10
star
15

hardhat-hethers

👷 Hardhat plugin for development on Hedera Hashgraph
TypeScript
10
star
16

react-native-auth-starter

Starter project for mobile app application with Home, Login and Register page. [ React Native, TypeScript, MobX, Axios ]
TypeScript
9
star
17

based-preconfirmations-research

8
star
18

forta-starter-kits

JavaScript
8
star
19

hashport-contracts

The EVM Smart Contracts of Hashport
JavaScript
6
star
20

IdentityProxy

Playground for identity proxies
JavaScript
5
star
21

HeliSwap-frontend

TypeScript
4
star
22

UpgradeableSolidityContract

Upgradeable Contracts Repository
JavaScript
4
star
23

limeacademy-next-web3-boilerplate

Boilerplate for Web3 Next dApp
TypeScript
4
star
24

stylus-benchmark

Repostory for benchmarking Stylus vs EVM contracts
Rust
3
star
25

APPCO

JavaScript
3
star
26

hardhat-hedera-example

Example project showcasing Smart Contract Development in Hedera Hashgraph
JavaScript
3
star
27

eoslime-shape-react

JavaScript
3
star
28

extractoor-sdk

TypeScript
3
star
29

wasm-injector

Rust-based command line utility to manipulate Substrate runtimes
Rust
2
star
30

limepay-contracts

JavaScript
2
star
31

SmartContracts-Template

Template repository for EVM Smart Contract Projects with Hardhat
TypeScript
2
star
32

forta-agent-scripts

JavaScript
2
star
33

goscale

TinyGo compatible SCALE codec
Go
2
star
34

mongoose-immutable-plugin

Mongoose plugin guarding fields from modifications
JavaScript
2
star
35

ethereum-transaction-debugger

JavaScript
2
star
36

ae_sophia

JavaScript
2
star
37

gosemble-research

Research on a Go-based Polkadot/Substrate Runtimes
Go
2
star
38

wisp-prover

Prover REST API of the Wisp Protocol
Go
2
star
39

LimeAcademy

JavaScript
2
star
40

wisp-protocol

Circuits and EVM Contracts for Wisp Protocol (Ethereum Cross Rollup Communication Protocol)
Solidity
2
star
41

forta-flashloan-detector

A library for Forta agents that detects if a transaction event contains a flashloan
JavaScript
2
star
42

hardhat-l2-starter

TypeScript
1
star
43

SupplyChainPOCs

Go
1
star
44

hardhat-graph-plugin

JavaScript
1
star
45

SportsIcon-Vesting

JavaScript
1
star
46

merkletree

Go
1
star
47

devBgWorkshop2019

TypeScript
1
star
48

local-hedera

Developer tooling for running Local Hedera Network (Consensus + Mirror Nodes)
JavaScript
1
star
49

tx-inclusion-contracts

Solidity
1
star
50

HCS-Integration-Node

Go
1
star
51

tx-inclusion-poc-script

TypeScript
1
star
52

hedera-tickets-frontend

JavaScript
1
star
53

etherlime-shape-angular

Ready to use dApp with predefined Anglular front-end framework.
TypeScript
1
star
54

HeliSwap-contracts

Smart Contracts for the HTS enabled Hedera DEX
TypeScript
1
star
55

dog

Decentralised Organisations Generator
Vue
1
star
56

react-bootstrap-starter

TypeScript
1
star
57

hedera-tickets-backend

TypeScript
1
star
58

hardhat-local-hedera

Hardhat Local Hedera Repository
TypeScript
1
star
59

mockusd-faucet

JavaScript
1
star
60

hedera-tickets-contracts

JavaScript
1
star
61

bonding_mathematics

JavaScript
1
star
62

HeliSwap-landing-page

JavaScript
1
star
63

web3-examples

JavaScript
1
star
64

ECRecover

JavaScript
1
star
65

etherlime-shape-react

JavaScript
1
star
66

contract-verifier

Playground for contract verification in etherscan.io thru api call
JavaScript
1
star
67

next-web3-boilerplate

TypeScript
1
star
68

wisp

Wisp Protocol Relayer implementation in TypeScript (NestJS)
TypeScript
1
star
69

ZK-Merkle-Inclusion-Proof

Repository containing Circom implementation of ZK Merkle Inclusion Proofs
Circom
1
star
70

BlockSplit-Demo

Demonstration of how to use ZK-Proof in dApps
TypeScript
1
star