-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fc5f0d
commit f6367e0
Showing
21 changed files
with
7,684 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
root = true | ||
[*] | ||
indent_style=tab | ||
indent_size=tab | ||
tab_width=4 | ||
end_of_line=lf | ||
charset=utf-8 | ||
trim_trailing_whitespace=true | ||
max_line_length=120 | ||
insert_final_newline=true | ||
|
||
[*.{yml,yaml}] | ||
indent_style=space | ||
indent_size=2 | ||
tab_width=8 | ||
end_of_line=lf | ||
|
||
[*.{js,ts}] | ||
indent_style=space | ||
tab_width=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vitest.config.ts | ||
.eslintrc.js | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module.exports = { | ||
root: true, | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint", "import", "sort-imports-es6-autofix"], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
], | ||
rules: { | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@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", | ||
{ | ||
argsIgnorePattern: "^_", | ||
varsIgnorePattern: "^_", | ||
caughtErrorsIgnorePattern: "^_", | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" # See documentation for possible values | ||
directory: "/" # Location of package manifests | ||
schedule: | ||
interval: "monthly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
cache: 'yarn' | ||
- run: yarn --immutable | ||
- run: yarn lint | ||
- run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,9 @@ dist | |
|
||
# TernJS port file | ||
.tern-port | ||
|
||
.yarn/* | ||
!.yarn/releases | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/sdks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
yarn lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.yarn | ||
*.yml | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
nodeLinker: node-modules | ||
|
||
plugins: | ||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs | ||
spec: "@yarnpkg/plugin-interactive-tools" | ||
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs | ||
spec: "@yarnpkg/plugin-typescript" | ||
|
||
yarnPath: .yarn/releases/yarn-3.2.4.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "e2e-tests", | ||
"version": "0.1.0", | ||
"author": "Ermal Kaleci <[email protected]>", | ||
"license": "MIT", | ||
"private": true, | ||
"packageManager": "[email protected]", | ||
"scripts": { | ||
"lint": "tsc --noEmit && eslint . --ext .js,.ts && prettier --check .", | ||
"fix": "eslint . --ext .js,.ts --fix && prettier -w .", | ||
"prepare": "husky install", | ||
"test": "LOG_LEVEL=error vitest --silent", | ||
"test:ui": "yarn test --ui", | ||
"test:dev": "vitest --inspect" | ||
}, | ||
"dependencies": { | ||
"@acala-network/chopsticks": "^0.3.6", | ||
"@types/node": "^18.11.18", | ||
"@typescript-eslint/eslint-plugin": "^5.48.2", | ||
"@typescript-eslint/parser": "^5.48.2", | ||
"@vitest/ui": "^0.28.1", | ||
"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", | ||
"typescript": "^4.9.4", | ||
"vitest": "^0.28.1" | ||
}, | ||
"engines": { | ||
"node": ">=v14" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { ApiPromise, WsProvider } from "@polkadot/api"; | ||
import { BuildBlockMode, setupWithServer } from "@acala-network/chopsticks"; | ||
import { Codec } from "@polkadot/types/types"; | ||
import { HexString } from "@polkadot/util/types"; | ||
import { Keyring } from "@polkadot/keyring"; | ||
import { StorageValues } from "@acala-network/chopsticks/dist/utils/set-storage"; | ||
import { expect } from "vitest"; | ||
|
||
export type SetupOption = { | ||
endpoint: string; | ||
blockNumber?: number; | ||
blockHash?: HexString; | ||
mockSignatureHost?: boolean; | ||
}; | ||
|
||
export const setupContext = async ({ endpoint, blockNumber, blockHash, mockSignatureHost }: SetupOption) => { | ||
const port = 8000; | ||
const config = { | ||
endpoint, | ||
port, | ||
block: blockNumber || blockHash, | ||
mockSignatureHost, | ||
"build-block-mode": BuildBlockMode.Manual, | ||
}; | ||
const { chain, listenPort, close } = await setupWithServer(config); | ||
|
||
const ws = new WsProvider(`ws://localhost:${listenPort}`); | ||
const api = await ApiPromise.create({ | ||
provider: ws, | ||
signedExtensions: { | ||
SetEvmOrigin: { | ||
extrinsic: {}, | ||
payload: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
await api.isReady; | ||
|
||
return { | ||
chain, | ||
ws, | ||
api, | ||
dev: { | ||
newBlock: (param?: { count?: number; to?: number }): Promise<string> => { | ||
return ws.send("dev_newBlock", [param]); | ||
}, | ||
setStorage: (values: StorageValues, blockHash?: string) => { | ||
return ws.send("dev_setStorage", [values, blockHash]); | ||
}, | ||
timeTravel: (date: string | number) => { | ||
return ws.send<number>("dev_timeTravel", [date]); | ||
}, | ||
setHead: (hashOrNumber: string | number) => { | ||
return ws.send("dev_setHead", [hashOrNumber]); | ||
}, | ||
}, | ||
async teardown() { | ||
await api.disconnect(); | ||
await close(); | ||
}, | ||
}; | ||
}; | ||
|
||
type CodecOrArray = Codec | Codec[]; | ||
|
||
export const matchSnapshot = (codec: CodecOrArray | Promise<CodecOrArray>) => { | ||
return expect( | ||
Promise.resolve(codec).then((x) => (Array.isArray(x) ? x.map((x) => x.toHuman()) : x.toHuman())) | ||
).resolves.toMatchSnapshot(); | ||
}; | ||
|
||
export const expectEvent = async (codec: Codec | Promise<Codec>, event: any) => { | ||
return expect(await Promise.resolve(codec).then((x) => x.toHuman())).toEqual( | ||
expect.arrayContaining([expect.objectContaining(event)]) | ||
); | ||
}; | ||
|
||
export const testingPairs = (ss58Format?: number) => { | ||
const keyring = new Keyring({ type: "ed25519", ss58Format }); // cannot use sr25519 as it is non determinstic | ||
const alice = keyring.addFromUri("//Alice"); | ||
const bob = keyring.addFromUri("//Bob"); | ||
const charlie = keyring.addFromUri("//Charlie"); | ||
const dave = keyring.addFromUri("//Dave"); | ||
const eve = keyring.addFromUri("//Eve"); | ||
const test1 = keyring.addFromUri("//test1"); | ||
const test2 = keyring.addFromUri("//test2"); | ||
return { | ||
alice, | ||
bob, | ||
charlie, | ||
dave, | ||
eve, | ||
test1, | ||
test2, | ||
keyring, | ||
}; | ||
}; |
47 changes: 47 additions & 0 deletions
47
tests/polkadot-acala/__snapshots__/transfer-reserve.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Vitest Snapshot v1 | ||
|
||
exports[`Polkadot <-> Acala > Polkadot transfer assets to Acala 1`] = ` | ||
{ | ||
"consumers": "0", | ||
"data": { | ||
"feeFrozen": "0", | ||
"free": "10,000,000,000,000", | ||
"miscFrozen": "0", | ||
"reserved": "0", | ||
}, | ||
"nonce": "0", | ||
"providers": "0", | ||
"sufficients": "0", | ||
} | ||
`; | ||
|
||
exports[`Polkadot <-> Acala > Polkadot transfer assets to Acala 2`] = ` | ||
{ | ||
"free": "0", | ||
"frozen": "0", | ||
"reserved": "0", | ||
} | ||
`; | ||
|
||
exports[`Polkadot <-> Acala > Polkadot transfer assets to Acala 3`] = ` | ||
{ | ||
"consumers": "0", | ||
"data": { | ||
"feeFrozen": "0", | ||
"free": "8,999,815,091,021", | ||
"miscFrozen": "0", | ||
"reserved": "0", | ||
}, | ||
"nonce": "1", | ||
"providers": "0", | ||
"sufficients": "0", | ||
} | ||
`; | ||
|
||
exports[`Polkadot <-> Acala > Polkadot transfer assets to Acala 4`] = ` | ||
{ | ||
"free": "999,998,266,092", | ||
"frozen": "0", | ||
"reserved": "0", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { afterAll, describe, expect, it } from "vitest"; | ||
import { connectVertical } from "@acala-network/chopsticks"; | ||
|
||
import { expectEvent, matchSnapshot, setupContext, testingPairs } from "../helper"; | ||
|
||
describe("Polkadot <-> Acala", async () => { | ||
const polkadot = await setupContext({ | ||
endpoint: "wss://rpc.polkadot.io", | ||
}); | ||
const acala = await setupContext({ | ||
endpoint: "wss://acala-rpc-1.aca-api.network", | ||
}); | ||
await connectVertical(polkadot.chain, acala.chain); | ||
|
||
const { alice } = testingPairs(); | ||
|
||
afterAll(async () => { | ||
await polkadot.teardown(); | ||
await acala.teardown(); | ||
}); | ||
|
||
it("Polkadot transfer assets to Acala", async () => { | ||
await polkadot.dev.setStorage({ | ||
System: { | ||
Account: [[[alice.address], { data: { free: 1000 * 1e10 } }]], | ||
}, | ||
}); | ||
|
||
await matchSnapshot(polkadot.api.query.system.account(alice.address)); | ||
await matchSnapshot(acala.api.query.tokens.accounts(alice.address, { token: "DOT" })); | ||
|
||
await polkadot.api.tx.xcmPallet | ||
.reserveTransferAssets( | ||
{ | ||
V0: { | ||
X1: { | ||
Parachain: 2000, | ||
}, | ||
}, | ||
}, | ||
{ | ||
V0: { | ||
X1: { | ||
AccountId32: { | ||
network: "Any", | ||
id: alice.addressRaw, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
V0: [ | ||
{ | ||
ConcreteFungible: { id: "Null", amount: 100e10 }, | ||
}, | ||
], | ||
}, | ||
0 | ||
) | ||
.signAndSend(alice); | ||
|
||
await polkadot.chain.newBlock(); | ||
await acala.chain.upcomingBlock(); | ||
|
||
await matchSnapshot(polkadot.api.query.system.account(alice.address)); | ||
await expectEvent(polkadot.api.query.system.events(), { | ||
event: expect.objectContaining({ | ||
section: "xcmPallet", | ||
method: "Attempted", | ||
}), | ||
}); | ||
|
||
await matchSnapshot(acala.api.query.tokens.accounts(alice.address, { token: "DOT" })); | ||
await expectEvent(acala.api.query.system.events(), { | ||
event: expect.objectContaining({ | ||
section: "parachainSystem", | ||
method: "DownwardMessagesReceived", | ||
}), | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.