Skip to content

Commit

Permalink
chore: e2e tests ah between current spiritnet runtime (#668)
Browse files Browse the repository at this point in the history
## fixes [#3507](KILTprotocol/ticket#3507)
Checks possible interaction between AH and Spiritnet. In the emulated
tests, it is checked that messages with the `Transact` instruction are
filtered out. Currently, there are only tests for extrinsics which
require sudo rights. If it is wished, I can add a test for that too.
  • Loading branch information
Ad96el committed Aug 20, 2024
1 parent 9089c46 commit ec64b89
Show file tree
Hide file tree
Showing 19 changed files with 852 additions and 64 deletions.
4 changes: 2 additions & 2 deletions integration-tests/chopsticks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"author": "[\"KILT <info@kilt.io>\"]",
"license": "MIT",
"devDependencies": {
"@acala-network/chopsticks": "0.10.0",
"@acala-network/chopsticks-testing": "0.10.1",
"@acala-network/chopsticks": "0.12.2",
"@acala-network/chopsticks-testing": "0.12.2",
"@polkadot/api": "^10.11.2",
"@types/node": "^20.11.30",
"@typescript-eslint/eslint-plugin": "^7.7.0",
Expand Down
65 changes: 65 additions & 0 deletions integration-tests/chopsticks/src/network/assetHub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { setupContext, SetupOption } from '@acala-network/chopsticks-testing'

import type { Config } from './types.js'
import { initialBalanceDOT, toNumber } from '../utils.js'

/// Options used to create the Spiritnet context
export const getSetupOptions = ({
blockNumber = undefined,
wasmOverride = undefined,
}: {
blockNumber?: number
wasmOverride?: string
}) =>
({
endpoint: process.env.ASSETHUB_WSS || 'wss://asset-hub-polkadot-rpc.dwellir.com',
db: './db/assethub.db.sqlite',
port: toNumber(process.env.ASSETHUB_PORT) || 9003,
wasmOverride,
blockNumber,
}) as SetupOption

export function assignKSMtoAccounts(addr: string[], balance: bigint = initialBalanceDOT) {
return {
foreignAssets: {
account: addr.map((addr) => [
[KSMAssetLocation, addr],
{
balance: balance,
status: 'Liquid',
reason: 'Consumer',
extra: null,
},
]),
},
}
}

/// AssetHub has no own coin. Teleported dots are used as the native token.
export function assignDotTokensToAccounts(addr: string[], balance: bigint = initialBalanceDOT) {
return {
System: {
Account: addr.map((address) => [[address], { providers: 1, data: { free: balance.toString() } }]),
},
}
}

/// AssetHub ParaId
export const paraId = 1000

export const KSMAssetLocation = {
parents: 2,
interior: {
X1: {
GlobalConsensus: 'Kusama',
},
},
}

// Sibling Sovereign Account
export const sovereignAccountOnSiblingChains = '4qXPdpimHh8TR24RSk994yVzxx4TLfvKj5i1qH5puvWmfAqy'

export async function getContext(): Promise<Config> {
const options = getSetupOptions({})
return setupContext(options)
}
8 changes: 8 additions & 0 deletions integration-tests/chopsticks/src/network/spiritnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export function setGovernance(addr: string[]) {
}
}

export function XcmPalletSafeVersion3StorageEntry() {
return {
polkadotXcm: {
safeXcmVersion: 3,
},
}
}

/// Spiritnet ParaId
export const paraId = 2086

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/chopsticks/src/network/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function getAccountLocationV3(addr: string) {
}
}

export function getNativeAssetIdLocation(amount: bigint) {
export function getNativeAssetIdLocation(amount: bigint | string) {
return {
id: { Concrete: { parents: 0, interior: 'Here' } },
fun: { Fungible: amount },
Expand Down
25 changes: 18 additions & 7 deletions integration-tests/chopsticks/src/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ import { setTimeout } from 'timers/promises'
import * as SpiritnetConfig from '../network/spiritnet.js'
import * as PolkadotConfig from '../network/polkadot.js'
import * as HydraDxConfig from '../network/hydraDx.js'
import * as AssetHubConfig from '../network/assetHub.js'
import type { Config } from '../network/types.js'

export let spiritnetContext: Config
export let hydradxContext: Config
export let polkadotContext: Config
export let assetHubContext: Config

beforeAll(async () => {
spiritnetContext = await SpiritnetConfig.getContext()
hydradxContext = await HydraDxConfig.getContext()
polkadotContext = await PolkadotConfig.getContext()
assetHubContext = await AssetHubConfig.getContext()

// Setup network
//@ts-expect-error Something weird in the exported types

await connectVertical(polkadotContext.chain, spiritnetContext.chain)
//@ts-expect-error Something weird in the exported types
await connectVertical(polkadotContext.chain, hydradxContext.chain)
//@ts-expect-error Something weird in the exported types
await connectParachains([spiritnetContext.chain, hydradxContext.chain])
await connectVertical(polkadotContext.chain, assetHubContext.chain)
await connectParachains([spiritnetContext.chain, hydradxContext.chain, assetHubContext.chain])

const newBlockConfig = { count: 2 }
// fixes api runtime disconnect warning
Expand All @@ -32,13 +34,22 @@ beforeAll(async () => {
polkadotContext.dev.newBlock(newBlockConfig),
spiritnetContext.dev.newBlock(newBlockConfig),
hydradxContext.dev.newBlock(newBlockConfig),
assetHubContext.dev.newBlock(newBlockConfig),
])
}, 300_000)

afterAll(async () => {
// fixes api runtime disconnect warning
await setTimeout(50)
await Promise.all([spiritnetContext.teardown(), hydradxContext.teardown(), polkadotContext.teardown()])
try {
await setTimeout(50)
await Promise.all([
spiritnetContext.teardown(),
hydradxContext.teardown(),
polkadotContext.teardown(),
assetHubContext.teardown(),
])
} catch (e) {
console.error(e)
}
})

export async function getFreeBalanceSpiritnet(account: string): Promise<bigint> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`Limited Reserve Transfers from AH Account Alice -> Spiritnet Account Alice > receiver spiritnet::XcmpQueue::[Fail] asset {"V3":[{"id":{"Concrete":{"parents":2,"interior":{"X1":{"GlobalConsensus":"Kusama"}}}},"fun":{"Fungible":"10000000000"}}]} 1`] = `
[
{
"data": {
"error": "UntrustedReserveLocation",
"messageHash": "(hash)",
"messageId": "(hash)",
"weight": {
"proofSize": 0,
"refTime": 200000000,
},
},
"method": "Fail",
"section": "xcmpQueue",
},
]
`;

exports[`Limited Reserve Transfers from AH Account Alice -> Spiritnet Account Alice > sender assetHub::foreignAssets::[Transferred] asset {"V3":[{"id":{"Concrete":{"parents":2,"interior":{"X1":{"GlobalConsensus":"Kusama"}}}},"fun":{"Fungible":"10000000000"}}]} 1`] = `
[
{
"data": {
"amount": 10000000000,
"assetId": {
"interior": {
"X1": {
"GlobalConsensus": "Kusama",
},
},
"parents": 2,
},
"from": "15jSz35ugoWTc61xHPoxEkHte4o7UanKCk1gx1dizA8yuNs8",
"to": "13cKp88mpGREFCq8KsJEFjpSBnjFuCNWq6bmD3js7fu4f66e",
},
"method": "Transferred",
"section": "foreignAssets",
},
]
`;

exports[`Limited Reserve Transfers from AH Account Alice -> Spiritnet Account Alice > sender assetHub::polkadotXcm::[Sent,FeesPaid,Attempted] asset {"V3":[{"id":{"Concrete":{"parents":2,"interior":{"X1":{"GlobalConsensus":"Kusama"}}}},"fun":{"Fungible":"10000000000"}}]} 1`] = `
[
{
"data": {
"outcome": {
"Complete": {
"used": {
"proofSize": "(rounded 6200)",
"refTime": "(rounded 290000000)",
},
},
},
},
"method": "Attempted",
"section": "polkadotXcm",
},
{
"data": {
"fees": [
{
"fun": {
"Fungible": 310000000,
},
"id": {
"interior": "Here",
"parents": 1,
},
},
],
"paying": {
"interior": {
"X1": [
{
"AccountId32": {
"id": "(hash)",
"network": "Polkadot",
},
},
],
},
"parents": 0,
},
},
"method": "FeesPaid",
"section": "polkadotXcm",
},
{
"data": {
"destination": {
"interior": {
"X1": [
{
"Parachain": "(rounded 2100)",
},
],
},
"parents": 1,
},
"message": [
{
"ReserveAssetDeposited": [
{
"fun": {
"Fungible": 10000000000,
},
"id": {
"interior": {
"X1": [
{
"GlobalConsensus": "Kusama",
},
],
},
"parents": 2,
},
},
],
},
"ClearOrigin",
{
"BuyExecution": {
"fees": {
"fun": {
"Fungible": 10000000000,
},
"id": {
"interior": {
"X1": [
{
"GlobalConsensus": "Kusama",
},
],
},
"parents": 2,
},
},
"weightLimit": "Unlimited",
},
},
{
"DepositAsset": {
"assets": {
"Wild": "All",
},
"beneficiary": {
"interior": {
"X1": [
{
"AccountId32": {
"id": "(hash)",
"network": null,
},
},
],
},
"parents": 0,
},
},
},
],
"messageId": "(hash)",
"origin": {
"interior": {
"X1": [
{
"AccountId32": {
"id": "(hash)",
"network": "Polkadot",
},
},
],
},
"parents": 0,
},
},
"method": "Sent",
"section": "polkadotXcm",
},
]
`;

exports[`Limited Reserve Transfers from AH Account Alice -> Spiritnet Account Alice > sender assetHub::xcmpQueue::[XcmpMessageSent] asset {"V3":[{"id":{"Concrete":{"parents":2,"interior":{"X1":{"GlobalConsensus":"Kusama"}}}},"fun":{"Fungible":"10000000000"}}]} 1`] = `
[
{
"data": {
"messageHash": "(hash)",
},
"method": "XcmpMessageSent",
"section": "xcmpQueue",
},
]
`;
Loading

0 comments on commit ec64b89

Please sign in to comment.