difftreelog
refactor use playgrounds in opal xcm tests
in: master
1 file changed
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {executeTransaction} from './../substrate/substrate-api';19import {bigIntToDecimals, getGenericResult, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';18import {bigIntToDecimals, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';20import getBalance from './../substrate/get-balance';21import {itSub, expect, describeXcm, usingPlaygrounds} from '../util/playgrounds';19import {itSub, expect, describeXcm, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/playgrounds';222023const STATEMINE_CHAIN = 1000;21const STATEMINE_CHAIN = 1000;24const UNIQUE_CHAIN = 2095;22const UNIQUE_CHAIN = 2095;68 bob = privateKey('//Bob'); // funds donor66 bob = privateKey('//Bob'); // funds donor69 });67 });706871 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {69 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {72 const api = helper.getApi();7374 // 350.00 (three hundred fifty) DOT70 // 350.00 (three hundred fifty) DOT75 const fundingAmount = 3_500_000_000_000; 71 const fundingAmount = 3_500_000_000_000n; 767277 const tx = api.tx.assets.create(ASSET_ID, alice.addressRaw, ASSET_METADATA_MINIMAL_BALANCE);73 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);78 const events = await executeTransaction(api, alice, tx);79 const result = getGenericResult(events);80 expect(result.success).to.be.true;8182 // set metadata83 const tx2 = api.tx.assets.setMetadata(ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);74 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);84 const events2 = await executeTransaction(api, alice, tx2);85 const result2 = getGenericResult(events2);86 expect(result2.success).to.be.true;8788 // mint some amount of asset89 const tx3 = api.tx.assets.mint(ASSET_ID, alice.addressRaw, ASSET_AMOUNT);75 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);90 const events3 = await executeTransaction(api, alice, tx3);91 const result3 = getGenericResult(events3);92 expect(result3.success).to.be.true;937694 // funding parachain sovereing account (Parachain: 2095)77 // funding parachain sovereing account (Parachain: 2095)95 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);78 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);96 const tx4 = api.tx.balances.transfer(parachainSovereingAccount, fundingAmount);79 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);97 const events4 = await executeTransaction(api, bob, tx4);98 const result4 = getGenericResult(events4);99 expect(result4.success).to.be.true;100101 });80 });10281127 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,106 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,128 };107 };129 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);108 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);130 // const tx = api.tx.foreignAssets.registerForeignAsset(alice.addressRaw, location, metadata);131 // const sudoTx = api.tx.sudo.sudo(tx as any);132 // const events = await executeTransaction(api, alice, sudoTx);133 // const result = getGenericResult(events);134 // expect(result.success).to.be.true;135136 // [balanceOpalBefore] = await getBalance(api, [alice.address]);137 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);109 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);138139 });110 });140111141112142 // Providing the relay currency to the unique sender account113 // Providing the relay currency to the unique sender account143 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {114 await usingRelayPlaygrounds(relayUrl, async (helper) => {144 const api = helper.getApi();145146 const destination = {115 const destination = {147 V1: {116 V1: {182151183 const feeAssetItem = 0;152 const feeAssetItem = 0;184185 const weightLimit = {153 const weightLimit = 5_000_000_000;186 Limited: 5_000_000_000,187 };188154189 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);155 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);190 const events = await executeTransaction(api, alice, tx);191 const result = getGenericResult(events);192 expect(result.success).to.be.true;193 });156 });194 157 195 });158 });196159197 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {160 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {198 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {161 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {199 const api = helper.getApi();200201 const dest = {162 const dest = {202 V1: {163 V1: {245206246 const feeAssetItem = 0;207 const feeAssetItem = 0;247248 const weightLimit = {208 const weightLimit = 5000000000;249 Limited: 5000000000,250 };251209252 [balanceStmnBefore] = await getBalance(api, [alice.address]);210 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);253254 const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(dest, beneficiary, assets, feeAssetItem, weightLimit);211 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);255 const events = await executeTransaction(api, alice, tx);256 const result = getGenericResult(events);257 expect(result.success).to.be.true;258212259 [balanceStmnAfter] = await getBalance(api, [alice.address]);213 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);260214261 // common good parachain take commission in it native token215 // common good parachain take commission in it native token262 console.log(216 console.log(269223270224271 // ensure that asset has been delivered225 // ensure that asset has been delivered272 // await waitNewBlocks(api, 3);273 await helper.wait.newBlocks(3);226 await helper.wait.newBlocks(3);274227275 // expext collection id will be with id 1228 // expext collection id will be with id 1276 // const free = (await api.query.fungible.balance(1, normalizeAccountId(alice.address))).toBigInt();277 const free = await helper.ft.getBalance(1, {Substrate: alice.address});229 const free = await helper.ft.getBalance(1, {Substrate: alice.address});278230279 // [balanceOpalAfter] = await getBalance(api, [alice.address]);280 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);231 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);281232282 // commission has not paid in USDT token233 // commission has not paid in USDT token294 });245 });295246296 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {247 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {297 const api = helper.getApi();298299 const destination = {248 const destination = {300 V1: {249 V1: {332 const feeItem = 1;281 const feeItem = 1;333 const destWeight = 500000000000;282 const destWeight = 500000000000;334283335 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);284 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);336 const events = await executeTransaction(api, alice, tx);285 337 const result = getGenericResult(events);338 expect(result.success).to.be.true;339 340 // the commission has been paid in parachain native token286 // the commission has been paid in parachain native token341 [balanceOpalFinal] = await getBalance(api, [alice.address]);287 balanceOpalFinal = await helper.balance.getSubstrate(alice.address);342 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;288 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;343289344 await usingPlaygrounds.atUrl(statemineUrl, async (helper) => {290 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {345 // await waitNewBlocks(api, 3);346 await helper.wait.newBlocks(3);291 await helper.wait.newBlocks(3);347292 348 const api = helper.getApi();349 350 // The USDT token never paid fees. Its amount not changed from begin value.293 // The USDT token never paid fees. Its amount not changed from begin value.351 // Also check that xcm transfer has been succeeded 294 // Also check that xcm transfer has been succeeded 352 const free = ((await api.query.assets.account(100, alice.address)).toHuman()) as any;353 expect(BigInt(free.balance.replace(/,/g, '')) == ASSET_AMOUNT).to.be.true;295 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;354 });296 });355 });297 });356298357 itSub('Should connect and send Relay token to Unique', async ({helper}) => {299 itSub('Should connect and send Relay token to Unique', async ({helper}) => {358 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;300 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;359301360 // [balanceBobBefore] = await getBalance(api, [bob.address]);361 // balanceBobRelayTokenBefore = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);362 balanceBobBefore = await helper.balance.getSubstrate(bob.address);302 balanceBobBefore = await helper.balance.getSubstrate(bob.address);363364 // TODO365 balanceBobRelayTokenBefore = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);303 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});366304367 // Providing the relay currency to the unique sender account305 // Providing the relay currency to the unique sender account368 await usingPlaygrounds.atUrl(relayUrl, async (helper) => {306 await usingRelayPlaygrounds(relayUrl, async (helper) => {369 const api = helper.getApi();370371 const destination = {307 const destination = {372 V1: {308 V1: {407343408 const feeAssetItem = 0;344 const feeAssetItem = 0;409410 const weightLimit = {345 const weightLimit = 5_000_000_000;411 Limited: 5_000_000_000,412 };413346414 const tx = api.tx.xcmPallet.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);347 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);415 const events = await executeTransaction(api, bob, tx);416 const result = getGenericResult(events);417 expect(result.success).to.be.true;418 });348 });419 349 420421 // await waitNewBlocks(api, 3);422 await helper.wait.newBlocks(3);350 await helper.wait.newBlocks(3);423351424 // [balanceBobAfter] = await getBalance(api, [bob.address]);425 // balanceBobRelayTokenAfter = BigInt(((await api.query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);426 balanceBobAfter = await helper.balance.getSubstrate(bob.address);352 balanceBobAfter = await helper.balance.getSubstrate(bob.address); 427 428 // TODO429 balanceBobRelayTokenAfter = BigInt(((await helper.getApi().query.tokens.accounts(bob.addressRaw, {NativeAssetId: 'Parent'})).toJSON() as any).free);353 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});430354431 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 355 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 432 console.log(356 console.log(471 const feeItem = 0;395 const feeItem = 0;472 const destWeight = 500000000000;396 const destWeight = 500000000000;473397474 // TODO475 const api = helper.getApi();476 const tx = api.tx.xTokens.transferMulticurrencies(currencies, feeItem, destination, destWeight);398 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);477 const events = await executeTransaction(api, bob, tx);399478 const result = getGenericResult(events);479 expect(result.success).to.be.true;480481 // [balanceBobFinal] = await getBalance(api, [bob.address]);482 balanceBobFinal = await helper.balance.getSubstrate(bob.address);400 balanceBobFinal = await helper.balance.getSubstrate(bob.address);483 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);401 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);484 });402 });