difftreelog
fix xcm tests ts errors
in: master
3 files changed
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';1920import {WsProvider} from '@polkadot/api';21import {ApiOptions} from '@polkadot/api/types';22import {IKeyringPair} from '@polkadot/types/types';23import usingApi, {submitTransactionAsync} from './../substrate/substrate-api';24import {bigIntToDecimals, 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 WESTMINT_DECIMALS = 12;4748const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4950// 10,000.00 (ten thousands) USDT51const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 5253describe('Integration test: Exchanging USDT with Westmint', () => {54 let alice: IKeyringPair;55 let bob: IKeyringPair;56 57 let balanceStmnBefore: bigint;58 let balanceStmnAfter: bigint;5960 let balanceOpalBefore: bigint;61 let balanceOpalAfter: bigint;62 let balanceOpalFinal: bigint;6364 let balanceBobBefore: bigint;65 let balanceBobAfter: bigint;66 let balanceBobFinal: bigint;6768 let balanceBobRelayTokenBefore: bigint;69 let balanceBobRelayTokenAfter: bigint;707172 before(async () => {73 await usingApi(async (api, privateKeyWrapper) => {74 alice = privateKeyWrapper('//Alice');75 bob = privateKeyWrapper('//Bob'); // funds donor76 });7778 const statemineApiOptions: ApiOptions = {79 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),80 };8182 const uniqueApiOptions: ApiOptions = {83 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),84 };8586 const relayApiOptions: ApiOptions = {87 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),88 };8990 await usingApi(async (api) => {9192 // 350.00 (three hundred fifty) DOT93 const fundingAmount = 3_500_000_000_000; 9495 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);96 const events = await submitTransactionAsync(alice, tx);97 const result = getGenericResult(events);98 expect(result.success).to.be.true;99100 // set metadata101 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);102 const events2 = await submitTransactionAsync(alice, tx2);103 const result2 = getGenericResult(events2);104 expect(result2.success).to.be.true;105106 // mint some amount of asset107 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);108 const events3 = await submitTransactionAsync(alice, tx3);109 const result3 = getGenericResult(events3);110 expect(result3.success).to.be.true;111112 // funding parachain sovereing account (Parachain: 2095)113 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);114 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);115 const events4 = await submitTransactionAsync(bob, tx4);116 const result4 = getGenericResult(events4);117 expect(result4.success).to.be.true;118119 }, statemineApiOptions);120121122 await usingApi(async (api) => {123124 const location = {125 V1: {126 parents: 1,127 interior: {X3: [128 {129 Parachain: STATEMINE_CHAIN,130 },131 {132 PalletInstance: STATEMINE_PALLET_INSTANCE,133 },134 {135 GeneralIndex: ASSET_ID,136 },137 ]},138 },139 };140141 const metadata =142 {143 name: ASSET_ID,144 symbol: ASSET_METADATA_NAME,145 decimals: ASSET_METADATA_DECIMALS,146 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,147 };148 //registerForeignAsset(owner, location, metadata)149 const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);150 const sudoTx = api.tx.sudo.sudo(tx as any);151 const events = await submitTransactionAsync(alice, sudoTx);152 const result = getGenericResult(events);153 expect(result.success).to.be.true;154155 [balanceOpalBefore] = await getBalance(api, [alice.address]);156157 }, uniqueApiOptions);158159160 // Providing the relay currency to the unique sender account161 await usingApi(async (api) => {162 const destination = {163 V1: {164 parents: 0,165 interior: {X1: {166 Parachain: UNIQUE_CHAIN,167 },168 },169 }};170171 const beneficiary = {172 V1: {173 parents: 0,174 interior: {X1: {175 AccountId32: {176 network: 'Any',177 id: alice.addressRaw,178 },179 }},180 },181 };182183 const assets = {184 V1: [185 {186 id: {187 Concrete: {188 parents: 0,189 interior: 'Here',190 },191 },192 fun: {193 Fungible: 50_000_000_000_000_000n,194 },195 },196 ],197 };198199 const feeAssetItem = 0;200201 const weightLimit = {202 Limited: 5_000_000_000,203 };204205 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);206 const events = await submitTransactionAsync(alice, tx);207 const result = getGenericResult(events);208 expect(result.success).to.be.true;209 }, relayApiOptions);210 211 });212213 it('Should connect and send USDT from Westmint to Opal', async () => {214 215 const statemineApiOptions: ApiOptions = {216 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),217 };218219 const uniqueApiOptions: ApiOptions = {220 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),221 };222223 await usingApi(async (api) => {224225 const dest = {226 V1: {227 parents: 1,228 interior: {X1: {229 Parachain: UNIQUE_CHAIN,230 },231 },232 }};233234 const beneficiary = {235 V1: {236 parents: 0,237 interior: {X1: {238 AccountId32: {239 network: 'Any',240 id: alice.addressRaw,241 },242 }},243 },244 };245246 const assets = {247 V1: [248 {249 id: {250 Concrete: {251 parents: 0,252 interior: {253 X2: [254 {255 PalletInstance: STATEMINE_PALLET_INSTANCE,256 },257 {258 GeneralIndex: ASSET_ID,259 }, 260 ]},261 },262 },263 fun: {264 Fungible: TRANSFER_AMOUNT,265 },266 },267 ],268 };269270 const feeAssetItem = 0;271272 const weightLimit = {273 Limited: 5000000000,274 };275276 [balanceStmnBefore] = await getBalance(api, [alice.address]);277278 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);279 const events = await submitTransactionAsync(alice, tx);280 const result = getGenericResult(events);281 expect(result.success).to.be.true;282283 [balanceStmnAfter] = await getBalance(api, [alice.address]);284285 // common good parachain take commission in it native token286 console.log(287 'Opal to Westmint transaction fees on Westmint: %s WND',288 bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),289 );290 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;291292 }, statemineApiOptions);293294295 // ensure that asset has been delivered296 await usingApi(async (api) => {297 await waitNewBlocks(api, 3);298 // expext collection id will be with id 1299 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();300301 [balanceOpalAfter] = await getBalance(api, [alice.address]);302303 // commission has not paid in USDT token304 expect(free == TRANSFER_AMOUNT).to.be.true;305 console.log(306 'Opal to Westmint transaction fees on Opal: %s USDT',307 bigIntToDecimals(TRANSFER_AMOUNT - free),308 );309 // ... and parachain native token310 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;311 console.log(312 'Opal to Westmint transaction fees on Opal: %s WND',313 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),314 );315316 }, uniqueApiOptions);317 318 });319320 it('Should connect and send USDT from Unique to Statemine back', async () => {321322 const uniqueApiOptions: ApiOptions = {323 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),324 };325326 const statemineApiOptions: ApiOptions = {327 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),328 };329330 await usingApi(async (api) => {331 const destination = {332 V1: {333 parents: 1,334 interior: {X2: [335 {336 Parachain: STATEMINE_CHAIN,337 },338 {339 AccountId32: {340 network: 'Any',341 id: alice.addressRaw,342 },343 },344 ]},345 },346 };347348 const currencies = [[349 {350 ForeignAssetId: 0,351 },352 //10_000_000_000_000_000n,353 TRANSFER_AMOUNT,354 ], 355 [356 {357 NativeAssetId: 'Parent',358 },359 400_000_000_000_000n,360 ]];361362 const feeItem = 1;363 const destWeight = 500000000000;364365 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);366 const events = await submitTransactionAsync(alice, tx);367 const result = getGenericResult(events);368 expect(result.success).to.be.true;369 370 // the commission has been paid in parachain native token371 [balanceOpalFinal] = await getBalance(api, [alice.address]);372 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;373 }, uniqueApiOptions);374375 await usingApi(async (api) => {376 await waitNewBlocks(api, 3);377 378 // The USDT token never paid fees. Its amount not changed from begin value.379 // Also check that xcm transfer has been succeeded 380 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;381 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;382 }, statemineApiOptions);383 });384385 it('Should connect and send Relay token to Unique', async () => {386387 const uniqueApiOptions: ApiOptions = {388 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),389 };390391 const uniqueApiOptions2: ApiOptions = {392 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),393 };394395 const relayApiOptions: ApiOptions = {396 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),397 };398399 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;400401 await usingApi(async (api) => {402 [balanceBobBefore] = await getBalance(api, [bob.address]);403 balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);404405 }, uniqueApiOptions);406407 // Providing the relay currency to the unique sender account408 await usingApi(async (api) => {409 const destination = {410 V1: {411 parents: 0,412 interior: {X1: {413 Parachain: UNIQUE_CHAIN,414 },415 },416 }};417418 const beneficiary = {419 V1: {420 parents: 0,421 interior: {X1: {422 AccountId32: {423 network: 'Any',424 id: bob.addressRaw,425 },426 }},427 },428 };429430 const assets = {431 V1: [432 {433 id: {434 Concrete: {435 parents: 0,436 interior: 'Here',437 },438 },439 fun: {440 Fungible: TRANSFER_AMOUNT_RELAY,441 },442 },443 ],444 };445446 const feeAssetItem = 0;447448 const weightLimit = {449 Limited: 5_000_000_000,450 };451452 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);453 const events = await submitTransactionAsync(bob, tx);454 const result = getGenericResult(events);455 expect(result.success).to.be.true;456 }, relayApiOptions);457 458459 await usingApi(async (api) => {460 await waitNewBlocks(api, 3);461462 [balanceBobAfter] = await getBalance(api, [bob.address]);463 balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);464 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 465 console.log(466 'Relay (Westend) to Opal transaction fees: %s OPL',467 bigIntToDecimals(balanceBobAfter - balanceBobBefore),468 );469 console.log(470 'Relay (Westend) to Opal transaction fees: %s WND',471 bigIntToDecimals(wndFee, WESTMINT_DECIMALS),472 );473 expect(balanceBobBefore == balanceBobAfter).to.be.true;474 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;475 }, uniqueApiOptions2);476477 });478479 it('Should connect and send Relay token back', async () => {480 const uniqueApiOptions: ApiOptions = {481 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),482 };483484 await usingApi(async (api) => {485 const destination = {486 V1: {487 parents: 1,488 interior: {X2: [489 {490 Parachain: STATEMINE_CHAIN,491 },492 {493 AccountId32: {494 network: 'Any',495 id: bob.addressRaw,496 },497 },498 ]},499 },500 };501502 const currencies = [503 [504 {505 NativeAssetId: 'Parent',506 },507 50_000_000_000_000_000n,508 ]];509510 const feeItem = 0;511 const destWeight = 500000000000;512513 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);514 const events = await submitTransactionAsync(bob, tx);515 const result = getGenericResult(events);516 expect(result.success).to.be.true;517518 [balanceBobFinal] = await getBalance(api, [bob.address]);519 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);520521 }, uniqueApiOptions);522 });523524});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 {bigIntToDecimals, describe_xcm, 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 WESTMINT_DECIMALS = 12;4748const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4950// 10,000.00 (ten thousands) USDT51const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 5253describe_xcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {54 let alice: IKeyringPair;55 let bob: IKeyringPair;56 57 let balanceStmnBefore: bigint;58 let balanceStmnAfter: bigint;5960 let balanceOpalBefore: bigint;61 let balanceOpalAfter: bigint;62 let balanceOpalFinal: bigint;6364 let balanceBobBefore: bigint;65 let balanceBobAfter: bigint;66 let balanceBobFinal: bigint;6768 let balanceBobRelayTokenBefore: bigint;69 let balanceBobRelayTokenAfter: bigint;707172 before(async () => {73 await usingApi(async (api, privateKeyWrapper) => {74 alice = privateKeyWrapper('//Alice');75 bob = privateKeyWrapper('//Bob'); // funds donor76 });7778 const statemineApiOptions: ApiOptions = {79 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),80 };8182 const uniqueApiOptions: ApiOptions = {83 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),84 };8586 const relayApiOptions: ApiOptions = {87 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),88 };8990 await usingApi(async (api) => {9192 // 350.00 (three hundred fifty) DOT93 const fundingAmount = 3_500_000_000_000; 9495 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);96 const events = await submitTransactionAsync(alice, tx);97 const result = getGenericResult(events);98 expect(result.success).to.be.true;99100 // set metadata101 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);102 const events2 = await submitTransactionAsync(alice, tx2);103 const result2 = getGenericResult(events2);104 expect(result2.success).to.be.true;105106 // mint some amount of asset107 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);108 const events3 = await submitTransactionAsync(alice, tx3);109 const result3 = getGenericResult(events3);110 expect(result3.success).to.be.true;111112 // funding parachain sovereing account (Parachain: 2095)113 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);114 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);115 const events4 = await submitTransactionAsync(bob, tx4);116 const result4 = getGenericResult(events4);117 expect(result4.success).to.be.true;118119 }, statemineApiOptions);120121122 await usingApi(async (api) => {123124 const location = {125 V1: {126 parents: 1,127 interior: {X3: [128 {129 Parachain: STATEMINE_CHAIN,130 },131 {132 PalletInstance: STATEMINE_PALLET_INSTANCE,133 },134 {135 GeneralIndex: ASSET_ID,136 },137 ]},138 },139 };140141 const metadata =142 {143 name: ASSET_ID,144 symbol: ASSET_METADATA_NAME,145 decimals: ASSET_METADATA_DECIMALS,146 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,147 };148 //registerForeignAsset(owner, location, metadata)149 const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);150 const sudoTx = api.tx.sudo.sudo(tx as any);151 const events = await submitTransactionAsync(alice, sudoTx);152 const result = getGenericResult(events);153 expect(result.success).to.be.true;154155 [balanceOpalBefore] = await getBalance(api, [alice.address]);156157 }, uniqueApiOptions);158159160 // Providing the relay currency to the unique sender account161 await usingApi(async (api) => {162 const destination = {163 V1: {164 parents: 0,165 interior: {X1: {166 Parachain: UNIQUE_CHAIN,167 },168 },169 }};170171 const beneficiary = {172 V1: {173 parents: 0,174 interior: {X1: {175 AccountId32: {176 network: 'Any',177 id: alice.addressRaw,178 },179 }},180 },181 };182183 const assets = {184 V1: [185 {186 id: {187 Concrete: {188 parents: 0,189 interior: 'Here',190 },191 },192 fun: {193 Fungible: 50_000_000_000_000_000n,194 },195 },196 ],197 };198199 const feeAssetItem = 0;200201 const weightLimit = {202 Limited: 5_000_000_000,203 };204205 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);206 const events = await submitTransactionAsync(alice, tx);207 const result = getGenericResult(events);208 expect(result.success).to.be.true;209 }, relayApiOptions);210 211 });212213 it('Should connect and send USDT from Westmint to Opal', async () => {214 215 const statemineApiOptions: ApiOptions = {216 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),217 };218219 const uniqueApiOptions: ApiOptions = {220 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),221 };222223 await usingApi(async (api) => {224225 const dest = {226 V1: {227 parents: 1,228 interior: {X1: {229 Parachain: UNIQUE_CHAIN,230 },231 },232 }};233234 const beneficiary = {235 V1: {236 parents: 0,237 interior: {X1: {238 AccountId32: {239 network: 'Any',240 id: alice.addressRaw,241 },242 }},243 },244 };245246 const assets = {247 V1: [248 {249 id: {250 Concrete: {251 parents: 0,252 interior: {253 X2: [254 {255 PalletInstance: STATEMINE_PALLET_INSTANCE,256 },257 {258 GeneralIndex: ASSET_ID,259 }, 260 ]},261 },262 },263 fun: {264 Fungible: TRANSFER_AMOUNT,265 },266 },267 ],268 };269270 const feeAssetItem = 0;271272 const weightLimit = {273 Limited: 5000000000,274 };275276 [balanceStmnBefore] = await getBalance(api, [alice.address]);277278 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);279 const events = await submitTransactionAsync(alice, tx);280 const result = getGenericResult(events);281 expect(result.success).to.be.true;282283 [balanceStmnAfter] = await getBalance(api, [alice.address]);284285 // common good parachain take commission in it native token286 console.log(287 'Opal to Westmint transaction fees on Westmint: %s WND',288 bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),289 );290 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;291292 }, statemineApiOptions);293294295 // ensure that asset has been delivered296 await usingApi(async (api) => {297 await waitNewBlocks(api, 3);298 // expext collection id will be with id 1299 const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();300301 [balanceOpalAfter] = await getBalance(api, [alice.address]);302303 // commission has not paid in USDT token304 expect(free == TRANSFER_AMOUNT).to.be.true;305 console.log(306 'Opal to Westmint transaction fees on Opal: %s USDT',307 bigIntToDecimals(TRANSFER_AMOUNT - free),308 );309 // ... and parachain native token310 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;311 console.log(312 'Opal to Westmint transaction fees on Opal: %s WND',313 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),314 );315316 }, uniqueApiOptions);317 318 });319320 it('Should connect and send USDT from Unique to Statemine back', async () => {321322 const uniqueApiOptions: ApiOptions = {323 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),324 };325326 const statemineApiOptions: ApiOptions = {327 provider: new WsProvider('ws://127.0.0.1:' + STATEMINE_PORT),328 };329330 await usingApi(async (api) => {331 const destination = {332 V1: {333 parents: 1,334 interior: {X2: [335 {336 Parachain: STATEMINE_CHAIN,337 },338 {339 AccountId32: {340 network: 'Any',341 id: alice.addressRaw,342 },343 },344 ]},345 },346 };347348 const currencies: [any, bigint][] = [349 [350 {351 ForeignAssetId: 0,352 },353 //10_000_000_000_000_000n,354 TRANSFER_AMOUNT,355 ], 356 [357 {358 NativeAssetId: 'Parent',359 },360 400_000_000_000_000n,361 ],362 ];363364 const feeItem = 1;365 const destWeight = 500000000000;366367 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);368 const events = await submitTransactionAsync(alice, tx);369 const result = getGenericResult(events);370 expect(result.success).to.be.true;371 372 // the commission has been paid in parachain native token373 [balanceOpalFinal] = await getBalance(api, [alice.address]);374 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;375 }, uniqueApiOptions);376377 await usingApi(async (api) => {378 await waitNewBlocks(api, 3);379 380 // The USDT token never paid fees. Its amount not changed from begin value.381 // Also check that xcm transfer has been succeeded 382 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;383 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;384 }, statemineApiOptions);385 });386387 it('Should connect and send Relay token to Unique', async () => {388389 const uniqueApiOptions: ApiOptions = {390 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),391 };392393 const uniqueApiOptions2: ApiOptions = {394 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),395 };396397 const relayApiOptions: ApiOptions = {398 provider: new WsProvider('ws://127.0.0.1:' + RELAY_PORT),399 };400401 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;402403 await usingApi(async (api) => {404 [balanceBobBefore] = await getBalance(api, [bob.address]);405 balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);406407 }, uniqueApiOptions);408409 // Providing the relay currency to the unique sender account410 await usingApi(async (api) => {411 const destination = {412 V1: {413 parents: 0,414 interior: {X1: {415 Parachain: UNIQUE_CHAIN,416 },417 },418 }};419420 const beneficiary = {421 V1: {422 parents: 0,423 interior: {X1: {424 AccountId32: {425 network: 'Any',426 id: bob.addressRaw,427 },428 }},429 },430 };431432 const assets = {433 V1: [434 {435 id: {436 Concrete: {437 parents: 0,438 interior: 'Here',439 },440 },441 fun: {442 Fungible: TRANSFER_AMOUNT_RELAY,443 },444 },445 ],446 };447448 const feeAssetItem = 0;449450 const weightLimit = {451 Limited: 5_000_000_000,452 };453454 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);455 const events = await submitTransactionAsync(bob, tx);456 const result = getGenericResult(events);457 expect(result.success).to.be.true;458 }, relayApiOptions);459 460461 await usingApi(async (api) => {462 await waitNewBlocks(api, 3);463464 [balanceBobAfter] = await getBalance(api, [bob.address]);465 balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);466 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 467 console.log(468 'Relay (Westend) to Opal transaction fees: %s OPL',469 bigIntToDecimals(balanceBobAfter - balanceBobBefore),470 );471 console.log(472 'Relay (Westend) to Opal transaction fees: %s WND',473 bigIntToDecimals(wndFee, WESTMINT_DECIMALS),474 );475 expect(balanceBobBefore == balanceBobAfter).to.be.true;476 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;477 }, uniqueApiOptions2);478479 });480481 it('Should connect and send Relay token back', async () => {482 const uniqueApiOptions: ApiOptions = {483 provider: new WsProvider('ws://127.0.0.1:' + UNIQUE_PORT),484 };485486 await usingApi(async (api) => {487 const destination = {488 V1: {489 parents: 1,490 interior: {X2: [491 {492 Parachain: STATEMINE_CHAIN,493 },494 {495 AccountId32: {496 network: 'Any',497 id: bob.addressRaw,498 },499 },500 ]},501 },502 };503504 const currencies: any = [505 [506 {507 NativeAssetId: 'Parent',508 },509 50_000_000_000_000_000n,510 ],511 ];512513 const feeItem = 0;514 const destWeight = 500000000000;515516 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);517 const events = await submitTransactionAsync(bob, tx);518 const result = getGenericResult(events);519 expect(result.success).to.be.true;520521 [balanceBobFinal] = await getBalance(api, [bob.address]);522 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);523524 }, uniqueApiOptions);525 });526527});tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -61,7 +61,7 @@
return parachainApiOptions(RELAY_PORT);
}
-describe_xcm('Integration test: Exchanging tokens with Karura', () => {
+describe_xcm('[XCM] Integration test: Exchanging tokens with Karura', () => {
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
@@ -246,7 +246,7 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id, TRANSFER_AMOUNT, destination, destWeight);
+ const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
const events = await submitTransactionAsync(randomAccount, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
@@ -290,7 +290,7 @@
});
// These tests are relevant only when the foreign asset pallet is disabled
-describe('Integration test: Quartz rejects non-native tokens', () => {
+describe_xcm('[XCM] Integration test: Quartz rejects non-native tokens', () => {
let alice: IKeyringPair;
before(async () => {
@@ -405,7 +405,7 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight);
+ const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
@@ -431,7 +431,7 @@
});
});
-describe_xcm('Integration test: Exchanging QTZ with Moonriver', () => {
+describe_xcm('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
// Quartz constants
let quartzAlice: IKeyringPair;
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -61,7 +61,7 @@
return parachainApiOptions(RELAY_PORT);
}
-describe_xcm('Integration test: Exchanging tokens with Acala', () => {
+describe_xcm('[XCM] Integration test: Exchanging tokens with Acala', () => {
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
@@ -246,7 +246,7 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id, TRANSFER_AMOUNT, destination, destWeight);
+ const tx = api.tx.xTokens.transfer(id as any, TRANSFER_AMOUNT, destination, destWeight);
const events = await submitTransactionAsync(randomAccount, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
@@ -290,7 +290,7 @@
});
// These tests are relevant only when the foreign asset pallet is disabled
-describe('Integration test: Unique rejects non-native tokens', () => {
+describe_xcm('[XCM] Integration test: Unique rejects non-native tokens', () => {
let alice: IKeyringPair;
before(async () => {
@@ -405,7 +405,7 @@
const destWeight = 50000000;
- const tx = api.tx.xTokens.transfer(id, 100_000_000_000, destination, destWeight);
+ const tx = api.tx.xTokens.transfer(id as any, 100_000_000_000, destination, destWeight);
const events = await submitTransactionAsync(alice, tx);
const result = getGenericResult(events);
expect(result.success).to.be.true;
@@ -431,7 +431,7 @@
});
});
-describe_xcm('Integration test: Exchanging UNQ with Moonbeam', () => {
+describe_xcm('[XCM] Integration test: Exchanging UNQ with Moonbeam', () => {
// Unique constants
let uniqueAlice: IKeyringPair;