difftreelog
fix remove deprecated helpers from opal xcm test
in: master
1 file changed
tests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {bigIntToDecimals, paraSiblingSovereignAccount} from './../deprecated-helpers/helpers';19import {itSub, expect, describeXcm, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/playgrounds';2021const STATEMINE_CHAIN = 1000;22const UNIQUE_CHAIN = 2095;2324const RELAY_PORT = '9844';25const STATEMINE_PORT = '9948';2627const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;28const statemineUrl = 'ws://127.0.0.1:' + STATEMINE_PORT;2930const STATEMINE_PALLET_INSTANCE = 50;31const ASSET_ID = 100;32const ASSET_METADATA_DECIMALS = 18;33const ASSET_METADATA_NAME = 'USDT';34const ASSET_METADATA_DESCRIPTION = 'USDT';35const ASSET_METADATA_MINIMAL_BALANCE = 1n;3637const WESTMINT_DECIMALS = 12;3839const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;4041// 10,000.00 (ten thousands) USDT42const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 4344describeXcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {45 let alice: IKeyringPair;46 let bob: IKeyringPair;47 48 let balanceStmnBefore: bigint;49 let balanceStmnAfter: bigint;5051 let balanceOpalBefore: bigint;52 let balanceOpalAfter: bigint;53 let balanceOpalFinal: bigint;5455 let balanceBobBefore: bigint;56 let balanceBobAfter: bigint;57 let balanceBobFinal: bigint;5859 let balanceBobRelayTokenBefore: bigint;60 let balanceBobRelayTokenAfter: bigint;616263 before(async () => {64 await usingPlaygrounds(async (_helper, privateKey) => {65 alice = privateKey('//Alice');66 bob = privateKey('//Bob'); // funds donor67 });6869 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {70 // 350.00 (three hundred fifty) DOT71 const fundingAmount = 3_500_000_000_000n; 7273 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);74 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);75 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);7677 // funding parachain sovereing account (Parachain: 2095)78 const parachainSovereingAccount = await paraSiblingSovereignAccount(UNIQUE_CHAIN);79 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);80 });818283 await usingPlaygrounds(async (helper) => {84 const location = {85 V1: {86 parents: 1,87 interior: {X3: [88 {89 Parachain: STATEMINE_CHAIN,90 },91 {92 PalletInstance: STATEMINE_PALLET_INSTANCE,93 },94 {95 GeneralIndex: ASSET_ID,96 },97 ]},98 },99 };100101 const metadata =102 {103 name: ASSET_ID,104 symbol: ASSET_METADATA_NAME,105 decimals: ASSET_METADATA_DECIMALS,106 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,107 };108 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);109 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);110 });111112113 // Providing the relay currency to the unique sender account114 await usingRelayPlaygrounds(relayUrl, async (helper) => {115 const destination = {116 V1: {117 parents: 0,118 interior: {X1: {119 Parachain: UNIQUE_CHAIN,120 },121 },122 }};123124 const beneficiary = {125 V1: {126 parents: 0,127 interior: {X1: {128 AccountId32: {129 network: 'Any',130 id: alice.addressRaw,131 },132 }},133 },134 };135136 const assets = {137 V1: [138 {139 id: {140 Concrete: {141 parents: 0,142 interior: 'Here',143 },144 },145 fun: {146 Fungible: 50_000_000_000_000_000n,147 },148 },149 ],150 };151152 const feeAssetItem = 0;153 const weightLimit = 5_000_000_000;154155 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);156 });157 158 });159160 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {161 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {162 const dest = {163 V1: {164 parents: 1,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: {190 X2: [191 {192 PalletInstance: STATEMINE_PALLET_INSTANCE,193 },194 {195 GeneralIndex: ASSET_ID,196 }, 197 ]},198 },199 },200 fun: {201 Fungible: TRANSFER_AMOUNT,202 },203 },204 ],205 };206207 const feeAssetItem = 0;208 const weightLimit = 5000000000;209210 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);211 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);212213 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);214215 // common good parachain take commission in it native token216 console.log(217 'Opal to Westmint transaction fees on Westmint: %s WND',218 bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),219 );220 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;221222 });223224225 // ensure that asset has been delivered226 await helper.wait.newBlocks(3);227228 // expext collection id will be with id 1229 const free = await helper.ft.getBalance(1, {Substrate: alice.address});230231 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);232233 // commission has not paid in USDT token234 expect(free == TRANSFER_AMOUNT).to.be.true;235 console.log(236 'Opal to Westmint transaction fees on Opal: %s USDT',237 bigIntToDecimals(TRANSFER_AMOUNT - free),238 );239 // ... and parachain native token240 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;241 console.log(242 'Opal to Westmint transaction fees on Opal: %s WND',243 bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),244 ); 245 });246247 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {248 const destination = {249 V1: {250 parents: 1,251 interior: {X2: [252 {253 Parachain: STATEMINE_CHAIN,254 },255 {256 AccountId32: {257 network: 'Any',258 id: alice.addressRaw,259 },260 },261 ]},262 },263 };264265 const currencies: [any, bigint][] = [266 [267 {268 ForeignAssetId: 0,269 },270 //10_000_000_000_000_000n,271 TRANSFER_AMOUNT,272 ], 273 [274 {275 NativeAssetId: 'Parent',276 },277 400_000_000_000_000n,278 ],279 ];280281 const feeItem = 1;282 const destWeight = 500000000000;283284 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);285 286 // the commission has been paid in parachain native token287 balanceOpalFinal = await helper.balance.getSubstrate(alice.address);288 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;289290 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {291 await helper.wait.newBlocks(3);292 293 // The USDT token never paid fees. Its amount not changed from begin value.294 // Also check that xcm transfer has been succeeded 295 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;296 });297 });298299 itSub('Should connect and send Relay token to Unique', async ({helper}) => {300 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;301302 balanceBobBefore = await helper.balance.getSubstrate(bob.address);303 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});304305 // Providing the relay currency to the unique sender account306 await usingRelayPlaygrounds(relayUrl, async (helper) => {307 const destination = {308 V1: {309 parents: 0,310 interior: {X1: {311 Parachain: UNIQUE_CHAIN,312 },313 },314 }};315316 const beneficiary = {317 V1: {318 parents: 0,319 interior: {X1: {320 AccountId32: {321 network: 'Any',322 id: bob.addressRaw,323 },324 }},325 },326 };327328 const assets = {329 V1: [330 {331 id: {332 Concrete: {333 parents: 0,334 interior: 'Here',335 },336 },337 fun: {338 Fungible: TRANSFER_AMOUNT_RELAY,339 },340 },341 ],342 };343344 const feeAssetItem = 0;345 const weightLimit = 5_000_000_000;346347 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);348 });349 350 await helper.wait.newBlocks(3);351352 balanceBobAfter = await helper.balance.getSubstrate(bob.address); 353 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});354355 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 356 console.log(357 'Relay (Westend) to Opal transaction fees: %s OPL',358 bigIntToDecimals(balanceBobAfter - balanceBobBefore),359 );360 console.log(361 'Relay (Westend) to Opal transaction fees: %s WND',362 bigIntToDecimals(wndFee, WESTMINT_DECIMALS),363 );364 expect(balanceBobBefore == balanceBobAfter).to.be.true;365 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;366 });367368 itSub('Should connect and send Relay token back', async ({helper}) => {369 const destination = {370 V1: {371 parents: 1,372 interior: {X2: [373 {374 Parachain: STATEMINE_CHAIN,375 },376 {377 AccountId32: {378 network: 'Any',379 id: bob.addressRaw,380 },381 },382 ]},383 },384 };385386 const currencies: any = [387 [388 {389 NativeAssetId: 'Parent',390 },391 50_000_000_000_000_000n,392 ],393 ];394395 const feeItem = 0;396 const destWeight = 500000000000;397398 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);399400 balanceBobFinal = await helper.balance.getSubstrate(bob.address);401 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);402 });403});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 {IKeyringPair} from '@polkadot/types/types';18import {itSub, expect, describeXcm, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util/playgrounds';1920const STATEMINE_CHAIN = 1000;21const UNIQUE_CHAIN = 2095;2223const RELAY_PORT = '9844';24const STATEMINE_PORT = '9948';2526const relayUrl = 'ws://127.0.0.1:' + RELAY_PORT;27const statemineUrl = 'ws://127.0.0.1:' + STATEMINE_PORT;2829const STATEMINE_PALLET_INSTANCE = 50;30const ASSET_ID = 100;31const ASSET_METADATA_DECIMALS = 18;32const ASSET_METADATA_NAME = 'USDT';33const ASSET_METADATA_DESCRIPTION = 'USDT';34const ASSET_METADATA_MINIMAL_BALANCE = 1n;3536const WESTMINT_DECIMALS = 12;3738const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;3940// 10,000.00 (ten thousands) USDT41const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 4243describeXcm('[XCM] Integration test: Exchanging USDT with Westmint', () => {44 let alice: IKeyringPair;45 let bob: IKeyringPair;46 47 let balanceStmnBefore: bigint;48 let balanceStmnAfter: bigint;4950 let balanceOpalBefore: bigint;51 let balanceOpalAfter: bigint;52 let balanceOpalFinal: bigint;5354 let balanceBobBefore: bigint;55 let balanceBobAfter: bigint;56 let balanceBobFinal: bigint;5758 let balanceBobRelayTokenBefore: bigint;59 let balanceBobRelayTokenAfter: bigint;606162 before(async () => {63 await usingPlaygrounds(async (_helper, privateKey) => {64 alice = privateKey('//Alice');65 bob = privateKey('//Bob'); // funds donor66 });6768 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {69 // 350.00 (three hundred fifty) DOT70 const fundingAmount = 3_500_000_000_000n; 7172 await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);73 await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);74 await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);7576 // funding parachain sovereing account (Parachain: 2095)77 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);78 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);79 });808182 await usingPlaygrounds(async (helper) => {83 const location = {84 V1: {85 parents: 1,86 interior: {X3: [87 {88 Parachain: STATEMINE_CHAIN,89 },90 {91 PalletInstance: STATEMINE_PALLET_INSTANCE,92 },93 {94 GeneralIndex: ASSET_ID,95 },96 ]},97 },98 };99100 const metadata =101 {102 name: ASSET_ID,103 symbol: ASSET_METADATA_NAME,104 decimals: ASSET_METADATA_DECIMALS,105 minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,106 };107 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);108 balanceOpalBefore = await helper.balance.getSubstrate(alice.address);109 });110111112 // Providing the relay currency to the unique sender account113 await usingRelayPlaygrounds(relayUrl, async (helper) => {114 const destination = {115 V1: {116 parents: 0,117 interior: {X1: {118 Parachain: UNIQUE_CHAIN,119 },120 },121 }};122123 const beneficiary = {124 V1: {125 parents: 0,126 interior: {X1: {127 AccountId32: {128 network: 'Any',129 id: alice.addressRaw,130 },131 }},132 },133 };134135 const assets = {136 V1: [137 {138 id: {139 Concrete: {140 parents: 0,141 interior: 'Here',142 },143 },144 fun: {145 Fungible: 50_000_000_000_000_000n,146 },147 },148 ],149 };150151 const feeAssetItem = 0;152 const weightLimit = 5_000_000_000;153154 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);155 });156 157 });158159 itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {160 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {161 const dest = {162 V1: {163 parents: 1,164 interior: {X1: {165 Parachain: UNIQUE_CHAIN,166 },167 },168 }};169170 const beneficiary = {171 V1: {172 parents: 0,173 interior: {X1: {174 AccountId32: {175 network: 'Any',176 id: alice.addressRaw,177 },178 }},179 },180 };181182 const assets = {183 V1: [184 {185 id: {186 Concrete: {187 parents: 0,188 interior: {189 X2: [190 {191 PalletInstance: STATEMINE_PALLET_INSTANCE,192 },193 {194 GeneralIndex: ASSET_ID,195 }, 196 ]},197 },198 },199 fun: {200 Fungible: TRANSFER_AMOUNT,201 },202 },203 ],204 };205206 const feeAssetItem = 0;207 const weightLimit = 5000000000;208209 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);210 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);211212 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);213214 // common good parachain take commission in it native token215 console.log(216 'Opal to Westmint transaction fees on Westmint: %s WND',217 helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),218 );219 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;220221 });222223224 // ensure that asset has been delivered225 await helper.wait.newBlocks(3);226227 // expext collection id will be with id 1228 const free = await helper.ft.getBalance(1, {Substrate: alice.address});229230 balanceOpalAfter = await helper.balance.getSubstrate(alice.address);231232 // commission has not paid in USDT token233 expect(free == TRANSFER_AMOUNT).to.be.true;234 console.log(235 'Opal to Westmint transaction fees on Opal: %s USDT',236 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free),237 );238 // ... and parachain native token239 expect(balanceOpalAfter == balanceOpalBefore).to.be.true;240 console.log(241 'Opal to Westmint transaction fees on Opal: %s WND',242 helper.util.bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),243 ); 244 });245246 itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {247 const destination = {248 V1: {249 parents: 1,250 interior: {X2: [251 {252 Parachain: STATEMINE_CHAIN,253 },254 {255 AccountId32: {256 network: 'Any',257 id: alice.addressRaw,258 },259 },260 ]},261 },262 };263264 const currencies: [any, bigint][] = [265 [266 {267 ForeignAssetId: 0,268 },269 //10_000_000_000_000_000n,270 TRANSFER_AMOUNT,271 ], 272 [273 {274 NativeAssetId: 'Parent',275 },276 400_000_000_000_000n,277 ],278 ];279280 const feeItem = 1;281 const destWeight = 500000000000;282283 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);284 285 // the commission has been paid in parachain native token286 balanceOpalFinal = await helper.balance.getSubstrate(alice.address);287 expect(balanceOpalAfter > balanceOpalFinal).to.be.true;288289 await usingWestmintPlaygrounds(statemineUrl, async (helper) => {290 await helper.wait.newBlocks(3);291 292 // The USDT token never paid fees. Its amount not changed from begin value.293 // Also check that xcm transfer has been succeeded 294 expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;295 });296 });297298 itSub('Should connect and send Relay token to Unique', async ({helper}) => {299 const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;300301 balanceBobBefore = await helper.balance.getSubstrate(bob.address);302 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});303304 // Providing the relay currency to the unique sender account305 await usingRelayPlaygrounds(relayUrl, async (helper) => {306 const destination = {307 V1: {308 parents: 0,309 interior: {X1: {310 Parachain: UNIQUE_CHAIN,311 },312 },313 }};314315 const beneficiary = {316 V1: {317 parents: 0,318 interior: {X1: {319 AccountId32: {320 network: 'Any',321 id: bob.addressRaw,322 },323 }},324 },325 };326327 const assets = {328 V1: [329 {330 id: {331 Concrete: {332 parents: 0,333 interior: 'Here',334 },335 },336 fun: {337 Fungible: TRANSFER_AMOUNT_RELAY,338 },339 },340 ],341 };342343 const feeAssetItem = 0;344 const weightLimit = 5_000_000_000;345346 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);347 });348 349 await helper.wait.newBlocks(3);350351 balanceBobAfter = await helper.balance.getSubstrate(bob.address); 352 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});353354 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 355 console.log(356 'Relay (Westend) to Opal transaction fees: %s OPL',357 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),358 );359 console.log(360 'Relay (Westend) to Opal transaction fees: %s WND',361 helper.util.bigIntToDecimals(wndFee, WESTMINT_DECIMALS),362 );363 expect(balanceBobBefore == balanceBobAfter).to.be.true;364 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;365 });366367 itSub('Should connect and send Relay token back', async ({helper}) => {368 const destination = {369 V1: {370 parents: 1,371 interior: {X2: [372 {373 Parachain: STATEMINE_CHAIN,374 },375 {376 AccountId32: {377 network: 'Any',378 id: bob.addressRaw,379 },380 },381 ]},382 },383 };384385 const currencies: any = [386 [387 {388 NativeAssetId: 'Parent',389 },390 50_000_000_000_000_000n,391 ],392 ];393394 const feeItem = 0;395 const destWeight = 500000000000;396397 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);398399 balanceBobFinal = await helper.balance.getSubstrate(bob.address);400 console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);401 });402});