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

browser support #352

Merged
merged 37 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ca60a1c
browser support
ermalkaleci Jul 29, 2023
0b57d60
Merge branch 'master' of github.com:AcalaNetwork/chopsticks into brow…
ermalkaleci Jul 29, 2023
8bfd7b3
update action
ermalkaleci Jul 29, 2023
b0e4882
update action
ermalkaleci Jul 29, 2023
f2fad3f
update action
ermalkaleci Jul 29, 2023
3be8a75
update action
ermalkaleci Jul 29, 2023
792adab
fix test
ermalkaleci Jul 29, 2023
765fc92
update action
ermalkaleci Jul 29, 2023
c49f8a8
refactor
ermalkaleci Jul 29, 2023
2e228b3
lint
ermalkaleci Jul 29, 2023
7c22f6a
fix
ermalkaleci Jul 31, 2023
f0cadf9
fix test
ermalkaleci Jul 31, 2023
31d86ce
fix lock
ermalkaleci Jul 31, 2023
2056c59
fixes
ermalkaleci Jul 31, 2023
6bb56b2
fix
ermalkaleci Jul 31, 2023
f3f6e50
lint
ermalkaleci Jul 31, 2023
b685918
fix
ermalkaleci Jul 31, 2023
f4083aa
fix lint
ermalkaleci Jul 31, 2023
504e0cb
disabel cache on CI
ermalkaleci Aug 1, 2023
715428d
inc timeout
ermalkaleci Aug 1, 2023
609660a
update tests
ermalkaleci Aug 1, 2023
4d5a0e6
Merge branch 'master' of github.com:AcalaNetwork/chopsticks into brow…
ermalkaleci Aug 1, 2023
a3151d8
update tests
ermalkaleci Aug 1, 2023
b997dc2
update config
ermalkaleci Aug 1, 2023
491e117
debug
ermalkaleci Aug 1, 2023
d88f500
debug
ermalkaleci Aug 1, 2023
ac0ae57
debug
ermalkaleci Aug 1, 2023
8c0b52b
fix gh action
ermalkaleci Aug 1, 2023
fa93f73
Merge branch 'master' of github.com:AcalaNetwork/chopsticks into brow…
ermalkaleci Aug 2, 2023
90b8828
fix after merge/master
ermalkaleci Aug 2, 2023
bbb3889
entity type
ermalkaleci Aug 3, 2023
fa2343d
entity type
ermalkaleci Aug 3, 2023
ce23a3c
Merge branch 'master' of github.com:AcalaNetwork/chopsticks into brow…
ermalkaleci Aug 7, 2023
408a89b
fix after merge
ermalkaleci Aug 7, 2023
e8cf611
refactor
ermalkaleci Aug 7, 2023
2d2b5e1
fix timeout
ermalkaleci Aug 8, 2023
2b2ade8
fix version
ermalkaleci Aug 8, 2023
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
executor/
vendor/
lib/
dist/
chopsticks.js
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,42 @@ jobs:
- name: Test substrate-api-sidecard with chopsticks node
if: ${{ github.ref_name == 'master' }}
run: yarn workspace @acala-network/chopsticks-e2e run sidecar

playwright:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
executor/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: nightly-2022-10-30
components: rustfmt
target: wasm32-unknown-unknown
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: 'yarn'
- run: yarn --immutable
- run: yarn build-wasm
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: yarn workspace @acala-network/web-test test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: packages/web-test/playwright-report/
retention-days: 30
12 changes: 4 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ jobs:
registry-url: https://registry.npmjs.org/
- run: yarn --immutable
- run: yarn check
- run: yarn build-wasm
- run: yarn build

# Make sure chopsticks and executor version are the same
- 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')"

# version containing a hyphen, publish as beta, i.e: 1.0.0-1
- run: |
if npm pkg get version --workspace @acala-network/chopsticks | jq '."@acala-network/chopsticks"' | grep '-'; then TAG='--tag beta'; fi
Expand All @@ -54,10 +50,10 @@ jobs:
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_TAG }}
# 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_TAG }}
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.NPM_TAG }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,4 @@ dist
preview/

lib
.parcel-cache
2 changes: 2 additions & 0 deletions executor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
browser
node
22 changes: 22 additions & 0 deletions executor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@acala-network/chopsticks-executor",
"description": "Chopsticks executor",
"version": "0.8.0-0",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/AcalaNetwork/chopsticks"
},
"scripts": {
"clean": "rm -rf web node",
"build": "wasm-pack build --target web --out-dir browser; wasm-pack build --target nodejs --out-dir node"
},
"files": [
"browser/chopsticks_*",
"node/chopsticks_*"
],
"main": "node/chopsticks_executor.js",
"types": "browser/chopsticks_executor.d.ts",
"browser": "browser/chopsticks_executor.js",
"stableVersion": "0.7.3"
}
17 changes: 0 additions & 17 deletions executor/pkg/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface JsCallback {
offchainGetStorage: (key: HexString) => Promise<string | undefined>
offchainTimestamp: () => Promise<number>
offchainRandomSeed: () => Promise<HexString>
offchainSubmitTransaction: (tx: HexString) => Promise<bool>
offchainSubmitTransaction: (tx: HexString) => Promise<boolean>
}
"#;

Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"private": true,
"workspaces": [
"packages/*",
"executor/pkg"
"executor"
],
"scripts": {
"lint": "tsc --noEmit --project tsconfig.json && eslint . --ext .js,.ts && prettier --check .",
"lint": "tsc --noEmit --project tsconfig.lint.json && eslint . --ext .js,.ts && prettier --check .",
"fix": "eslint . --ext .js,.ts --fix && prettier -w .",
"prepare": "husky install",
"clean": "yarn workspaces foreach -pvit run clean",
"build": "yarn workspaces foreach -pvit run build",
"build-wasm": "wasm-pack build executor --target nodejs --scope acala-network && echo '' >> executor/pkg/package.json",
"build-wasm": "yarn workspace @acala-network/chopsticks-executor build",
"check": "cd executor && cargo check --locked",
"test": "vitest run",
"test:watch": "vitest",
Expand Down Expand Up @@ -51,10 +51,5 @@
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.33.0",
"wasm-pack": "^0.12.1"
},
"exports": {
".": "./lib/index.js",
"./*": "./lib/*.js",
"./package.json": "./package.json"
}
}
27 changes: 12 additions & 15 deletions packages/chopsticks/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
{
"name": "@acala-network/chopsticks",
"version": "0.7.3",
"version": "0.8.0-0",
"author": "Bryan Chen <[email protected]>",
"license": "Apache-2.0",
"bin": "./chopsticks.js",
"scripts": {
"clean": "rm -rf lib tsconfig.tsbuildinfo",
"build": "tsc -p ./tsconfig.json",
"script:start": "cd ../..; ts-node --transpile-only packages/chopsticks/src/cli.ts",
"script:run": "cd ../..; LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/dev.yml",
"dev:karura": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/karura.yml",
"dev:acala": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/acala.yml",
"dev:polkadot": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/polkadot.yml",
"dev:moonriver": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonriver.yml",
"dev:moonbeam": "cd ../..; ts-node-dev --transpile-only --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonbeam.yml"
"script:start": "cd ../..; ts-node --transpile-only -r tsconfig-paths/register packages/chopsticks/src/cli.ts",
"script:run": "cd ../..; LOG_LEVEL=trace ts-node-dev --transpile-only -r tsconfig-paths/register --inspect --notify=false packages/chopsticks/src/cli.ts -- --config=configs/dev.yml",
"dev:karura": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/karura.yml",
"dev:acala": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/acala.yml",
"dev:polkadot": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/polkadot.yml",
"dev:moonriver": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonriver.yml",
"dev:moonbeam": "cd ../..; ts-node-dev --transpile-only --inspect -r tsconfig-paths/register --notify=false packages/chopsticks/src/cli.ts -- --config=configs/moonbeam.yml"
},
"dependencies": {
"@acala-network/chopsticks-executor": "workspace:*",
"@acala-network/chopsticks-core": "workspace:*",
"@pnpm/npm-conf": "^2.2.2",
"@polkadot/api": "^10.9.1",
"axios": "^1.4.0",
"dotenv": "^16.3.1",
"global-agent": "^3.0.0",
"js-yaml": "^4.1.0",
"jsondiffpatch": "^0.4.1",
"lodash": "^4.17.21",
"pino": "^8.14.2",
"pino-pretty": "^10.2.0",
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.1.6",
"typeorm": "^0.3.17",
"ws": "^8.13.0",
"yargs": "^17.7.2",
"zod": "^3.21.4"
Expand Down Expand Up @@ -61,5 +57,6 @@
"default": "./lib/*.js"
},
"./package.json": "./package.json"
}
},
"stableVersion": "0.7.3"
}
3 changes: 2 additions & 1 deletion packages/chopsticks/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { hideBin } from 'yargs/helpers'
import _ from 'lodash'
import yargs from 'yargs'

import { Blockchain, BuildBlockMode, connectParachains, connectVertical, setupWithServer } from '.'
import { Blockchain, BuildBlockMode, connectParachains, connectVertical } from '@acala-network/chopsticks-core'
import { Config, fetchConfig } from './schema'
import { defaultOptions, mockOptions } from './cli-options'
import { pluginExtendCli } from './plugins'
import { setupWithServer } from '.'

dotenvConfig()

Expand Down
38 changes: 38 additions & 0 deletions packages/chopsticks/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import './utils/tunnel'
import { Config } from './schema'
import { HexString } from '@polkadot/util/types'
import { overrideStorage, overrideWasm } from './utils/override'
import { setup, timeTravel } from '@acala-network/chopsticks-core'

export const setupContext = async (argv: Config, overrideParent = false) => {
const chain = await setup({
endpoint: argv.endpoint,
block: argv.block,
genesis: argv.genesis,
buildBlockMode: argv['build-block-mode'],
db: argv.db,
mockSignatureHost: argv['mock-signature-host'],
allowUnresolvedImports: argv['allow-unresolved-imports'],
runtimeLogLevel: argv['runtime-log-level'],
registeredTypes: argv['registered-types'],
offchainWorker: argv['offchain-worker'],
maxMemoryBlockCount: argv['max-memory-block-count'],
})

if (argv.timestamp) await timeTravel(chain, argv.timestamp)

let at: HexString | undefined
if (overrideParent) {
// in case of run block we need to apply wasm-override and import-storage to parent block
const block = await chain.head.parentBlock
if (!block) throw new Error('Cannot find parent block')
at = block.hash
}

// override wasm before importing storage, in case new pallets have been
// added that have storage imports
await overrideStorage(chain, argv['import-storage'], at)
await overrideWasm(chain, argv['wasm-override'], at)

return { chain }
}
36 changes: 0 additions & 36 deletions packages/chopsticks/src/db/entities.ts

This file was deleted.

9 changes: 2 additions & 7 deletions packages/chopsticks/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
export { Api } from './api'
export { Blockchain } from './blockchain'
export { BuildBlockMode } from './blockchain/txpool'
export { connectParachains, connectVertical } from './xcm'
export { setup } from './setup'
export * from '@acala-network/chopsticks-core'
export { setupWithServer } from './setup-with-server'
export { Config, fetchConfig } from './schema'
export * from './blockchain/inherent'
export { fetchConfig } from './schema'
41 changes: 1 addition & 40 deletions packages/chopsticks/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1 @@
import createLogger from 'pino'

export const defaultLogger = createLogger({
level: process.env.LOG_LEVEL || 'info',
transport: {
target: 'pino-pretty',
},
})

const innerTruncate =
(level = 0) =>
(val: any) => {
const verboseLog = !!process.env.VERBOSE_LOG
const levelLimit = verboseLog ? 10 : 5
if (val == null) {
return val
}
if (level > levelLimit) {
return '( Too Deep )'
}
switch (typeof val) {
case 'string':
if (val.length > 66 && !verboseLog) {
return val.slice(0, 34) + '…' + val.slice(-32)
} else {
return val
}
case 'object':
if (Array.isArray(val)) {
return val.map(innerTruncate(level + 1))
}
return Object.fromEntries(
Object.entries(val.toJSON ? val.toJSON() : val).map(([k, v]) => [k, innerTruncate(level + 1)(v)]),
)
default:
return val
}
}

export const truncate = (val: any) => innerTruncate(0)(val)
export { defaultLogger, truncate } from '@acala-network/chopsticks-core'
6 changes: 3 additions & 3 deletions packages/chopsticks/src/plugins/decode-key/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Config } from '../..'
import { Config } from '../../schema'
import { HexString } from '@polkadot/util/types'
import { decodeKey } from '../../utils/decoder'
import { defaultOptions } from '../../cli-options'
import { setup } from '../../setup'
import { setupContext } from '../../context'
import type yargs from 'yargs'

export const cli = (y: yargs.Argv) => {
Expand All @@ -19,7 +19,7 @@ export const cli = (y: yargs.Argv) => {
...defaultOptions,
}),
async (argv) => {
const context = await setup(argv as Config)
const context = await setupContext(argv as Config)
const { storage, decodedKey } = decodeKey(
await context.chain.head.meta,
context.chain.head,
Expand Down
5 changes: 3 additions & 2 deletions packages/chopsticks/src/plugins/dry-run/cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config } from '../..'
import { defaultOptions } from '../../cli-options'
import { Config } from '../../schema'
import { defaultOptions, mockOptions } from '../../cli-options'
import { dryRunExtrinsic } from './dry-run-extrinsic'
import { dryRunPreimage } from './dry-run-preimage'
import type yargs from 'yargs'
Expand All @@ -11,6 +11,7 @@ export const cli = (y: yargs.Argv) => {
(yargs) =>
yargs.options({
...defaultOptions,
...mockOptions,
extrinsic: {
desc: 'Extrinsic or call to dry run. If you pass call here then address is required to fake signature',
string: true,
Expand Down
Loading