Skip to content

Commit e8ac473

Browse files
committed
lint
1 parent deb0940 commit e8ac473

File tree

23 files changed

+263
-176
lines changed

23 files changed

+263
-176
lines changed

.github/workflows/napi-release.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: release napi to npm
22
env:
33
DEBUG: napi:*
44
APP_NAME: lib
5-
MACOSX_DEPLOYMENT_TARGET: "10.13"
5+
MACOSX_DEPLOYMENT_TARGET: '10.13'
66
permissions:
77
contents: write
88
id-token: write
@@ -78,7 +78,11 @@ jobs:
7878
if: ${{ matrix.settings.docker }}
7979
with:
8080
image: ${{ matrix.settings.docker }}
81-
options: "--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build/libs/napi"
81+
options:
82+
'--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v
83+
${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{
84+
github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{
85+
github.workspace }}:/build -w /build/libs/napi'
8286
run: ${{ matrix.settings.build }}
8387
- name: Build
8488
run: ${{ matrix.settings.build }}
@@ -157,4 +161,4 @@ jobs:
157161
npm publish --access public
158162
env:
159163
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
164+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/cli/src/commands/test.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { Args, Command, Flags } from '@oclif/core'
2-
import { Matchstick, loadYamlConfig, checkForMatchstickBinary, downloadLatestBinary } from '@graph-tooling/matchstick'
1+
import {
2+
checkForMatchstickBinary,
3+
downloadLatestBinary,
4+
loadYamlConfig,
5+
Matchstick,
6+
} from '@graph-tooling/matchstick';
7+
import { Args, Command, Flags } from '@oclif/core';
38

49
export default class TestCommand extends Command {
510
static description = 'Runs rust binary for subgraph testing.';
@@ -35,11 +40,14 @@ export default class TestCommand extends Command {
3540
};
3641

3742
async run() {
38-
const { args: { datasource }, flags } = await this.parse(TestCommand)
43+
const {
44+
args: { datasource },
45+
flags,
46+
} = await this.parse(TestCommand);
3947

4048
// Load configuration from YAML file
41-
const config = loadYamlConfig('./matchstick.yaml')
42-
const testsDir = config.testsFolder || './tests'
49+
const config = loadYamlConfig('./matchstick.yaml');
50+
const testsDir = config.testsFolder || './tests';
4351

4452
// Matchstick binary setup
4553
const matchstick = new Matchstick({
@@ -49,15 +57,14 @@ export default class TestCommand extends Command {
4957
enableCoverage: flags.coverage,
5058
enableRecompile: flags.recompile,
5159
logs: flags.logs,
52-
})
60+
});
5361

5462
// Ensure binary is ready
5563
if (!checkForMatchstickBinary(testsDir) || flags.force) {
56-
await downloadLatestBinary(testsDir)
64+
await downloadLatestBinary(testsDir);
5765
}
5866

5967
// Execute tests
60-
matchstick.run(datasource)
68+
matchstick.run(datasource);
6169
}
6270
}
63-

packages/matchstick/.github/workflows/CI.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ jobs:
142142
if: ${{ matrix.settings.docker }}
143143
with:
144144
image: ${{ matrix.settings.docker }}
145-
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
145+
options:
146+
'--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v
147+
${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{
148+
github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{
149+
github.workspace }}:/build -w /build'
146150
run: ${{ matrix.settings.build }}
147151
- name: Build
148152
run: ${{ matrix.settings.build }}

packages/matchstick/README.md

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,93 @@
22

33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44

5-
👋 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!
5+
👋 Welcome to **Matchstick** - a unit testing framework for The Graph protocol. Try out your mapping
6+
logic in a sandboxed environment and ensure your handlers run correctly when deploying your awesome
7+
subgraph!
68

79
## Quick Start 🚀
810

9-
**Matchstick** relies on a helper library - [matchstick-as](https://github.com/LimeChain/matchstick-as "matchstick-as"), written in **AssemblyScript** and used as an import in the unit tests.
11+
**Matchstick** relies on a helper library -
12+
[matchstick-as](https://github.com/LimeChain/matchstick-as 'matchstick-as'), written in
13+
**AssemblyScript** and used as an import in the unit tests.
1014

1115
### Configuration ⚙️
12-
Matchstick can be configured to use a custom tests and libs folder via `matchstick.yaml` config file:
16+
17+
Matchstick can be configured to use a custom tests and libs folder via `matchstick.yaml` config
18+
file:
1319

1420
- To change the default tests location (./tests), add `testsFolder: path/to/tests_folder`
1521

1622
- To change the default libs location (./node_modules), add `libsFolder: path/to/node_modules`
1723

18-
- To change the default manifest location (./subgraph.yaml), add `manifestPath: path/to/subgraph.yaml`
24+
- To change the default manifest location (./subgraph.yaml), add
25+
`manifestPath: path/to/subgraph.yaml`
1926

2027
### Docker 🐳
21-
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:
28+
29+
The quickest way to use **Matchstick** "out of the box" is to build and run an ubuntu-based Docker
30+
container with a **Matchstick** image. Steps:
2231

2332
- Install [Docker](https://docs.docker.com/get-docker/) if you don't have it already.
2433

25-
- Create a file named `Dockerfile` in the root folder of your subgraph project, and paste [the contents of this file](https://github.com/LimeChain/demo-subgraph/blob/main/Dockerfile) there. Replace `<MATCHSTICK_VERSION>` placeholder with the desired matchstick version. You can find all available versions [here](https://github.com/LimeChain/matchstick/releases)
34+
- Create a file named `Dockerfile` in the root folder of your subgraph project, and paste
35+
[the contents of this file](https://github.com/LimeChain/demo-subgraph/blob/main/Dockerfile)
36+
there. Replace `<MATCHSTICK_VERSION>` placeholder with the desired matchstick version. You can
37+
find all available versions [here](https://github.com/LimeChain/matchstick/releases)
2638

2739
- Build a **Matchstick** image using the following command:
40+
2841
```
2942
docker build -t matchstick .
3043
```
3144

32-
- The build step might take a while, but once that's done we can quickly run our tests like this:
45+
- The build step might take a while, but once that's done we can quickly run our tests like this:
3346

3447
```
3548
docker run -it --rm --mount type=bind,source=<absolute/path/to/project>,target=/matchstick matchstick
3649
```
3750

38-
❗ 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:
51+
❗ If you want to pass arguments to **Matchstick** (for instance to test only a specific datasource
52+
or to generate a test coverage report) you can do so like this:
3953

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

44-
**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](https://docs.docker.com/storage/bind-mounts/)
58+
**Note:** The command will mount the project folder in the container, so you don't need to
59+
rebuild the image after every change to your code. Also any changes that happen to files during the
60+
run will persist on the host machine as well.
61+
[More info about docker bind mounts](https://docs.docker.com/storage/bind-mounts/)
4562

46-
After that you can go straight to [the final setup step](https://github.com/LimeChain/matchstick/tree/dockerize#install-dependencies) and you'll be all set to start writing your first unit test.
63+
After that you can go straight to
64+
[the final setup step](https://github.com/LimeChain/matchstick/tree/dockerize#install-dependencies)
65+
and you'll be all set to start writing your first unit test.
4766

48-
❗ 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`
67+
❗ If you have previously ran `graph test` you may encounter the following error during
68+
`docker build`:
69+
`error from sender: failed to xattr node_modules/binary-install-raw/bin/binary-<platform>: permission denied`.
70+
In this case create a file named `.dockerignore` in the root folder and add
71+
`node_modules/binary-install-raw/bin`
4972

50-
❗ 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.
73+
❗ Although using the Docker approach is easy, we highly recommend using **Matchstick** via
74+
OS-specific binary (which is downloaded automatically when you run `graph test`). The Docker
75+
approach should only be considered if for some reason you cannot get `graph test` to work, or if you
76+
just want to quickly try something out.
5177

5278
### OS-specific release binaries ⚙️
53-
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`.
79+
80+
The release binary comes in two flavours - for **МacOS** and **Linux**. To add **Matchstick** to
81+
your subgraph project just open up a terminal, navigate to the root folder of your project and
82+
simply run `graph test` - it downloads the latest **Matchstick** binary and runs the specified test
83+
or all tests in a test folder (or all existing tests if no datasource flag is specified). Example
84+
usage: `graph test gravity`.
5485

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

5890
#### MacOS 
91+
5992
❗ Postgres installation command:
6093

6194
```
@@ -69,45 +102,82 @@ ln -sf /usr/local/opt/postgresql@14/lib/postgresql@14/libpq.5.dylib /usr/local/o
69102
```
70103

71104
#### Linux 🐧
105+
72106
❗ Postgres installation command (depends on your distro):
107+
73108
```
74109
sudo apt install postgresql
75110
```
76111

77-
#### WSL (Windows Subsystem for Linux) 🤖
78-
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:
112+
#### WSL (Windows Subsystem for Linux) 🤖
79113

80-
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"`).
114+
You can use Matchstick on WSL both using the Docker approach and the binary approach. As WSL can be
115+
a bit tricky, here's a few tips in case you encounter issues like
116+
`static BYTES = Symbol("Bytes") SyntaxError: Unexpected token =` or
117+
`<PROJECT_PATH>/node_modules/gluegun/build/index.js:13 throw up;`, or anything else that looks off:
118+
119+
Please make sure you're on a newer version of Node.js (graph-cli doesn't support **v10.19.0**
120+
anymore, and that is still the default version for new Ubuntu images on WSL. For instance Matchstick
121+
is confirmed to be working on WSL with **v18.1.0**, you can switch to it either via **nvm** or if
122+
you update your global Node.js). Don't forget to delete `node_modules` and to run `npm install`
123+
again after updating you nodejs! Then, make sure you have **libpq** installed, you can do that by
124+
running `sudo apt-get install libpq-dev`. And finally, do not use `graph test` (which uses your
125+
global installation of graph-cli and for some reason that looks like it's broken on WSL currently),
126+
instead use `yarn test` or `npm run test` (that will use the local, project-level instance of
127+
graph-cli, which works like a charm. For that you would of course need to have a "test" script in
128+
your package.json file which can be something as simple as `"test": "graph test"`).
81129

82130
### Install dependencies
83-
In order to use the test helper methods and run the tests, you will need to install the following dependencies:
131+
132+
In order to use the test helper methods and run the tests, you will need to install the following
133+
dependencies:
84134

85135
```
86136
yarn add --dev matchstick-as
87137
```
88138

89-
Now you can jump straight to the [examples](https://github.com/LimeChain/demo-subgraph#readme "examples of tests") in our [demo-subgraph](https://github.com/LimeChain/demo-subgraph "demo-subgraph") and start your journey in Subgraph unit testing!
139+
Now you can jump straight to the
140+
[examples](https://github.com/LimeChain/demo-subgraph#readme 'examples of tests') in our
141+
[demo-subgraph](https://github.com/LimeChain/demo-subgraph 'demo-subgraph') and start your journey
142+
in Subgraph unit testing!
90143

91144
## Building from source
145+
92146
### Prerequisites
147+
93148
To build and run **Matchstick** you need to have the following installed on your system:
94149

95-
- Rust - [How to install Rust](https://www.rust-lang.org/en-US/install.html "How to install Rust")
150+
- Rust - [How to install Rust](https://www.rust-lang.org/en-US/install.html 'How to install Rust')
96151
- PostgreSQL – [PostgreSQL Downloads](https://www.postgresql.org/download/)
97152

98153
### Setup
99-
Clone this repository and run `cargo build`. If that executes successfully congratulations 🎉 you're all set.
100154

101-
**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.*
155+
Clone this repository and run `cargo build`. If that executes successfully congratulations 🎉 you're
156+
all set.
157+
158+
**NOTE:** _You may encounter an error, related to missing `libpq` dependencies on your system. In
159+
that case - install the missing dependencies (listed in the error log) with your package manager._
102160

103161
## Next steps 🎯
104-
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.
105162

106-
There's a GitHub project board where we keep track of day to day work which you can check out [here](https://github.com/LimeChain/matchstick/projects/1 "here").
163+
There is a lot of room for improvements to **Matchstick**. We're trying to gather as much feedback
164+
from subgraph developers as we can, to understand how we can solve the problems they face when
165+
building subgraphs, as well as how we can make the overall testing process as smooth and streamlined
166+
as possible.
167+
168+
There's a GitHub project board where we keep track of day to day work which you can check out
169+
[here](https://github.com/LimeChain/matchstick/projects/1 'here').
107170

108171
You can check out the full list of tasks [here](https://github.com/LimeChain/matchstick/projects/2).
109172

110173
## Technologies used 💻
174+
111175
![diagram-resized](https://user-images.githubusercontent.com/32264020/128724602-81699397-1bb9-4e54-94f5-bb0f40c2a38b.jpg)
112176

113-
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](https://github.com/graphprotocol/graph-node/tree/master/graph "graph-node repo"), because it needs to pass down all the usual imports, as well as a few bonus/mocked ones glued on top.
177+
The **Matchstick** framework is built in **Rust** and acts as a wrapper for the generated
178+
WebAssembly module that contains the mappings and the unit tests. It passes the host function
179+
implementations down to the module, to be used in the tests (and in the mappings if needed). The
180+
framework also acts as a proxy for structs defined in the
181+
[graph-node repo](https://github.com/graphprotocol/graph-node/tree/master/graph 'graph-node repo'),
182+
because it needs to pass down all the usual imports, as well as a few bonus/mocked ones glued on
183+
top.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import test from 'ava'
1+
import test from 'ava';
2+
import { sum } from '../index.js';
23

3-
import { sum } from '../index.js'
4-
5-
test('sum from native', (t) => {
6-
t.is(sum(1, 2), 3)
7-
})
4+
test('sum from native', t => {
5+
t.is(sum(1, 2), 3);
6+
});
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
import { handleNewGravatars, createNewGravatarEvent, trySaveGravatarFromContract, saveGravatarFromContract } from "./utils"
2-
import { test, log } from 'matchstick-as/assembly/index'
3-
import { handleCreateGravatar, handleNewGravatar } from "../src/gravity"
1+
import { log, test } from 'matchstick-as/assembly/index';
2+
import { handleCreateGravatar, handleNewGravatar } from '../src/gravity';
3+
import {
4+
createNewGravatarEvent,
5+
handleNewGravatars,
6+
saveGravatarFromContract,
7+
trySaveGravatarFromContract,
8+
} from './utils';
49

5-
test("0", () => {})
10+
test('0', () => {});
611

7-
test("1", () => {})
12+
test('1', () => {});
813

9-
test("2", () => {})
14+
test('2', () => {});
1015

11-
test("3", () => {})
16+
test('3', () => {});
1217

13-
test("4", () => {})
18+
test('4', () => {});
1419

15-
test("5", () => {})
20+
test('5', () => {});
1621

17-
test("6", () => {})
22+
test('6', () => {});

packages/matchstick/mocks/as/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Mock file
2-
import { Gravatar } from '../generated/schema'
2+
import { Gravatar } from '../generated/schema';
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

packages/matchstick/mocks/yamls/subgraph_invalid.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: Demo Subgraph showcasing unit testing with Matchstick!
33
repository: https://github.com/LimeChain/demo-subgraph
44
schema:
55
file: ./schema.graphql
6-
invalid
76
dataSources:
87
- kind: ethereum/contract
98
name: Gravity
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "matchstick-android-arm-eabi",
33
"version": "0.0.0",
4-
"os": [
5-
"android"
6-
],
4+
"license": "MIT",
5+
"engines": {
6+
"node": ">= 10"
7+
},
78
"cpu": [
89
"arm"
910
],
11+
"os": [
12+
"android"
13+
],
1014
"main": "matchstick.android-arm-eabi.node",
1115
"files": [
1216
"matchstick.android-arm-eabi.node"
13-
],
14-
"license": "MIT",
15-
"engines": {
16-
"node": ">= 10"
17-
}
18-
}
17+
]
18+
}

0 commit comments

Comments
 (0)