difftreelog
refactor draft move xcm tests to playgrounds
in: master
3 files changed
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {executeTransaction} from './../substrate/substrate-api';24import {bigIntToDecimals, describe_xcm, getGenericResult, paraSiblingSovereignAccount, normalizeAccountId} from './../deprecated-helpers/helpers';25import waitNewBlocks from './../substrate/wait-new-blocks';26import getBalance from './../substrate/get-balance';272829chai.use(chaiAsPromised);30const expect = chai.expect;3132const STATEMINE_CHAIN = 1000;33const UNIQUE_CHAIN = 2095;3435const RELAY_PORT = '9844';36const UNIQUE_PORT = '9944';37const STATEMINE_PORT = '9948';38const STATEMINE_PALLET_INSTANCE = 50;39const ASSET_ID = 100;40const ASSET_METADATA_DECIMALS = 18;41const ASSET_METADATA_NAME = 'USDT';42const ASSET_METADATA_DESCRIPTION = 'USDT';43const ASSET_METADATA_MINIMAL_BALANCE = 1;4445const WESTMINT_DECIMALS = 12;4647const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4849// 10,000.00 (ten thousands) USDT50const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 5152describe_xcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {53 let alice: IKeyringPair;54 let bob: IKeyringPair;55 56 let balanceStmnBefore: bigint;57 let balanceStmnAfter: bigint;5859 let balanceOpalBefore: bigint;60 let balanceOpalAfter: bigint;61 let balanceOpalFinal: bigint;6263 let balanceBobBefore: bigint;64 let balanceBobAfter: bigint;65 let balanceBobFinal: bigint;6667 let balanceBobRelayTokenBefore: bigint;68 let balanceBobRelayTokenAfter: bigint;697071 before(async () => {72 await usingApi(async (api, privateKeyWrapper) => {73 alice = privateKeyWrapper('//Alice');74 bob = privateKeyWrapper('//Bob'); // funds donor75 });7677 const statemineApiOptions: ApiOptions = {78 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),79 };8081 const uniqueApiOptions: ApiOptions = {82 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),83 };8485 const relayApiOptions: ApiOptions = {86 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),87 };8889 await usingApi(async (api) => {9091 // 350.00 (three hundred fifty) DOT92 const fundingAmount = 3_500_000_000_000; 9394 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);95 const events = await executeTransaction(api, alice, tx);96 const result = getGenericResult(events);97 expect(result.success).to.be.true;9899 // set metadata100 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);101 const events2 = await executeTransaction(api, alice, tx2);102 const result2 = getGenericResult(events2);103 expect(result2.success).to.be.true;104105 // mint some amount of asset106 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);107 const events3 = await executeTransaction(api, alice, tx3);108 const result3 = getGenericResult(events3);109 expect(result3.success).to.be.true;110111 // funding parachain sovereing account (Parachain: 2095)112 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);113 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);114 const events4 = await executeTransaction(api, bob, tx4);115 const result4 = getGenericResult(events4);116 expect(result4.success).to.be.true;117118 }, statemineApiOptions);119120121 await usingApi(async (api) => {122123 const location = {124 V1: {125 parents: 1,126 interior: {X3: [127 {128 Parachain: STATEMINE_CHAIN,129 },130 {131 PalletInstance: STATEMINE_PALLET_INSTANCE,132 },133 {134 GeneralIndex: ASSET_ID,135 },136 ]},137 },138 };139140 const metadata =141 {142 name: ASSET_ID,143 symbol: ASSET_METADATA_NAME,144 decimals: ASSET_METADATA_DECIMALS,145 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,146 };147 //registerForeignAsset(owner, location, metadata)148 const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);149 const sudoTx = api.tx.sudo.sudo(tx as any);150 const events = await executeTransaction(api, alice, sudoTx);151 const result = getGenericResult(events);152 expect(result.success).to.be.true;153154 [balanceOpalBefore] = await getBalance(api, [alice.address]);155156 }, uniqueApiOptions);157158159 // Providing the relay currency to the unique sender account160 await usingApi(async (api) => {161 const destination = {162 V1: {163 parents: 0,164 interior: {X1: {165 Parachain: UNIQUE_CHAIN,166 },167 },168 }};169170 const beneficiary = {171 V1: {172 parents: 0,173 interior: {X1: {174 AccountId32: {175 network: 'Any',176 id: alice.addressRaw,177 },178 }},179 },180 };181182 const assets = {183 V1: [184 {185 id: {186 Concrete: {187 parents: 0,188 interior: 'Here',189 },190 },191 fun: {192 Fungible: 50_000_000_000_000_000n,193 },194 },195 ],196 };197198 const feeAssetItem = 0;199200 const weightLimit = {201 Limited: 5_000_000_000,202 };203204 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);205 const events = await executeTransaction(api, alice, tx);206 const result = getGenericResult(events);207 expect(result.success).to.be.true;208 }, relayApiOptions);209 210 });211212 it('Should connect and send USDT from Westmint to Opal', async () => {213 214 const statemineApiOptions: ApiOptions = {215 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),216 };217218 const uniqueApiOptions: ApiOptions = {219 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),220 };221222 await usingApi(async (api) => {223224 const dest = {225 V1: {226 parents: 1,227 interior: {X1: {228 Parachain: UNIQUE_CHAIN,229 },230 },231 }};232233 const beneficiary = {234 V1: {235 parents: 0,236 interior: {X1: {237 AccountId32: {238 network: 'Any',239 id: alice.addressRaw,240 },241 }},242 },243 };244245 const assets = {246 V1: [247 {248 id: {249 Concrete: {250 parents: 0,251 interior: {252 X2: [253 {254 PalletInstance: STATEMINE_PALLET_INSTANCE,255 },256 {257 GeneralIndex: ASSET_ID,258 }, 259 ]},260 },261 },262 fun: {263 Fungible: TRANSFER_AMOUNT,264 },265 },266 ],267 };268269 const feeAssetItem = 0;270271 const weightLimit = {272 Limited: 5000000000,273 };274275 [balanceStmnBefore] = await getBalance(api, [alice.address]);276277 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);278 const events = await executeTransaction(api, alice, tx);279 const result = getGenericResult(events);280 expect(result.success).to.be.true;281282 [balanceStmnAfter] = await getBalance(api, [alice.address]);283284 // common good parachain take commission in it native token285 console.log(286 'Opal to Westmint transaction fees on Westmint: %s WND',287 bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),288 );289 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;290291 }, statemineApiOptions);292293294 // ensure that asset has been delivered295 await usingApi(async (api) => {296 await waitNewBlocks(api, 3);297 // expext collection id will be with id 1298 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();299300 [balanceOpalAfter] = await getBalance(api, [alice.address]);301302 // commission has not paid in USDT token303 expect(free == TRANSFER_AMOUNT).to.be.true;304 console.log(305 'Opal to Westmint transaction fees on Opal: %s USDT',306 bigIntToDecimals(TRANSFER_AMOUNT - free),307 );308 // ... and parachain native token309 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;310 console.log(311 'Opal to Westmint transaction fees on Opal: %s WND',312 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),313 );314315 }, uniqueApiOptions);316 317 });318319 it('Should connect and send USDT from Unique to Statemine back', async () => {320321 const uniqueApiOptions: ApiOptions = {322 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),323 };324325 const statemineApiOptions: ApiOptions = {326 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),327 };328329 await usingApi(async (api) => {330 const destination = {331 V1: {332 parents: 1,333 interior: {X2: [334 {335 Parachain: STATEMINE_CHAIN,336 },337 {338 AccountId32: {339 network: 'Any',340 id: alice.addressRaw,341 },342 },343 ]},344 },345 };346347 const currencies: [any, bigint][] = [348 [349 {350 ForeignAssetId: 0,351 },352 //10_000_000_000_000_000n,353 TRANSFER_AMOUNT,354 ], 355 [356 {357 NativeAssetId: 'Parent',358 },359 400_000_000_000_000n,360 ],361 ];362363 const feeItem = 1;364 const destWeight = 500000000000;365366 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);367 const events = await executeTransaction(api, alice, tx);368 const result = getGenericResult(events);369 expect(result.success).to.be.true;370 371 // the commission has been paid in parachain native token372 [balanceOpalFinal] = await getBalance(api, [alice.address]);373 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;374 }, uniqueApiOptions);375376 await usingApi(async (api) => {377 await waitNewBlocks(api, 3);378 379 // The USDT token never paid fees. Its amount not changed from begin value.380 // Also check that xcm transfer has been succeeded 381 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;382 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;383 }, statemineApiOptions);384 });385386 it('Should connect and send Relay token to Unique', async () => {387388 const uniqueApiOptions: ApiOptions = {389 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),390 };391392 const uniqueApiOptions2: ApiOptions = {393 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),394 };395396 const relayApiOptions: ApiOptions = {397 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),398 };399400 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;401402 await usingApi(async (api) => {403 [balanceBobBefore] = await getBalance(api, [bob.address]);404 balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);405406 }, uniqueApiOptions);407408 // Providing the relay currency to the unique sender account409 await usingApi(async (api) => {410 const destination = {411 V1: {412 parents: 0,413 interior: {X1: {414 Parachain: UNIQUE_CHAIN,415 },416 },417 }};418419 const beneficiary = {420 V1: {421 parents: 0,422 interior: {X1: {423 AccountId32: {424 network: 'Any',425 id: bob.addressRaw,426 },427 }},428 },429 };430431 const assets = {432 V1: [433 {434 id: {435 Concrete: {436 parents: 0,437 interior: 'Here',438 },439 },440 fun: {441 Fungible: TRANSFER_AMOUNT_RELAY,442 },443 },444 ],445 };446447 const feeAssetItem = 0;448449 const weightLimit = {450 Limited: 5_000_000_000,451 };452453 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);454 const events = await executeTransaction(api, bob, tx);455 const result = getGenericResult(events);456 expect(result.success).to.be.true;457 }, relayApiOptions);458 459460 await usingApi(async (api) => {461 await waitNewBlocks(api, 3);462463 [balanceBobAfter] = await getBalance(api, [bob.address]);464 balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);465 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 466 console.log(467 'Relay (Westend) to Opal transaction fees: %s OPL',468 bigIntToDecimals(balanceBobAfter - balanceBobBefore),469 );470 console.log(471 'Relay (Westend) to Opal transaction fees: %s WND',472 bigIntToDecimals(wndFee, WESTMINT_DECIMALS),473 );474 expect(balanceBobBefore == balanceBobAfter).to.be.true;475 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;476 }, uniqueApiOptions2);477478 });479480 it('Should connect and send Relay token back', async () => {481 const uniqueApiOptions: ApiOptions = {482 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),483 };484485 await usingApi(async (api) => {486 const destination = {487 V1: {488 parents: 1,489 interior: {X2: [490 {491 Parachain: STATEMINE_CHAIN,492 },493 {494 AccountId32: {495 network: 'Any',496 id: bob.addressRaw,497 },498 },499 ]},500 },501 };502503 const currencies: any = [504 [505 {506 NativeAssetId: 'Parent',507 },508 50_000_000_000_000_000n,509 ],510 ];511512 const feeItem = 0;513 const destWeight = 500000000000;514515 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);516 const events = await executeTransaction(api, bob, tx);517 const result = getGenericResult(events);518 expect(result.success).to.be.true;519520 [balanceBobFinal] = await getBalance(api, [bob.address]);521 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);522523 }, uniqueApiOptions);524 });525526});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {executeTransaction} from './../substrate/substrate-api';19import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';20import getBalance from './../substrate/get-balance';21import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';2223const STATEMINE_CHAIN = 1000;24const UNIQUE_CHAIN = 2095;2526const RELAY_PORT = '9844';27const STATEMINE_PORT = '9948';2829const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;30const statemineUrl = 'ws://127.0.0.1:' + STATEMINE_PORT;3132const STATEMINE_PALLET_INSTANCE = 50;33const ASSET_ID = 100;34const ASSET_METADATA_DECIMALS = 18;35const ASSET_METADATA_NAME = 'USDT';36const ASSET_METADATA_DESCRIPTION = 'USDT';37const ASSET_METADATA_MINIMAL_BALANCE = 1n;3839const WESTMINT_DECIMALS = 12;4041const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4243// 10,000.00 (ten thousands) USDT44const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 4546describeXcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {47 let alice: IKeyringPair;48 let bob: IKeyringPair;49 50 let balanceStmnBefore: bigint;51 let balanceStmnAfter: bigint;5253 let balanceOpalBefore: bigint;54 let balanceOpalAfter: bigint;55 let balanceOpalFinal: bigint;5657 let balanceBobBefore: bigint;58 let balanceBobAfter: bigint;59 let balanceBobFinal: bigint;6061 let balanceBobRelayTokenBefore: bigint;62 let balanceBobRelayTokenAfter: bigint;636465 before(async () => {66 await usingPlaygrounds(async (_helper, privateKey) => {67 alice = privateKey('//Alice');68 bob = privateKey('//Bob'); // funds donor69 });7071 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {72 const api = helper.getApi();7374 // 350.00 (three hundred fifty) DOT75 const fundingAmount = 3_500_000_000_000; 7677 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);78 const events = await executeTransaction(api, alice, tx);79 const result = getGenericResult(events);80 expect(result.success).to.be.true;8182 // set metadata83 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);84 const events2 = await executeTransaction(api, alice, tx2);85 const result2 = getGenericResult(events2);86 expect(result2.success).to.be.true;8788 // mint some amount of asset89 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);90 const events3 = await executeTransaction(api, alice, tx3);91 const result3 = getGenericResult(events3);92 expect(result3.success).to.be.true;9394 // funding parachain sovereing account (Parachain: 2095)95 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);96 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);97 const events4 = await executeTransaction(api, bob, tx4);98 const result4 = getGenericResult(events4);99 expect(result4.success).to.be.true;100101 });102103104 await usingPlaygrounds(async (helper) => {105 const location = {106 V1: {107 parents: 1,108 interior: {X3: [109 {110 Parachain: STATEMINE_CHAIN,111 },112 {113 PalletInstance: STATEMINE_PALLET_INSTANCE,114 },115 {116 GeneralIndex: ASSET_ID,117 },118 ]},119 },120 };121122 const metadata =123 {124 name: ASSET_ID,125 symbol: ASSET_METADATA_NAME,126 decimals: ASSET_METADATA_DECIMALS,127 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,128 };129 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);130 // const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);131 // const sudoTx = api.tx.sudo.sudo(tx as any);132 // const events = await executeTransaction(api, alice, sudoTx);133 // const result = getGenericResult(events);134 // expect(result.success).to.be.true;135136 // [balanceOpalBefore] = await getBalance(api, [alice.address]);137 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);138139 });140141142 // Providing the relay currency to the unique sender account143 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {144 const api = helper.getApi();145146 const destination = {147 V1: {148 parents: 0,149 interior: {X1: {150 Parachain: UNIQUE_CHAIN,151 },152 },153 }};154155 const beneficiary = {156 V1: {157 parents: 0,158 interior: {X1: {159 AccountId32: {160 network: 'Any',161 id: alice.addressRaw,162 },163 }},164 },165 };166167 const assets = {168 V1: [169 {170 id: {171 Concrete: {172 parents: 0,173 interior: 'Here',174 },175 },176 fun: {177 Fungible: 50_000_000_000_000_000n,178 },179 },180 ],181 };182183 const feeAssetItem = 0;184185 const weightLimit = {186 Limited: 5_000_000_000,187 };188189 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);190 const events = await executeTransaction(api, alice, tx);191 const result = getGenericResult(events);192 expect(result.success).to.be.true;193 });194 195 });196197 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {198 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {199 const api = helper.getApi();200201 const dest = {202 V1: {203 parents: 1,204 interior: {X1: {205 Parachain: UNIQUE_CHAIN,206 },207 },208 }};209210 const beneficiary = {211 V1: {212 parents: 0,213 interior: {X1: {214 AccountId32: {215 network: 'Any',216 id: alice.addressRaw,217 },218 }},219 },220 };221222 const assets = {223 V1: [224 {225 id: {226 Concrete: {227 parents: 0,228 interior: {229 X2: [230 {231 PalletInstance: STATEMINE_PALLET_INSTANCE,232 },233 {234 GeneralIndex: ASSET_ID,235 }, 236 ]},237 },238 },239 fun: {240 Fungible: TRANSFER_AMOUNT,241 },242 },243 ],244 };245246 const feeAssetItem = 0;247248 const weightLimit = {249 Limited: 5000000000,250 };251252 [balanceStmnBefore] = await getBalance(api, [alice.address]);253254 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);255 const events = await executeTransaction(api, alice, tx);256 const result = getGenericResult(events);257 expect(result.success).to.be.true;258259 [balanceStmnAfter] = await getBalance(api, [alice.address]);260261 // common good parachain take commission in it native token262 console.log(263 'Opal to Westmint transaction fees on Westmint: %s WND',264 bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),265 );266 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;267268 });269270271 // ensure that asset has been delivered272 // await waitNewBlocks(api, 3);273 await helper.wait.newBlocks(3);274275 // expext collection id will be with id 1276 // const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();277 const free = await helper.ft.getBalance(1, {Substrate: alice.address});278279 // [balanceOpalAfter] = await getBalance(api, [alice.address]);280 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);281282 // commission has not paid in USDT token283 expect(free == TRANSFER_AMOUNT).to.be.true;284 console.log(285 'Opal to Westmint transaction fees on Opal: %s USDT',286 bigIntToDecimals(TRANSFER_AMOUNT - free),287 );288 // ... and parachain native token289 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;290 console.log(291 'Opal to Westmint transaction fees on Opal: %s WND',292 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),293 ); 294 });295296 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {297 const api = helper.getApi();298299 const destination = {300 V1: {301 parents: 1,302 interior: {X2: [303 {304 Parachain: STATEMINE_CHAIN,305 },306 {307 AccountId32: {308 network: 'Any',309 id: alice.addressRaw,310 },311 },312 ]},313 },314 };315316 const currencies: [any, bigint][] = [317 [318 {319 ForeignAssetId: 0,320 },321 //10_000_000_000_000_000n,322 TRANSFER_AMOUNT,323 ], 324 [325 {326 NativeAssetId: 'Parent',327 },328 400_000_000_000_000n,329 ],330 ];331332 const feeItem = 1;333 const destWeight = 500000000000;334335 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);336 const events = await executeTransaction(api, alice, tx);337 const result = getGenericResult(events);338 expect(result.success).to.be.true;339 340 // the commission has been paid in parachain native token341 [balanceOpalFinal] = await getBalance(api, [alice.address]);342 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;343344 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {345 // await waitNewBlocks(api, 3);346 await helper.wait.newBlocks(3);347348 const api = helper.getApi();349 350 // The USDT token never paid fees. Its amount not changed from begin value.351 // Also check that xcm transfer has been succeeded 352 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;353 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;354 });355 });356357 itSub('Should connect and send Relay token to Unique', async ({helper}) => {358 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;359360 // [balanceBobBefore] = await getBalance(api, [bob.address]);361 // balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);362 balanceBobBefore = await helper.balance.getSubstrate(bob.address);363364 // TODO365 balanceBobRelayTokenBefore = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);366367 // Providing the relay currency to the unique sender account368 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {369 const api = helper.getApi();370371 const destination = {372 V1: {373 parents: 0,374 interior: {X1: {375 Parachain: UNIQUE_CHAIN,376 },377 },378 }};379380 const beneficiary = {381 V1: {382 parents: 0,383 interior: {X1: {384 AccountId32: {385 network: 'Any',386 id: bob.addressRaw,387 },388 }},389 },390 };391392 const assets = {393 V1: [394 {395 id: {396 Concrete: {397 parents: 0,398 interior: 'Here',399 },400 },401 fun: {402 Fungible: TRANSFER_AMOUNT_RELAY,403 },404 },405 ],406 };407408 const feeAssetItem = 0;409410 const weightLimit = {411 Limited: 5_000_000_000,412 };413414 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);415 const events = await executeTransaction(api, bob, tx);416 const result = getGenericResult(events);417 expect(result.success).to.be.true;418 });419 420421 // await waitNewBlocks(api, 3);422 await helper.wait.newBlocks(3);423424 // [balanceBobAfter] = await getBalance(api, [bob.address]);425 // balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);426 balanceBobAfter = await helper.balance.getSubstrate(bob.address);427 428 // TODO429 balanceBobRelayTokenAfter = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);430431 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 432 console.log(433 'Relay (Westend) to Opal transaction fees: %s OPL',434 bigIntToDecimals(balanceBobAfter - balanceBobBefore),435 );436 console.log(437 'Relay (Westend) to Opal transaction fees: %s WND',438 bigIntToDecimals(wndFee, WESTMINT_DECIMALS),439 );440 expect(balanceBobBefore == balanceBobAfter).to.be.true;441 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;442 });443444 itSub('Should connect and send Relay token back', async ({helper}) => {445 const destination = {446 V1: {447 parents: 1,448 interior: {X2: [449 {450 Parachain: STATEMINE_CHAIN,451 },452 {453 AccountId32: {454 network: 'Any',455 id: bob.addressRaw,456 },457 },458 ]},459 },460 };461462 const currencies: any = [463 [464 {465 NativeAssetId: 'Parent',466 },467 50_000_000_000_000_000n,468 ],469 ];470471 const feeItem = 0;472 const destWeight = 500000000000;473474 // TODO475 const api = helper.getApi();476 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);477 const events = await executeTransaction(api, bob, tx);478 const result = getGenericResult(events);479 expect(result.success).to.be.true;480481 // [balanceBobFinal] = await getBalance(api, [bob.address]);482 balanceBobFinal = await helper.balance.getSubstrate(bob.address);483 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);484 });485486});tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -14,23 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-
-import {WsProvider, Keyring} from '@polkadot/api';
-import {ApiOptions} from '@polkadot/api/types';
+import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
-import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';
+import {submitTransactionAsync} from '../substrate/substrate-api';
+import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
import {MultiLocation} from '@polkadot/types/interfaces';
import {blake2AsHex} from '@polkadot/util-crypto';
-import waitNewBlocks from '../substrate/wait-new-blocks';
import getBalance from '../substrate/get-balance';
import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';
+import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
const QUARTZ_CHAIN = 2095;
const KARURA_CHAIN = 2000;
const MOONRIVER_CHAIN = 2023;
@@ -39,29 +32,15 @@
const KARURA_PORT = 9946;
const MOONRIVER_PORT = 9947;
+const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
+const karuraUrl = 'ws://127.0.0.1:' + KARURA_PORT;
+const moonriverUrl = 'ws://127.0.0.1:' + MOONRIVER_PORT;
+
const KARURA_DECIMALS = 12;
const TRANSFER_AMOUNT = 2000000000000000000000000n;
-function parachainApiOptions(port: number): ApiOptions {
- return {
- provider: new WsProvider('ws://127.0.0.1:' + port.toString()),
- };
-}
-
-function karuraOptions(): ApiOptions {
- return parachainApiOptions(KARURA_PORT);
-}
-
-function moonriverOptions(): ApiOptions {
- return parachainApiOptions(MOONRIVER_PORT);
-}
-
-function relayOptions(): ApiOptions {
- return parachainApiOptions(RELAY_PORT);
-}
-
-describe_xcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
+describeXcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
@@ -76,233 +55,234 @@
let balanceQuartzForeignTokenFinal: bigint;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingPlaygrounds(async (helper, privateKey) => {
const keyringSr25519 = new Keyring({type: 'sr25519'});
- alice = privateKeyWrapper('//Alice');
+ alice = privateKey('//Alice');
randomAccount = generateKeyringPair(keyringSr25519);
});
// Karura side
- await usingApi(
- async (api) => {
- const destination = {
- V0: {
- X2: [
- 'Parent',
- {
- Parachain: QUARTZ_CHAIN,
- },
- ],
- },
- };
+ await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+ const api = helper.getApi();
+
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: QUARTZ_CHAIN,
+ },
+ ],
+ },
+ };
- const metadata = {
- name: 'QTZ',
- symbol: 'QTZ',
- decimals: 18,
- minimalBalance: 1,
- };
+ const metadata = {
+ name: 'QTZ',
+ symbol: 'QTZ',
+ decimals: 18,
+ minimalBalance: 1,
+ };
- const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
- const sudoTx = api.tx.sudo.sudo(tx as any);
- const events = await submitTransactionAsync(alice, sudoTx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
+ const sudoTx = api.tx.sudo.sudo(tx as any);
+ const events = await submitTransactionAsync(alice, sudoTx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
- const events1 = await submitTransactionAsync(alice, tx1);
- const result1 = getGenericResult(events1);
- expect(result1.success).to.be.true;
+ const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
+ const events1 = await submitTransactionAsync(alice, tx1);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
- [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
- {
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
- balanceQuartzForeignTokenInit = BigInt(free);
- }
- },
- karuraOptions(),
- );
+ [balanceKaruraTokenInit] = await getBalance(api, [randomAccount.address]);
+ {
+ const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceQuartzForeignTokenInit = BigInt(free);
+ }
+ });
// Quartz side
- await usingApi(async (api) => {
- const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
- const events0 = await submitTransactionAsync(alice, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
+ await usingPlaygrounds(async (helper) => {
+ // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
+ // const events0 = await submitTransactionAsync(alice, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
- [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
+ // [balanceQuartzTokenInit] = await getBalance(api, [randomAccount.address]);
+ balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);
});
});
- it('Should connect and send QTZ to Karura', async () => {
+ itSub('Should connect and send QTZ to Karura', async ({helper}) => {
// Quartz side
- await usingApi(async (api) => {
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: KARURA_CHAIN,
+ },
+ ],
+ },
+ };
- const destination = {
- V0: {
- X2: [
- 'Parent',
- {
- Parachain: KARURA_CHAIN,
- },
- ],
+ const beneficiary = {
+ V0: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
},
- };
+ },
+ };
- const beneficiary = {
- V0: {
- X1: {
- AccountId32: {
- network: 'Any',
- id: randomAccount.addressRaw,
+ const assets = {
+ V1: [
+ {
+ id: {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
},
},
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
},
- };
+ ],
+ };
- const assets = {
- V1: [
- {
- id: {
- Concrete: {
- parents: 0,
- interior: 'Here',
- },
- },
- fun: {
- Fungible: TRANSFER_AMOUNT,
- },
- },
- ],
- };
+ const feeAssetItem = 0;
- const feeAssetItem = 0;
-
- const weightLimit = {
- Limited: 5000000000,
- };
+ const weightLimit = {
+ Limited: 5000000000,
+ };
- const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
- const events = await submitTransactionAsync(randomAccount, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
- const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
- expect(qtzFees > 0n).to.be.true;
- });
+ const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
+ expect(qtzFees > 0n).to.be.true;
// Karura side
- await usingApi(
- async (api) => {
- await waitNewBlocks(api, 3);
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
- balanceQuartzForeignTokenMiddle = BigInt(free);
+ await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
+
+ // TODO
+ const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceQuartzForeignTokenMiddle = BigInt(free);
- [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ // [balanceKaruraTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
- const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
- const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
+ const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
+ const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
- console.log(
- '[Quartz -> Karura] transaction fees on Karura: %s KAR',
- bigIntToDecimals(karFees, KARURA_DECIMALS),
- );
- console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
- expect(karFees == 0n).to.be.true;
- expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- karuraOptions(),
- );
+ console.log(
+ '[Quartz -> Karura] transaction fees on Karura: %s KAR',
+ bigIntToDecimals(karFees, KARURA_DECIMALS),
+ );
+ console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
+ expect(karFees == 0n).to.be.true;
+ expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
});
- it('Should connect to Karura and send QTZ back', async () => {
+ itSub('Should connect to Karura and send QTZ back', async ({helper}) => {
// Karura side
- await usingApi(
- async (api) => {
- const destination = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: QUARTZ_CHAIN},
- {
- AccountId32: {
- network: 'Any',
- id: randomAccount.addressRaw,
- },
+ await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: QUARTZ_CHAIN},
+ {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
},
- ],
- },
+ },
+ ],
},
- };
+ },
+ };
- const id = {
- ForeignAsset: 0,
- };
+ const id = {
+ ForeignAsset: 0,
+ };
- const destWeight = 50000000;
+ const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
- const events = await submitTransactionAsync(randomAccount, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
- {
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
- balanceQuartzForeignTokenFinal = BigInt(free);
- }
+ // [balanceKaruraTokenFinal] = await getBalance(api, [randomAccount.address]);
+ balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+ {
+ // TODO
+ const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
+ balanceQuartzForeignTokenFinal = BigInt(free);
+ }
- const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
- const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
+ const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
+ const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
- console.log(
- '[Karura -> Quartz] transaction fees on Karura: %s KAR',
- bigIntToDecimals(karFees, KARURA_DECIMALS),
- );
- console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
+ console.log(
+ '[Karura -> Quartz] transaction fees on Karura: %s KAR',
+ bigIntToDecimals(karFees, KARURA_DECIMALS),
+ );
+ console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
- expect(karFees > 0).to.be.true;
- expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- karuraOptions(),
- );
+ expect(karFees > 0).to.be.true;
+ expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
// Quartz side
- await usingApi(async (api) => {
- await waitNewBlocks(api, 3);
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
- const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
- expect(actuallyDelivered > 0).to.be.true;
+ // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccount.address]);
+ balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+ const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
- console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
+ console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
- const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
- expect(qtzFees == 0n).to.be.true;
- });
+ const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
+ expect(qtzFees == 0n).to.be.true;
});
});
// These tests are relevant only when the foreign asset pallet is disabled
-describe_xcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
+describeXcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
let alice: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
+ await usingPlaygrounds(async (_helper, privateKey) => {
+ alice = privateKey('//Alice');
});
});
- it('Quartz rejects tokens from the Relay', async () => {
- await usingApi(async (api) => {
+ itSub('Quartz rejects tokens from the Relay', async ({helper}) => {
+ await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
const destination = {
V1: {
parents: 0,
@@ -346,44 +326,45 @@
Limited: 5_000_000_000,
};
- const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+ // TODO
+ const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- }, relayOptions());
+ });
- await usingApi(async api => {
- const maxWaitBlocks = 3;
- const dmpQueueExecutedDownward = await waitEvent(
- api,
- maxWaitBlocks,
- 'dmpQueue',
- 'ExecutedDownward',
- );
+ const maxWaitBlocks = 3;
- expect(
- dmpQueueExecutedDownward != null,
- '[Relay] dmpQueue.ExecutedDownward event is expected',
- ).to.be.true;
+ // TODO
+ const dmpQueueExecutedDownward = await waitEvent(
+ helper.getApi(),
+ maxWaitBlocks,
+ 'dmpQueue',
+ 'ExecutedDownward',
+ );
- const event = dmpQueueExecutedDownward!.event;
- const outcome = event.data[1] as XcmV2TraitsOutcome;
+ expect(
+ dmpQueueExecutedDownward != null,
+ '[Relay] dmpQueue.ExecutedDownward event is expected',
+ ).to.be.true;
- expect(
- outcome.isIncomplete,
- '[Relay] The outcome of the XCM should be `Incomplete`',
- ).to.be.true;
+ const event = dmpQueueExecutedDownward!.event;
+ const outcome = event.data[1] as XcmV2TraitsOutcome;
+
+ expect(
+ outcome.isIncomplete,
+ '[Relay] The outcome of the XCM should be `Incomplete`',
+ ).to.be.true;
- const incomplete = outcome.asIncomplete;
- expect(
- incomplete[1].toString() == 'AssetNotFound',
- '[Relay] The XCM error should be `AssetNotFound`',
- ).to.be.true;
- });
+ const incomplete = outcome.asIncomplete;
+ expect(
+ incomplete[1].toString() == 'AssetNotFound',
+ '[Relay] The XCM error should be `AssetNotFound`',
+ ).to.be.true;
});
- it('Quartz rejects KAR tokens from Karura', async () => {
- await usingApi(async (api) => {
+ itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
+ await usingPlaygrounds.atUrl(karuraUrl, async (helper) => {
const destination = {
V1: {
parents: 1,
@@ -407,33 +388,34 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- }, karuraOptions());
+ });
- await usingApi(async api => {
- const maxWaitBlocks = 3;
- const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
+ const maxWaitBlocks = 3;
- expect(
- xcmpQueueFailEvent != null,
- '[Karura] xcmpQueue.FailEvent event is expected',
- ).to.be.true;
+ // TODO
+ const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
- const event = xcmpQueueFailEvent!.event;
- const outcome = event.data[1] as XcmV2TraitsError;
+ expect(
+ xcmpQueueFailEvent != null,
+ '[Karura] xcmpQueue.FailEvent event is expected',
+ ).to.be.true;
- expect(
- outcome.isUntrustedReserveLocation,
- '[Karura] The XCM error should be `UntrustedReserveLocation`',
- ).to.be.true;
- });
+ const event = xcmpQueueFailEvent!.event;
+ const outcome = event.data[1] as XcmV2TraitsError;
+
+ expect(
+ outcome.isUntrustedReserveLocation,
+ '[Karura] The XCM error should be `UntrustedReserveLocation`',
+ ).to.be.true;
});
});
-describe_xcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
+describeXcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
// Quartz constants
let quartzAlice: IKeyringPair;
@@ -478,322 +460,327 @@
let balanceMovrTokenFinal: bigint;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingPlaygrounds(async (_helper, privateKey) => {
const keyringEth = new Keyring({type: 'ethereum'});
const keyringSr25519 = new Keyring({type: 'sr25519'});
- quartzAlice = privateKeyWrapper('//Alice');
+ quartzAlice = privateKey('//Alice');
randomAccountQuartz = generateKeyringPair(keyringSr25519);
randomAccountMoonriver = generateKeyringPair(keyringEth);
balanceForeignQtzTokenInit = 0n;
});
- await usingApi(
- async (api) => {
+ await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+ // TODO
- // >>> Sponsoring Dorothy >>>
- console.log('Sponsoring Dorothy.......');
- const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
- const events0 = await submitTransactionAsync(alithAccount, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
- console.log('Sponsoring Dorothy.......DONE');
- // <<< Sponsoring Dorothy <<<
+ const api = helper.getApi();
- const sourceLocation: MultiLocation = api.createType(
- 'MultiLocation',
- {
- parents: 1,
- interior: {X1: {Parachain: QUARTZ_CHAIN}},
- },
- );
+ // >>> Sponsoring Dorothy >>>
+ console.log('Sponsoring Dorothy.......');
+ // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
+ // const events0 = await submitTransactionAsync(alithAccount, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
+ console.log('Sponsoring Dorothy.......DONE');
+ // <<< Sponsoring Dorothy <<<
- quartzAssetLocation = {XCM: sourceLocation};
- const existentialDeposit = 1;
- const isSufficient = true;
- const unitsPerSecond = '1';
- const numAssetsWeightHint = 0;
+ const sourceLocation: MultiLocation = api.createType(
+ 'MultiLocation',
+ {
+ parents: 1,
+ interior: {X1: {Parachain: QUARTZ_CHAIN}},
+ },
+ );
- const registerTx = api.tx.assetManager.registerForeignAsset(
- quartzAssetLocation,
- quartzAssetMetadata,
- existentialDeposit,
- isSufficient,
- );
- console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
+ quartzAssetLocation = {XCM: sourceLocation};
+ const existentialDeposit = 1;
+ const isSufficient = true;
+ const unitsPerSecond = '1';
+ const numAssetsWeightHint = 0;
- const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
- quartzAssetLocation,
- unitsPerSecond,
- numAssetsWeightHint,
- );
- console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
+ const registerTx = api.tx.assetManager.registerForeignAsset(
+ quartzAssetLocation,
+ quartzAssetMetadata,
+ existentialDeposit,
+ isSufficient,
+ );
+ console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
- const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
- console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
+ const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
+ quartzAssetLocation,
+ unitsPerSecond,
+ numAssetsWeightHint,
+ );
+ console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
- // >>> Note motion preimage >>>
- console.log('Note motion preimage.......');
- const encodedProposal = batchCall?.method.toHex() || '';
- const proposalHash = blake2AsHex(encodedProposal);
- console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
- console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
- console.log('Encoded length %d', encodedProposal.length);
+ const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
+ console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
- const tx1 = api.tx.democracy.notePreimage(encodedProposal);
- const events1 = await submitTransactionAsync(baltatharAccount, tx1);
- const result1 = getGenericResult(events1);
- expect(result1.success).to.be.true;
- console.log('Note motion preimage.......DONE');
- // <<< Note motion preimage <<<
+ // >>> Note motion preimage >>>
+ console.log('Note motion preimage.......');
+ const encodedProposal = batchCall?.method.toHex() || '';
+ const proposalHash = blake2AsHex(encodedProposal);
+ console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
+ console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
+ console.log('Encoded length %d', encodedProposal.length);
- // >>> Propose external motion through council >>>
- console.log('Propose external motion through council.......');
- const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
- const tx2 = api.tx.councilCollective.propose(
- councilVotingThreshold,
- externalMotion,
- externalMotion.encodedLength,
- );
- const events2 = await submitTransactionAsync(baltatharAccount, tx2);
- const result2 = getGenericResult(events2);
- expect(result2.success).to.be.true;
+ const tx1 = api.tx.democracy.notePreimage(encodedProposal);
+ const events1 = await submitTransactionAsync(baltatharAccount, tx1);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
+ console.log('Note motion preimage.......DONE');
+ // <<< Note motion preimage <<<
- const encodedMotion = externalMotion?.method.toHex() || '';
- const motionHash = blake2AsHex(encodedMotion);
- console.log('Motion hash is %s', motionHash);
+ // >>> Propose external motion through council >>>
+ console.log('Propose external motion through council.......');
+ const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
+ const tx2 = api.tx.councilCollective.propose(
+ councilVotingThreshold,
+ externalMotion,
+ externalMotion.encodedLength,
+ );
+ const events2 = await submitTransactionAsync(baltatharAccount, tx2);
+ const result2 = getGenericResult(events2);
+ expect(result2.success).to.be.true;
- const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
- {
- const events3 = await submitTransactionAsync(dorothyAccount, tx3);
- const result3 = getGenericResult(events3);
- expect(result3.success).to.be.true;
- }
- {
- const events3 = await submitTransactionAsync(baltatharAccount, tx3);
- const result3 = getGenericResult(events3);
- expect(result3.success).to.be.true;
- }
+ const encodedMotion = externalMotion?.method.toHex() || '';
+ const motionHash = blake2AsHex(encodedMotion);
+ console.log('Motion hash is %s', motionHash);
- const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
- const events4 = await submitTransactionAsync(dorothyAccount, tx4);
- const result4 = getGenericResult(events4);
- expect(result4.success).to.be.true;
- console.log('Propose external motion through council.......DONE');
- // <<< Propose external motion through council <<<
+ const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
+ {
+ const events3 = await submitTransactionAsync(dorothyAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
+ {
+ const events3 = await submitTransactionAsync(baltatharAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
- // >>> Fast track proposal through technical committee >>>
- console.log('Fast track proposal through technical committee.......');
- const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
- const tx5 = api.tx.techCommitteeCollective.propose(
- technicalCommitteeThreshold,
- fastTrack,
- fastTrack.encodedLength,
- );
- const events5 = await submitTransactionAsync(alithAccount, tx5);
- const result5 = getGenericResult(events5);
- expect(result5.success).to.be.true;
+ const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
+ const events4 = await submitTransactionAsync(dorothyAccount, tx4);
+ const result4 = getGenericResult(events4);
+ expect(result4.success).to.be.true;
+ console.log('Propose external motion through council.......DONE');
+ // <<< Propose external motion through council <<<
- const encodedFastTrack = fastTrack?.method.toHex() || '';
- const fastTrackHash = blake2AsHex(encodedFastTrack);
- console.log('FastTrack hash is %s', fastTrackHash);
+ // >>> Fast track proposal through technical committee >>>
+ console.log('Fast track proposal through technical committee.......');
+ const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
+ const tx5 = api.tx.techCommitteeCollective.propose(
+ technicalCommitteeThreshold,
+ fastTrack,
+ fastTrack.encodedLength,
+ );
+ const events5 = await submitTransactionAsync(alithAccount, tx5);
+ const result5 = getGenericResult(events5);
+ expect(result5.success).to.be.true;
- const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
- const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
- {
- const events6 = await submitTransactionAsync(baltatharAccount, tx6);
- const result6 = getGenericResult(events6);
- expect(result6.success).to.be.true;
- }
- {
- const events6 = await submitTransactionAsync(alithAccount, tx6);
- const result6 = getGenericResult(events6);
- expect(result6.success).to.be.true;
- }
+ const encodedFastTrack = fastTrack?.method.toHex() || '';
+ const fastTrackHash = blake2AsHex(encodedFastTrack);
+ console.log('FastTrack hash is %s', fastTrackHash);
- const tx7 = api.tx.techCommitteeCollective
- .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
- const events7 = await submitTransactionAsync(baltatharAccount, tx7);
- const result7 = getGenericResult(events7);
- expect(result7.success).to.be.true;
- console.log('Fast track proposal through technical committee.......DONE');
- // <<< Fast track proposal through technical committee <<<
+ const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
+ const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
+ {
+ const events6 = await submitTransactionAsync(baltatharAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
+ {
+ const events6 = await submitTransactionAsync(alithAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
- // >>> Referendum voting >>>
- console.log('Referendum voting.......');
- const tx8 = api.tx.democracy.vote(
- 0,
- {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
- );
- const events8 = await submitTransactionAsync(dorothyAccount, tx8);
- const result8 = getGenericResult(events8);
- expect(result8.success).to.be.true;
- console.log('Referendum voting.......DONE');
- // <<< Referendum voting <<<
+ const tx7 = api.tx.techCommitteeCollective
+ .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
+ const events7 = await submitTransactionAsync(baltatharAccount, tx7);
+ const result7 = getGenericResult(events7);
+ expect(result7.success).to.be.true;
+ console.log('Fast track proposal through technical committee.......DONE');
+ // <<< Fast track proposal through technical committee <<<
- // >>> Acquire Quartz AssetId Info on Moonriver >>>
- console.log('Acquire Quartz AssetId Info on Moonriver.......');
+ // >>> Referendum voting >>>
+ console.log('Referendum voting.......');
+ const tx8 = api.tx.democracy.vote(
+ 0,
+ {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
+ );
+ const events8 = await submitTransactionAsync(dorothyAccount, tx8);
+ const result8 = getGenericResult(events8);
+ expect(result8.success).to.be.true;
+ console.log('Referendum voting.......DONE');
+ // <<< Referendum voting <<<
- // Wait for the democracy execute
- await waitNewBlocks(api, 5);
+ // >>> Acquire Quartz AssetId Info on Moonriver >>>
+ console.log('Acquire Quartz AssetId Info on Moonriver.......');
- assetId = (await api.query.assetManager.assetTypeId({
- XCM: sourceLocation,
- })).toString();
+ // Wait for the democracy execute
+ // await waitNewBlocks(api, 5);
+ await helper.wait.newBlocks(5);
- console.log('QTZ asset ID is %s', assetId);
- console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
- // >>> Acquire Quartz AssetId Info on Moonriver >>>
+ assetId = (await api.query.assetManager.assetTypeId({
+ XCM: sourceLocation,
+ })).toString();
- // >>> Sponsoring random Account >>>
- console.log('Sponsoring random Account.......');
- const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
- const events10 = await submitTransactionAsync(baltatharAccount, tx10);
- const result10 = getGenericResult(events10);
- expect(result10.success).to.be.true;
- console.log('Sponsoring random Account.......DONE');
- // <<< Sponsoring random Account <<<
+ console.log('QTZ asset ID is %s', assetId);
+ console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');
+ // >>> Acquire Quartz AssetId Info on Moonriver >>>
- [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
- },
- moonriverOptions(),
- );
+ // >>> Sponsoring random Account >>>
+ console.log('Sponsoring random Account.......');
+ // const tx10 = api.tx.balances.transfer(randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
+ // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
+ // const result10 = getGenericResult(events10);
+ // expect(result10.success).to.be.true;
+ await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);
+ console.log('Sponsoring random Account.......DONE');
+ // <<< Sponsoring random Account <<<
- await usingApi(async (api) => {
- const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
- const events0 = await submitTransactionAsync(quartzAlice, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
+ // [balanceMovrTokenInit] = await getBalance(api, [randomAccountMoonriver.address]);
+ balanceMovrTokenInit = await helper.balance.getSubstrate(randomAccountMoonriver.address);
+ });
- [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
+ await usingPlaygrounds(async (helper) => {
+ // const tx0 = api.tx.balances.transfer(randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
+ // const events0 = await submitTransactionAsync(quartzAlice, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(quartzAlice, randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);
+
+ // [balanceQuartzTokenInit] = await getBalance(api, [randomAccountQuartz.address]);
+ balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);
});
});
- it('Should connect and send QTZ to Moonriver', async () => {
- await usingApi(async (api) => {
- const currencyId = {
- NativeAssetId: 'Here',
- };
- const dest = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: MOONRIVER_CHAIN},
- {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
- ],
- },
+ itSub('Should connect and send QTZ to Moonriver', async ({helper}) => {
+ const currencyId = {
+ NativeAssetId: 'Here',
+ };
+ const dest = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: MOONRIVER_CHAIN},
+ {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},
+ ],
},
- };
- const amount = TRANSFER_AMOUNT;
- const destWeight = 850000000;
+ },
+ };
+ const amount = TRANSFER_AMOUNT;
+ const destWeight = 850000000;
- const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
- const events = await submitTransactionAsync(randomAccountQuartz, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
+ const events = await submitTransactionAsync(randomAccountQuartz, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
- expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
+ // [balanceQuartzTokenMiddle] = await getBalance(api, [randomAccountQuartz.address]);
+ balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);
+ expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
- const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
- expect(transactionFees > 0).to.be.true;
- });
+ const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
+ expect(transactionFees > 0).to.be.true;
- await usingApi(
- async (api) => {
- await waitNewBlocks(api, 3);
+ await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
+ // [balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
+ balanceMovrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonriver.address);
- const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
- console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
- expect(movrFees == 0n).to.be.true;
+ const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
+ console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
+ expect(movrFees == 0n).to.be.true;
- const qtzRandomAccountAsset = (
- await api.query.assets.account(assetId, randomAccountMoonriver.address)
- ).toJSON()! as any;
+ // TODO
+ const qtzRandomAccountAsset = (
+ await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
+ ).toJSON()! as any;
- balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
- const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
- console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
- expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- moonriverOptions(),
- );
+ balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
+ const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
+ console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
+ expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
});
- it('Should connect to Moonriver and send QTZ back', async () => {
- await usingApi(
- async (api) => {
- const asset = {
- V1: {
- id: {
- Concrete: {
- parents: 1,
- interior: {
- X1: {Parachain: QUARTZ_CHAIN},
- },
+ itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {
+ await usingPlaygrounds.atUrl(moonriverUrl, async (helper) => {
+ const asset = {
+ V1: {
+ id: {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {Parachain: QUARTZ_CHAIN},
},
},
- fun: {
- Fungible: TRANSFER_AMOUNT,
- },
},
- };
- const destination = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: QUARTZ_CHAIN},
- {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
- ],
- },
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
+ },
+ };
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: QUARTZ_CHAIN},
+ {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},
+ ],
},
- };
- const destWeight = 50000000;
+ },
+ };
+ const destWeight = 50000000;
- const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);
- const events = await submitTransactionAsync(randomAccountMoonriver, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccountMoonriver, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
+ // [balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
+ balanceMovrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonriver.address);
- const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
- console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
- expect(movrFees > 0).to.be.true;
+ const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
+ console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
+ expect(movrFees > 0).to.be.true;
- const qtzRandomAccountAsset = (
- await api.query.assets.account(assetId, randomAccountMoonriver.address)
- ).toJSON()! as any;
+ const qtzRandomAccountAsset = (
+ await helper.getApi().query.assets.account(assetId, randomAccountMoonriver.address)
+ ).toJSON()! as any;
- expect(qtzRandomAccountAsset).to.be.null;
+ expect(qtzRandomAccountAsset).to.be.null;
- balanceForeignQtzTokenFinal = 0n;
+ balanceForeignQtzTokenFinal = 0n;
- const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
- console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
- expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- moonriverOptions(),
- );
+ const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
+ console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
+ expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
- await usingApi(async (api) => {
- await waitNewBlocks(api, 3);
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
- const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
- expect(actuallyDelivered > 0).to.be.true;
+ // [balanceQuartzTokenFinal] = await getBalance(api, [randomAccountQuartz.address]);
+ balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);
+ const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
- console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
+ console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
- const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
- expect(qtzFees == 0n).to.be.true;
- });
+ const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
+ expect(qtzFees == 0n).to.be.true;
});
});
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -14,23 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-
-import {WsProvider, Keyring} from '@polkadot/api';
-import {ApiOptions} from '@polkadot/api/types';
+import {Keyring} from '@polkadot/api';
import {IKeyringPair} from '@polkadot/types/types';
-import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../deprecated-helpers/helpers';
+import {submitTransactionAsync} from '../substrate/substrate-api';
+import {getGenericResult, generateKeyringPair, waitEvent, bigIntToDecimals} from '../deprecated-helpers/helpers';
import {MultiLocation} from '@polkadot/types/interfaces';
import {blake2AsHex} from '@polkadot/util-crypto';
-import waitNewBlocks from '../substrate/wait-new-blocks';
import getBalance from '../substrate/get-balance';
import {XcmV2TraitsError, XcmV2TraitsOutcome} from '../interfaces';
+import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';
-chai.use(chaiAsPromised);
-const expect = chai.expect;
-
const UNIQUE_CHAIN = 2037;
const ACALA_CHAIN = 2000;
const MOONBEAM_CHAIN = 2004;
@@ -39,29 +32,15 @@
const ACALA_PORT = 9946;
const MOONBEAM_PORT = 9947;
+const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;
+const acalaUrl = 'ws://127.0.0.1:' + ACALA_PORT;
+const moonbeamUrl = 'ws://127.0.0.1:' + MOONBEAM_PORT;
+
const ACALA_DECIMALS = 12;
const TRANSFER_AMOUNT = 2000000000000000000000000n;
-function parachainApiOptions(port: number): ApiOptions {
- return {
- provider: new WsProvider('ws://127.0.0.1:' + port.toString()),
- };
-}
-
-function acalaOptions(): ApiOptions {
- return parachainApiOptions(ACALA_PORT);
-}
-
-function moonbeamOptions(): ApiOptions {
- return parachainApiOptions(MOONBEAM_PORT);
-}
-
-function relayOptions(): ApiOptions {
- return parachainApiOptions(RELAY_PORT);
-}
-
-describe_xcm('[XCM] Integration test: Exchanging tokens with Acala', () => {
+describeXcm('[XCM] Integration test: Exchanging tokens with Acala', () => {
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
@@ -76,233 +55,235 @@
let balanceUniqueForeignTokenFinal: bigint;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingPlaygrounds(async (_helper, privateKey) => {
const keyringSr25519 = new Keyring({type: 'sr25519'});
- alice = privateKeyWrapper('//Alice');
+ alice = privateKey('//Alice');
randomAccount = generateKeyringPair(keyringSr25519);
});
// Acala side
- await usingApi(
- async (api) => {
- const destination = {
- V0: {
- X2: [
- 'Parent',
- {
- Parachain: UNIQUE_CHAIN,
- },
- ],
- },
- };
+ await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: UNIQUE_CHAIN,
+ },
+ ],
+ },
+ };
- const metadata = {
- name: 'UNQ',
- symbol: 'UNQ',
- decimals: 18,
- minimalBalance: 1,
- };
+ const metadata = {
+ name: 'UNQ',
+ symbol: 'UNQ',
+ decimals: 18,
+ minimalBalance: 1,
+ };
- const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
- const sudoTx = api.tx.sudo.sudo(tx as any);
- const events = await submitTransactionAsync(alice, sudoTx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.assetRegistry.registerForeignAsset(destination, metadata);
+ const sudoTx = helper.getApi().tx.sudo.sudo(tx as any);
+ const events = await submitTransactionAsync(alice, sudoTx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
- const events1 = await submitTransactionAsync(alice, tx1);
- const result1 = getGenericResult(events1);
- expect(result1.success).to.be.true;
+ // const tx1 = api.tx.balances.transfer(randomAccount.address, 10000000000000n);
+ // const events1 = await submitTransactionAsync(alice, tx1);
+ // const result1 = getGenericResult(events1);
+ // expect(result1.success).to.be.true;
+ await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);
- [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);
- {
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
- balanceUniqueForeignTokenInit = BigInt(free);
- }
- },
- acalaOptions(),
- );
+ // [balanceAcalaTokenInit] = await getBalance(api, [randomAccount.address]);
+ balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);
+ {
+ // TODO
+ const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceUniqueForeignTokenInit = BigInt(free);
+ }
+ });
// Unique side
- await usingApi(async (api) => {
- const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
- const events0 = await submitTransactionAsync(alice, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
+ await usingPlaygrounds(async (helper) => {
+ // const tx0 = api.tx.balances.transfer(randomAccount.address, 10n * TRANSFER_AMOUNT);
+ // const events0 = await submitTransactionAsync(alice, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);
- [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);
+ // [balanceUniqueTokenInit] = await getBalance(api, [randomAccount.address]);
+ balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccount.address);
});
});
- it('Should connect and send UNQ to Acala', async () => {
+ itSub('Should connect and send UNQ to Acala', async ({helper}) => {
// Unique side
- await usingApi(async (api) => {
+ const destination = {
+ V0: {
+ X2: [
+ 'Parent',
+ {
+ Parachain: ACALA_CHAIN,
+ },
+ ],
+ },
+ };
- const destination = {
- V0: {
- X2: [
- 'Parent',
- {
- Parachain: ACALA_CHAIN,
- },
- ],
+ const beneficiary = {
+ V0: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
},
- };
+ },
+ };
- const beneficiary = {
- V0: {
- X1: {
- AccountId32: {
- network: 'Any',
- id: randomAccount.addressRaw,
+ const assets = {
+ V1: [
+ {
+ id: {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
},
},
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
},
- };
+ ],
+ };
- const assets = {
- V1: [
- {
- id: {
- Concrete: {
- parents: 0,
- interior: 'Here',
- },
- },
- fun: {
- Fungible: TRANSFER_AMOUNT,
- },
- },
- ],
- };
+ const feeAssetItem = 0;
- const feeAssetItem = 0;
-
- const weightLimit = {
- Limited: 5000000000,
- };
+ const weightLimit = {
+ Limited: 5000000000,
+ };
- const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
- const events = await submitTransactionAsync(randomAccount, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
- const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
- expect(unqFees > 0n).to.be.true;
- });
+ const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
+ expect(unqFees > 0n).to.be.true;
// Acala side
- await usingApi(
- async (api) => {
- await waitNewBlocks(api, 3);
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
- balanceUniqueForeignTokenMiddle = BigInt(free);
+ await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ // TODO
+ const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+ balanceUniqueForeignTokenMiddle = BigInt(free);
- const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
- const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;
+ // [balanceAcalaTokenMiddle] = await getBalance(api, [randomAccount.address]);
+ balanceAcalaTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);
- console.log(
- '[Unique -> Acala] transaction fees on Acala: %s ACA',
- bigIntToDecimals(acaFees, ACALA_DECIMALS),
- );
- console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
- expect(acaFees == 0n).to.be.true;
- expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- acalaOptions(),
- );
+ const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
+ const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;
+
+ console.log(
+ '[Unique -> Acala] transaction fees on Acala: %s ACA',
+ bigIntToDecimals(acaFees, ACALA_DECIMALS),
+ );
+ console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
+ expect(acaFees == 0n).to.be.true;
+ expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
});
- it('Should connect to Acala and send UNQ back', async () => {
+ itSub('Should connect to Acala and send UNQ back', async ({helper}) => {
// Acala side
- await usingApi(
- async (api) => {
- const destination = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: UNIQUE_CHAIN},
- {
- AccountId32: {
- network: 'Any',
- id: randomAccount.addressRaw,
- },
+ await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: UNIQUE_CHAIN},
+ {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
},
- ],
- },
+ },
+ ],
},
- };
+ },
+ };
- const id = {
- ForeignAsset: 0,
- };
+ const id = {
+ ForeignAsset: 0,
+ };
- const destWeight = 50000000;
+ const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
- const events = await submitTransactionAsync(randomAccount, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccount, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
- {
- const {free} = (await api.query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
- balanceUniqueForeignTokenFinal = BigInt(free);
- }
+ // [balanceAcalaTokenFinal] = await getBalance(api, [randomAccount.address]);
+ balanceAcalaTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+ {
+ // TODO
+ const {free} = (await helper.getApi().query.tokens.accounts(randomAccount.addressRaw, id)).toJSON() as any;
+ balanceUniqueForeignTokenFinal = BigInt(free);
+ }
- const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;
- const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;
+ const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;
+ const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;
- console.log(
- '[Acala -> Unique] transaction fees on Acala: %s ACA',
- bigIntToDecimals(acaFees, ACALA_DECIMALS),
- );
- console.log('[Acala -> Unique] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
+ console.log(
+ '[Acala -> Unique] transaction fees on Acala: %s ACA',
+ bigIntToDecimals(acaFees, ACALA_DECIMALS),
+ );
+ console.log('[Acala -> Unique] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
- expect(acaFees > 0).to.be.true;
- expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- acalaOptions(),
- );
+ expect(acaFees > 0).to.be.true;
+ expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
- // Unique side
- await usingApi(async (api) => {
- await waitNewBlocks(api, 3);
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
- const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
- expect(actuallyDelivered > 0).to.be.true;
+ // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccount.address]);
+ balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
+ const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
- console.log('[Acala -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
+ console.log('[Acala -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
- const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
- expect(unqFees == 0n).to.be.true;
- });
+ const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
+ expect(unqFees == 0n).to.be.true;
});
});
// These tests are relevant only when the foreign asset pallet is disabled
-describe_xcm('[XCM] Integration test: Unique rejects non-native tokens', () => {
+describeXcm('[XCM] Integration test: Unique rejects non-native tokens', () => {
let alice: IKeyringPair;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
- alice = privateKeyWrapper('//Alice');
+ await usingPlaygrounds(async (_helper, privateKey) => {
+ alice = privateKey('//Alice');
});
});
- it('Unique rejects tokens from the Relay', async () => {
- await usingApi(async (api) => {
+ itSub('Unique rejects tokens from the Relay', async ({helper}) => {
+ await usingPlaygrounds.atUrl(relayUrl, async (helper) => {
const destination = {
V1: {
parents: 0,
@@ -346,44 +327,45 @@
Limited: 5_000_000_000,
};
- const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+ // TODO
+ const tx = helper.getApi().tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- }, relayOptions());
+ });
- await usingApi(async api => {
- const maxWaitBlocks = 3;
- const dmpQueueExecutedDownward = await waitEvent(
- api,
- maxWaitBlocks,
- 'dmpQueue',
- 'ExecutedDownward',
- );
+ const maxWaitBlocks = 3;
- expect(
- dmpQueueExecutedDownward != null,
- '[Relay] dmpQueue.ExecutedDownward event is expected',
- ).to.be.true;
+ // TODO
+ const dmpQueueExecutedDownward = await waitEvent(
+ helper.getApi(),
+ maxWaitBlocks,
+ 'dmpQueue',
+ 'ExecutedDownward',
+ );
- const event = dmpQueueExecutedDownward!.event;
- const outcome = event.data[1] as XcmV2TraitsOutcome;
+ expect(
+ dmpQueueExecutedDownward != null,
+ '[Relay] dmpQueue.ExecutedDownward event is expected',
+ ).to.be.true;
- expect(
- outcome.isIncomplete,
- '[Relay] The outcome of the XCM should be `Incomplete`',
- ).to.be.true;
+ const event = dmpQueueExecutedDownward!.event;
+ const outcome = event.data[1] as XcmV2TraitsOutcome;
+
+ expect(
+ outcome.isIncomplete,
+ '[Relay] The outcome of the XCM should be `Incomplete`',
+ ).to.be.true;
- const incomplete = outcome.asIncomplete;
- expect(
- incomplete[1].toString() == 'AssetNotFound',
- '[Relay] The XCM error should be `AssetNotFound`',
- ).to.be.true;
- });
+ const incomplete = outcome.asIncomplete;
+ expect(
+ incomplete[1].toString() == 'AssetNotFound',
+ '[Relay] The XCM error should be `AssetNotFound`',
+ ).to.be.true;
});
- it('Unique rejects ACA tokens from Acala', async () => {
- await usingApi(async (api) => {
+ itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
+ await usingPlaygrounds.atUrl(acalaUrl, async (helper) => {
const destination = {
V1: {
parents: 1,
@@ -407,33 +389,34 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
- }, acalaOptions());
+ });
- await usingApi(async api => {
- const maxWaitBlocks = 3;
- const xcmpQueueFailEvent = await waitEvent(api, maxWaitBlocks, 'xcmpQueue', 'Fail');
+ const maxWaitBlocks = 3;
- expect(
- xcmpQueueFailEvent != null,
- '[Acala] xcmpQueue.FailEvent event is expected',
- ).to.be.true;
+ // TODO
+ const xcmpQueueFailEvent = await waitEvent(helper.getApi(), maxWaitBlocks, 'xcmpQueue', 'Fail');
- const event = xcmpQueueFailEvent!.event;
- const outcome = event.data[1] as XcmV2TraitsError;
+ expect(
+ xcmpQueueFailEvent != null,
+ '[Acala] xcmpQueue.FailEvent event is expected',
+ ).to.be.true;
+
+ const event = xcmpQueueFailEvent!.event;
+ const outcome = event.data[1] as XcmV2TraitsError;
- expect(
- outcome.isUntrustedReserveLocation,
- '[Acala] The XCM error should be `UntrustedReserveLocation`',
- ).to.be.true;
- });
+ expect(
+ outcome.isUntrustedReserveLocation,
+ '[Acala] The XCM error should be `UntrustedReserveLocation`',
+ ).to.be.true;
});
});
-describe_xcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
+describeXcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
// Unique constants
let uniqueAlice: IKeyringPair;
@@ -478,322 +461,327 @@
let balanceGlmrTokenFinal: bigint;
before(async () => {
- await usingApi(async (api, privateKeyWrapper) => {
+ await usingPlaygrounds(async (_helper, privateKey) => {
const keyringEth = new Keyring({type: 'ethereum'});
const keyringSr25519 = new Keyring({type: 'sr25519'});
- uniqueAlice = privateKeyWrapper('//Alice');
+ uniqueAlice = privateKey('//Alice');
randomAccountUnique = generateKeyringPair(keyringSr25519);
randomAccountMoonbeam = generateKeyringPair(keyringEth);
balanceForeignUnqTokenInit = 0n;
});
- await usingApi(
- async (api) => {
+ await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
+ // TODO
+
+ const api = helper.getApi();
- // >>> Sponsoring Dorothy >>>
- console.log('Sponsoring Dorothy.......');
- const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
- const events0 = await submitTransactionAsync(alithAccount, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
- console.log('Sponsoring Dorothy.......DONE');
- // <<< Sponsoring Dorothy <<<
+ // >>> Sponsoring Dorothy >>>
+ console.log('Sponsoring Dorothy.......');
+ // const tx0 = api.tx.balances.transfer(dorothyAccount.address, 11_000_000_000_000_000_000n);
+ // const events0 = await submitTransactionAsync(alithAccount, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);
+ console.log('Sponsoring Dorothy.......DONE');
+ // <<< Sponsoring Dorothy <<<
- const sourceLocation: MultiLocation = api.createType(
- 'MultiLocation',
- {
- parents: 1,
- interior: {X1: {Parachain: UNIQUE_CHAIN}},
- },
- );
+ const sourceLocation: MultiLocation = api.createType(
+ 'MultiLocation',
+ {
+ parents: 1,
+ interior: {X1: {Parachain: UNIQUE_CHAIN}},
+ },
+ );
- uniqueAssetLocation = {XCM: sourceLocation};
- const existentialDeposit = 1;
- const isSufficient = true;
- const unitsPerSecond = '1';
- const numAssetsWeightHint = 0;
+ uniqueAssetLocation = {XCM: sourceLocation};
+ const existentialDeposit = 1;
+ const isSufficient = true;
+ const unitsPerSecond = '1';
+ const numAssetsWeightHint = 0;
- const registerTx = api.tx.assetManager.registerForeignAsset(
- uniqueAssetLocation,
- uniqueAssetMetadata,
- existentialDeposit,
- isSufficient,
- );
- console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
+ const registerTx = api.tx.assetManager.registerForeignAsset(
+ uniqueAssetLocation,
+ uniqueAssetMetadata,
+ existentialDeposit,
+ isSufficient,
+ );
+ console.log('Encoded proposal for registerAsset is %s', registerTx.method.toHex() || '');
- const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
- uniqueAssetLocation,
- unitsPerSecond,
- numAssetsWeightHint,
- );
- console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
+ const setUnitsTx = api.tx.assetManager.setAssetUnitsPerSecond(
+ uniqueAssetLocation,
+ unitsPerSecond,
+ numAssetsWeightHint,
+ );
+ console.log('Encoded proposal for setAssetUnitsPerSecond is %s', setUnitsTx.method.toHex() || '');
- const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
- console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
+ const batchCall = api.tx.utility.batchAll([registerTx, setUnitsTx]);
+ console.log('Encoded proposal for batchCall is %s', batchCall.method.toHex() || '');
- // >>> Note motion preimage >>>
- console.log('Note motion preimage.......');
- const encodedProposal = batchCall?.method.toHex() || '';
- const proposalHash = blake2AsHex(encodedProposal);
- console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
- console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
- console.log('Encoded length %d', encodedProposal.length);
+ // >>> Note motion preimage >>>
+ console.log('Note motion preimage.......');
+ const encodedProposal = batchCall?.method.toHex() || '';
+ const proposalHash = blake2AsHex(encodedProposal);
+ console.log('Encoded proposal for batch utility after schedule is %s', encodedProposal);
+ console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);
+ console.log('Encoded length %d', encodedProposal.length);
- const tx1 = api.tx.democracy.notePreimage(encodedProposal);
- const events1 = await submitTransactionAsync(baltatharAccount, tx1);
- const result1 = getGenericResult(events1);
- expect(result1.success).to.be.true;
- console.log('Note motion preimage.......DONE');
- // <<< Note motion preimage <<<
+ const tx1 = api.tx.democracy.notePreimage(encodedProposal);
+ const events1 = await submitTransactionAsync(baltatharAccount, tx1);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
+ console.log('Note motion preimage.......DONE');
+ // <<< Note motion preimage <<<
- // >>> Propose external motion through council >>>
- console.log('Propose external motion through council.......');
- const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
- const tx2 = api.tx.councilCollective.propose(
- councilVotingThreshold,
- externalMotion,
- externalMotion.encodedLength,
- );
- const events2 = await submitTransactionAsync(baltatharAccount, tx2);
- const result2 = getGenericResult(events2);
- expect(result2.success).to.be.true;
+ // >>> Propose external motion through council >>>
+ console.log('Propose external motion through council.......');
+ const externalMotion = api.tx.democracy.externalProposeMajority(proposalHash);
+ const tx2 = api.tx.councilCollective.propose(
+ councilVotingThreshold,
+ externalMotion,
+ externalMotion.encodedLength,
+ );
+ const events2 = await submitTransactionAsync(baltatharAccount, tx2);
+ const result2 = getGenericResult(events2);
+ expect(result2.success).to.be.true;
- const encodedMotion = externalMotion?.method.toHex() || '';
- const motionHash = blake2AsHex(encodedMotion);
- console.log('Motion hash is %s', motionHash);
+ const encodedMotion = externalMotion?.method.toHex() || '';
+ const motionHash = blake2AsHex(encodedMotion);
+ console.log('Motion hash is %s', motionHash);
- const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
- {
- const events3 = await submitTransactionAsync(dorothyAccount, tx3);
- const result3 = getGenericResult(events3);
- expect(result3.success).to.be.true;
- }
- {
- const events3 = await submitTransactionAsync(baltatharAccount, tx3);
- const result3 = getGenericResult(events3);
- expect(result3.success).to.be.true;
- }
+ const tx3 = api.tx.councilCollective.vote(motionHash, 0, true);
+ {
+ const events3 = await submitTransactionAsync(dorothyAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
+ {
+ const events3 = await submitTransactionAsync(baltatharAccount, tx3);
+ const result3 = getGenericResult(events3);
+ expect(result3.success).to.be.true;
+ }
- const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
- const events4 = await submitTransactionAsync(dorothyAccount, tx4);
- const result4 = getGenericResult(events4);
- expect(result4.success).to.be.true;
- console.log('Propose external motion through council.......DONE');
- // <<< Propose external motion through council <<<
+ const tx4 = api.tx.councilCollective.close(motionHash, 0, 1_000_000_000, externalMotion.encodedLength);
+ const events4 = await submitTransactionAsync(dorothyAccount, tx4);
+ const result4 = getGenericResult(events4);
+ expect(result4.success).to.be.true;
+ console.log('Propose external motion through council.......DONE');
+ // <<< Propose external motion through council <<<
- // >>> Fast track proposal through technical committee >>>
- console.log('Fast track proposal through technical committee.......');
- const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
- const tx5 = api.tx.techCommitteeCollective.propose(
- technicalCommitteeThreshold,
- fastTrack,
- fastTrack.encodedLength,
- );
- const events5 = await submitTransactionAsync(alithAccount, tx5);
- const result5 = getGenericResult(events5);
- expect(result5.success).to.be.true;
+ // >>> Fast track proposal through technical committee >>>
+ console.log('Fast track proposal through technical committee.......');
+ const fastTrack = api.tx.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);
+ const tx5 = api.tx.techCommitteeCollective.propose(
+ technicalCommitteeThreshold,
+ fastTrack,
+ fastTrack.encodedLength,
+ );
+ const events5 = await submitTransactionAsync(alithAccount, tx5);
+ const result5 = getGenericResult(events5);
+ expect(result5.success).to.be.true;
- const encodedFastTrack = fastTrack?.method.toHex() || '';
- const fastTrackHash = blake2AsHex(encodedFastTrack);
- console.log('FastTrack hash is %s', fastTrackHash);
+ const encodedFastTrack = fastTrack?.method.toHex() || '';
+ const fastTrackHash = blake2AsHex(encodedFastTrack);
+ console.log('FastTrack hash is %s', fastTrackHash);
- const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
- const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
- {
- const events6 = await submitTransactionAsync(baltatharAccount, tx6);
- const result6 = getGenericResult(events6);
- expect(result6.success).to.be.true;
- }
- {
- const events6 = await submitTransactionAsync(alithAccount, tx6);
- const result6 = getGenericResult(events6);
- expect(result6.success).to.be.true;
- }
+ const proposalIdx = Number(await api.query.techCommitteeCollective.proposalCount()) - 1;
+ const tx6 = api.tx.techCommitteeCollective.vote(fastTrackHash, proposalIdx, true);
+ {
+ const events6 = await submitTransactionAsync(baltatharAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
+ {
+ const events6 = await submitTransactionAsync(alithAccount, tx6);
+ const result6 = getGenericResult(events6);
+ expect(result6.success).to.be.true;
+ }
- const tx7 = api.tx.techCommitteeCollective
- .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
- const events7 = await submitTransactionAsync(baltatharAccount, tx7);
- const result7 = getGenericResult(events7);
- expect(result7.success).to.be.true;
- console.log('Fast track proposal through technical committee.......DONE');
- // <<< Fast track proposal through technical committee <<<
+ const tx7 = api.tx.techCommitteeCollective
+ .close(fastTrackHash, proposalIdx, 1_000_000_000, fastTrack.encodedLength);
+ const events7 = await submitTransactionAsync(baltatharAccount, tx7);
+ const result7 = getGenericResult(events7);
+ expect(result7.success).to.be.true;
+ console.log('Fast track proposal through technical committee.......DONE');
+ // <<< Fast track proposal through technical committee <<<
- // >>> Referendum voting >>>
- console.log('Referendum voting.......');
- const tx8 = api.tx.democracy.vote(
- 0,
- {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
- );
- const events8 = await submitTransactionAsync(dorothyAccount, tx8);
- const result8 = getGenericResult(events8);
- expect(result8.success).to.be.true;
- console.log('Referendum voting.......DONE');
- // <<< Referendum voting <<<
+ // >>> Referendum voting >>>
+ console.log('Referendum voting.......');
+ const tx8 = api.tx.democracy.vote(
+ 0,
+ {Standard: {balance: 10_000_000_000_000_000_000n, vote: {aye: true, conviction: 1}}},
+ );
+ const events8 = await submitTransactionAsync(dorothyAccount, tx8);
+ const result8 = getGenericResult(events8);
+ expect(result8.success).to.be.true;
+ console.log('Referendum voting.......DONE');
+ // <<< Referendum voting <<<
- // >>> Acquire Unique AssetId Info on Moonbeam >>>
- console.log('Acquire Unique AssetId Info on Moonbeam.......');
+ // >>> Acquire Unique AssetId Info on Moonbeam >>>
+ console.log('Acquire Unique AssetId Info on Moonbeam.......');
- // Wait for the democracy execute
- await waitNewBlocks(api, 5);
+ // Wait for the democracy execute
+ // await waitNewBlocks(api, 5);
+ await helper.wait.newBlocks(5);
- assetId = (await api.query.assetManager.assetTypeId({
- XCM: sourceLocation,
- })).toString();
+ assetId = (await api.query.assetManager.assetTypeId({
+ XCM: sourceLocation,
+ })).toString();
- console.log('UNQ asset ID is %s', assetId);
- console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');
- // >>> Acquire Unique AssetId Info on Moonbeam >>>
+ console.log('UNQ asset ID is %s', assetId);
+ console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');
+ // >>> Acquire Unique AssetId Info on Moonbeam >>>
- // >>> Sponsoring random Account >>>
- console.log('Sponsoring random Account.......');
- const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
- const events10 = await submitTransactionAsync(baltatharAccount, tx10);
- const result10 = getGenericResult(events10);
- expect(result10.success).to.be.true;
- console.log('Sponsoring random Account.......DONE');
- // <<< Sponsoring random Account <<<
+ // >>> Sponsoring random Account >>>
+ console.log('Sponsoring random Account.......');
+ // const tx10 = api.tx.balances.transfer(randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
+ // const events10 = await submitTransactionAsync(baltatharAccount, tx10);
+ // const result10 = getGenericResult(events10);
+ // expect(result10.success).to.be.true;
+ await helper.balance.transferToSubstrate(baltatharAccount, randomAccountMoonbeam.address, 11_000_000_000_000_000_000n);
+ console.log('Sponsoring random Account.......DONE');
+ // <<< Sponsoring random Account <<<
- [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);
- },
- moonbeamOptions(),
- );
+ [balanceGlmrTokenInit] = await getBalance(api, [randomAccountMoonbeam.address]);
+ });
- await usingApi(async (api) => {
- const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
- const events0 = await submitTransactionAsync(uniqueAlice, tx0);
- const result0 = getGenericResult(events0);
- expect(result0.success).to.be.true;
+ await usingPlaygrounds(async (helper) => {
+ // const tx0 = api.tx.balances.transfer(randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
+ // const events0 = await submitTransactionAsync(uniqueAlice, tx0);
+ // const result0 = getGenericResult(events0);
+ // expect(result0.success).to.be.true;
+ await helper.balance.transferToSubstrate(uniqueAlice, randomAccountUnique.address, 10n * TRANSFER_AMOUNT);
- [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);
+ // [balanceUniqueTokenInit] = await getBalance(api, [randomAccountUnique.address]);
+ balanceUniqueTokenInit = await helper.balance.getSubstrate(randomAccountUnique.address);
});
});
- it('Should connect and send UNQ to Moonbeam', async () => {
- await usingApi(async (api) => {
- const currencyId = {
- NativeAssetId: 'Here',
- };
- const dest = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: MOONBEAM_CHAIN},
- {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},
- ],
- },
+ itSub('Should connect and send UNQ to Moonbeam', async ({helper}) => {
+ const currencyId = {
+ NativeAssetId: 'Here',
+ };
+ const dest = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: MOONBEAM_CHAIN},
+ {AccountKey20: {network: 'Any', key: randomAccountMoonbeam.address}},
+ ],
},
- };
- const amount = TRANSFER_AMOUNT;
- const destWeight = 850000000;
+ },
+ };
+ const amount = TRANSFER_AMOUNT;
+ const destWeight = 850000000;
- const tx = api.tx.xTokens.transfer(currencyId, amount, dest, destWeight);
- const events = await submitTransactionAsync(randomAccountUnique, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transfer(currencyId, amount, dest, destWeight);
+ const events = await submitTransactionAsync(randomAccountUnique, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);
- expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
+ // [balanceUniqueTokenMiddle] = await getBalance(api, [randomAccountUnique.address]);
+ balanceUniqueTokenMiddle = await helper.balance.getSubstrate(randomAccountUnique.address);
+ expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
- const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));
- expect(transactionFees > 0).to.be.true;
- });
+ const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
+ console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));
+ expect(transactionFees > 0).to.be.true;
- await usingApi(
- async (api) => {
- await waitNewBlocks(api, 3);
+ await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);
+ // [balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);
+ balanceGlmrTokenMiddle = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
- const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;
- console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
- expect(glmrFees == 0n).to.be.true;
+ const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;
+ console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
+ expect(glmrFees == 0n).to.be.true;
- const unqRandomAccountAsset = (
- await api.query.assets.account(assetId, randomAccountMoonbeam.address)
- ).toJSON()! as any;
+ // TODO
+ const unqRandomAccountAsset = (
+ await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
+ ).toJSON()! as any;
- balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);
- const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;
- console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
- expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- moonbeamOptions(),
- );
+ balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);
+ const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;
+ console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
+ expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
});
- it('Should connect to Moonbeam and send UNQ back', async () => {
- await usingApi(
- async (api) => {
- const asset = {
- V1: {
- id: {
- Concrete: {
- parents: 1,
- interior: {
- X1: {Parachain: UNIQUE_CHAIN},
- },
+ itSub('Should connect to Moonbeam and send UNQ back', async ({helper}) => {
+ await usingPlaygrounds.atUrl(moonbeamUrl, async (helper) => {
+ const asset = {
+ V1: {
+ id: {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {Parachain: UNIQUE_CHAIN},
},
},
- fun: {
- Fungible: TRANSFER_AMOUNT,
- },
},
- };
- const destination = {
- V1: {
- parents: 1,
- interior: {
- X2: [
- {Parachain: UNIQUE_CHAIN},
- {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},
- ],
- },
+ fun: {
+ Fungible: TRANSFER_AMOUNT,
+ },
+ },
+ };
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [
+ {Parachain: UNIQUE_CHAIN},
+ {AccountId32: {network: 'Any', id: randomAccountUnique.addressRaw}},
+ ],
},
- };
- const destWeight = 50000000;
+ },
+ };
+ const destWeight = 50000000;
- const tx = api.tx.xTokens.transferMultiasset(asset, destination, destWeight);
- const events = await submitTransactionAsync(randomAccountMoonbeam, tx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
+ // TODO
+ const tx = helper.getApi().tx.xTokens.transferMultiasset(asset, destination, destWeight);
+ const events = await submitTransactionAsync(randomAccountMoonbeam, tx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
- [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
+ // [balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
+ balanceGlmrTokenFinal = await helper.balance.getSubstrate(randomAccountMoonbeam.address);
- const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;
- console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
- expect(glmrFees > 0).to.be.true;
+ const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;
+ console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
+ expect(glmrFees > 0).to.be.true;
- const unqRandomAccountAsset = (
- await api.query.assets.account(assetId, randomAccountMoonbeam.address)
- ).toJSON()! as any;
+ // TODO
+ const unqRandomAccountAsset = (
+ await helper.getApi().query.assets.account(assetId, randomAccountMoonbeam.address)
+ ).toJSON()! as any;
- expect(unqRandomAccountAsset).to.be.null;
+ expect(unqRandomAccountAsset).to.be.null;
- balanceForeignUnqTokenFinal = 0n;
+ balanceForeignUnqTokenFinal = 0n;
- const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;
- console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
- expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
- },
- moonbeamOptions(),
- );
+ const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;
+ console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
+ expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
+ });
- await usingApi(async (api) => {
- await waitNewBlocks(api, 3);
+ // await waitNewBlocks(api, 3);
+ await helper.wait.newBlocks(3);
- [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
- const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
- expect(actuallyDelivered > 0).to.be.true;
+ // [balanceUniqueTokenFinal] = await getBalance(api, [randomAccountUnique.address]);
+ balanceUniqueTokenFinal = await helper.balance.getSubstrate(randomAccountUnique.address);
+ const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
+ expect(actuallyDelivered > 0).to.be.true;
- console.log('[Moonbeam -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
+ console.log('[Moonbeam -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
- const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
- expect(unqFees == 0n).to.be.true;
- });
+ const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
+ console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
+ expect(unqFees == 0n).to.be.true;
});
});