Skip to content

Commit

Permalink
first intermediate
Browse files Browse the repository at this point in the history
  • Loading branch information
Ad96el committed May 31, 2024
1 parent 5fa72f9 commit 0b5d6ce
Show file tree
Hide file tree
Showing 23 changed files with 6,994 additions and 805 deletions.
3 changes: 3 additions & 0 deletions integration-tests/chopsticks/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- split network into chains -> runtimes + utilty chain
- investigate if limitedReserveTransferAssets should be split into different versions (Outcome: each testpairs for different versions.)
- For the future: Test against generic transact
8 changes: 4 additions & 4 deletions integration-tests/chopsticks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"author": "[\"KILT <[email protected]>\"]",
"license": "MIT",
"devDependencies": {
"@acala-network/chopsticks": "0.10.0",
"@acala-network/chopsticks-testing": "0.10.1",
"@acala-network/chopsticks": "0.11.0",
"@acala-network/chopsticks-testing": "0.11.0",
"@polkadot/api": "^10.11.2",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.7.0",
Expand All @@ -19,15 +19,15 @@
"eslint-config-prettier": "^9.1.0",
"eslint-config-standard-with-typescript": "^43.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-n": "^15.0.0 || ^16.0.0 ",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.0.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"tsx": "^4.7.1",
"typescript": "*",
"vitest": "^1.4.0",
"eslint-plugin-jsx-a11y": "^6.8.0"
"vitest": "^1.4.0"
},
"scripts": {
"ts-check": "tsc --noEmit",
Expand Down
159 changes: 159 additions & 0 deletions integration-tests/chopsticks/src/helper/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ApiPromise } from '@polkadot/api'

export const xtokens = {
parachainV2: (paraId: number) => (acc: any) => ({
V1: {
parents: 1,
interior: {
X2: [
{ Parachain: paraId },
{
AccountId32: {
network: 'Any',
id: acc,
},
},
],
},
},
}),
parachainV3: (paraId: number) => (acc: any) => ({
V3: {
parents: 1,
interior: {
X2: [
{ Parachain: paraId },
{
AccountId32: {
id: acc,
},
},
],
},
},
}),
transfer:
(token: any, amount: any, dest: (dest: any) => any, weight: any = 'Unlimited') =>
({ api }: { api: ApiPromise }, acc: any) =>
api.tx.xTokens.transfer(token, amount, dest(acc), weight),
}

export const xcmPallet = {
parachainV2: (parents: number, paraId: number) => ({
V2: {
parents,
interior: {
X1: { Parachain: paraId },
},
},
}),
parachainV3: (parents: number, paraId: any) => ({
V3: {
parents,
interior: {
X1: { Parachain: paraId },
},
},
}),
limitedTeleportAssets:
(token: any, amount: any, dest: any) =>
({ api }: { api: ApiPromise }, acc: any) =>
(api.tx.xcmPallet || api.tx.polkadotXcm).limitedTeleportAssets(
dest,
{
V3: {
parents: 0,
interior: {
X1: {
AccountId32: {
// network: 'Any',
id: acc,
},
},
},
},
},
{
V3: [
{
id: token,
fun: { Fungible: amount },
},
],
},
0,
'Unlimited'
),
limitedReserveTransferAssetsV2:
(token: any, dest: any) =>
({ api }: { api: ApiPromise }, acc: any, amount: any) =>
(api.tx.xcmPallet || api.tx.polkadotXcm).limitedReserveTransferAssets(
dest,
{
V2: {
parents: 0,
interior: {
X1: {
AccountId32: {
network: 'Any',
id: acc,
},
},
},
},
},
{
V2: [
{
id: token,
fun: { Fungible: amount },
},
],
},
0,
'Unlimited'
),
limitedReserveTransferAssetsV3:
(token: any, amount: any, dest: any) =>
({ api }: { api: ApiPromise }, acc: any) =>
(api.tx.xcmPallet || api.tx.polkadotXcm).limitedReserveTransferAssets(
dest,
{
V3: {
parents: 0,
interior: {
X1: {
AccountId32: {
id: acc,
},
},
},
},
},
{
V3: [
{
id: token,
fun: { Fungible: amount },
},
],
},
0,
'Unlimited'
),
}

export const tx = {
xtokens,
xcmPallet,
}

export const query = {
balances: async ({ api }: { api: ApiPromise }, address: string) =>
BigInt(((await api.query.system.account(address)) as any).data.free),
tokens:
(token: any) =>
async ({ api }: { api: ApiPromise }, address: string) =>
BigInt(((await api.query.tokens.accounts(address, token)) as any).free),
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { setupContext, SetupOption } from '@acala-network/chopsticks-testing'
import type { Config } from './types.js'
import { initialBalanceHDX, initialBalanceKILT, toNumber } from '../utils.js'
import { SetupOption } from '@acala-network/chopsticks-testing'

import { initialBalanceHDX, initialBalanceKILT, toNumber } from '../../helper/utils.js'

/// Options used to create the HydraDx context
export const options: SetupOption = {
endpoint: process.env.HYDRADX_WS || ['wss://hydradx-rpc.dwellir.com', 'wss://rpc.hydradx.cloud'],
db: './db/hydradx.db.sqlite',
port: toNumber(process.env.HYDRADX_PORT) || 9001,
}
export const getSetupOptions = (blockNumber: number | undefined = undefined) =>
({
endpoint: process.env.HYDRADX_WS || ['wss://hydradx-rpc.dwellir.com', 'wss://rpc.hydradx.cloud'],
db: './db/hydradx.db.sqlite',
port: toNumber(process.env.HYDRADX_PORT) || 9001,
blockNumber,
}) as SetupOption

export const kiltTokenId = 28

Expand Down Expand Up @@ -42,7 +44,3 @@ export const paraId = 2034

/// Omnipool account
export const omnipoolAccount = '7L53bUTBbfuj14UpdCNPwmgzzHSsrsTWBHX5pys32mVWM3C1'

export async function getContext(): Promise<Config> {
return setupContext(options)
}
13 changes: 13 additions & 0 deletions integration-tests/chopsticks/src/network/polkadot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as SpiritnetConfig from './spiritnet.js'
import * as PolkadotConfig from './relay.js'
import * as HydraDxConfig from './hydraDx.js'
import { ChainConfigs } from '../types.js'

const BLOCK_NUMBER_SPIRITNET = 5_000_000
const BLOCK_NUMBER_HYDRADX_POLKADOT = 4_000_000

export const chainConfigs: ChainConfigs = {
spiritnet: { config: SpiritnetConfig.getSetupOptions, blockNumber: BLOCK_NUMBER_SPIRITNET, name: 'spiritnet' },
hydraDx: { config: HydraDxConfig.getSetupOptions, blockNumber: BLOCK_NUMBER_HYDRADX_POLKADOT, name: 'hydradx' },
polkadot: { config: PolkadotConfig.getSetupOptions, blockNumber: BLOCK_NUMBER_HYDRADX_POLKADOT, name: 'polkadot' },
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { setupContext, SetupOption } from '@acala-network/chopsticks-testing'
import type { Config } from './types.js'
import { initialBalanceDOT, toNumber } from '../utils.js'
import type { SetupOption } from '@acala-network/chopsticks-testing'

import { initialBalanceDOT, toNumber } from '../../helper/utils.js'

/// Options used to create the HydraDx context
export const options: SetupOption = {
endpoint: process.env.POLKADOT_WS || [
'wss://rpc.polkadot.io',
'wss://polkadot-rpc.dwellir.com',
'wss://rpc.ibp.network/polkadot',
],
db: './db/polkadot.db.sqlite',
port: toNumber(process.env.POLKADOT_PORT) || 9000,
}
export const getSetupOptions = (blockNumber: number | undefined = undefined) =>
({
endpoint: process.env.POLKADOT_WS || [
'wss://rpc.polkadot.io',
'wss://polkadot-rpc.dwellir.com',
'wss://rpc.ibp.network/polkadot',
],
db: './db/polkadot.db.sqlite',
port: toNumber(process.env.POLKADOT_PORT) || 9000,
blockNumber,
}) as SetupOption

/// Assigns the native tokens to an accounts
export function assignNativeTokensToAccounts(addr: string[], balance: bigint = initialBalanceDOT) {
Expand All @@ -34,7 +36,3 @@ export function removeDisputesAndMessageQueues() {
},
}
}

export async function getContext(): Promise<Config> {
return setupContext(options)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { setupContext, SetupOption } from '@acala-network/chopsticks-testing'
import type { Config } from './types.js'
import { initialBalanceKILT, toNumber } from '../utils.js'
import { SetupOption } from '@acala-network/chopsticks-testing'

import { initialBalanceKILT, toNumber } from '../../helper/utils.js'

/// Options used to create the Spiritnet context
const options: SetupOption = {
endpoint: process.env.SPIRITNET_WS || 'wss://kilt-rpc.dwellir.com',
db: './db/spiritnet.db.sqlite',
port: toNumber(process.env.SPIRITNET_PORT) || 9002,
}
export const getSetupOptions = (blockNumber: number | undefined = undefined) =>
({
endpoint: process.env.SPIRITNET_WS || 'wss://kilt-rpc.dwellir.com',
db: './db/spiritnet.db.sqlite',
port: toNumber(process.env.SPIRITNET_PORT) || 9002,
blockNumber,
}) as SetupOption

/// Assigns the native tokens to an accounts
export function assignNativeTokensToAccounts(addr: string[], balance: bigint = initialBalanceKILT) {
Expand All @@ -28,11 +30,7 @@ export function setGovernance(addr: string[]) {

/// Spiritnet ParaId
export const paraId = 2086
export const KILT = { Concrete: { parents: 0, interior: 'Here' } }

/// The sovereign account of HydraDx in Spiritnet
export const hydraDxSovereignAccount = '4qXPdpioJ6D8cgdeYXaukV2Y2oAQUHaX1VnGhdbSRqJn2CBt'

/// Returns the Spiritnet context for the given options
export async function getContext(): Promise<Config> {
return setupContext(options)
}
10 changes: 9 additions & 1 deletion integration-tests/chopsticks/src/network/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import type { setupContext } from '@acala-network/chopsticks-testing'
import type { SetupOption, setupContext } from '@acala-network/chopsticks-testing'

export type Config = Awaited<ReturnType<typeof setupContext>>

export interface Chain {
config: (blockNumber?: number | undefined) => SetupOption
blockNumber: number
name: string
}

export type ChainConfigs = Record<string, Chain>
53 changes: 0 additions & 53 deletions integration-tests/chopsticks/src/network/utils.ts

This file was deleted.

Loading

0 comments on commit 0b5d6ce

Please sign in to comment.