difftreelog
fix parse bitint to decimals
in: master
4 files changed
tests/src/util/helpers.tsdiffbeforeafterboth103 return api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();103 return api.registry.createType('AccountId', '0x' + number.toString(16).padStart(64, '0')).toJSON();104}104}105106export function bigIntToDecimals(number: bigint, decimals = 18): string {107 let numberStr = number.toString();108 console.log('[0] str = ', numberStr);109110 // Get rid of `n` at the end111 numberStr = numberStr.substring(0, numberStr.length - 1);112 console.log('[1] str = ', numberStr);113114 const dotPos = numberStr.length - decimals;115 if (dotPos <= 0) {116 return '0.' + numberStr;117 } else {118 const intPart = numberStr.substring(0, dotPos);119 const fractPart = numberStr.substring(dotPos);120 return intPart + '.' + fractPart;121 }122}105123106export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {124export function normalizeAccountId(input: string | AccountId | CrossAccountId | IKeyringPair): CrossAccountId {107 if (typeof input === 'string') {125 if (typeof input === 'string') {tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmOpal.test.ts
+++ b/tests/src/xcm/xcmOpal.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, paraSiblingSovereignAccount} from './../util/helpers';
+import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../util/helpers';
import waitNewBlocks from './../substrate/wait-new-blocks';
import {normalizeAccountId} from './../util/helpers';
import getBalance from './../substrate/get-balance';
@@ -43,6 +43,8 @@
const ASSET_METADATA_DESCRIPTION = 'USDT';
const ASSET_METADATA_MINIMAL_BALANCE = 1;
+const WESTMINT_DECIMALS = 12;
+
const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;
// 10,000.00 (ten thousands) USDT
@@ -281,7 +283,10 @@
[balanceStmnAfter] = await getBalance(api, [alice.address]);
// common good parachain take commission in it native token
- console.log('Opal to Westmint transaction fees on Westmint: %s WND', balanceStmnBefore - balanceStmnAfter);
+ console.log(
+ 'Opal to Westmint transaction fees on Westmint: %s WND',
+ bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),
+ );
expect(balanceStmnBefore > balanceStmnAfter).to.be.true;
}, statemineApiOptions);
@@ -297,10 +302,16 @@
// commission has not paid in USDT token
expect(free == TRANSFER_AMOUNT).to.be.true;
- console.log('Opal to Westmint transaction fees on Opal: %s USDT', TRANSFER_AMOUNT - free);
+ console.log(
+ 'Opal to Westmint transaction fees on Opal: %s USDT',
+ bigIntToDecimals(TRANSFER_AMOUNT - free),
+ );
// ... and parachain native token
expect(balanceOpalAfter == balanceOpalBefore).to.be.true;
- console.log('Opal to Westmint transaction fees on Opal: %s WND', balanceOpalAfter - balanceOpalBefore);
+ console.log(
+ 'Opal to Westmint transaction fees on Opal: %s WND',
+ bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),
+ );
}, uniqueApiOptions);
@@ -451,8 +462,14 @@
[balanceBobAfter] = await getBalance(api, [bob.address]);
balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);
const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore;
- console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobBefore);
- console.log('Relay (Westend) to Opal transaction fees: %s WND', wndFee);
+ console.log(
+ 'Relay (Westend) to Opal transaction fees: %s OPL',
+ bigIntToDecimals(balanceBobAfter - balanceBobBefore),
+ );
+ console.log(
+ 'Relay (Westend) to Opal transaction fees: %s WND',
+ bigIntToDecimals(wndFee, WESTMINT_DECIMALS),
+ );
expect(balanceBobBefore == balanceBobAfter).to.be.true;
expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;
}, uniqueApiOptions2);
@@ -504,4 +521,4 @@
}, uniqueApiOptions);
});
-});
\ No newline at end of file
+});
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;
});
});