|
| 1 | +import { test } from 'vitest' |
| 2 | +import { sendTransaction, withExpect } from '@acala-network/chopsticks-testing' |
| 3 | + |
| 4 | +import * as HydraDxConfig from '../../network/hydraDx.js' |
| 5 | +import * as SpiritnetConfig from '../../network/spiritnet.js' |
| 6 | +import { KILT, initialBalanceKILT, keysAlice, keysBob } from '../../utils.js' |
| 7 | +import { getFreeBalanceHydraDxKilt, getFreeBalanceSpiritnet, hydradxContext, spiritnetContext } from '../index.js' |
| 8 | +import { checkBalance, createBlock, hexAddress, setStorage } from '../utils.js' |
| 9 | + |
| 10 | +const aliceLocation = { |
| 11 | + V3: { |
| 12 | + parents: 1, |
| 13 | + interior: { |
| 14 | + X2: [ |
| 15 | + { Parachain: SpiritnetConfig.paraId }, |
| 16 | + { |
| 17 | + AccountId32: { |
| 18 | + id: hexAddress(keysAlice.address), |
| 19 | + }, |
| 20 | + }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + }, |
| 24 | +} |
| 25 | + |
| 26 | +test('Limited Reserve Transfers from HydraDx Account Bob -> Spiritnet', async ({ expect }) => { |
| 27 | + const { checkEvents, checkSystemEvents } = withExpect(expect) |
| 28 | + |
| 29 | + const hydraDxConfig = { |
| 30 | + ...HydraDxConfig.assignKiltTokensToAccounts([keysBob.address, HydraDxConfig.omnipoolAccount]), |
| 31 | + ...HydraDxConfig.assignNativeTokensToAccounts([keysBob.address, HydraDxConfig.omnipoolAccount]), |
| 32 | + } |
| 33 | + |
| 34 | + // Update storage |
| 35 | + await setStorage( |
| 36 | + spiritnetContext, |
| 37 | + SpiritnetConfig.assignNativeTokensToAccounts([SpiritnetConfig.hydraDxSovereignAccount]) |
| 38 | + ) |
| 39 | + await setStorage(hydradxContext, hydraDxConfig) |
| 40 | + |
| 41 | + await createBlock(spiritnetContext) |
| 42 | + await createBlock(hydradxContext) |
| 43 | + |
| 44 | + // check initial balance of alice |
| 45 | + await checkBalance(getFreeBalanceSpiritnet, keysAlice.address, expect) |
| 46 | + |
| 47 | + const signedTx = hydradxContext.api.tx.xTokens |
| 48 | + .transfer(HydraDxConfig.kiltTokenId, KILT, aliceLocation, 'Unlimited') |
| 49 | + .signAsync(keysBob) |
| 50 | + |
| 51 | + const events = await sendTransaction(signedTx) |
| 52 | + |
| 53 | + // Check sender state |
| 54 | + await createBlock(hydradxContext) |
| 55 | + |
| 56 | + // Check events sender |
| 57 | + checkEvents(events, 'xcmpQueue').toMatchSnapshot('sender events xcm queue pallet') |
| 58 | + checkEvents(events, { section: 'currencies', method: 'Withdrawn' }).toMatchSnapshot('sender events currencies') |
| 59 | + checkEvents(events, 'xTokens').toMatchSnapshot('sender events currencies') |
| 60 | + |
| 61 | + // Check balance |
| 62 | + await checkBalance(getFreeBalanceHydraDxKilt, keysBob.address, expect, initialBalanceKILT - KILT) |
| 63 | + |
| 64 | + // Check receiver state |
| 65 | + await createBlock(spiritnetContext) |
| 66 | + |
| 67 | + // check events receiver |
| 68 | + checkSystemEvents(spiritnetContext, 'xcmpQueue').toMatchSnapshot('receiver events xcmpQueue') |
| 69 | + checkSystemEvents(spiritnetContext, { section: 'balances', method: 'Withdraw' }).toMatchSnapshot( |
| 70 | + 'receiver events Balances' |
| 71 | + ) |
| 72 | + checkSystemEvents(spiritnetContext, { section: 'balances', method: 'Endowed' }).toMatchSnapshot( |
| 73 | + 'receiver events Balances' |
| 74 | + ) |
| 75 | + |
| 76 | + // Check balance receiver |
| 77 | + await checkBalance( |
| 78 | + getFreeBalanceSpiritnet, |
| 79 | + SpiritnetConfig.hydraDxSovereignAccount, |
| 80 | + expect, |
| 81 | + initialBalanceKILT - KILT |
| 82 | + ) |
| 83 | + // Alice receives a bit less since the tx fees has to be paid. |
| 84 | + await checkBalance(getFreeBalanceSpiritnet, keysAlice.address, expect, BigInt('999999999971175')) |
| 85 | +}, 20_000) |
0 commit comments