Skip to content

Commit

Permalink
change to use the monorepo (#193)
Browse files Browse the repository at this point in the history
* move to package/core

* fix

* update

* update

* update

* update

* watch

* start

* rename

* add core

* fix lint

* fix

* fix ci

* update

* exclude lib

* update port

* fix

* change script

* fix

* fixes

* update script

* update action

---------

Co-authored-by: Ermal Kaleci <[email protected]>
  • Loading branch information
ntduan and ermalkaleci authored Feb 20, 2023
1 parent d27e43b commit 62318df
Show file tree
Hide file tree
Showing 117 changed files with 450 additions and 535 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module.exports = {
'@typescript-eslint/explicit-module-boundary-types': 'off',
'sort-imports-es6-autofix/sort-imports-es6': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- run: yarn check
- run: yarn build-wasm
- run: yarn lint
- run: yarn test
- run: yarn build
- run: yarn test
- name: Test substrate-api-sidecard with chopsticks node
run: sh e2e/scripts/sidecard-chopsticks.sh
run: yarn workspace @acala-network/chopsticks-e2e run sidecar
6 changes: 5 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ jobs:
- run: yarn check
- run: yarn build-wasm
- run: yarn build
- run: node -e "assert(require('./package.json').version === require('./executor/pkg/package.json').version, 'Chopsticks and executor version not the same. Please update Cargo.toml version')"
- run: node -e "assert(require('./packages/chopsticks/package.json').version === require('./executor/pkg/package.json').version, 'Chopsticks and executor version not the same. Please update Cargo.toml version')"
# Writes token to .yarnrc.yml. If written directly in .yarnrc.yml, it will cause an error
- run: |
echo npmAuthToken: "\${NPM_AUTH_TOKEN}" >> ./.yarnrc.yml
- name: Publish @acala-network/chopsticks
run: yarn workspace @acala-network/chopsticks npm publish --tolerate-republish --access public
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
# - name: Publish @acala-network/chopsticks-core
# run: yarn workspace @acala-network/chopsticks-core npm publish --tolerate-republish --access public
# env:
# NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
- name: Publish @acala-network/chopsticks-executor
run: yarn workspace @acala-network/chopsticks-executor npm publish --tolerate-republish --access public
env:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,5 @@ dist
.DS_store

preview/

lib
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

5 changes: 0 additions & 5 deletions .husky/pre-commit

This file was deleted.

2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ executor/
vendor/
.pnp.cjs
.pnp.loader.mjs
dist/
preview/
28 changes: 28 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ plugins:
spec: "@yarnpkg/plugin-typescript"
- path: .yarn/plugins/@yarnpkg/plugin-version.cjs
spec: "@yarnpkg/plugin-version"
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: "@yarnpkg/plugin-workspace-tools"

yarnPath: .yarn/releases/yarn-3.2.4.cjs
File renamed without changes.
2 changes: 0 additions & 2 deletions chopsticks.js

This file was deleted.

2 changes: 2 additions & 0 deletions e2e/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vitest.config.ts
node_modules/
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
substrate-api-sidecar
38 changes: 38 additions & 0 deletions e2e/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@acala-network/chopsticks-e2e",
"author": "Bryan Chen <[email protected]>",
"license": "Apache-2.0",
"scripts": {
"lint": "tsc --noEmit --project tsconfig.json && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"test": "vitest --silent",
"sidecar": "sh ./scripts/sidecar-chopsticks.sh"
},
"engines": {
"node": ">=v14"
},
"dependencies": {
"@acala-network/chopsticks": "workspace:*",
"@polkadot/api": "^9.12.1"
},
"devDependencies": {
"@types/prettier": "^2",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"prettier": "^2.8.4",
"vitest": "^0.28.3"
},
"prettier": {
"tabWidth": 2,
"semi": false,
"singleQuote": true
},
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
"*.{js,ts,css,md}": "prettier --write"
}
}
23 changes: 23 additions & 0 deletions e2e/scripts/sidecar-chopsticks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -xe

rm -rf substrate-api-sidecar

# clone sidecard
git clone https://github.com/paritytech/substrate-api-sidecar.git

# run chopsticks node
yarn workspace @acala-network/chopsticks run start dev --endpoint wss://rpc.polkadot.io --port 8011 & POLKADOT_PID=$!
yarn workspace @acala-network/chopsticks run start dev --endpoint wss://statemint-rpc.polkadot.io --port 8012 & STATEMINT_PID=$!

# run tests
(cd substrate-api-sidecar && \
yarn && \
yarn test:latest-e2e-tests --local ws://localhost:8011 --chain polkadot && \
yarn test:latest-e2e-tests --local ws://localhost:8012 --chain statemint)

# cleanup
rm -rf substrate-api-sidecar
kill $POLKADOT_PID
kill $STATEMINT_PID
21 changes: 0 additions & 21 deletions e2e/scripts/sidecard-chopsticks.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/decoder.test.ts → e2e/src/decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chain, setupAll, setupApi } from './helper'
import { decodeKey, decodeKeyValue } from '../src/utils/decoder'
import { decodeKey, decodeKeyValue } from '@acala-network/chopsticks/src/utils/decoder'
import { describe, expect, it } from 'vitest'

setupApi({
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions e2e/helper.ts → e2e/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { HexString } from '@polkadot/util/types'
import { Keyring } from '@polkadot/keyring'
import { beforeAll, beforeEach, expect, vi } from 'vitest'

import { Api } from '../src/api'
import { Blockchain } from '../src/blockchain'
import { BuildBlockMode } from '../src/blockchain/txpool'
import { GenesisProvider } from '../src/genesis-provider'
import { Api } from '@acala-network/chopsticks/src/api'
import { Blockchain } from '@acala-network/chopsticks/src/blockchain'
import { BuildBlockMode } from '@acala-network/chopsticks/src/blockchain/txpool'
import { GenesisProvider } from '@acala-network/chopsticks/src/genesis-provider'
import {
InherentProviders,
ParaInherentEnter,
SetBabeRandomness,
SetNimbusAuthorInherent,
SetTimestamp,
SetValidationData,
} from '../src/blockchain/inherent'
import { StorageValues } from '../src/utils/set-storage'
import { createServer } from '../src/server'
import { handler } from '../src/rpc'
} from '@acala-network/chopsticks/src/blockchain/inherent'
import { StorageValues } from '@acala-network/chopsticks/src/utils/set-storage'
import { createServer } from '@acala-network/chopsticks/src/server'
import { handler } from '@acala-network/chopsticks/src/rpc'

export type SetupOption = {
endpoint?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
import path from 'path'

import { api, chain, setupApi } from '../helper'
import { importStorage, overrideWasm } from '../../src/utils/import-storage'
import { importStorage, overrideWasm } from '@acala-network/chopsticks/src/utils/import-storage'

setupApi({
endpoint: 'wss://acala-rpc-1.aca-api.network',
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('import-storage', () => {
it('wasm override works', async () => {
expect(await chain.head.runtimeVersion).toContain({ specVersion: 2096 })
const oldWasm = await chain.head.wasm
await overrideWasm(chain, path.join(__dirname, '../blobs/acala-runtime-2101.txt'))
await overrideWasm(chain, path.join(__dirname, '../../../blobs/acala-runtime-2101.txt'))
expect(await chain.head.wasm).not.eq(oldWasm)
expect(await chain.head.runtimeVersion).toContain({ specVersion: 2101 })
const blockNumber = chain.head.number
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ Tokens:
- 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
- Token: ACA
# value
- free:
1000000000000000
- free: 1000000000000000
- # 2nd record
# keys
- [5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY, Token: AUSD]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/time-travel.test.ts → e2e/src/time-travel.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HexString } from '@polkadot/util/types'
import { chain, setupApi, ws } from './helper'
import { describe, expect, it } from 'vitest'
import { getCurrentTimestamp, getSlotDuration, timeTravel } from '../src/utils/time-travel'
import { getCurrentTimestamp, getSlotDuration, timeTravel } from '@acala-network/chopsticks/src/utils/time-travel'

describe.each([
{
Expand Down
2 changes: 1 addition & 1 deletion e2e/upgrade.test.ts → e2e/src/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('upgrade', () => {
},
})

const runtime = String(readFileSync(path.join(__dirname, './blobs/acala-runtime-2101.txt'))).trim()
const runtime = String(readFileSync(path.join(__dirname, '../../blobs/acala-runtime-2101.txt'))).trim()

expect(await chain.head.runtimeVersion).toContain({ specVersion: 2096 })
await api.tx.sudo.sudo(api.tx.parachainSystem.authorizeUpgrade(blake2AsHex(runtime))).signAndSend(alice)
Expand Down
8 changes: 4 additions & 4 deletions e2e/xcm.test.ts → e2e/src/xcm.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { afterAll, describe, it } from 'vitest'

import { DownwardMessage, HorizontalMessage } from '../src/blockchain/txpool'
import { connectDownward } from '../src/xcm/downward'
import { connectUpward } from '../src/xcm/upward'
import { DownwardMessage, HorizontalMessage } from '@acala-network/chopsticks/src/blockchain/txpool'
import { connectDownward } from '@acala-network/chopsticks/src/xcm/downward'
import { connectUpward } from '@acala-network/chopsticks/src/xcm/upward'
import { matchSnapshot, setupAll, testingPairs } from './helper'
import { setStorage } from '../src/utils/set-storage'
import { setStorage } from '@acala-network/chopsticks/src/utils/set-storage'

const downwardMessages: DownwardMessage[] = [
{
Expand Down
3 changes: 3 additions & 0 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.base.json"
}
File renamed without changes.
83 changes: 17 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,81 +1,28 @@
{
"name": "@acala-network/chopsticks",
"version": "0.3.12",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"author": "Bryan Chen <[email protected]>",
"license": "Apache-2.0",
"packageManager": "[email protected]",
"workspaces": [
".",
"executor/pkg"
"packages/*",
"executor/pkg",
"e2e"
],
"bin": "./chopsticks.js",
"scripts": {
"lint": "tsc --noEmit --project tsconfig.json && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"lint": "yarn workspaces foreach run lint",
"fix": "yarn workspaces foreach run fix",
"prepare": "husky install",
"start": "ts-node --transpile-only src/cli.ts",
"build": "rm -rf dist && tsc -p tsconfig.prod.json",
"build": "yarn workspaces foreach run build",
"build-wasm": "wasm-pack build executor --target nodejs --scope acala-network",
"build-wasm-logging": "yarn build-wasm --features=logging",
"check": "cd executor && cargo check --locked",
"test": "vitest --silent",
"test:dev": "LOG_LEVEL=trace vitest --inspect",
"dev": "LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/dev.yml",
"dev:karura": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/karura.yml",
"dev:acala": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/acala.yml",
"dev:moonriver": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/moonriver.yml",
"dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/moonbeam.yml"
"test": "yarn workspaces foreach run test",
"start": "yarn workspace @acala-network/chopsticks run start",
"dev": "yarn workspace @acala-network/chopsticks run dev",
"dev:karura": "yarn workspace @acala-network/chopsticks run dev:karura",
"dev:acala": "yarn workspace @acala-network/chopsticks run dev:acala",
"dev:moonriver": "yarn workspace @acala-network/chopsticks run dev:moonriver",
"dev:moonbeam": "yarn workspace @acala-network/chopsticks run dev:moonbeam"
},
"dependencies": {
"@acala-network/chopsticks-executor": "workspace:*",
"@polkadot/api": "^9.12.1",
"@polkadot/rpc-provider": "^9.12.1",
"@polkadot/types": "^9.12.1",
"@polkadot/types-codec": "^9.12.1",
"@polkadot/types-known": "^9.12.1",
"@polkadot/util": "^10.2.6",
"@polkadot/util-crypto": "^10.2.6",
"axios": "^1.2.5",
"js-yaml": "^4.1.0",
"jsondiffpatch": "^0.4.1",
"lodash": "^4.17.21",
"pino": "^8.8.0",
"pino-pretty": "^9.1.1",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.1.4",
"typeorm": "^0.3.11",
"typescript": "^4.9.4",
"ws": "^8.12.0",
"yargs": "^17.6.2",
"zod": "^3.20.2"
},
"devDependencies": {
"@types/js-yaml": "^4.0.5",
"@types/lodash": "^4.14.191",
"@types/node": "^18.11.18",
"@types/ws": "^8.5.4",
"@types/yargs": "^17.0.20",
"@typescript-eslint/eslint-plugin": "^5.50.0",
"@typescript-eslint/parser": "^5.50.0",
"eslint": "^8.32.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
"husky": "^8.0.3",
"lint-staged": "^13.1.0",
"prettier": "^2.8.3",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"vitest": "^0.28.3",
"wasm-pack": "^0.10.3"
},
"files": [
"dist",
"bin",
"template"
],
"engines": {
"node": ">=v14"
},
Expand All @@ -87,5 +34,9 @@
"lint-staged": {
"*.{js,ts}": "eslint --cache --fix",
"*.{js,ts,css,md}": "prettier --write"
},
"devDependencies": {
"husky": "^8.0.3",
"wasm-pack": "^0.10.3"
}
}
5 changes: 1 addition & 4 deletions .eslintignore → packages/chopsticks/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
vitest.config.ts
.eslintrc.js
node_modules/
executor/
vendor/
dist/
lib/
preview/
chopsticks.js
2 changes: 2 additions & 0 deletions packages/chopsticks/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
preview/
2 changes: 2 additions & 0 deletions packages/chopsticks/chopsticks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('./lib/cli.js')
Loading

0 comments on commit 62318df

Please sign in to comment.