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

PoC: trying papi #118

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default tseslint.config(
"**/vitest.config.mts",
".yarn/",
".github/command-runner/", // TODO: enable lint for those files
"**/.papi/",
],
}
)
3 changes: 2 additions & 1 deletion packages/networks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@e2e-test/networks",
"type": "module",
"dependencies": {
"@acala-network/chopsticks-testing": "^1.0.1"
"@acala-network/chopsticks-testing": "^1.0.1",
"polkadot-api": "^1.7.7"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
16 changes: 16 additions & 0 deletions packages/networks/src/createNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { connectParachains, connectVertical } from '@acala-network/chopsticks'
import { setupContext } from '@acala-network/chopsticks-testing'

import { createClient, PolkadotClient } from "polkadot-api"

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/assetHubKusama.karura.test.ts)

packages/kusama/src/assetHubKusama.karura.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/basilisk.karura.test.ts)

packages/kusama/src/basilisk.karura.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/coretimeKusama.kusama.test.ts)

packages/kusama/src/coretimeKusama.kusama.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/karura.kusama.test.ts)

packages/kusama/src/karura.kusama.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/kusama.shiden.test.ts)

packages/kusama/src/kusama.shiden.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/people.kusama.e2e.test.ts)

packages/kusama/src/people.kusama.e2e.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (kusama/src/people.kusama.test.ts)

packages/kusama/src/people.kusama.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/acala.assetHubPolkadot.test.ts)

packages/polkadot/src/acala.assetHubPolkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/acala.moonbeam.test.ts)

packages/polkadot/src/acala.moonbeam.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/acala.polkadot.test.ts)

packages/polkadot/src/acala.polkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/assetHub.polkadot.test.ts)

packages/polkadot/src/assetHub.polkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/astar.polkadot.test.ts)

packages/polkadot/src/astar.polkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/coretimePolkadot.polkadot.test.ts)

packages/polkadot/src/coretimePolkadot.polkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/hydration.moonbeam.test.ts)

packages/polkadot/src/hydration.moonbeam.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/people.polkadot.e2e.test.ts)

packages/polkadot/src/people.polkadot.e2e.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31

Check failure on line 4 in packages/networks/src/createNetwork.ts

View workflow job for this annotation

GitHub Actions / tests (polkadot/src/people.polkadot.test.ts)

packages/polkadot/src/people.polkadot.test.ts

ReferenceError: WebSocket is not defined ❯ node_modules/@polkadot-api/ws-provider/src/web.ts:6:52 ❯ packages/networks/src/createNetwork.ts:4:31
import { getWsProvider } from "polkadot-api/ws-provider/web";
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";

import { Chain } from './types.js'

export async function createNetwork<T extends Chain>(chainConfig: T) {
Expand All @@ -10,9 +14,21 @@
await network.dev.setStorage(chainConfig.initStorages)
}

let papi: PolkadotClient | undefined

return {
...network,
config: chainConfig,
papi() {
if (!papi) {
papi = createClient(
withPolkadotSdkCompat(
getWsProvider(network.url)
)
)
}
return papi
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions packages/shared/.papi/descriptors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!package.json
24 changes: 24 additions & 0 deletions packages/shared/.papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.1.0-autogenerated.11833360389215873333",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"module": "./dist/index.mjs",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"browser": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"sideEffects": false,
"peerDependencies": {
"polkadot-api": "*"
}
}
Binary file not shown.
10 changes: 10 additions & 0 deletions packages/shared/.papi/polkadot-api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 0,
"descriptorPath": ".papi/descriptors",
"entries": {
"polkadotPeople": {
"chain": "polkadot_people",
"metadata": ".papi/metadata/polkadotPeople.scale"
}
}
}
4 changes: 4 additions & 0 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
"@acala-network/chopsticks": "1.0.1",
"@acala-network/chopsticks-testing": "1.0.1",
"@e2e-test/networks": "workspace:*",
"@polkadot-api/descriptors": "portal:.papi/descriptors",
"@polkadot/api": "14.3.1",
"@polkadot/types": "14.3.1",
"@polkadot/types-augment": "14.3.1"
},
"scripts": {
"postinstall": "npx papi"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/src/people-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import { PalletIdentityLegacyIdentityInfo, PalletIdentityRegistration } from '@polkadot/types/lookup'
import { encodeAddress } from '@polkadot/util-crypto'
import { u128 } from '@polkadot/types'
import { polkadotPeople } from '@polkadot-api/descriptors'

import { check, checkEvents } from './helpers/index.js'
import { setupNetworks } from './setup.js'
Expand Down Expand Up @@ -54,6 +55,9 @@
>(peopleChain: Chain<TCustom, TInitStorages>) {
const [peopleClient] = await setupNetworks(peopleChain)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When considering using PAPI in tests, in general, will we also want to keep this kind of call alongside the ones you introduce below? We will effectively have 2 clients available during testing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

people can choose pjs or papi to use when writing a test and in the unlikely case, they can write tests using both.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, <pjs_client_name>.dev.{newBlock, setStorage, timeTravel, setHead} are wrappers over WebSocket calls to RPC endpoints that chopsticks-utils layers on top of the "real" node.

  1. Do you think it makes sense to offer the same functionality for PAPI clients in chopsticks,
  2. Or is it extraneous work, and for the time being this can remain available via PJS clients? E.g. tests using PAPI may rely on PJS clients for chopsticks-specific endpoints (new block, set storage, etc).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it makes sense to offer the same functionality for PAPI clients in chopsticks,

No. It wouldn't make any difference.

Or is it extraneous work, and for the time being this can remain available via PJS clients? E.g. tests using PAPI may rely on PJS clients for chopsticks-specific endpoints (new block, set storage, etc).

The usage is completely hidden and shouldn't matter at all. People can use them and yes it may indirectly depends on pjs but who cares?

In fact, it will be a good idea to write those to invoke the chain API directly, instead of using websocket calls (AcalaNetwork/chopsticks#861)


const papi = peopleClient.papi()
const typedPapi = papi.getTypedApi(polkadotPeople)

Check failure on line 59 in packages/shared/src/people-chains.ts

View workflow job for this annotation

GitHub Actions / lint

'typedPapi' is declared but its value is never read.

const querier = peopleClient.api.query
const txApi = peopleClient.api.tx

Expand Down
Loading
Loading