difftreelog
Test logs
in: master
1 file changed
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './../substrate/substrate-api';24import {getGenericResult, paraSiblingSovereignAccount} from './../util/helpers';25import waitNewBlocks from './../substrate/wait-new-blocks';26import {normalizeAccountId} from './../util/helpers';27import getBalance from './../substrate/get-balance';282930chai.use(chaiAsPromised);31const expect = chai.expect;3233const STATEMINE_CHAIN = 1000;34const UNIQUE_CHAIN = 2095;3536const RELAY_PORT = '9844';37const UNIQUE_PORT = '9944';38const STATEMINE_PORT = '9948';39const STATEMINE_PALLET_INSTANCE = 50;40const ASSET_ID = 100;41const ASSET_METADATA_DECIMALS = 18;42const ASSET_METADATA_NAME = 'USDT';43const ASSET_METADATA_DESCRIPTION = 'USDT';44const ASSET_METADATA_MINIMAL_BALANCE = 1;4546const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4748// 10,000.00 (ten thousands) USDT49const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 5051describe('Integration test: Exchanging USDT with Westmint', () => {52 let alice: IKeyringPair;53 let bob: IKeyringPair;54 55 let balanceStmnBefore: bigint;56 let balanceStmnAfter: bigint;5758 let balanceOpalBefore: bigint;59 let balanceOpalAfter: bigint;60 let balanceOpalFinal: bigint;6162 let balanceBobBefore: bigint;63 let balanceBobAfter: bigint;6465 before(async () => {66 await usingApi(async (api, privateKeyWrapper) => {67 alice = privateKeyWrapper('//Alice');68 bob = privateKeyWrapper('//Bob'); // funds donor69 });7071 const statemineApiOptions: ApiOptions = {72 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),73 };7475 const uniqueApiOptions: ApiOptions = {76 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),77 };7879 const relayApiOptions: ApiOptions = {80 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),81 };8283 await usingApi(async (api) => {8485 // 350.00 (three hundred fifty) DOT86 const fundingAmount = 3_500_000_000_000; 8788 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);89 const events = await submitTransactionAsync(alice, tx);90 const result = getGenericResult(events);91 expect(result.success).to.be.true;9293 // set metadata94 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);95 const events2 = await submitTransactionAsync(alice, tx2);96 const result2 = getGenericResult(events2);97 expect(result2.success).to.be.true;9899 // mint some amount of asset100 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);101 const events3 = await submitTransactionAsync(alice, tx3);102 const result3 = getGenericResult(events3);103 expect(result3.success).to.be.true;104105 // funding parachain sovereing account (Parachain: 2095)106 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);107 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);108 const events4 = await submitTransactionAsync(bob, tx4);109 const result4 = getGenericResult(events4);110 expect(result4.success).to.be.true;111112 }, statemineApiOptions);113114115 await usingApi(async (api) => {116117 const location = {118 V1: {119 parents: 1,120 interior: {X3: [121 {122 Parachain: STATEMINE_CHAIN,123 },124 {125 PalletInstance: STATEMINE_PALLET_INSTANCE,126 },127 {128 GeneralIndex: ASSET_ID,129 },130 ]},131 },132 };133134 const metadata =135 {136 name: ASSET_ID,137 symbol: ASSET_METADATA_NAME,138 decimals: ASSET_METADATA_DECIMALS,139 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,140 };141 //registerForeignAsset(owner, location, metadata)142 const tx = api.tx.foreingAssets.registerForeignAsset(alice.addressRaw, location, metadata);143 const sudoTx = api.tx.sudo.sudo(tx as any);144 const events = await submitTransactionAsync(alice, sudoTx);145 const result = getGenericResult(events);146 expect(result.success).to.be.true;147148 [balanceOpalBefore] = await getBalance(api, [alice.address]);149150 }, uniqueApiOptions);151152153 // Providing the relay currency to the unique sender account154 await usingApi(async (api) => {155 const destination = {156 V1: {157 parents: 0,158 interior: {X1: {159 Parachain: UNIQUE_CHAIN,160 },161 },162 }};163164 const beneficiary = {165 V1: {166 parents: 0,167 interior: {X1: {168 AccountId32: {169 network: 'Any',170 id: alice.addressRaw,171 },172 }},173 },174 };175176 const assets = {177 V1: [178 {179 id: {180 Concrete: {181 parents: 0,182 interior: 'Here',183 },184 },185 fun: {186 Fungible: 50_000_000_000_000_000n,187 },188 },189 ],190 };191192 const feeAssetItem = 0;193194 const weightLimit = {195 Limited: 5_000_000_000,196 };197198 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);199 const events = await submitTransactionAsync(alice, tx);200 const result = getGenericResult(events);201 expect(result.success).to.be.true;202 }, relayApiOptions);203 204 });205206 it('Should connect and send USDT from Westmint to Opal', async () => {207 208 const statemineApiOptions: ApiOptions = {209 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),210 };211212 const uniqueApiOptions: ApiOptions = {213 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),214 };215216 await usingApi(async (api) => {217218 const dest = {219 V1: {220 parents: 1,221 interior: {X1: {222 Parachain: UNIQUE_CHAIN,223 },224 },225 }};226227 const beneficiary = {228 V1: {229 parents: 0,230 interior: {X1: {231 AccountId32: {232 network: 'Any',233 id: alice.addressRaw,234 },235 }},236 },237 };238239 const assets = {240 V1: [241 {242 id: {243 Concrete: {244 parents: 0,245 interior: {246 X2: [247 {248 PalletInstance: STATEMINE_PALLET_INSTANCE,249 },250 {251 GeneralIndex: ASSET_ID,252 }, 253 ]},254 },255 },256 fun: {257 Fungible: TRANSFER_AMOUNT,258 },259 },260 ],261 };262263 const feeAssetItem = 0;264265 const weightLimit = {266 Limited: 5000000000,267 };268269 [balanceStmnBefore] = await getBalance(api, [alice.address]);270271 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);272 const events = await submitTransactionAsync(alice, tx);273 const result = getGenericResult(events);274 expect(result.success).to.be.true;275276 [balanceStmnAfter] = await getBalance(api, [alice.address]);277278 // common good parachain take commission in it native token279 console.log('Opal to Westmint transaction fees on Westmint: %s WND', balanceStmnBefore - balanceStmnAfter);280 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;281282 }, statemineApiOptions);283284285 // ensure that asset has been delivered286 await usingApi(async (api) => {287 await waitNewBlocks(api, 3);288 // expext collection id will be with id 1289 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();290291 [balanceOpalAfter] = await getBalance(api, [alice.address]);292293 // commission has not paid in USDT token294 expect(free == TRANSFER_AMOUNT).to.be.true;295 console.log('Opal to Westmint transaction fees on Opal: %s USDT', TRANSFER_AMOUNT - free);296 // ... and parachain native token297 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;298 console.log('Opal to Westmint transaction fees on Opal: %s WND', balanceOpalAfter - balanceOpalBefore);299300 }, uniqueApiOptions);301 302 });303304 it('Should connect and send USDT from Unique to Statemine back', async () => {305306 const uniqueApiOptions: ApiOptions = {307 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),308 };309310 const statemineApiOptions: ApiOptions = {311 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),312 };313314 await usingApi(async (api) => {315 const destination = {316 V1: {317 parents: 1,318 interior: {X2: [319 {320 Parachain: STATEMINE_CHAIN,321 },322 {323 AccountId32: {324 network: 'Any',325 id: alice.addressRaw,326 },327 },328 ]},329 },330 };331332 const currencies = [[333 {334 ForeignAssetId: 0,335 },336 //10_000_000_000_000_000n,337 TRANSFER_AMOUNT,338 ], 339 [340 {341 NativeAssetId: 'Parent',342 },343 400_000_000_000_000n,344 ]];345346 const feeItem = 1;347 const destWeight = 500000000000;348349 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);350 const events = await submitTransactionAsync(alice, tx);351 const result = getGenericResult(events);352 expect(result.success).to.be.true;353 354 // the commission has been paid in parachain native token355 [balanceOpalFinal] = await getBalance(api, [alice.address]);356 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;357 }, uniqueApiOptions);358359 await usingApi(async (api) => {360 await waitNewBlocks(api, 3);361 362 // The USDT token never paid fees. Its amount not changed from begin value.363 // Also check that xcm transfer has been succeeded 364 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;365 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;366 }, statemineApiOptions);367 });368369 it('Should connect and send Relay token to Unique', async () => {370371 const uniqueApiOptions: ApiOptions = {372 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),373 };374375 const uniqueApiOptions2: ApiOptions = {376 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),377 };378379 const relayApiOptions: ApiOptions = {380 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),381 };382383 await usingApi(async (api) => {384 [balanceBobBefore] = await getBalance(api, [alice.address]);385 }, uniqueApiOptions);386387 // Providing the relay currency to the unique sender account388 await usingApi(async (api) => {389 const destination = {390 V1: {391 parents: 0,392 interior: {X1: {393 Parachain: UNIQUE_CHAIN,394 },395 },396 }};397398 const beneficiary = {399 V1: {400 parents: 0,401 interior: {X1: {402 AccountId32: {403 network: 'Any',404 id: bob.addressRaw,405 },406 }},407 },408 };409410 const assets = {411 V1: [412 {413 id: {414 Concrete: {415 parents: 0,416 interior: 'Here',417 },418 },419 fun: {420 Fungible: 50_000_000_000_000_000n,421 },422 },423 ],424 };425426 const feeAssetItem = 0;427428 const weightLimit = {429 Limited: 5_000_000_000,430 };431432 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);433 const events = await submitTransactionAsync(bob, tx);434 const result = getGenericResult(events);435 expect(result.success).to.be.true;436 }, relayApiOptions);437 438439 await usingApi(async (api) => {440 await waitNewBlocks(api, 3);441442 [balanceBobAfter] = await getBalance(api, [alice.address]);443 expect(balanceBobBefore == balanceBobAfter).to.be.true;444 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobBefore);445446 }, uniqueApiOptions2);447448 });449450 it('Should connect and send Relay token back', async () => {451452 const uniqueApiOptions: ApiOptions = {453 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),454 };455456 await usingApi(async (api) => {457 const destination = {458 V1: {459 parents: 1,460 interior: {X2: [461 {462 Parachain: STATEMINE_CHAIN,463 },464 {465 AccountId32: {466 network: 'Any',467 id: bob.addressRaw,468 },469 },470 ]},471 },472 };473474 const currencies = [475 [476 {477 NativeAssetId: 'Parent',478 },479 50_000_000_000_000_000n,480 ]];481482 const feeItem = 0;483 const destWeight = 500000000000;484485 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);486 const events = await submitTransactionAsync(bob, tx);487 const result = getGenericResult(events);488 expect(result.success).to.be.true;489 }, uniqueApiOptions);490 });491492});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 chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './../substrate/substrate-api';24import {getGenericResult, paraSiblingSovereignAccount} from './../util/helpers';25import waitNewBlocks from './../substrate/wait-new-blocks';26import {normalizeAccountId} from './../util/helpers';27import getBalance from './../substrate/get-balance';282930chai.use(chaiAsPromised);31const expect = chai.expect;3233const STATEMINE_CHAIN = 1000;34const UNIQUE_CHAIN = 2095;3536const RELAY_PORT = '9844';37const UNIQUE_PORT = '9944';38const STATEMINE_PORT = '9946';39const STATEMINE_PALLET_INSTANCE = 50;40const ASSET_ID = 100;41const ASSET_METADATA_DECIMALS = 18;42const ASSET_METADATA_NAME = 'USDT';43const ASSET_METADATA_DESCRIPTION = 'USDT';44const ASSET_METADATA_MINIMAL_BALANCE = 1;4546const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4748// 10,000.00 (ten thousands) USDT49const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 5051describe('Integration test: Exchanging USDT with Westmint', () => {52 let alice: IKeyringPair;53 let bob: IKeyringPair;54 55 let balanceStmnBefore: bigint;56 let balanceStmnAfter: bigint;5758 let balanceOpalBefore: bigint;59 let balanceOpalAfter: bigint;60 let balanceOpalFinal: bigint;6162 let balanceBobBefore: bigint;63 let balanceBobAfter: bigint;64 let balanceBobFinal: bigint;6566 let balanceBobRelayTokenBefore: bigint;67 let balanceBobRelayTokenAfter: bigint;686970 before(async () => {71 await usingApi(async (api, privateKeyWrapper) => {72 alice = privateKeyWrapper('//Alice');73 bob = privateKeyWrapper('//Bob'); // funds donor74 });7576 const statemineApiOptions: ApiOptions = {77 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),78 };7980 const uniqueApiOptions: ApiOptions = {81 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),82 };8384 const relayApiOptions: ApiOptions = {85 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),86 };8788 await usingApi(async (api) => {8990 // 350.00 (three hundred fifty) DOT91 const fundingAmount = 3_500_000_000_000; 9293 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);94 const events = await submitTransactionAsync(alice, tx);95 const result = getGenericResult(events);96 expect(result.success).to.be.true;9798 // set metadata99 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);100 const events2 = await submitTransactionAsync(alice, tx2);101 const result2 = getGenericResult(events2);102 expect(result2.success).to.be.true;103104 // mint some amount of asset105 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);106 const events3 = await submitTransactionAsync(alice, tx3);107 const result3 = getGenericResult(events3);108 expect(result3.success).to.be.true;109110 // funding parachain sovereing account (Parachain: 2095)111 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);112 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);113 const events4 = await submitTransactionAsync(bob, tx4);114 const result4 = getGenericResult(events4);115 expect(result4.success).to.be.true;116117 }, statemineApiOptions);118119120 await usingApi(async (api) => {121122 const location = {123 V1: {124 parents: 1,125 interior: {X3: [126 {127 Parachain: STATEMINE_CHAIN,128 },129 {130 PalletInstance: STATEMINE_PALLET_INSTANCE,131 },132 {133 GeneralIndex: ASSET_ID,134 },135 ]},136 },137 };138139 const metadata =140 {141 name: ASSET_ID,142 symbol: ASSET_METADATA_NAME,143 decimals: ASSET_METADATA_DECIMALS,144 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,145 };146 //registerForeignAsset(owner, location, metadata)147 const tx = api.tx.foreingAssets.registerForeignAsset(alice.addressRaw, location, metadata);148 const sudoTx = api.tx.sudo.sudo(tx as any);149 const events = await submitTransactionAsync(alice, sudoTx);150 const result = getGenericResult(events);151 expect(result.success).to.be.true;152153 [balanceOpalBefore] = await getBalance(api, [alice.address]);154155 }, uniqueApiOptions);156157158 // Providing the relay currency to the unique sender account159 await usingApi(async (api) => {160 const destination = {161 V1: {162 parents: 0,163 interior: {X1: {164 Parachain: UNIQUE_CHAIN,165 },166 },167 }};168169 const beneficiary = {170 V1: {171 parents: 0,172 interior: {X1: {173 AccountId32: {174 network: 'Any',175 id: alice.addressRaw,176 },177 }},178 },179 };180181 const assets = {182 V1: [183 {184 id: {185 Concrete: {186 parents: 0,187 interior: 'Here',188 },189 },190 fun: {191 Fungible: 50_000_000_000_000_000n,192 },193 },194 ],195 };196197 const feeAssetItem = 0;198199 const weightLimit = {200 Limited: 5_000_000_000,201 };202203 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);204 const events = await submitTransactionAsync(alice, tx);205 const result = getGenericResult(events);206 expect(result.success).to.be.true;207 }, relayApiOptions);208 209 });210211 it('Should connect and send USDT from Westmint to Opal', async () => {212 213 const statemineApiOptions: ApiOptions = {214 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),215 };216217 const uniqueApiOptions: ApiOptions = {218 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),219 };220221 await usingApi(async (api) => {222223 const dest = {224 V1: {225 parents: 1,226 interior: {X1: {227 Parachain: UNIQUE_CHAIN,228 },229 },230 }};231232 const beneficiary = {233 V1: {234 parents: 0,235 interior: {X1: {236 AccountId32: {237 network: 'Any',238 id: alice.addressRaw,239 },240 }},241 },242 };243244 const assets = {245 V1: [246 {247 id: {248 Concrete: {249 parents: 0,250 interior: {251 X2: [252 {253 PalletInstance: STATEMINE_PALLET_INSTANCE,254 },255 {256 GeneralIndex: ASSET_ID,257 }, 258 ]},259 },260 },261 fun: {262 Fungible: TRANSFER_AMOUNT,263 },264 },265 ],266 };267268 const feeAssetItem = 0;269270 const weightLimit = {271 Limited: 5000000000,272 };273274 [balanceStmnBefore] = await getBalance(api, [alice.address]);275276 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);277 const events = await submitTransactionAsync(alice, tx);278 const result = getGenericResult(events);279 expect(result.success).to.be.true;280281 [balanceStmnAfter] = await getBalance(api, [alice.address]);282283 // common good parachain take commission in it native token284 console.log('Opal to Westmint transaction fees on Westmint: %s WND', balanceStmnBefore - balanceStmnAfter);285 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;286287 }, statemineApiOptions);288289290 // ensure that asset has been delivered291 await usingApi(async (api) => {292 await waitNewBlocks(api, 3);293 // expext collection id will be with id 1294 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();295296 [balanceOpalAfter] = await getBalance(api, [alice.address]);297298 // commission has not paid in USDT token299 expect(free == TRANSFER_AMOUNT).to.be.true;300 console.log('Opal to Westmint transaction fees on Opal: %s USDT', TRANSFER_AMOUNT - free);301 // ... and parachain native token302 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;303 console.log('Opal to Westmint transaction fees on Opal: %s WND', balanceOpalAfter - balanceOpalBefore);304305 }, uniqueApiOptions);306 307 });308309 it('Should connect and send USDT from Unique to Statemine back', async () => {310311 const uniqueApiOptions: ApiOptions = {312 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),313 };314315 const statemineApiOptions: ApiOptions = {316 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),317 };318319 await usingApi(async (api) => {320 const destination = {321 V1: {322 parents: 1,323 interior: {X2: [324 {325 Parachain: STATEMINE_CHAIN,326 },327 {328 AccountId32: {329 network: 'Any',330 id: alice.addressRaw,331 },332 },333 ]},334 },335 };336337 const currencies = [[338 {339 ForeignAssetId: 0,340 },341 //10_000_000_000_000_000n,342 TRANSFER_AMOUNT,343 ], 344 [345 {346 NativeAssetId: 'Parent',347 },348 400_000_000_000_000n,349 ]];350351 const feeItem = 1;352 const destWeight = 500000000000;353354 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);355 const events = await submitTransactionAsync(alice, tx);356 const result = getGenericResult(events);357 expect(result.success).to.be.true;358 359 // the commission has been paid in parachain native token360 [balanceOpalFinal] = await getBalance(api, [alice.address]);361 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;362 }, uniqueApiOptions);363364 await usingApi(async (api) => {365 await waitNewBlocks(api, 3);366 367 // The USDT token never paid fees. Its amount not changed from begin value.368 // Also check that xcm transfer has been succeeded 369 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;370 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;371 }, statemineApiOptions);372 });373374 it('Should connect and send Relay token to Unique', async () => {375376 const uniqueApiOptions: ApiOptions = {377 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),378 };379380 const uniqueApiOptions2: ApiOptions = {381 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),382 };383384 const relayApiOptions: ApiOptions = {385 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),386 };387388 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;389390 await usingApi(async (api) => {391 [balanceBobBefore] = await getBalance(api, [bob.address]);392 balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);393394 }, uniqueApiOptions);395396 // Providing the relay currency to the unique sender account397 await usingApi(async (api) => {398 const destination = {399 V1: {400 parents: 0,401 interior: {X1: {402 Parachain: UNIQUE_CHAIN,403 },404 },405 }};406407 const beneficiary = {408 V1: {409 parents: 0,410 interior: {X1: {411 AccountId32: {412 network: 'Any',413 id: bob.addressRaw,414 },415 }},416 },417 };418419 const assets = {420 V1: [421 {422 id: {423 Concrete: {424 parents: 0,425 interior: 'Here',426 },427 },428 fun: {429 Fungible: TRANSFER_AMOUNT_RELAY,430 },431 },432 ],433 };434435 const feeAssetItem = 0;436437 const weightLimit = {438 Limited: 5_000_000_000,439 };440441 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);442 const events = await submitTransactionAsync(bob, tx);443 const result = getGenericResult(events);444 expect(result.success).to.be.true;445 }, relayApiOptions);446 447448 await usingApi(async (api) => {449 await waitNewBlocks(api, 3);450451 [balanceBobAfter] = await getBalance(api, [bob.address]);452 balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);453 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 454 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobBefore);455 console.log('Relay (Westend) to Opal transaction fees: %s WND', wndFee);456 expect(balanceBobBefore == balanceBobAfter).to.be.true;457 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;458 }, uniqueApiOptions2);459460 });461462 it('Should connect and send Relay token back', async () => {463 const uniqueApiOptions: ApiOptions = {464 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),465 };466467 await usingApi(async (api) => {468 const destination = {469 V1: {470 parents: 1,471 interior: {X2: [472 {473 Parachain: STATEMINE_CHAIN,474 },475 {476 AccountId32: {477 network: 'Any',478 id: bob.addressRaw,479 },480 },481 ]},482 },483 };484485 const currencies = [486 [487 {488 NativeAssetId: 'Parent',489 },490 50_000_000_000_000_000n,491 ]];492493 const feeItem = 0;494 const destWeight = 500000000000;495496 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);497 const events = await submitTransactionAsync(bob, tx);498 const result = getGenericResult(events);499 expect(result.success).to.be.true;500501 [balanceBobFinal] = await getBalance(api, [bob.address]);502 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);503504 }, uniqueApiOptions);505 });506507});