forked from open-web3-stack/polkadot-ecosystem-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runXtokenstHorizontal.ts
72 lines (63 loc) · 2.13 KB
/
runXtokenstHorizontal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { type KeyringPair } from '@polkadot/keyring/types'
import { it } from 'vitest'
import { sendTransaction } from '@acala-network/chopsticks-testing'
import { Client, defaultAccounts } from '@e2e-test/networks'
import { GetBalance, Tx } from './types.js'
import { check, checkEvents, checkHrmp, checkSystemEvents, checkUmp } from '../helpers/index.js'
export const runXtokenstHorizontal = (
name: string,
setup: () => Promise<{
fromChain: Client
toChain: Client
tx: Tx
fromBalance: GetBalance
toBalance: GetBalance
routeChain?: Client
fromAccount?: KeyringPair
toAccount?: KeyringPair
isCheckUmp?: boolean
precision?: number
}>,
options: { only?: boolean } = {},
) => {
const itfn = options.only ? it.only : it
itfn(
name,
async () => {
const {
fromChain,
toChain,
tx,
fromBalance,
toBalance,
routeChain,
fromAccount = defaultAccounts.alice,
toAccount = defaultAccounts.bob,
isCheckUmp = false,
precision = 3,
} = await setup()
const txx = tx(fromChain, toAccount.addressRaw)
const tx0 = await sendTransaction(txx.signAsync(fromAccount))
await fromChain.chain.newBlock()
await check(fromBalance(fromChain, fromAccount.address))
.redact({ number: precision })
.toMatchSnapshot('balance on from chain')
await checkEvents(tx0, 'xTokens').toMatchSnapshot('tx events')
if (isCheckUmp) {
await checkUmp(fromChain).toMatchSnapshot('from chain ump messages')
} else {
await checkHrmp(fromChain).toMatchSnapshot('from chain hrmp messages')
}
if (routeChain) {
await routeChain.chain.newBlock()
await checkSystemEvents(routeChain, 'messageQueue').toMatchSnapshot('route chain xcm events')
}
await toChain.chain.newBlock()
await check(toBalance(toChain, toAccount.address))
.redact({ number: precision })
.toMatchSnapshot('balance on to chain')
await checkSystemEvents(toChain, 'xcmpQueue', 'dmpQueue', 'messageQueue').toMatchSnapshot('to chain xcm events')
},
240000,
)
}