Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated tests and bundling #34

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/bundle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Bundle"

on:
workflow_dispatch:
push:
branches:
- main
paths:
- "modules/*.json"
- "infra/*.json"

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.16.1
- name: Set up foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install
run: yarn install --frozen-lockfile
- name: Bundle
run: |
yarn bundle
yarn format-bundle
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "automated bundle"
git push
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Test"

on: [pull_request]

env:
GOERLI_RPC: https://goerli.infura.io/v3/${{ secrets.INFURA_KEY }}
SEPOLIA_RPC: https://sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}
MAINNET_RPC: https://mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
POLYGON_RPC: https://polygon-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
OPTIMISM_RPC: https://optimism-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
ARBITRUM_RPC: https://arbitrum-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}
GNOSIS_RPC: https://gnosis.publicnode.com
BASE_RPC: https://base.publicnode.com
PGN_RPC: https://rpc.publicgoods.network
CELO_RPC: https://forno.celo.org
ETHERSCAN_KEY: ${{ secrets.ETHERSCAN_KEY }}

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18.16.1
- name: Set up foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install
run: yarn install --frozen-lockfile
- name: Check Format
run: yarn prettier . --check
- name: Test
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: yarn test
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ Following the [example JSON](#module-registry-schema) and existing modules, fill

Keep in mind that much of the metadata will be seen by end users in apps that use the registry, so make sure to be clear and concise.

### Step 2 - Bundle

Consumers of the modules registry do so from a single bundle, so new modules — or changes to existing modules — need to be added to the bundle.
### Step 2 - Test

Install dependencies:

Expand All @@ -235,24 +233,16 @@ yarn install

Then run:

```bash
yarn bundle
```

### Step 3 - Test

Run:

```bash
yarn test
```

### Step 4 - Format
### Step 3 - Format

Run:

```bash
yarn prettier
yarn format-all
```

י
30 changes: 30 additions & 0 deletions bundler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as fs from "fs";

export function bundleModules() {
const factoryBuffer = fs.readFileSync("./infra/factory.json");
const factory = JSON.parse(factoryBuffer.toString());

const eligibilitiesChainBuffer = fs.readFileSync(
"./infra/eligibilitiesChain.json",
);
const eligibilitiesChain = JSON.parse(eligibilitiesChainBuffer.toString());

const togglesChainBuffer = fs.readFileSync("./infra/togglesChain.json");
const togglesChain = JSON.parse(togglesChainBuffer.toString());

let moduleFiles = fs.readdirSync("modules");
const modules = [];
for (let i = 0; i < moduleFiles.length; i++) {
const moduleFile = moduleFiles[i];
const moduleBuffer = fs.readFileSync(`./modules/${moduleFile}`);
const module = JSON.parse(moduleBuffer.toString());
modules.push(module);
}

return {
factory,
eligibilitiesChain,
togglesChain,
modules,
};
}
37 changes: 0 additions & 37 deletions merger.mjs

This file was deleted.

14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@
"version": "0.1.0",
"author": "Haberdasher Labs",
"license": "MIT",
"type": "module",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules yarn exec jest -- -i",
"bundle": "node merger.mjs",
"prettier": "prettier --write ."
"bundle": "tsx ./publish.ts",
"format-all": "prettier --write .",
"format-bundle": "prettier --write modules.json"
},
"devDependencies": {
"@hatsprotocol/modules-sdk": "^0.14.1",
"@types/jest": "^29.5.4",
"@viem/anvil": "^0.0.6",
"@viem/anvil": "0.0.5",
"async-sema": "^3.1.1",
"axios": "^1.6.1",
"dotenv": "^16.3.1",
"jest": "^29.6.3",
"prettier": "3.0.2",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"tsx": "^4.7.0",
"typescript": "^5.1.6",
"viem": "1.9.5",
"viem": "1.11.0",
"zod": "^3.22.4"
}
}
9 changes: 9 additions & 0 deletions publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { bundleModules } from "./bundler";
import * as fs from "fs";

export function updateBundle() {
const bundledModules = bundleModules();
fs.writeFileSync("modules.json", JSON.stringify(bundledModules));
}

updateBundle();
6 changes: 2 additions & 4 deletions test/arbitrumDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { arbitrum } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Arbitrum deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/baseDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Base deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/celoDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { celo } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Celo deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
7 changes: 3 additions & 4 deletions test/gnosisDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { gnosis } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand All @@ -28,6 +28,7 @@ describe("Gnosis deployments", () => {
beforeAll(async () => {
anvil = createAnvil({
forkUrl: process.env.GNOSIS_RPC,
startTimeout: 20000,
});
await anvil.start();

Expand All @@ -45,9 +46,7 @@ describe("Gnosis deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
7 changes: 3 additions & 4 deletions test/goerliDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { goerli } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand All @@ -28,6 +28,7 @@ describe("Goerli deployments", () => {
beforeAll(async () => {
anvil = createAnvil({
forkUrl: process.env.GOERLI_RPC,
startTimeout: 20000,
});
await anvil.start();

Expand All @@ -45,9 +46,7 @@ describe("Goerli deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/mainnetDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { mainnet } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Mainnet deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
6 changes: 2 additions & 4 deletions test/optimismDeployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { optimism } from "viem/chains";
import { createAnvil } from "@viem/anvil";
import * as fs from "fs";
import { bundleModules } from "../bundler";
import type {
PublicClient,
WalletClient,
Expand Down Expand Up @@ -45,9 +45,7 @@ describe("Optimism deployments", () => {
transport: http("http://127.0.0.1:8545"),
});

const modulesFile = new URL("../modules.json", import.meta.url);
const data = fs.readFileSync(modulesFile, "utf-8");
const registryModules: Registry = JSON.parse(data);
const registryModules: Registry = bundleModules() as unknown as Registry;

hatsModulesClient = new HatsModulesClient({
publicClient,
Expand Down
Loading