difftreelog
fix yarn fix
in: master
4 files changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -442,13 +442,13 @@
Fungible: amount,
},
},
- weightLimit: 'Unlimited'
+ weightLimit: 'Unlimited',
},
},
{
DepositAsset: {
assets: {
- Wild: 'All'
+ Wild: 'All',
},
maxAssets: 1,
beneficiary: {
@@ -457,7 +457,7 @@
X1: {
AccountId32: {
network: 'Any',
- id: beneficiary
+ id: beneficiary,
},
},
},
@@ -489,13 +489,13 @@
Fungible: amount,
},
},
- weightLimit: 'Unlimited'
+ weightLimit: 'Unlimited',
},
},
{
DepositAsset: {
assets: {
- Wild: 'All'
+ Wild: 'All',
},
maxAssets: 1,
beneficiary: {
@@ -504,7 +504,7 @@
X1: {
AccountId32: {
network: 'Any',
- id: beneficiary
+ id: beneficiary,
},
},
},
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -3031,7 +3031,7 @@
message,
],
true,
- );
+ );
}
}
tests/src/xcm/xcmQuartz.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 {IKeyringPair} from '@polkadot/types/types';18import {blake2AsHex} from '@polkadot/util-crypto';19import config from '../config';20import {XcmV2TraitsError} from '../interfaces';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';22import {DevUniqueHelper} from '../util/playgrounds/unique.dev';2324const QUARTZ_CHAIN = 2095;25const STATEMINE_CHAIN = 1000;26const KARURA_CHAIN = 2000;27const MOONRIVER_CHAIN = 2023;28const SHIDEN_CHAIN = 2007;2930const STATEMINE_PALLET_INSTANCE = 50;3132const relayUrl = config.relayUrl;33const statemineUrl = config.statemineUrl;34const karuraUrl = config.karuraUrl;35const moonriverUrl = config.moonriverUrl;36const shidenUrl = config.shidenUrl;3738const RELAY_DECIMALS = 12;39const STATEMINE_DECIMALS = 12;40const KARURA_DECIMALS = 12;41const SHIDEN_DECIMALS = 18n;42const QTZ_DECIMALS = 18n;4344const TRANSFER_AMOUNT = 2000000000000000000000000n;4546const FUNDING_AMOUNT = 3_500_000_0000_000_000n;4748const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;4950const USDT_ASSET_ID = 100;51const USDT_ASSET_METADATA_DECIMALS = 18;52const USDT_ASSET_METADATA_NAME = 'USDT';53const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';54const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;55const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;5657const SAFE_XCM_VERSION = 2;5859describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {60 let alice: IKeyringPair;61 let bob: IKeyringPair;6263 let balanceStmnBefore: bigint;64 let balanceStmnAfter: bigint;6566 let balanceQuartzBefore: bigint;67 let balanceQuartzAfter: bigint;68 let balanceQuartzFinal: bigint;6970 let balanceBobBefore: bigint;71 let balanceBobAfter: bigint;72 let balanceBobFinal: bigint;7374 let balanceBobRelayTokenBefore: bigint;75 let balanceBobRelayTokenAfter: bigint;767778 before(async () => {79 await usingPlaygrounds(async (helper, privateKey) => {80 alice = await privateKey('//Alice');81 bob = await privateKey('//Bob'); // sovereign account on Statemine(t) funds donor8283 // Set the default version to wrap the first message to other chains.84 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);85 });8687 await usingRelayPlaygrounds(relayUrl, async (helper) => {88 // Fund accounts on Statemine(t)89 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, alice.addressRaw, FUNDING_AMOUNT);90 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, bob.addressRaw, FUNDING_AMOUNT);91 });9293 await usingStateminePlaygrounds(statemineUrl, async (helper) => {94 const sovereignFundingAmount = 3_500_000_000n;9596 await helper.assets.create(97 alice,98 USDT_ASSET_ID,99 alice.address,100 USDT_ASSET_METADATA_MINIMAL_BALANCE,101 );102 await helper.assets.setMetadata(103 alice,104 USDT_ASSET_ID,105 USDT_ASSET_METADATA_NAME,106 USDT_ASSET_METADATA_DESCRIPTION,107 USDT_ASSET_METADATA_DECIMALS,108 );109 await helper.assets.mint(110 alice,111 USDT_ASSET_ID,112 alice.address,113 USDT_ASSET_AMOUNT,114 );115116 // funding parachain sovereing account on Statemine(t).117 // The sovereign account should be created before any action118 // (the assets pallet on Statemine(t) check if the sovereign account exists)119 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(QUARTZ_CHAIN);120 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, sovereignFundingAmount);121 });122123124 await usingPlaygrounds(async (helper) => {125 const location = {126 V2: {127 parents: 1,128 interior: {X3: [129 {130 Parachain: STATEMINE_CHAIN,131 },132 {133 PalletInstance: STATEMINE_PALLET_INSTANCE,134 },135 {136 GeneralIndex: USDT_ASSET_ID,137 },138 ]},139 },140 };141142 const metadata =143 {144 name: USDT_ASSET_ID,145 symbol: USDT_ASSET_METADATA_NAME,146 decimals: USDT_ASSET_METADATA_DECIMALS,147 minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE,148 };149 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);150 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);151 });152153154 // Providing the relay currency to the quartz sender account155 // (fee for USDT XCM are paid in relay tokens)156 await usingRelayPlaygrounds(relayUrl, async (helper) => {157 const destination = {158 V2: {159 parents: 0,160 interior: {X1: {161 Parachain: QUARTZ_CHAIN,162 },163 },164 }};165166 const beneficiary = {167 V2: {168 parents: 0,169 interior: {X1: {170 AccountId32: {171 network: 'Any',172 id: alice.addressRaw,173 },174 }},175 },176 };177178 const assets = {179 V2: [180 {181 id: {182 Concrete: {183 parents: 0,184 interior: 'Here',185 },186 },187 fun: {188 Fungible: TRANSFER_AMOUNT_RELAY,189 },190 },191 ],192 };193194 const feeAssetItem = 0;195196 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, 'Unlimited');197 });198199 });200201 itSub('Should connect and send USDT from Statemine to Quartz', async ({helper}) => {202 await usingStateminePlaygrounds(statemineUrl, async (helper) => {203 const dest = {204 V2: {205 parents: 1,206 interior: {X1: {207 Parachain: QUARTZ_CHAIN,208 },209 },210 }};211212 const beneficiary = {213 V2: {214 parents: 0,215 interior: {X1: {216 AccountId32: {217 network: 'Any',218 id: alice.addressRaw,219 },220 }},221 },222 };223224 const assets = {225 V2: [226 {227 id: {228 Concrete: {229 parents: 0,230 interior: {231 X2: [232 {233 PalletInstance: STATEMINE_PALLET_INSTANCE,234 },235 {236 GeneralIndex: USDT_ASSET_ID,237 },238 ]},239 },240 },241 fun: {242 Fungible: TRANSFER_AMOUNT,243 },244 },245 ],246 };247248 const feeAssetItem = 0;249250 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);251 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, 'Unlimited');252253 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);254255 // common good parachain take commission in it native token256 console.log(257 '[Statemine -> Quartz] transaction fees on Statemine: %s WND',258 helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, STATEMINE_DECIMALS),259 );260 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;261262 });263264265 // ensure that asset has been delivered266 await helper.wait.newBlocks(3);267268 // expext collection id will be with id 1269 const free = await helper.ft.getBalance(1, {Substrate: alice.address});270271 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);272273 console.log(274 '[Statemine -> Quartz] transaction fees on Quartz: %s USDT',275 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, USDT_ASSET_METADATA_DECIMALS),276 );277 console.log(278 '[Statemine -> Quartz] transaction fees on Quartz: %s QTZ',279 helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzBefore),280 );281 // commission has not paid in USDT token282 expect(free).to.be.equal(TRANSFER_AMOUNT);283 // ... and parachain native token284 expect(balanceQuartzAfter == balanceQuartzBefore).to.be.true;285 });286287 itSub('Should connect and send USDT from Quartz to Statemine back', async ({helper}) => {288 const destination = {289 V2: {290 parents: 1,291 interior: {X2: [292 {293 Parachain: STATEMINE_CHAIN,294 },295 {296 AccountId32: {297 network: 'Any',298 id: alice.addressRaw,299 },300 },301 ]},302 },303 };304305 const relayFee = 400_000_000_000_000n;306 const currencies: [any, bigint][] = [307 [308 {309 ForeignAssetId: 0,310 },311 TRANSFER_AMOUNT,312 ],313 [314 {315 NativeAssetId: 'Parent',316 },317 relayFee,318 ],319 ];320321 const feeItem = 1;322323 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, 'Unlimited');324325 // the commission has been paid in parachain native token326 balanceQuartzFinal = await helper.balance.getSubstrate(alice.address);327 console.log('[Quartz -> Statemine] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzFinal));328 expect(balanceQuartzAfter > balanceQuartzFinal).to.be.true;329330 await usingStateminePlaygrounds(statemineUrl, async (helper) => {331 await helper.wait.newBlocks(3);332333 // The USDT token never paid fees. Its amount not changed from begin value.334 // Also check that xcm transfer has been succeeded335 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == USDT_ASSET_AMOUNT).to.be.true;336 });337 });338339 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {340 balanceBobBefore = await helper.balance.getSubstrate(bob.address);341 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});342343 await usingRelayPlaygrounds(relayUrl, async (helper) => {344 const destination = {345 V2: {346 parents: 0,347 interior: {X1: {348 Parachain: QUARTZ_CHAIN,349 },350 },351 }};352353 const beneficiary = {354 V2: {355 parents: 0,356 interior: {X1: {357 AccountId32: {358 network: 'Any',359 id: bob.addressRaw,360 },361 }},362 },363 };364365 const assets = {366 V2: [367 {368 id: {369 Concrete: {370 parents: 0,371 interior: 'Here',372 },373 },374 fun: {375 Fungible: TRANSFER_AMOUNT_RELAY,376 },377 },378 ],379 };380381 const feeAssetItem = 0;382383 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, 'Unlimited');384 });385386 await helper.wait.newBlocks(3);387388 balanceBobAfter = await helper.balance.getSubstrate(bob.address);389 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});390391 const wndFeeOnQuartz = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;392 const wndDiffOnQuartz = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;393 console.log(394 '[Relay (Westend) -> Quartz] transaction fees: %s QTZ',395 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),396 );397 console.log(398 '[Relay (Westend) -> Quartz] transaction fees: %s WND',399 helper.util.bigIntToDecimals(wndFeeOnQuartz, STATEMINE_DECIMALS),400 );401 console.log('[Relay (Westend) -> Quartz] actually delivered: %s WND', wndDiffOnQuartz);402 expect(wndFeeOnQuartz == 0n, 'No incoming WND fees should be taken').to.be.true;403 expect(balanceBobBefore == balanceBobAfter, 'No incoming QTZ fees should be taken').to.be.true;404 });405406 itSub('Should connect and send Relay token back', async ({helper}) => {407 let relayTokenBalanceBefore: bigint;408 let relayTokenBalanceAfter: bigint;409 await usingRelayPlaygrounds(relayUrl, async (helper) => {410 relayTokenBalanceBefore = await helper.balance.getSubstrate(bob.address);411 });412413 const destination = {414 V2: {415 parents: 1,416 interior: {417 X1:{418 AccountId32: {419 network: 'Any',420 id: bob.addressRaw,421 },422 },423 },424 },425 };426427 const currencies: any = [428 [429 {430 NativeAssetId: 'Parent',431 },432 TRANSFER_AMOUNT_RELAY,433 ],434 ];435436 const feeItem = 0;437438 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, 'Unlimited');439440 balanceBobFinal = await helper.balance.getSubstrate(bob.address);441 console.log('[Quartz -> Relay (Westend)] transaction fees: %s QTZ', helper.util.bigIntToDecimals(balanceBobAfter - balanceBobFinal));442443 await usingRelayPlaygrounds(relayUrl, async (helper) => {444 await helper.wait.newBlocks(10);445 relayTokenBalanceAfter = await helper.balance.getSubstrate(bob.address);446447 const diff = relayTokenBalanceAfter - relayTokenBalanceBefore;448 console.log('[Quartz -> Relay (Westend)] actually delivered: %s WND', helper.util.bigIntToDecimals(diff, RELAY_DECIMALS));449 expect(diff > 0, 'Relay tokens was not delivered back').to.be.true;450 });451 });452});453454describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {455 let alice: IKeyringPair;456 let randomAccount: IKeyringPair;457458 let balanceQuartzTokenInit: bigint;459 let balanceQuartzTokenMiddle: bigint;460 let balanceQuartzTokenFinal: bigint;461 let balanceKaruraTokenInit: bigint;462 let balanceKaruraTokenMiddle: bigint;463 let balanceKaruraTokenFinal: bigint;464 let balanceQuartzForeignTokenInit: bigint;465 let balanceQuartzForeignTokenMiddle: bigint;466 let balanceQuartzForeignTokenFinal: bigint;467468 // computed by a test transfer from prod Quartz to prod Karura.469 // 2 QTZ sent https://quartz.subscan.io/xcm_message/kusama-f60d821b049f8835a3005ce7102285006f5b61e9470 // 1.919176000000000000 QTZ received (you can check Karura's chain state in the corresponding block)471 const expectedKaruraIncomeFee = 2000000000000000000n - 1919176000000000000n;472473 const KARURA_BACKWARD_TRANSFER_AMOUNT = TRANSFER_AMOUNT - expectedKaruraIncomeFee;474475 before(async () => {476 await usingPlaygrounds(async (helper, privateKey) => {477 alice = await privateKey('//Alice');478 [randomAccount] = await helper.arrange.createAccounts([0n], alice);479480 // Set the default version to wrap the first message to other chains.481 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);482 });483484 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {485 const destination = {486 V1: {487 parents: 1,488 interior: {489 X1: {490 Parachain: QUARTZ_CHAIN,491 },492 },493 },494 };495496 const metadata = {497 name: 'Quartz',498 symbol: 'QTZ',499 decimals: 18,500 minimalBalance: 1000000000000000000n,501 };502503 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);504 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);505 balanceKaruraTokenInit = await helper.balance.getSubstrate(randomAccount.address);506 balanceQuartzForeignTokenInit = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});507 });508509 await usingPlaygrounds(async (helper) => {510 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);511 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);512 });513 });514515 itSub('Should connect and send QTZ to Karura', async ({helper}) => {516 const destination = {517 V2: {518 parents: 1,519 interior: {520 X1: {521 Parachain: KARURA_CHAIN,522 },523 },524 },525 };526527 const beneficiary = {528 V2: {529 parents: 0,530 interior: {531 X1: {532 AccountId32: {533 network: 'Any',534 id: randomAccount.addressRaw,535 },536 },537 },538 },539 };540541 const assets = {542 V2: [543 {544 id: {545 Concrete: {546 parents: 0,547 interior: 'Here',548 },549 },550 fun: {551 Fungible: TRANSFER_AMOUNT,552 },553 },554 ],555 };556557 const feeAssetItem = 0;558559 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');560 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);561562 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;563 expect(qtzFees > 0n, 'Negative fees QTZ, looks like nothing was transferred').to.be.true;564 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));565566 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {567 await helper.wait.newBlocks(3);568569 balanceQuartzForeignTokenMiddle = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});570 balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);571572 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;573 const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;574 const karUnqFees = TRANSFER_AMOUNT - qtzIncomeTransfer;575576 console.log(577 '[Quartz -> Karura] transaction fees on Karura: %s KAR',578 helper.util.bigIntToDecimals(karFees, KARURA_DECIMALS),579 );580 console.log(581 '[Quartz -> Karura] transaction fees on Karura: %s QTZ',582 helper.util.bigIntToDecimals(karUnqFees),583 );584 console.log('[Quartz -> Karura] income %s QTZ', helper.util.bigIntToDecimals(qtzIncomeTransfer));585 expect(karFees == 0n).to.be.true;586 expect(587 karUnqFees == expectedKaruraIncomeFee,588 'Karura took different income fee, check the Karura foreign asset config',589 ).to.be.true;590 });591 });592593 itSub('Should connect to Karura and send QTZ back', async ({helper}) => {594 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {595 const destination = {596 V1: {597 parents: 1,598 interior: {599 X2: [600 {Parachain: QUARTZ_CHAIN},601 {602 AccountId32: {603 network: 'Any',604 id: randomAccount.addressRaw,605 },606 },607 ],608 },609 },610 };611612 const id = {613 ForeignAsset: 0,614 };615616 await helper.xTokens.transfer(randomAccount, id, KARURA_BACKWARD_TRANSFER_AMOUNT, destination, 'Unlimited');617 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);618 balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);619620 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;621 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;622623 console.log(624 '[Karura -> Quartz] transaction fees on Karura: %s KAR',625 helper.util.bigIntToDecimals(karFees, KARURA_DECIMALS),626 );627 console.log('[Karura -> Quartz] outcome %s QTZ', helper.util.bigIntToDecimals(qtzOutcomeTransfer));628629 expect(karFees > 0, 'Negative fees KAR, looks like nothing was transferred').to.be.true;630 expect(qtzOutcomeTransfer == KARURA_BACKWARD_TRANSFER_AMOUNT).to.be.true;631 });632633 await helper.wait.newBlocks(3);634635 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);636 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;637 expect(actuallyDelivered > 0).to.be.true;638639 console.log('[Karura -> Quartz] actually delivered %s QTZ', helper.util.bigIntToDecimals(actuallyDelivered));640641 const qtzFees = KARURA_BACKWARD_TRANSFER_AMOUNT - actuallyDelivered;642 console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));643 expect(qtzFees == 0n).to.be.true;644 });645646 itSub('Karura can send only up to its balance', async ({helper}) => {647 // set Karura's sovereign account's balance648 const karuraBalance = 10000n * (10n ** QTZ_DECIMALS);649 const karuraSovereignAccount = helper.address.paraSiblingSovereignAccount(KARURA_CHAIN);650 await helper.getSudo().balance.setBalanceSubstrate(alice, karuraSovereignAccount, karuraBalance);651652 const moreThanKaruraHas = karuraBalance * 2n;653654 let targetAccountBalance = 0n;655 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);656657 const quartzMultilocation = {658 V1: {659 parents: 1,660 interior: {661 X1: {Parachain: QUARTZ_CHAIN},662 },663 },664 };665666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(667 targetAccount.addressRaw,668 {669 Concrete: {670 parents: 0,671 interior: 'Here',672 },673 },674 moreThanKaruraHas,675 );676677 // Try to trick Quartz678 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {679 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);680 });681682 const maxWaitBlocks = 3;683684 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(685 maxWaitBlocks,686 'xcmpQueue',687 'Fail',688 );689690 expect(691 xcmpQueueFailEvent != null,692 `'xcmpQueue.FailEvent' event is expected`,693 ).to.be.true;694695 expect(696 xcmpQueueFailEvent!.isFailedToTransactAsset,697 `The XCM error should be 'FailedToTransactAsset'`,698 ).to.be.true;699700 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);701 expect(targetAccountBalance).to.be.equal(0n);702703 // But Karura still can send the correct amount704 const validTransferAmount = karuraBalance / 2n;705 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(706 targetAccount.addressRaw,707 {708 Concrete: {709 parents: 0,710 interior: 'Here',711 },712 },713 validTransferAmount,714 );715716 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {717 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);718 });719720 await helper.wait.newBlocks(maxWaitBlocks);721722 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);723 expect(targetAccountBalance).to.be.equal(validTransferAmount);724 });725726 itSub('Should not accept reserve transfer of QTZ from Karura', async ({helper}) => {727 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);728 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);729730 const quartzMultilocation = {731 V1: {732 parents: 1,733 interior: {734 X1: {735 Parachain: QUARTZ_CHAIN,736 },737 },738 },739 };740741 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(742 targetAccount.addressRaw,743 {744 Concrete: {745 parents: 1,746 interior: {747 X1: {748 Parachain: QUARTZ_CHAIN,749 },750 },751 },752 },753 testAmount,754 );755756 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {757 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);758 });759760 const maxWaitBlocks = 3;761762 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(763 maxWaitBlocks,764 'xcmpQueue',765 'Fail',766 );767768 expect(769 xcmpQueueFailEvent != null,770 `'xcmpQueue.FailEvent' event is expected`,771 ).to.be.true;772773 expect(774 xcmpQueueFailEvent!.isUntrustedReserveLocation,775 `The XCM error should be 'isUntrustedReserveLocation'`,776 ).to.be.true;777778 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);779 expect(accountBalance).to.be.equal(0n);780 });781});782783// These tests are relevant only when784// the the corresponding foreign assets are not registered785describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {786 let alice: IKeyringPair;787 let alith: IKeyringPair;788789 const testAmount = 100_000_000_000n;790 let quartzParachainJunction;791 let quartzAccountJunction;792793 let quartzParachainMultilocation: any;794 let quartzAccountMultilocation: any;795 let quartzCombinedMultilocation: any;796797 before(async () => {798 await usingPlaygrounds(async (helper, privateKey) => {799 alice = await privateKey('//Alice');800801 quartzParachainJunction = {Parachain: QUARTZ_CHAIN};802 quartzAccountJunction = {803 AccountId32: {804 network: 'Any',805 id: alice.addressRaw,806 },807 };808809 quartzParachainMultilocation = {810 V1: {811 parents: 1,812 interior: {813 X1: quartzParachainJunction,814 },815 },816 };817818 quartzAccountMultilocation = {819 V1: {820 parents: 0,821 interior: {822 X1: quartzAccountJunction,823 },824 },825 };826827 quartzCombinedMultilocation = {828 V1: {829 parents: 1,830 interior: {831 X2: [quartzParachainJunction, quartzAccountJunction],832 },833 },834 };835836 // Set the default version to wrap the first message to other chains.837 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);838 });839840 // eslint-disable-next-line require-await841 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {842 alith = helper.account.alithAccount();843 });844 });845846 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {847 const maxWaitBlocks = 3;848849 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(850 maxWaitBlocks,851 'xcmpQueue',852 'Fail',853 );854855 expect(856 xcmpQueueFailEvent != null,857 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,858 ).to.be.true;859860 expect(861 xcmpQueueFailEvent!.isFailedToTransactAsset,862 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,863 ).to.be.true;864 };865866 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {867 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {868 const id = {869 Token: 'KAR',870 };871 const destination = quartzCombinedMultilocation;872 await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');873 });874875 await expectFailedToTransact('KAR', helper);876 });877878 itSub('Quartz rejects MOVR tokens from Moonriver', async ({helper}) => {879 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {880 const id = 'SelfReserve';881 const destination = quartzCombinedMultilocation;882 await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');883 });884885 await expectFailedToTransact('MOVR', helper);886 });887888 itSub('Quartz rejects SDN tokens from Shiden', async ({helper}) => {889 await usingShidenPlaygrounds(shidenUrl, async (helper) => {890 const destinationParachain = quartzParachainMultilocation;891 const beneficiary = quartzAccountMultilocation;892 const assets = {893 V1: [{894 id: {895 Concrete: {896 parents: 0,897 interior: 'Here',898 },899 },900 fun: {901 Fungible: testAmount,902 },903 }],904 };905 const feeAssetItem = 0;906907 await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [908 destinationParachain,909 beneficiary,910 assets,911 feeAssetItem,912 ]);913 });914915 await expectFailedToTransact('SDN', helper);916 });917});918919describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {920 // Quartz constants921 let quartzDonor: IKeyringPair;922 let quartzAssetLocation;923924 let randomAccountQuartz: IKeyringPair;925 let randomAccountMoonriver: IKeyringPair;926927 // Moonriver constants928 let assetId: string;929930 const councilVotingThreshold = 2;931 const technicalCommitteeThreshold = 2;932 const votingPeriod = 3;933 const delayPeriod = 0;934935 const quartzAssetMetadata = {936 name: 'xcQuartz',937 symbol: 'xcQTZ',938 decimals: 18,939 isFrozen: false,940 minimalBalance: 1n,941 };942943 let balanceQuartzTokenInit: bigint;944 let balanceQuartzTokenMiddle: bigint;945 let balanceQuartzTokenFinal: bigint;946 let balanceForeignQtzTokenInit: bigint;947 let balanceForeignQtzTokenMiddle: bigint;948 let balanceForeignQtzTokenFinal: bigint;949 let balanceMovrTokenInit: bigint;950 let balanceMovrTokenMiddle: bigint;951 let balanceMovrTokenFinal: bigint;952953 before(async () => {954 await usingPlaygrounds(async (helper, privateKey) => {955 quartzDonor = await privateKey('//Alice');956 [randomAccountQuartz] = await helper.arrange.createAccounts([0n], quartzDonor);957958 balanceForeignQtzTokenInit = 0n;959960 // Set the default version to wrap the first message to other chains.961 const alice = quartzDonor;962 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);963 });964965 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {966 const alithAccount = helper.account.alithAccount();967 const baltatharAccount = helper.account.baltatharAccount();968 const dorothyAccount = helper.account.dorothyAccount();969970 randomAccountMoonriver = helper.account.create();971972 // >>> Sponsoring Dorothy >>>973 console.log('Sponsoring Dorothy.......');974 await helper.balance.transferToEthereum(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);975 console.log('Sponsoring Dorothy.......DONE');976 // <<< Sponsoring Dorothy <<<977978 quartzAssetLocation = {979 XCM: {980 parents: 1,981 interior: {X1: {Parachain: QUARTZ_CHAIN}},982 },983 };984 const existentialDeposit = 1n;985 const isSufficient = true;986 const unitsPerSecond = 1n;987 const numAssetsWeightHint = 0;988989 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({990 location: quartzAssetLocation,991 metadata: quartzAssetMetadata,992 existentialDeposit,993 isSufficient,994 unitsPerSecond,995 numAssetsWeightHint,996 });997 const proposalHash = blake2AsHex(encodedProposal);998999 console.log('Encoded proposal for registerForeignAsset & setAssetUnitsPerSecond is %s', encodedProposal);1000 console.log('Encoded length %d', encodedProposal.length);1001 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);10021003 // >>> Note motion preimage >>>1004 console.log('Note motion preimage.......');1005 await helper.democracy.notePreimage(baltatharAccount, encodedProposal);1006 console.log('Note motion preimage.......DONE');1007 // <<< Note motion preimage <<<10081009 // >>> Propose external motion through council >>>1010 console.log('Propose external motion through council.......');1011 const externalMotion = helper.democracy.externalProposeMajority({Legacy: proposalHash});1012 const encodedMotion = externalMotion?.method.toHex() || '';1013 const motionHash = blake2AsHex(encodedMotion);1014 console.log('Motion hash is %s', motionHash);10151016 await helper.collective.council.propose(baltatharAccount, councilVotingThreshold, externalMotion, externalMotion.encodedLength);10171018 const councilProposalIdx = await helper.collective.council.proposalCount() - 1;1019 await helper.collective.council.vote(dorothyAccount, motionHash, councilProposalIdx, true);1020 await helper.collective.council.vote(baltatharAccount, motionHash, councilProposalIdx, true);10211022 await helper.collective.council.close(1023 dorothyAccount,1024 motionHash,1025 councilProposalIdx,1026 {1027 refTime: 1_000_000_000,1028 proofSize: 1_000_000,1029 },1030 externalMotion.encodedLength,1031 );1032 console.log('Propose external motion through council.......DONE');1033 // <<< Propose external motion through council <<<10341035 // >>> Fast track proposal through technical committee >>>1036 console.log('Fast track proposal through technical committee.......');1037 const fastTrack = helper.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);1038 const encodedFastTrack = fastTrack?.method.toHex() || '';1039 const fastTrackHash = blake2AsHex(encodedFastTrack);1040 console.log('FastTrack hash is %s', fastTrackHash);10411042 await helper.collective.techCommittee.propose(alithAccount, technicalCommitteeThreshold, fastTrack, fastTrack.encodedLength);10431044 const techProposalIdx = await helper.collective.techCommittee.proposalCount() - 1;1045 await helper.collective.techCommittee.vote(baltatharAccount, fastTrackHash, techProposalIdx, true);1046 await helper.collective.techCommittee.vote(alithAccount, fastTrackHash, techProposalIdx, true);10471048 await helper.collective.techCommittee.close(1049 baltatharAccount,1050 fastTrackHash,1051 techProposalIdx,1052 {1053 refTime: 1_000_000_000,1054 proofSize: 1_000_000,1055 },1056 fastTrack.encodedLength,1057 );1058 console.log('Fast track proposal through technical committee.......DONE');1059 // <<< Fast track proposal through technical committee <<<10601061 // >>> Referendum voting >>>1062 console.log('Referendum voting.......');1063 await helper.democracy.referendumVote(dorothyAccount, 0, {1064 balance: 10_000_000_000_000_000_000n,1065 vote: {aye: true, conviction: 1},1066 });1067 console.log('Referendum voting.......DONE');1068 // <<< Referendum voting <<<10691070 // >>> Acquire Quartz AssetId Info on Moonriver >>>1071 console.log('Acquire Quartz AssetId Info on Moonriver.......');10721073 // Wait for the democracy execute1074 await helper.wait.newBlocks(5);10751076 assetId = (await helper.assetManager.assetTypeId(quartzAssetLocation)).toString();10771078 console.log('QTZ asset ID is %s', assetId);1079 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');1080 // >>> Acquire Quartz AssetId Info on Moonriver >>>10811082 // >>> Sponsoring random Account >>>1083 console.log('Sponsoring random Account.......');1084 await helper.balance.transferToEthereum(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);1085 console.log('Sponsoring random Account.......DONE');1086 // <<< Sponsoring random Account <<<10871088 balanceMovrTokenInit = await helper.balance.getEthereum(randomAccountMoonriver.address);1089 });10901091 await usingPlaygrounds(async (helper) => {1092 await helper.balance.transferToSubstrate(quartzDonor, randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);1093 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);1094 });1095 });10961097 itSub('Should connect and send QTZ to Moonriver', async ({helper}) => {1098 const currencyId = {1099 NativeAssetId: 'Here',1100 };1101 const dest = {1102 V2: {1103 parents: 1,1104 interior: {1105 X2: [1106 {Parachain: MOONRIVER_CHAIN},1107 {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},1108 ],1109 },1110 },1111 };1112 const amount = TRANSFER_AMOUNT;11131114 await helper.xTokens.transfer(randomAccountQuartz, currencyId, amount, dest, 'Unlimited');11151116 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);1117 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;11181119 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;1120 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(transactionFees));1121 expect(transactionFees > 0, 'Negative fees QTZ, looks like nothing was transferred').to.be.true;11221123 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {1124 await helper.wait.newBlocks(3);11251126 balanceMovrTokenMiddle = await helper.balance.getEthereum(randomAccountMoonriver.address);11271128 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;1129 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',helper.util.bigIntToDecimals(movrFees));1130 expect(movrFees == 0n).to.be.true;11311132 balanceForeignQtzTokenMiddle = (await helper.assets.account(assetId, randomAccountMoonriver.address))!; // BigInt(qtzRandomAccountAsset['balance']);1133 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;1134 console.log('[Quartz -> Moonriver] income %s QTZ', helper.util.bigIntToDecimals(qtzIncomeTransfer));1135 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;1136 });1137 });11381139 itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {1140 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {1141 const asset = {1142 V1: {1143 id: {1144 Concrete: {1145 parents: 1,1146 interior: {1147 X1: {Parachain: QUARTZ_CHAIN},1148 },1149 },1150 },1151 fun: {1152 Fungible: TRANSFER_AMOUNT,1153 },1154 },1155 };1156 const destination = {1157 V1: {1158 parents: 1,1159 interior: {1160 X2: [1161 {Parachain: QUARTZ_CHAIN},1162 {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},1163 ],1164 },1165 },1166 };11671168 await helper.xTokens.transferMultiasset(randomAccountMoonriver, asset, destination, 'Unlimited');11691170 balanceMovrTokenFinal = await helper.balance.getEthereum(randomAccountMoonriver.address);11711172 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;1173 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', helper.util.bigIntToDecimals(movrFees));1174 expect(movrFees > 0, 'Negative fees MOVR, looks like nothing was transferred').to.be.true;11751176 const qtzRandomAccountAsset = await helper.assets.account(assetId, randomAccountMoonriver.address);11771178 expect(qtzRandomAccountAsset).to.be.null;11791180 balanceForeignQtzTokenFinal = 0n;11811182 const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;1183 console.log('[Quartz -> Moonriver] outcome %s QTZ', helper.util.bigIntToDecimals(qtzOutcomeTransfer));1184 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;1185 });11861187 await helper.wait.newBlocks(3);11881189 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);1190 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;1191 expect(actuallyDelivered > 0).to.be.true;11921193 console.log('[Moonriver -> Quartz] actually delivered %s QTZ', helper.util.bigIntToDecimals(actuallyDelivered));11941195 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;1196 console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));1197 expect(qtzFees == 0n).to.be.true;1198 });11991200 itSub.skip('Moonriver can send only up to its balance', async ({helper}) => {1201 throw Error("Not yet implemented");1202 });12031204 itSub.skip('Should not accept reserve transfer of QTZ from Moonriver', async ({helper}) => {1205 throw Error("Not yet implemented");1206 });1207});12081209describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1210 let alice: IKeyringPair;1211 let sender: IKeyringPair;12121213 const QTZ_ASSET_ID_ON_SHIDEN = 1;1214 const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;12151216 // Quartz -> Shiden1217 const shidenInitialBalance = 1n * (10n ** SHIDEN_DECIMALS); // 1 SHD, existential deposit required to actually create the account on Shiden1218 const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?1219 const qtzToShidenTransferred = 10n * (10n ** QTZ_DECIMALS); // 10 QTZ1220 const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens12211222 // Shiden -> Quartz1223 const qtzFromShidenTransfered = 5n * (10n ** QTZ_DECIMALS); // 5 QTZ1224 const qtzOnShidenLeft = qtzToShidenArrived - qtzFromShidenTransfered; // 4.999_999_999_088_000_000n QTZ12251226 let balanceAfterQuartzToShidenXCM: bigint;12271228 before(async () => {1229 await usingPlaygrounds(async (helper, privateKey) => {1230 alice = await privateKey('//Alice');1231 [sender] = await helper.arrange.createAccounts([100n], alice);1232 console.log('sender', sender.address);12331234 // Set the default version to wrap the first message to other chains.1235 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);1236 });12371238 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1239 console.log('1. Create foreign asset and metadata');1240 // TODO update metadata with values from production1241 await helper.assets.create(1242 alice,1243 QTZ_ASSET_ID_ON_SHIDEN,1244 alice.address,1245 QTZ_MINIMAL_BALANCE_ON_SHIDEN,1246 );12471248 await helper.assets.setMetadata(1249 alice,1250 QTZ_ASSET_ID_ON_SHIDEN,1251 'Cross chain QTZ',1252 'xcQTZ',1253 Number(QTZ_DECIMALS),1254 );12551256 console.log('2. Register asset location on Shiden');1257 const assetLocation = {1258 V1: {1259 parents: 1,1260 interior: {1261 X1: {1262 Parachain: QUARTZ_CHAIN,1263 },1264 },1265 },1266 };12671268 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, QTZ_ASSET_ID_ON_SHIDEN]);12691270 console.log('3. Set QTZ payment for XCM execution on Shiden');1271 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);12721273 console.log('4. Transfer 1 SDN to recipient to create the account (needed due to existential balance)');1274 await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);1275 });1276 });12771278 itSub('Should connect and send QTZ to Shiden', async ({helper}) => {1279 const destination = {1280 V2: {1281 parents: 1,1282 interior: {1283 X1: {1284 Parachain: SHIDEN_CHAIN,1285 },1286 },1287 },1288 };12891290 const beneficiary = {1291 V2: {1292 parents: 0,1293 interior: {1294 X1: {1295 AccountId32: {1296 network: 'Any',1297 id: sender.addressRaw,1298 },1299 },1300 },1301 },1302 };13031304 const assets = {1305 V2: [1306 {1307 id: {1308 Concrete: {1309 parents: 0,1310 interior: 'Here',1311 },1312 },1313 fun: {1314 Fungible: qtzToShidenTransferred,1315 },1316 },1317 ],1318 };13191320 // Initial balance is 100 QTZ1321 const balanceBefore = await helper.balance.getSubstrate(sender.address);1322 console.log(`Initial balance is: ${balanceBefore}`);13231324 const feeAssetItem = 0;1325 await helper.xcm.limitedReserveTransferAssets(sender, destination, beneficiary, assets, feeAssetItem, 'Unlimited');13261327 // Balance after reserve transfer is less than 901328 balanceAfterQuartzToShidenXCM = await helper.balance.getSubstrate(sender.address);1329 console.log(`QTZ Balance on Quartz after XCM is: ${balanceAfterQuartzToShidenXCM}`);1330 console.log(`Quartz's QTZ commission is: ${balanceBefore-balanceAfterQuartzToShidenXCM}`);1331 expect(balanceBefore - balanceAfterQuartzToShidenXCM > 0).to.be.true;13321333 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1334 await helper.wait.newBlocks(3);1335 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);1336 const shidenBalance = await helper.balance.getSubstrate(sender.address);13371338 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);1339 console.log(`Shiden's QTZ commission is: ${qtzToShidenTransferred-xcQTZbalance!}`);13401341 expect(xcQTZbalance).to.eq(qtzToShidenArrived);1342 // SHD balance does not changed:1343 expect(shidenBalance).to.eq(shidenInitialBalance);1344 });1345 });13461347 itSub('Should connect to Shiden and send QTZ back', async ({helper}) => {1348 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1349 const destination = {1350 V1: {1351 parents: 1,1352 interior: {1353 X1: {1354 Parachain: QUARTZ_CHAIN,1355 },1356 },1357 },1358 };13591360 const beneficiary = {1361 V1: {1362 parents: 0,1363 interior: {1364 X1: {1365 AccountId32: {1366 network: 'Any',1367 id: sender.addressRaw,1368 },1369 },1370 },1371 },1372 };13731374 const assets = {1375 V1: [1376 {1377 id: {1378 Concrete: {1379 parents: 1,1380 interior: {1381 X1: {1382 Parachain: QUARTZ_CHAIN,1383 },1384 },1385 },1386 },1387 fun: {1388 Fungible: qtzFromShidenTransfered,1389 },1390 },1391 ],1392 };13931394 // Initial balance is 1 SDN1395 const balanceSDNbefore = await helper.balance.getSubstrate(sender.address);1396 console.log(`SDN balance is: ${balanceSDNbefore}, it does not changed`);1397 expect(balanceSDNbefore).to.eq(shidenInitialBalance);13981399 const feeAssetItem = 0;1400 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw1401 await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);14021403 // Balance after reserve transfer is less than 1 SDN1404 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);1405 const balanceSDN = await helper.balance.getSubstrate(sender.address);1406 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);14071408 // Assert: xcQTZ balance correctly decreased1409 expect(xcQTZbalance).to.eq(qtzOnShidenLeft);1410 // Assert: SDN balance is 0.996...1411 expect(balanceSDN / (10n ** (SHIDEN_DECIMALS - 3n))).to.eq(996n);1412 });14131414 await helper.wait.newBlocks(3);1415 const balanceQTZ = await helper.balance.getSubstrate(sender.address);1416 console.log(`QTZ Balance on Quartz after XCM is: ${balanceQTZ}`);1417 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);1418 });14191420 itSub('Shiden can send only up to its balance', async ({helper}) => {1421 // set Shiden's sovereign account's balance1422 const shidenBalance = 10000n * (10n ** QTZ_DECIMALS);1423 const shidenSovereignAccount = helper.address.paraSiblingSovereignAccount(SHIDEN_CHAIN);1424 await helper.getSudo().balance.setBalanceSubstrate(alice, shidenSovereignAccount, shidenBalance);14251426 const moreThanShidenHas = shidenBalance * 2n;14271428 let targetAccountBalance = 0n;1429 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);14301431 const quartzMultilocation = {1432 V1: {1433 parents: 1,1434 interior: {1435 X1: {Parachain: QUARTZ_CHAIN},1436 },1437 },1438 };14391440 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1441 targetAccount.addressRaw,1442 {1443 Concrete: {1444 parents: 0,1445 interior: 'Here',1446 },1447 },1448 moreThanShidenHas,1449 );14501451 // Try to trick Quartz1452 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1453 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1454 });14551456 const maxWaitBlocks = 3;14571458 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1459 maxWaitBlocks,1460 'xcmpQueue',1461 'Fail',1462 );14631464 expect(1465 xcmpQueueFailEvent != null,1466 `'xcmpQueue.FailEvent' event is expected`,1467 ).to.be.true;14681469 expect(1470 xcmpQueueFailEvent!.isFailedToTransactAsset,1471 `The XCM error should be 'FailedToTransactAsset'`,1472 ).to.be.true;14731474 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1475 expect(targetAccountBalance).to.be.equal(0n);14761477 // But Shiden still can send the correct amount1478 const validTransferAmount = shidenBalance / 2n;1479 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1480 targetAccount.addressRaw,1481 {1482 Concrete: {1483 parents: 0,1484 interior: 'Here',1485 },1486 },1487 validTransferAmount,1488 );14891490 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1491 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);1492 });14931494 await helper.wait.newBlocks(maxWaitBlocks);14951496 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1497 expect(targetAccountBalance).to.be.equal(validTransferAmount);1498 });14991500 itSub('Should not accept reserve transfer of QTZ from Shiden', async ({helper}) => {1501 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);1502 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);15031504 const quartzMultilocation = {1505 V1: {1506 parents: 1,1507 interior: {1508 X1: {1509 Parachain: QUARTZ_CHAIN,1510 },1511 },1512 },1513 };15141515 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(1516 targetAccount.addressRaw,1517 {1518 Concrete: {1519 parents: 1,1520 interior: {1521 X1: {1522 Parachain: QUARTZ_CHAIN,1523 },1524 },1525 },1526 },1527 testAmount,1528 );15291530 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1531 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1532 });15331534 const maxWaitBlocks = 3;15351536 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1537 maxWaitBlocks,1538 'xcmpQueue',1539 'Fail',1540 );15411542 expect(1543 xcmpQueueFailEvent != null,1544 `'xcmpQueue.FailEvent' event is expected`,1545 ).to.be.true;15461547 expect(1548 xcmpQueueFailEvent!.isUntrustedReserveLocation,1549 `The XCM error should be 'isUntrustedReserveLocation'`,1550 ).to.be.true;15511552 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);1553 expect(accountBalance).to.be.equal(0n);1554 });1555});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 {blake2AsHex} from '@polkadot/util-crypto';19import config from '../config';20import {XcmV2TraitsError} from '../interfaces';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';22import {DevUniqueHelper} from '../util/playgrounds/unique.dev';2324const QUARTZ_CHAIN = 2095;25const STATEMINE_CHAIN = 1000;26const KARURA_CHAIN = 2000;27const MOONRIVER_CHAIN = 2023;28const SHIDEN_CHAIN = 2007;2930const STATEMINE_PALLET_INSTANCE = 50;3132const relayUrl = config.relayUrl;33const statemineUrl = config.statemineUrl;34const karuraUrl = config.karuraUrl;35const moonriverUrl = config.moonriverUrl;36const shidenUrl = config.shidenUrl;3738const RELAY_DECIMALS = 12;39const STATEMINE_DECIMALS = 12;40const KARURA_DECIMALS = 12;41const SHIDEN_DECIMALS = 18n;42const QTZ_DECIMALS = 18n;4344const TRANSFER_AMOUNT = 2000000000000000000000000n;4546const FUNDING_AMOUNT = 3_500_000_0000_000_000n;4748const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;4950const USDT_ASSET_ID = 100;51const USDT_ASSET_METADATA_DECIMALS = 18;52const USDT_ASSET_METADATA_NAME = 'USDT';53const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';54const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;55const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;5657const SAFE_XCM_VERSION = 2;5859describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {60 let alice: IKeyringPair;61 let bob: IKeyringPair;6263 let balanceStmnBefore: bigint;64 let balanceStmnAfter: bigint;6566 let balanceQuartzBefore: bigint;67 let balanceQuartzAfter: bigint;68 let balanceQuartzFinal: bigint;6970 let balanceBobBefore: bigint;71 let balanceBobAfter: bigint;72 let balanceBobFinal: bigint;7374 let balanceBobRelayTokenBefore: bigint;75 let balanceBobRelayTokenAfter: bigint;767778 before(async () => {79 await usingPlaygrounds(async (helper, privateKey) => {80 alice = await privateKey('//Alice');81 bob = await privateKey('//Bob'); // sovereign account on Statemine(t) funds donor8283 // Set the default version to wrap the first message to other chains.84 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);85 });8687 await usingRelayPlaygrounds(relayUrl, async (helper) => {88 // Fund accounts on Statemine(t)89 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, alice.addressRaw, FUNDING_AMOUNT);90 await helper.xcm.teleportNativeAsset(alice, STATEMINE_CHAIN, bob.addressRaw, FUNDING_AMOUNT);91 });9293 await usingStateminePlaygrounds(statemineUrl, async (helper) => {94 const sovereignFundingAmount = 3_500_000_000n;9596 await helper.assets.create(97 alice,98 USDT_ASSET_ID,99 alice.address,100 USDT_ASSET_METADATA_MINIMAL_BALANCE,101 );102 await helper.assets.setMetadata(103 alice,104 USDT_ASSET_ID,105 USDT_ASSET_METADATA_NAME,106 USDT_ASSET_METADATA_DESCRIPTION,107 USDT_ASSET_METADATA_DECIMALS,108 );109 await helper.assets.mint(110 alice,111 USDT_ASSET_ID,112 alice.address,113 USDT_ASSET_AMOUNT,114 );115116 // funding parachain sovereing account on Statemine(t).117 // The sovereign account should be created before any action118 // (the assets pallet on Statemine(t) check if the sovereign account exists)119 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(QUARTZ_CHAIN);120 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, sovereignFundingAmount);121 });122123124 await usingPlaygrounds(async (helper) => {125 const location = {126 V2: {127 parents: 1,128 interior: {X3: [129 {130 Parachain: STATEMINE_CHAIN,131 },132 {133 PalletInstance: STATEMINE_PALLET_INSTANCE,134 },135 {136 GeneralIndex: USDT_ASSET_ID,137 },138 ]},139 },140 };141142 const metadata =143 {144 name: USDT_ASSET_ID,145 symbol: USDT_ASSET_METADATA_NAME,146 decimals: USDT_ASSET_METADATA_DECIMALS,147 minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE,148 };149 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);150 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);151 });152153154 // Providing the relay currency to the quartz sender account155 // (fee for USDT XCM are paid in relay tokens)156 await usingRelayPlaygrounds(relayUrl, async (helper) => {157 const destination = {158 V2: {159 parents: 0,160 interior: {X1: {161 Parachain: QUARTZ_CHAIN,162 },163 },164 }};165166 const beneficiary = {167 V2: {168 parents: 0,169 interior: {X1: {170 AccountId32: {171 network: 'Any',172 id: alice.addressRaw,173 },174 }},175 },176 };177178 const assets = {179 V2: [180 {181 id: {182 Concrete: {183 parents: 0,184 interior: 'Here',185 },186 },187 fun: {188 Fungible: TRANSFER_AMOUNT_RELAY,189 },190 },191 ],192 };193194 const feeAssetItem = 0;195196 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, 'Unlimited');197 });198199 });200201 itSub('Should connect and send USDT from Statemine to Quartz', async ({helper}) => {202 await usingStateminePlaygrounds(statemineUrl, async (helper) => {203 const dest = {204 V2: {205 parents: 1,206 interior: {X1: {207 Parachain: QUARTZ_CHAIN,208 },209 },210 }};211212 const beneficiary = {213 V2: {214 parents: 0,215 interior: {X1: {216 AccountId32: {217 network: 'Any',218 id: alice.addressRaw,219 },220 }},221 },222 };223224 const assets = {225 V2: [226 {227 id: {228 Concrete: {229 parents: 0,230 interior: {231 X2: [232 {233 PalletInstance: STATEMINE_PALLET_INSTANCE,234 },235 {236 GeneralIndex: USDT_ASSET_ID,237 },238 ]},239 },240 },241 fun: {242 Fungible: TRANSFER_AMOUNT,243 },244 },245 ],246 };247248 const feeAssetItem = 0;249250 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);251 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, 'Unlimited');252253 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);254255 // common good parachain take commission in it native token256 console.log(257 '[Statemine -> Quartz] transaction fees on Statemine: %s WND',258 helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, STATEMINE_DECIMALS),259 );260 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;261262 });263264265 // ensure that asset has been delivered266 await helper.wait.newBlocks(3);267268 // expext collection id will be with id 1269 const free = await helper.ft.getBalance(1, {Substrate: alice.address});270271 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);272273 console.log(274 '[Statemine -> Quartz] transaction fees on Quartz: %s USDT',275 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, USDT_ASSET_METADATA_DECIMALS),276 );277 console.log(278 '[Statemine -> Quartz] transaction fees on Quartz: %s QTZ',279 helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzBefore),280 );281 // commission has not paid in USDT token282 expect(free).to.be.equal(TRANSFER_AMOUNT);283 // ... and parachain native token284 expect(balanceQuartzAfter == balanceQuartzBefore).to.be.true;285 });286287 itSub('Should connect and send USDT from Quartz to Statemine back', async ({helper}) => {288 const destination = {289 V2: {290 parents: 1,291 interior: {X2: [292 {293 Parachain: STATEMINE_CHAIN,294 },295 {296 AccountId32: {297 network: 'Any',298 id: alice.addressRaw,299 },300 },301 ]},302 },303 };304305 const relayFee = 400_000_000_000_000n;306 const currencies: [any, bigint][] = [307 [308 {309 ForeignAssetId: 0,310 },311 TRANSFER_AMOUNT,312 ],313 [314 {315 NativeAssetId: 'Parent',316 },317 relayFee,318 ],319 ];320321 const feeItem = 1;322323 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, 'Unlimited');324325 // the commission has been paid in parachain native token326 balanceQuartzFinal = await helper.balance.getSubstrate(alice.address);327 console.log('[Quartz -> Statemine] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzFinal));328 expect(balanceQuartzAfter > balanceQuartzFinal).to.be.true;329330 await usingStateminePlaygrounds(statemineUrl, async (helper) => {331 await helper.wait.newBlocks(3);332333 // The USDT token never paid fees. Its amount not changed from begin value.334 // Also check that xcm transfer has been succeeded335 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == USDT_ASSET_AMOUNT).to.be.true;336 });337 });338339 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {340 balanceBobBefore = await helper.balance.getSubstrate(bob.address);341 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});342343 await usingRelayPlaygrounds(relayUrl, async (helper) => {344 const destination = {345 V2: {346 parents: 0,347 interior: {X1: {348 Parachain: QUARTZ_CHAIN,349 },350 },351 }};352353 const beneficiary = {354 V2: {355 parents: 0,356 interior: {X1: {357 AccountId32: {358 network: 'Any',359 id: bob.addressRaw,360 },361 }},362 },363 };364365 const assets = {366 V2: [367 {368 id: {369 Concrete: {370 parents: 0,371 interior: 'Here',372 },373 },374 fun: {375 Fungible: TRANSFER_AMOUNT_RELAY,376 },377 },378 ],379 };380381 const feeAssetItem = 0;382383 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, 'Unlimited');384 });385386 await helper.wait.newBlocks(3);387388 balanceBobAfter = await helper.balance.getSubstrate(bob.address);389 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});390391 const wndFeeOnQuartz = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;392 const wndDiffOnQuartz = balanceBobRelayTokenAfter - balanceBobRelayTokenBefore;393 console.log(394 '[Relay (Westend) -> Quartz] transaction fees: %s QTZ',395 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),396 );397 console.log(398 '[Relay (Westend) -> Quartz] transaction fees: %s WND',399 helper.util.bigIntToDecimals(wndFeeOnQuartz, STATEMINE_DECIMALS),400 );401 console.log('[Relay (Westend) -> Quartz] actually delivered: %s WND', wndDiffOnQuartz);402 expect(wndFeeOnQuartz == 0n, 'No incoming WND fees should be taken').to.be.true;403 expect(balanceBobBefore == balanceBobAfter, 'No incoming QTZ fees should be taken').to.be.true;404 });405406 itSub('Should connect and send Relay token back', async ({helper}) => {407 let relayTokenBalanceBefore: bigint;408 let relayTokenBalanceAfter: bigint;409 await usingRelayPlaygrounds(relayUrl, async (helper) => {410 relayTokenBalanceBefore = await helper.balance.getSubstrate(bob.address);411 });412413 const destination = {414 V2: {415 parents: 1,416 interior: {417 X1:{418 AccountId32: {419 network: 'Any',420 id: bob.addressRaw,421 },422 },423 },424 },425 };426427 const currencies: any = [428 [429 {430 NativeAssetId: 'Parent',431 },432 TRANSFER_AMOUNT_RELAY,433 ],434 ];435436 const feeItem = 0;437438 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, 'Unlimited');439440 balanceBobFinal = await helper.balance.getSubstrate(bob.address);441 console.log('[Quartz -> Relay (Westend)] transaction fees: %s QTZ', helper.util.bigIntToDecimals(balanceBobAfter - balanceBobFinal));442443 await usingRelayPlaygrounds(relayUrl, async (helper) => {444 await helper.wait.newBlocks(10);445 relayTokenBalanceAfter = await helper.balance.getSubstrate(bob.address);446447 const diff = relayTokenBalanceAfter - relayTokenBalanceBefore;448 console.log('[Quartz -> Relay (Westend)] actually delivered: %s WND', helper.util.bigIntToDecimals(diff, RELAY_DECIMALS));449 expect(diff > 0, 'Relay tokens was not delivered back').to.be.true;450 });451 });452});453454describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {455 let alice: IKeyringPair;456 let randomAccount: IKeyringPair;457458 let balanceQuartzTokenInit: bigint;459 let balanceQuartzTokenMiddle: bigint;460 let balanceQuartzTokenFinal: bigint;461 let balanceKaruraTokenInit: bigint;462 let balanceKaruraTokenMiddle: bigint;463 let balanceKaruraTokenFinal: bigint;464 let balanceQuartzForeignTokenInit: bigint;465 let balanceQuartzForeignTokenMiddle: bigint;466 let balanceQuartzForeignTokenFinal: bigint;467468 // computed by a test transfer from prod Quartz to prod Karura.469 // 2 QTZ sent https://quartz.subscan.io/xcm_message/kusama-f60d821b049f8835a3005ce7102285006f5b61e9470 // 1.919176000000000000 QTZ received (you can check Karura's chain state in the corresponding block)471 const expectedKaruraIncomeFee = 2000000000000000000n - 1919176000000000000n;472473 const KARURA_BACKWARD_TRANSFER_AMOUNT = TRANSFER_AMOUNT - expectedKaruraIncomeFee;474475 before(async () => {476 await usingPlaygrounds(async (helper, privateKey) => {477 alice = await privateKey('//Alice');478 [randomAccount] = await helper.arrange.createAccounts([0n], alice);479480 // Set the default version to wrap the first message to other chains.481 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);482 });483484 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {485 const destination = {486 V1: {487 parents: 1,488 interior: {489 X1: {490 Parachain: QUARTZ_CHAIN,491 },492 },493 },494 };495496 const metadata = {497 name: 'Quartz',498 symbol: 'QTZ',499 decimals: 18,500 minimalBalance: 1000000000000000000n,501 };502503 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);504 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);505 balanceKaruraTokenInit = await helper.balance.getSubstrate(randomAccount.address);506 balanceQuartzForeignTokenInit = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});507 });508509 await usingPlaygrounds(async (helper) => {510 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10n * TRANSFER_AMOUNT);511 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccount.address);512 });513 });514515 itSub('Should connect and send QTZ to Karura', async ({helper}) => {516 const destination = {517 V2: {518 parents: 1,519 interior: {520 X1: {521 Parachain: KARURA_CHAIN,522 },523 },524 },525 };526527 const beneficiary = {528 V2: {529 parents: 0,530 interior: {531 X1: {532 AccountId32: {533 network: 'Any',534 id: randomAccount.addressRaw,535 },536 },537 },538 },539 };540541 const assets = {542 V2: [543 {544 id: {545 Concrete: {546 parents: 0,547 interior: 'Here',548 },549 },550 fun: {551 Fungible: TRANSFER_AMOUNT,552 },553 },554 ],555 };556557 const feeAssetItem = 0;558559 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');560 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);561562 const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;563 expect(qtzFees > 0n, 'Negative fees QTZ, looks like nothing was transferred').to.be.true;564 console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));565566 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {567 await helper.wait.newBlocks(3);568569 balanceQuartzForeignTokenMiddle = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});570 balanceKaruraTokenMiddle = await helper.balance.getSubstrate(randomAccount.address);571572 const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;573 const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;574 const karUnqFees = TRANSFER_AMOUNT - qtzIncomeTransfer;575576 console.log(577 '[Quartz -> Karura] transaction fees on Karura: %s KAR',578 helper.util.bigIntToDecimals(karFees, KARURA_DECIMALS),579 );580 console.log(581 '[Quartz -> Karura] transaction fees on Karura: %s QTZ',582 helper.util.bigIntToDecimals(karUnqFees),583 );584 console.log('[Quartz -> Karura] income %s QTZ', helper.util.bigIntToDecimals(qtzIncomeTransfer));585 expect(karFees == 0n).to.be.true;586 expect(587 karUnqFees == expectedKaruraIncomeFee,588 'Karura took different income fee, check the Karura foreign asset config',589 ).to.be.true;590 });591 });592593 itSub('Should connect to Karura and send QTZ back', async ({helper}) => {594 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {595 const destination = {596 V1: {597 parents: 1,598 interior: {599 X2: [600 {Parachain: QUARTZ_CHAIN},601 {602 AccountId32: {603 network: 'Any',604 id: randomAccount.addressRaw,605 },606 },607 ],608 },609 },610 };611612 const id = {613 ForeignAsset: 0,614 };615616 await helper.xTokens.transfer(randomAccount, id, KARURA_BACKWARD_TRANSFER_AMOUNT, destination, 'Unlimited');617 balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);618 balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);619620 const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;621 const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;622623 console.log(624 '[Karura -> Quartz] transaction fees on Karura: %s KAR',625 helper.util.bigIntToDecimals(karFees, KARURA_DECIMALS),626 );627 console.log('[Karura -> Quartz] outcome %s QTZ', helper.util.bigIntToDecimals(qtzOutcomeTransfer));628629 expect(karFees > 0, 'Negative fees KAR, looks like nothing was transferred').to.be.true;630 expect(qtzOutcomeTransfer == KARURA_BACKWARD_TRANSFER_AMOUNT).to.be.true;631 });632633 await helper.wait.newBlocks(3);634635 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccount.address);636 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;637 expect(actuallyDelivered > 0).to.be.true;638639 console.log('[Karura -> Quartz] actually delivered %s QTZ', helper.util.bigIntToDecimals(actuallyDelivered));640641 const qtzFees = KARURA_BACKWARD_TRANSFER_AMOUNT - actuallyDelivered;642 console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));643 expect(qtzFees == 0n).to.be.true;644 });645646 itSub('Karura can send only up to its balance', async ({helper}) => {647 // set Karura's sovereign account's balance648 const karuraBalance = 10000n * (10n ** QTZ_DECIMALS);649 const karuraSovereignAccount = helper.address.paraSiblingSovereignAccount(KARURA_CHAIN);650 await helper.getSudo().balance.setBalanceSubstrate(alice, karuraSovereignAccount, karuraBalance);651652 const moreThanKaruraHas = karuraBalance * 2n;653654 let targetAccountBalance = 0n;655 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);656657 const quartzMultilocation = {658 V1: {659 parents: 1,660 interior: {661 X1: {Parachain: QUARTZ_CHAIN},662 },663 },664 };665666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(667 targetAccount.addressRaw,668 {669 Concrete: {670 parents: 0,671 interior: 'Here',672 },673 },674 moreThanKaruraHas,675 );676677 // Try to trick Quartz678 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {679 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);680 });681682 const maxWaitBlocks = 3;683684 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(685 maxWaitBlocks,686 'xcmpQueue',687 'Fail',688 );689690 expect(691 xcmpQueueFailEvent != null,692 '\'xcmpQueue.FailEvent\' event is expected',693 ).to.be.true;694695 expect(696 xcmpQueueFailEvent!.isFailedToTransactAsset,697 'The XCM error should be \'FailedToTransactAsset\'',698 ).to.be.true;699700 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);701 expect(targetAccountBalance).to.be.equal(0n);702703 // But Karura still can send the correct amount704 const validTransferAmount = karuraBalance / 2n;705 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(706 targetAccount.addressRaw,707 {708 Concrete: {709 parents: 0,710 interior: 'Here',711 },712 },713 validTransferAmount,714 );715716 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {717 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);718 });719720 await helper.wait.newBlocks(maxWaitBlocks);721722 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);723 expect(targetAccountBalance).to.be.equal(validTransferAmount);724 });725726 itSub('Should not accept reserve transfer of QTZ from Karura', async ({helper}) => {727 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);728 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);729730 const quartzMultilocation = {731 V1: {732 parents: 1,733 interior: {734 X1: {735 Parachain: QUARTZ_CHAIN,736 },737 },738 },739 };740741 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(742 targetAccount.addressRaw,743 {744 Concrete: {745 parents: 1,746 interior: {747 X1: {748 Parachain: QUARTZ_CHAIN,749 },750 },751 },752 },753 testAmount,754 );755756 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {757 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);758 });759760 const maxWaitBlocks = 3;761762 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(763 maxWaitBlocks,764 'xcmpQueue',765 'Fail',766 );767768 expect(769 xcmpQueueFailEvent != null,770 '\'xcmpQueue.FailEvent\' event is expected',771 ).to.be.true;772773 expect(774 xcmpQueueFailEvent!.isUntrustedReserveLocation,775 'The XCM error should be \'isUntrustedReserveLocation\'',776 ).to.be.true;777778 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);779 expect(accountBalance).to.be.equal(0n);780 });781});782783// These tests are relevant only when784// the the corresponding foreign assets are not registered785describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {786 let alice: IKeyringPair;787 let alith: IKeyringPair;788789 const testAmount = 100_000_000_000n;790 let quartzParachainJunction;791 let quartzAccountJunction;792793 let quartzParachainMultilocation: any;794 let quartzAccountMultilocation: any;795 let quartzCombinedMultilocation: any;796797 before(async () => {798 await usingPlaygrounds(async (helper, privateKey) => {799 alice = await privateKey('//Alice');800801 quartzParachainJunction = {Parachain: QUARTZ_CHAIN};802 quartzAccountJunction = {803 AccountId32: {804 network: 'Any',805 id: alice.addressRaw,806 },807 };808809 quartzParachainMultilocation = {810 V1: {811 parents: 1,812 interior: {813 X1: quartzParachainJunction,814 },815 },816 };817818 quartzAccountMultilocation = {819 V1: {820 parents: 0,821 interior: {822 X1: quartzAccountJunction,823 },824 },825 };826827 quartzCombinedMultilocation = {828 V1: {829 parents: 1,830 interior: {831 X2: [quartzParachainJunction, quartzAccountJunction],832 },833 },834 };835836 // Set the default version to wrap the first message to other chains.837 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);838 });839840 // eslint-disable-next-line require-await841 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {842 alith = helper.account.alithAccount();843 });844 });845846 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {847 const maxWaitBlocks = 3;848849 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(850 maxWaitBlocks,851 'xcmpQueue',852 'Fail',853 );854855 expect(856 xcmpQueueFailEvent != null,857 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,858 ).to.be.true;859860 expect(861 xcmpQueueFailEvent!.isFailedToTransactAsset,862 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,863 ).to.be.true;864 };865866 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {867 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {868 const id = {869 Token: 'KAR',870 };871 const destination = quartzCombinedMultilocation;872 await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');873 });874875 await expectFailedToTransact('KAR', helper);876 });877878 itSub('Quartz rejects MOVR tokens from Moonriver', async ({helper}) => {879 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {880 const id = 'SelfReserve';881 const destination = quartzCombinedMultilocation;882 await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');883 });884885 await expectFailedToTransact('MOVR', helper);886 });887888 itSub('Quartz rejects SDN tokens from Shiden', async ({helper}) => {889 await usingShidenPlaygrounds(shidenUrl, async (helper) => {890 const destinationParachain = quartzParachainMultilocation;891 const beneficiary = quartzAccountMultilocation;892 const assets = {893 V1: [{894 id: {895 Concrete: {896 parents: 0,897 interior: 'Here',898 },899 },900 fun: {901 Fungible: testAmount,902 },903 }],904 };905 const feeAssetItem = 0;906907 await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [908 destinationParachain,909 beneficiary,910 assets,911 feeAssetItem,912 ]);913 });914915 await expectFailedToTransact('SDN', helper);916 });917});918919describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {920 // Quartz constants921 let quartzDonor: IKeyringPair;922 let quartzAssetLocation;923924 let randomAccountQuartz: IKeyringPair;925 let randomAccountMoonriver: IKeyringPair;926927 // Moonriver constants928 let assetId: string;929930 const councilVotingThreshold = 2;931 const technicalCommitteeThreshold = 2;932 const votingPeriod = 3;933 const delayPeriod = 0;934935 const quartzAssetMetadata = {936 name: 'xcQuartz',937 symbol: 'xcQTZ',938 decimals: 18,939 isFrozen: false,940 minimalBalance: 1n,941 };942943 let balanceQuartzTokenInit: bigint;944 let balanceQuartzTokenMiddle: bigint;945 let balanceQuartzTokenFinal: bigint;946 let balanceForeignQtzTokenInit: bigint;947 let balanceForeignQtzTokenMiddle: bigint;948 let balanceForeignQtzTokenFinal: bigint;949 let balanceMovrTokenInit: bigint;950 let balanceMovrTokenMiddle: bigint;951 let balanceMovrTokenFinal: bigint;952953 before(async () => {954 await usingPlaygrounds(async (helper, privateKey) => {955 quartzDonor = await privateKey('//Alice');956 [randomAccountQuartz] = await helper.arrange.createAccounts([0n], quartzDonor);957958 balanceForeignQtzTokenInit = 0n;959960 // Set the default version to wrap the first message to other chains.961 const alice = quartzDonor;962 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);963 });964965 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {966 const alithAccount = helper.account.alithAccount();967 const baltatharAccount = helper.account.baltatharAccount();968 const dorothyAccount = helper.account.dorothyAccount();969970 randomAccountMoonriver = helper.account.create();971972 // >>> Sponsoring Dorothy >>>973 console.log('Sponsoring Dorothy.......');974 await helper.balance.transferToEthereum(alithAccount, dorothyAccount.address, 11_000_000_000_000_000_000n);975 console.log('Sponsoring Dorothy.......DONE');976 // <<< Sponsoring Dorothy <<<977978 quartzAssetLocation = {979 XCM: {980 parents: 1,981 interior: {X1: {Parachain: QUARTZ_CHAIN}},982 },983 };984 const existentialDeposit = 1n;985 const isSufficient = true;986 const unitsPerSecond = 1n;987 const numAssetsWeightHint = 0;988989 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({990 location: quartzAssetLocation,991 metadata: quartzAssetMetadata,992 existentialDeposit,993 isSufficient,994 unitsPerSecond,995 numAssetsWeightHint,996 });997 const proposalHash = blake2AsHex(encodedProposal);998999 console.log('Encoded proposal for registerForeignAsset & setAssetUnitsPerSecond is %s', encodedProposal);1000 console.log('Encoded length %d', encodedProposal.length);1001 console.log('Encoded proposal hash for batch utility after schedule is %s', proposalHash);10021003 // >>> Note motion preimage >>>1004 console.log('Note motion preimage.......');1005 await helper.democracy.notePreimage(baltatharAccount, encodedProposal);1006 console.log('Note motion preimage.......DONE');1007 // <<< Note motion preimage <<<10081009 // >>> Propose external motion through council >>>1010 console.log('Propose external motion through council.......');1011 const externalMotion = helper.democracy.externalProposeMajority({Legacy: proposalHash});1012 const encodedMotion = externalMotion?.method.toHex() || '';1013 const motionHash = blake2AsHex(encodedMotion);1014 console.log('Motion hash is %s', motionHash);10151016 await helper.collective.council.propose(baltatharAccount, councilVotingThreshold, externalMotion, externalMotion.encodedLength);10171018 const councilProposalIdx = await helper.collective.council.proposalCount() - 1;1019 await helper.collective.council.vote(dorothyAccount, motionHash, councilProposalIdx, true);1020 await helper.collective.council.vote(baltatharAccount, motionHash, councilProposalIdx, true);10211022 await helper.collective.council.close(1023 dorothyAccount,1024 motionHash,1025 councilProposalIdx,1026 {1027 refTime: 1_000_000_000,1028 proofSize: 1_000_000,1029 },1030 externalMotion.encodedLength,1031 );1032 console.log('Propose external motion through council.......DONE');1033 // <<< Propose external motion through council <<<10341035 // >>> Fast track proposal through technical committee >>>1036 console.log('Fast track proposal through technical committee.......');1037 const fastTrack = helper.democracy.fastTrack(proposalHash, votingPeriod, delayPeriod);1038 const encodedFastTrack = fastTrack?.method.toHex() || '';1039 const fastTrackHash = blake2AsHex(encodedFastTrack);1040 console.log('FastTrack hash is %s', fastTrackHash);10411042 await helper.collective.techCommittee.propose(alithAccount, technicalCommitteeThreshold, fastTrack, fastTrack.encodedLength);10431044 const techProposalIdx = await helper.collective.techCommittee.proposalCount() - 1;1045 await helper.collective.techCommittee.vote(baltatharAccount, fastTrackHash, techProposalIdx, true);1046 await helper.collective.techCommittee.vote(alithAccount, fastTrackHash, techProposalIdx, true);10471048 await helper.collective.techCommittee.close(1049 baltatharAccount,1050 fastTrackHash,1051 techProposalIdx,1052 {1053 refTime: 1_000_000_000,1054 proofSize: 1_000_000,1055 },1056 fastTrack.encodedLength,1057 );1058 console.log('Fast track proposal through technical committee.......DONE');1059 // <<< Fast track proposal through technical committee <<<10601061 // >>> Referendum voting >>>1062 console.log('Referendum voting.......');1063 await helper.democracy.referendumVote(dorothyAccount, 0, {1064 balance: 10_000_000_000_000_000_000n,1065 vote: {aye: true, conviction: 1},1066 });1067 console.log('Referendum voting.......DONE');1068 // <<< Referendum voting <<<10691070 // >>> Acquire Quartz AssetId Info on Moonriver >>>1071 console.log('Acquire Quartz AssetId Info on Moonriver.......');10721073 // Wait for the democracy execute1074 await helper.wait.newBlocks(5);10751076 assetId = (await helper.assetManager.assetTypeId(quartzAssetLocation)).toString();10771078 console.log('QTZ asset ID is %s', assetId);1079 console.log('Acquire Quartz AssetId Info on Moonriver.......DONE');1080 // >>> Acquire Quartz AssetId Info on Moonriver >>>10811082 // >>> Sponsoring random Account >>>1083 console.log('Sponsoring random Account.......');1084 await helper.balance.transferToEthereum(baltatharAccount, randomAccountMoonriver.address, 11_000_000_000_000_000_000n);1085 console.log('Sponsoring random Account.......DONE');1086 // <<< Sponsoring random Account <<<10871088 balanceMovrTokenInit = await helper.balance.getEthereum(randomAccountMoonriver.address);1089 });10901091 await usingPlaygrounds(async (helper) => {1092 await helper.balance.transferToSubstrate(quartzDonor, randomAccountQuartz.address, 10n * TRANSFER_AMOUNT);1093 balanceQuartzTokenInit = await helper.balance.getSubstrate(randomAccountQuartz.address);1094 });1095 });10961097 itSub('Should connect and send QTZ to Moonriver', async ({helper}) => {1098 const currencyId = {1099 NativeAssetId: 'Here',1100 };1101 const dest = {1102 V2: {1103 parents: 1,1104 interior: {1105 X2: [1106 {Parachain: MOONRIVER_CHAIN},1107 {AccountKey20: {network: 'Any', key: randomAccountMoonriver.address}},1108 ],1109 },1110 },1111 };1112 const amount = TRANSFER_AMOUNT;11131114 await helper.xTokens.transfer(randomAccountQuartz, currencyId, amount, dest, 'Unlimited');11151116 balanceQuartzTokenMiddle = await helper.balance.getSubstrate(randomAccountQuartz.address);1117 expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;11181119 const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;1120 console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(transactionFees));1121 expect(transactionFees > 0, 'Negative fees QTZ, looks like nothing was transferred').to.be.true;11221123 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {1124 await helper.wait.newBlocks(3);11251126 balanceMovrTokenMiddle = await helper.balance.getEthereum(randomAccountMoonriver.address);11271128 const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;1129 console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',helper.util.bigIntToDecimals(movrFees));1130 expect(movrFees == 0n).to.be.true;11311132 balanceForeignQtzTokenMiddle = (await helper.assets.account(assetId, randomAccountMoonriver.address))!; // BigInt(qtzRandomAccountAsset['balance']);1133 const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;1134 console.log('[Quartz -> Moonriver] income %s QTZ', helper.util.bigIntToDecimals(qtzIncomeTransfer));1135 expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;1136 });1137 });11381139 itSub('Should connect to Moonriver and send QTZ back', async ({helper}) => {1140 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {1141 const asset = {1142 V1: {1143 id: {1144 Concrete: {1145 parents: 1,1146 interior: {1147 X1: {Parachain: QUARTZ_CHAIN},1148 },1149 },1150 },1151 fun: {1152 Fungible: TRANSFER_AMOUNT,1153 },1154 },1155 };1156 const destination = {1157 V1: {1158 parents: 1,1159 interior: {1160 X2: [1161 {Parachain: QUARTZ_CHAIN},1162 {AccountId32: {network: 'Any', id: randomAccountQuartz.addressRaw}},1163 ],1164 },1165 },1166 };11671168 await helper.xTokens.transferMultiasset(randomAccountMoonriver, asset, destination, 'Unlimited');11691170 balanceMovrTokenFinal = await helper.balance.getEthereum(randomAccountMoonriver.address);11711172 const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;1173 console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', helper.util.bigIntToDecimals(movrFees));1174 expect(movrFees > 0, 'Negative fees MOVR, looks like nothing was transferred').to.be.true;11751176 const qtzRandomAccountAsset = await helper.assets.account(assetId, randomAccountMoonriver.address);11771178 expect(qtzRandomAccountAsset).to.be.null;11791180 balanceForeignQtzTokenFinal = 0n;11811182 const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;1183 console.log('[Quartz -> Moonriver] outcome %s QTZ', helper.util.bigIntToDecimals(qtzOutcomeTransfer));1184 expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;1185 });11861187 await helper.wait.newBlocks(3);11881189 balanceQuartzTokenFinal = await helper.balance.getSubstrate(randomAccountQuartz.address);1190 const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;1191 expect(actuallyDelivered > 0).to.be.true;11921193 console.log('[Moonriver -> Quartz] actually delivered %s QTZ', helper.util.bigIntToDecimals(actuallyDelivered));11941195 const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;1196 console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));1197 expect(qtzFees == 0n).to.be.true;1198 });11991200 // eslint-disable-next-line require-await1201 itSub.skip('Moonriver can send only up to its balance', async ({helper}) => {1202 throw Error('Not yet implemented');1203 });12041205 // eslint-disable-next-line require-await1206 itSub.skip('Should not accept reserve transfer of QTZ from Moonriver', async ({helper}) => {1207 throw Error('Not yet implemented');1208 });1209});12101211describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1212 let alice: IKeyringPair;1213 let sender: IKeyringPair;12141215 const QTZ_ASSET_ID_ON_SHIDEN = 1;1216 const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;12171218 // Quartz -> Shiden1219 const shidenInitialBalance = 1n * (10n ** SHIDEN_DECIMALS); // 1 SHD, existential deposit required to actually create the account on Shiden1220 const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?1221 const qtzToShidenTransferred = 10n * (10n ** QTZ_DECIMALS); // 10 QTZ1222 const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens12231224 // Shiden -> Quartz1225 const qtzFromShidenTransfered = 5n * (10n ** QTZ_DECIMALS); // 5 QTZ1226 const qtzOnShidenLeft = qtzToShidenArrived - qtzFromShidenTransfered; // 4.999_999_999_088_000_000n QTZ12271228 let balanceAfterQuartzToShidenXCM: bigint;12291230 before(async () => {1231 await usingPlaygrounds(async (helper, privateKey) => {1232 alice = await privateKey('//Alice');1233 [sender] = await helper.arrange.createAccounts([100n], alice);1234 console.log('sender', sender.address);12351236 // Set the default version to wrap the first message to other chains.1237 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);1238 });12391240 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1241 console.log('1. Create foreign asset and metadata');1242 // TODO update metadata with values from production1243 await helper.assets.create(1244 alice,1245 QTZ_ASSET_ID_ON_SHIDEN,1246 alice.address,1247 QTZ_MINIMAL_BALANCE_ON_SHIDEN,1248 );12491250 await helper.assets.setMetadata(1251 alice,1252 QTZ_ASSET_ID_ON_SHIDEN,1253 'Cross chain QTZ',1254 'xcQTZ',1255 Number(QTZ_DECIMALS),1256 );12571258 console.log('2. Register asset location on Shiden');1259 const assetLocation = {1260 V1: {1261 parents: 1,1262 interior: {1263 X1: {1264 Parachain: QUARTZ_CHAIN,1265 },1266 },1267 },1268 };12691270 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, QTZ_ASSET_ID_ON_SHIDEN]);12711272 console.log('3. Set QTZ payment for XCM execution on Shiden');1273 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);12741275 console.log('4. Transfer 1 SDN to recipient to create the account (needed due to existential balance)');1276 await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);1277 });1278 });12791280 itSub('Should connect and send QTZ to Shiden', async ({helper}) => {1281 const destination = {1282 V2: {1283 parents: 1,1284 interior: {1285 X1: {1286 Parachain: SHIDEN_CHAIN,1287 },1288 },1289 },1290 };12911292 const beneficiary = {1293 V2: {1294 parents: 0,1295 interior: {1296 X1: {1297 AccountId32: {1298 network: 'Any',1299 id: sender.addressRaw,1300 },1301 },1302 },1303 },1304 };13051306 const assets = {1307 V2: [1308 {1309 id: {1310 Concrete: {1311 parents: 0,1312 interior: 'Here',1313 },1314 },1315 fun: {1316 Fungible: qtzToShidenTransferred,1317 },1318 },1319 ],1320 };13211322 // Initial balance is 100 QTZ1323 const balanceBefore = await helper.balance.getSubstrate(sender.address);1324 console.log(`Initial balance is: ${balanceBefore}`);13251326 const feeAssetItem = 0;1327 await helper.xcm.limitedReserveTransferAssets(sender, destination, beneficiary, assets, feeAssetItem, 'Unlimited');13281329 // Balance after reserve transfer is less than 901330 balanceAfterQuartzToShidenXCM = await helper.balance.getSubstrate(sender.address);1331 console.log(`QTZ Balance on Quartz after XCM is: ${balanceAfterQuartzToShidenXCM}`);1332 console.log(`Quartz's QTZ commission is: ${balanceBefore-balanceAfterQuartzToShidenXCM}`);1333 expect(balanceBefore - balanceAfterQuartzToShidenXCM > 0).to.be.true;13341335 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1336 await helper.wait.newBlocks(3);1337 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);1338 const shidenBalance = await helper.balance.getSubstrate(sender.address);13391340 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);1341 console.log(`Shiden's QTZ commission is: ${qtzToShidenTransferred-xcQTZbalance!}`);13421343 expect(xcQTZbalance).to.eq(qtzToShidenArrived);1344 // SHD balance does not changed:1345 expect(shidenBalance).to.eq(shidenInitialBalance);1346 });1347 });13481349 itSub('Should connect to Shiden and send QTZ back', async ({helper}) => {1350 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1351 const destination = {1352 V1: {1353 parents: 1,1354 interior: {1355 X1: {1356 Parachain: QUARTZ_CHAIN,1357 },1358 },1359 },1360 };13611362 const beneficiary = {1363 V1: {1364 parents: 0,1365 interior: {1366 X1: {1367 AccountId32: {1368 network: 'Any',1369 id: sender.addressRaw,1370 },1371 },1372 },1373 },1374 };13751376 const assets = {1377 V1: [1378 {1379 id: {1380 Concrete: {1381 parents: 1,1382 interior: {1383 X1: {1384 Parachain: QUARTZ_CHAIN,1385 },1386 },1387 },1388 },1389 fun: {1390 Fungible: qtzFromShidenTransfered,1391 },1392 },1393 ],1394 };13951396 // Initial balance is 1 SDN1397 const balanceSDNbefore = await helper.balance.getSubstrate(sender.address);1398 console.log(`SDN balance is: ${balanceSDNbefore}, it does not changed`);1399 expect(balanceSDNbefore).to.eq(shidenInitialBalance);14001401 const feeAssetItem = 0;1402 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw1403 await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);14041405 // Balance after reserve transfer is less than 1 SDN1406 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);1407 const balanceSDN = await helper.balance.getSubstrate(sender.address);1408 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);14091410 // Assert: xcQTZ balance correctly decreased1411 expect(xcQTZbalance).to.eq(qtzOnShidenLeft);1412 // Assert: SDN balance is 0.996...1413 expect(balanceSDN / (10n ** (SHIDEN_DECIMALS - 3n))).to.eq(996n);1414 });14151416 await helper.wait.newBlocks(3);1417 const balanceQTZ = await helper.balance.getSubstrate(sender.address);1418 console.log(`QTZ Balance on Quartz after XCM is: ${balanceQTZ}`);1419 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);1420 });14211422 itSub('Shiden can send only up to its balance', async ({helper}) => {1423 // set Shiden's sovereign account's balance1424 const shidenBalance = 10000n * (10n ** QTZ_DECIMALS);1425 const shidenSovereignAccount = helper.address.paraSiblingSovereignAccount(SHIDEN_CHAIN);1426 await helper.getSudo().balance.setBalanceSubstrate(alice, shidenSovereignAccount, shidenBalance);14271428 const moreThanShidenHas = shidenBalance * 2n;14291430 let targetAccountBalance = 0n;1431 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);14321433 const quartzMultilocation = {1434 V1: {1435 parents: 1,1436 interior: {1437 X1: {Parachain: QUARTZ_CHAIN},1438 },1439 },1440 };14411442 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1443 targetAccount.addressRaw,1444 {1445 Concrete: {1446 parents: 0,1447 interior: 'Here',1448 },1449 },1450 moreThanShidenHas,1451 );14521453 // Try to trick Quartz1454 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1455 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1456 });14571458 const maxWaitBlocks = 3;14591460 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1461 maxWaitBlocks,1462 'xcmpQueue',1463 'Fail',1464 );14651466 expect(1467 xcmpQueueFailEvent != null,1468 '\'xcmpQueue.FailEvent\' event is expected',1469 ).to.be.true;14701471 expect(1472 xcmpQueueFailEvent!.isFailedToTransactAsset,1473 'The XCM error should be \'FailedToTransactAsset\'',1474 ).to.be.true;14751476 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1477 expect(targetAccountBalance).to.be.equal(0n);14781479 // But Shiden still can send the correct amount1480 const validTransferAmount = shidenBalance / 2n;1481 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1482 targetAccount.addressRaw,1483 {1484 Concrete: {1485 parents: 0,1486 interior: 'Here',1487 },1488 },1489 validTransferAmount,1490 );14911492 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1493 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);1494 });14951496 await helper.wait.newBlocks(maxWaitBlocks);14971498 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1499 expect(targetAccountBalance).to.be.equal(validTransferAmount);1500 });15011502 itSub('Should not accept reserve transfer of QTZ from Shiden', async ({helper}) => {1503 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);1504 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);15051506 const quartzMultilocation = {1507 V1: {1508 parents: 1,1509 interior: {1510 X1: {1511 Parachain: QUARTZ_CHAIN,1512 },1513 },1514 },1515 };15161517 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(1518 targetAccount.addressRaw,1519 {1520 Concrete: {1521 parents: 1,1522 interior: {1523 X1: {1524 Parachain: QUARTZ_CHAIN,1525 },1526 },1527 },1528 },1529 testAmount,1530 );15311532 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1533 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1534 });15351536 const maxWaitBlocks = 3;15371538 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1539 maxWaitBlocks,1540 'xcmpQueue',1541 'Fail',1542 );15431544 expect(1545 xcmpQueueFailEvent != null,1546 '\'xcmpQueue.FailEvent\' event is expected',1547 ).to.be.true;15481549 expect(1550 xcmpQueueFailEvent!.isUntrustedReserveLocation,1551 'The XCM error should be \'isUntrustedReserveLocation\'',1552 ).to.be.true;15531554 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);1555 expect(accountBalance).to.be.equal(0n);1556 });1557});tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -691,12 +691,12 @@
expect(
xcmpQueueFailEvent != null,
- `'xcmpQueue.FailEvent' event is expected`,
+ '\'xcmpQueue.FailEvent\' event is expected',
).to.be.true;
expect(
xcmpQueueFailEvent!.isFailedToTransactAsset,
- `The XCM error should be 'FailedToTransactAsset'`,
+ 'The XCM error should be \'FailedToTransactAsset\'',
).to.be.true;
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
@@ -769,12 +769,12 @@
expect(
xcmpQueueFailEvent != null,
- `'xcmpQueue.FailEvent' event is expected`,
+ '\'xcmpQueue.FailEvent\' event is expected',
).to.be.true;
expect(
xcmpQueueFailEvent!.isUntrustedReserveLocation,
- `The XCM error should be 'isUntrustedReserveLocation'`,
+ 'The XCM error should be \'isUntrustedReserveLocation\'',
).to.be.true;
const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
@@ -1200,12 +1200,14 @@
expect(unqFees == 0n).to.be.true;
});
+ // eslint-disable-next-line require-await
itSub.skip('Moonbeam can send only up to its balance', async ({helper}) => {
- throw Error("Not yet implemented");
+ throw Error('Not yet implemented');
});
+ // eslint-disable-next-line require-await
itSub.skip('Should not accept reserve transfer of UNQ from Moonbeam', async ({helper}) => {
- throw Error("Not yet implemented");
+ throw Error('Not yet implemented');
});
});
@@ -1465,12 +1467,12 @@
expect(
xcmpQueueFailEvent != null,
- `'xcmpQueue.FailEvent' event is expected`,
+ '\'xcmpQueue.FailEvent\' event is expected',
).to.be.true;
expect(
xcmpQueueFailEvent!.isFailedToTransactAsset,
- `The XCM error should be 'FailedToTransactAsset'`,
+ 'The XCM error should be \'FailedToTransactAsset\'',
).to.be.true;
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
@@ -1543,12 +1545,12 @@
expect(
xcmpQueueFailEvent != null,
- `'xcmpQueue.FailEvent' event is expected`,
+ '\'xcmpQueue.FailEvent\' event is expected',
).to.be.true;
expect(
xcmpQueueFailEvent!.isUntrustedReserveLocation,
- `The XCM error should be 'isUntrustedReserveLocation'`,
+ 'The XCM error should be \'isUntrustedReserveLocation\'',
).to.be.true;
const accountBalance = await helper.balance.getSubstrate(targetAccount.address);