difftreelog
fix parse bitint to decimals
in: master
4 files changed
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -103,6 +103,24 @@
return api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();
}
+export function bigIntToDecimals(number: bigint, decimals = 18): string {
+ let numberStr = number.toString();
+ console.log('[0] str = ', numberStr);
+
+ // Get rid of `n` at the end
+ numberStr = numberStr.substring(0, numberStr.length - 1);
+ console.log('[1] str = ', numberStr);
+
+ const dotPos = numberStr.length - decimals;
+ if (dotPos <= 0) {
+ return '0.' + numberStr;
+ } else {
+ const intPart = numberStr.substring(0, dotPos);
+ const fractPart = numberStr.substring(dotPos);
+ return intPart + '.' + fractPart;
+ }
+}
+
export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {
if (typeof input === 'string') {
if (input.length >= 47) {
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 = '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});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, 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 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.foreingAssets.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});tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -21,7 +21,7 @@
import {ApiOptions} from '@polkadot/api/types';
import {IKeyringPair} from '@polkadot/types/types';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers';
+import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../util/helpers';
import {MultiLocation} from '@polkadot/types/interfaces';
import {blake2AsHex} from '@polkadot/util-crypto';
import waitNewBlocks from '../substrate/wait-new-blocks';
@@ -37,6 +37,8 @@
const KARURA_PORT = 9946;
const MOONRIVER_PORT = 9947;
+const KARURA_DECIMALS = 12;
+
const TRANSFER_AMOUNT = 2000000000000000000000000n;
function parachainApiOptions(port: number): ApiOptions {
@@ -182,7 +184,7 @@
[balanceQuartzTokenMiddle] = await getBalance(api, [randomAccount.address]);
const qtzFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', qtzFees);
+ console.log('[Quartz -> Karura] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
expect(qtzFees > 0n).to.be.true;
});
@@ -198,8 +200,11 @@
const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
- console.log('[Quartz -> Karura] transaction fees on Karura: %s KAR', karFees);
- console.log('[Quartz -> Karura] income %s QTZ', qtzIncomeTransfer);
+ console.log('
+ [Quartz -> Karura] transaction fees on Karura: %s KAR',
+ bigIntToDecimals(karFees, KARURA_DECIMALS),
+ );
+ console.log('[Quartz -> Karura] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
expect(karFees == 0n).to.be.true;
expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
@@ -249,8 +254,11 @@
const karFees = balanceKaruraTokenMiddle - balanceKaruraTokenFinal;
const qtzOutcomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenFinal;
- console.log('[Karura -> Quartz] transaction fees on Karura: %s KAR', karFees);
- console.log('[Karura -> Quartz] outcome %s QTZ', qtzOutcomeTransfer);
+ console.log(
+ '[Karura -> Quartz] transaction fees on Karura: %s KAR',
+ bigIntToDecimals(karFees, KARURA_DECIMALS),
+ );
+ console.log('[Karura -> Quartz] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
expect(karFees > 0).to.be.true;
expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
@@ -266,10 +274,10 @@
const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
expect(actuallyDelivered > 0).to.be.true;
- console.log('[Karura -> Quartz] actually delivered %s QTZ', actuallyDelivered);
+ console.log('[Karura -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', qtzFees);
+ console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
expect(qtzFees == 0n).to.be.true;
});
});
@@ -581,7 +589,7 @@
expect(balanceQuartzTokenMiddle < balanceQuartzTokenInit).to.be.true;
const transactionFees = balanceQuartzTokenInit - balanceQuartzTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', transactionFees);
+ console.log('[Quartz -> Moonriver] transaction fees on Quartz: %s QTZ', bigIntToDecimals(transactionFees));
expect(transactionFees > 0).to.be.true;
});
@@ -592,7 +600,7 @@
[balanceMovrTokenMiddle] = await getBalance(api, [randomAccountMoonriver.address]);
const movrFees = balanceMovrTokenInit - balanceMovrTokenMiddle;
- console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR', movrFees);
+ console.log('[Quartz -> Moonriver] transaction fees on Moonriver: %s MOVR',bigIntToDecimals(movrFees));
expect(movrFees == 0n).to.be.true;
const qtzRandomAccountAsset = (
@@ -601,7 +609,7 @@
balanceForeignQtzTokenMiddle = BigInt(qtzRandomAccountAsset['balance']);
const qtzIncomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenInit;
- console.log('[Quartz -> Moonriver] income %s QTZ', qtzIncomeTransfer);
+ console.log('[Quartz -> Moonriver] income %s QTZ', bigIntToDecimals(qtzIncomeTransfer));
expect(qtzIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
moonriverOptions(),
@@ -647,7 +655,7 @@
[balanceMovrTokenFinal] = await getBalance(api, [randomAccountMoonriver.address]);
const movrFees = balanceMovrTokenMiddle - balanceMovrTokenFinal;
- console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', movrFees);
+ console.log('[Moonriver -> Quartz] transaction fees on Moonriver: %s MOVR', bigIntToDecimals(movrFees));
expect(movrFees > 0).to.be.true;
const qtzRandomAccountAsset = (
@@ -659,7 +667,7 @@
balanceForeignQtzTokenFinal = 0n;
const qtzOutcomeTransfer = balanceForeignQtzTokenMiddle - balanceForeignQtzTokenFinal;
- console.log('[Quartz -> Moonriver] outcome %s QTZ', qtzOutcomeTransfer);
+ console.log('[Quartz -> Moonriver] outcome %s QTZ', bigIntToDecimals(qtzOutcomeTransfer));
expect(qtzOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
moonriverOptions(),
@@ -672,10 +680,10 @@
const actuallyDelivered = balanceQuartzTokenFinal - balanceQuartzTokenMiddle;
expect(actuallyDelivered > 0).to.be.true;
- console.log('[Moonriver -> Quartz] actually delivered %s QTZ', actuallyDelivered);
+ console.log('[Moonriver -> Quartz] actually delivered %s QTZ', bigIntToDecimals(actuallyDelivered));
const qtzFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', qtzFees);
+ console.log('[Moonriver -> Quartz] transaction fees on Quartz: %s QTZ', bigIntToDecimals(qtzFees));
expect(qtzFees == 0n).to.be.true;
});
});
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -21,7 +21,7 @@
import {ApiOptions} from '@polkadot/api/types';
import {IKeyringPair} from '@polkadot/types/types';
import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';
-import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm} from '../util/helpers';
+import {getGenericResult, generateKeyringPair, waitEvent, describe_xcm, bigIntToDecimals} from '../util/helpers';
import {MultiLocation} from '@polkadot/types/interfaces';
import {blake2AsHex} from '@polkadot/util-crypto';
import waitNewBlocks from '../substrate/wait-new-blocks';
@@ -37,6 +37,8 @@
const ACALA_PORT = 9946;
const MOONBEAM_PORT = 9947;
+const ACALA_DECIMALS = 12;
+
const TRANSFER_AMOUNT = 2000000000000000000000000n;
function parachainApiOptions(port: number): ApiOptions {
@@ -182,7 +184,7 @@
[balanceUniqueTokenMiddle] = await getBalance(api, [randomAccount.address]);
const unqFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', unqFees);
+ console.log('[Unique -> Acala] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
expect(unqFees > 0n).to.be.true;
});
@@ -198,8 +200,11 @@
const acaFees = balanceAcalaTokenInit - balanceAcalaTokenMiddle;
const unqIncomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenInit;
- console.log('[Unique -> Acala] transaction fees on Acala: %s ACA', acaFees);
- console.log('[Unique -> Acala] income %s UNQ', unqIncomeTransfer);
+ console.log(
+ '[Unique -> Acala] transaction fees on Acala: %s ACA',
+ bigIntToDecimals(acaFees, ACALA_DECIMALS),
+ );
+ console.log('[Unique -> Acala] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
expect(acaFees == 0n).to.be.true;
expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
@@ -249,8 +254,11 @@
const acaFees = balanceAcalaTokenMiddle - balanceAcalaTokenFinal;
const unqOutcomeTransfer = balanceUniqueForeignTokenMiddle - balanceUniqueForeignTokenFinal;
- console.log('[Acala -> Unique] transaction fees on Acala: %s ACA', acaFees);
- console.log('[Acala -> Unique] outcome %s UNQ', unqOutcomeTransfer);
+ console.log(
+ '[Acala -> Unique] transaction fees on Acala: %s ACA',
+ bigIntToDecimals(acaFees, ACALA_DECIMALS),
+ );
+ console.log('[Acala -> Unique] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
expect(acaFees > 0).to.be.true;
expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
@@ -266,10 +274,10 @@
const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
expect(actuallyDelivered > 0).to.be.true;
- console.log('[Acala -> Unique] actually delivered %s UNQ', actuallyDelivered);
+ console.log('[Acala -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', unqFees);
+ console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
expect(unqFees == 0n).to.be.true;
});
});
@@ -581,7 +589,7 @@
expect(balanceUniqueTokenMiddle < balanceUniqueTokenInit).to.be.true;
const transactionFees = balanceUniqueTokenInit - balanceUniqueTokenMiddle - TRANSFER_AMOUNT;
- console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', transactionFees);
+ console.log('[Unique -> Moonbeam] transaction fees on Unique: %s UNQ', bigIntToDecimals(transactionFees));
expect(transactionFees > 0).to.be.true;
});
@@ -592,7 +600,7 @@
[balanceGlmrTokenMiddle] = await getBalance(api, [randomAccountMoonbeam.address]);
const glmrFees = balanceGlmrTokenInit - balanceGlmrTokenMiddle;
- console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', glmrFees);
+ console.log('[Unique -> Moonbeam] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
expect(glmrFees == 0n).to.be.true;
const unqRandomAccountAsset = (
@@ -601,7 +609,7 @@
balanceForeignUnqTokenMiddle = BigInt(unqRandomAccountAsset['balance']);
const unqIncomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenInit;
- console.log('[Unique -> Moonbeam] income %s UNQ', unqIncomeTransfer);
+ console.log('[Unique -> Moonbeam] income %s UNQ', bigIntToDecimals(unqIncomeTransfer));
expect(unqIncomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
moonbeamOptions(),
@@ -647,7 +655,7 @@
[balanceGlmrTokenFinal] = await getBalance(api, [randomAccountMoonbeam.address]);
const glmrFees = balanceGlmrTokenMiddle - balanceGlmrTokenFinal;
- console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', glmrFees);
+ console.log('[Moonbeam -> Unique] transaction fees on Moonbeam: %s GLMR', bigIntToDecimals(glmrFees));
expect(glmrFees > 0).to.be.true;
const unqRandomAccountAsset = (
@@ -659,7 +667,7 @@
balanceForeignUnqTokenFinal = 0n;
const unqOutcomeTransfer = balanceForeignUnqTokenMiddle - balanceForeignUnqTokenFinal;
- console.log('[Unique -> Moonbeam] outcome %s UNQ', unqOutcomeTransfer);
+ console.log('[Unique -> Moonbeam] outcome %s UNQ', bigIntToDecimals(unqOutcomeTransfer));
expect(unqOutcomeTransfer == TRANSFER_AMOUNT).to.be.true;
},
moonbeamOptions(),
@@ -672,10 +680,10 @@
const actuallyDelivered = balanceUniqueTokenFinal - balanceUniqueTokenMiddle;
expect(actuallyDelivered > 0).to.be.true;
- console.log('[Moonbeam -> Unique] actually delivered %s UNQ', actuallyDelivered);
+ console.log('[Moonbeam -> Unique] actually delivered %s UNQ', bigIntToDecimals(actuallyDelivered));
const unqFees = TRANSFER_AMOUNT - actuallyDelivered;
- console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', unqFees);
+ console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', bigIntToDecimals(unqFees));
expect(unqFees == 0n).to.be.true;
});
});