difftreelog
test statemine usdt exchange
in: master
4 files changed
tests/src/config.tsdiffbeforeafterboth25 moonbeamUrl: process.env.moonbeamUrl || 'ws://127.0.0.1:9947',25 moonbeamUrl: process.env.moonbeamUrl || 'ws://127.0.0.1:9947',26 moonriverUrl: process.env.moonbeamUrl || 'ws://127.0.0.1:9947',26 moonriverUrl: process.env.moonbeamUrl || 'ws://127.0.0.1:9947',27 westmintUrl: process.env.westmintUrl || 'ws://127.0.0.1:9948',27 westmintUrl: process.env.westmintUrl || 'ws://127.0.0.1:9948',28 statemineUrl: process.env.statemineUrl || 'ws://127.0.0.1:9948',29 statemintUrl: process.env.statemintUrl || 'ws://127.0.0.1:9948',28};30};293130export default config;32export default config;tests/src/util/index.tsdiffbeforeafterboth11import config from '../config';11import config from '../config';12import {ChainHelperBase} from './playgrounds/unique';12import {ChainHelperBase} from './playgrounds/unique';13import {ILogger} from './playgrounds/types';13import {ILogger} from './playgrounds/types';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper} from './playgrounds/unique.dev';14import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper} from './playgrounds/unique.dev';151516chai.use(chaiAsPromised);16chai.use(chaiAsPromised);17chai.use(chaiSubset);17chai.use(chaiSubset);65 return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);65 return usingPlaygroundsGeneral<DevWestmintHelper>(DevWestmintHelper, url, code);66};66};6768export const usingStateminePlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {69 return usingPlaygroundsGeneral<DevStatemineHelper>(DevWestmintHelper, url, code);70};7172export const usingStatemintPlaygrounds = (url: string, code: (helper: DevWestmintHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {73 return usingPlaygroundsGeneral<DevStatemintHelper>(DevWestmintHelper, url, code);74};677568export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {76export const usingRelayPlaygrounds = (url: string, code: (helper: DevRelayHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {69 return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);77 return usingPlaygroundsGeneral<DevRelayHelper>(DevRelayHelper, url, code);tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth131 }131 }132}132}133134export class DevStatemineHelper extends DevWestmintHelper {}135136export class DevStatemintHelper extends DevWestmintHelper {}133137134export class DevMoonbeamHelper extends MoonbeamHelper {138export class DevMoonbeamHelper extends MoonbeamHelper {135 account: MoonbeamAccountGroup;139 account: MoonbeamAccountGroup;tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth18import {blake2AsHex} from '@polkadot/util-crypto';18import {blake2AsHex} from '@polkadot/util-crypto';19import config from '../config';19import config from '../config';20import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';20import {XcmV2TraitsOutcome, XcmV2TraitsError} from '../interfaces';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds} from '../util';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds} from '../util';222223const QUARTZ_CHAIN = 2095;23const QUARTZ_CHAIN = 2095;24const STATEMINE_CHAIN = 1000;24const KARURA_CHAIN = 2000;25const KARURA_CHAIN = 2000;25const MOONRIVER_CHAIN = 2023;26const MOONRIVER_CHAIN = 2023;2728const STATEMINE_PALLET_INSTANCE = 50;262927const relayUrl = config.relayUrl;30const relayUrl = config.relayUrl;31const statemineUrl = config.statemineUrl;28const karuraUrl = config.karuraUrl;32const karuraUrl = config.karuraUrl;29const moonriverUrl = config.moonriverUrl;33const moonriverUrl = config.moonriverUrl;303435const STATEMINE_DECIMALS = 12;31const KARURA_DECIMALS = 12;36const KARURA_DECIMALS = 12;323733const TRANSFER_AMOUNT = 2000000000000000000000000n;38const TRANSFER_AMOUNT = 2000000000000000000000000n;3940const USDT_ASSET_ID = 100;41const USDT_ASSET_METADATA_DECIMALS = 18;42const USDT_ASSET_METADATA_NAME = 'USDT';43const USDT_ASSET_METADATA_DESCRIPTION = 'USDT';44const USDT_ASSET_METADATA_MINIMAL_BALANCE = 1n;4546describeXCM('[XCM] Integration test: Exchanging USDT with Statemine', () => {47 let alice: IKeyringPair;48 let bob: IKeyringPair;49 50 let balanceStmnBefore: bigint;51 let balanceStmnAfter: bigint;5253 let balanceQuartzBefore: bigint;54 let balanceQuartzAfter: bigint;55 let balanceQuartzFinal: bigint;5657 let balanceBobBefore: bigint;58 let balanceBobAfter: bigint;59 let balanceBobFinal: bigint;6061 let balanceBobRelayTokenBefore: bigint;62 let balanceBobRelayTokenAfter: bigint;636465 before(async () => {66 await usingPlaygrounds(async (_helper, privateKey) => {67 alice = await privateKey('//Alice');68 bob = await privateKey('//Bob'); // funds donor69 });7071 await usingStateminePlaygrounds(statemineUrl, async (helper) => {72 // 350.00 (three hundred fifty) DOT73 const fundingAmount = 3_500_000_000_000n; 7475 await helper.assets.create(76 alice,77 USDT_ASSET_ID,78 alice.address,79 USDT_ASSET_METADATA_MINIMAL_BALANCE,80 );81 await helper.assets.setMetadata(82 alice,83 USDT_ASSET_ID,84 USDT_ASSET_METADATA_NAME,85 USDT_ASSET_METADATA_DESCRIPTION,86 USDT_ASSET_METADATA_DECIMALS,87 );88 await helper.assets.mint(89 alice,90 USDT_ASSET_ID,91 alice.address,92 TRANSFER_AMOUNT,93 );9495 // funding parachain sovereing account (Parachain: 2095)96 const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(QUARTZ_CHAIN);97 await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);98 });99100101 await usingPlaygrounds(async (helper) => {102 const location = {103 V1: {104 parents: 1,105 interior: {X3: [106 {107 Parachain: STATEMINE_CHAIN,108 },109 {110 PalletInstance: STATEMINE_PALLET_INSTANCE,111 },112 {113 GeneralIndex: USDT_ASSET_ID,114 },115 ]},116 },117 };118119 const metadata =120 {121 name: USDT_ASSET_ID,122 symbol: USDT_ASSET_METADATA_NAME,123 decimals: USDT_ASSET_METADATA_DECIMALS,124 minimalBalance: USDT_ASSET_METADATA_MINIMAL_BALANCE,125 };126 await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);127 balanceQuartzBefore = await helper.balance.getSubstrate(alice.address);128 });129130131 // Providing the relay currency to the unique sender account132 await usingRelayPlaygrounds(relayUrl, async (helper) => {133 const destination = {134 V1: {135 parents: 0,136 interior: {X1: {137 Parachain: QUARTZ_CHAIN,138 },139 },140 }};141142 const beneficiary = {143 V1: {144 parents: 0,145 interior: {X1: {146 AccountId32: {147 network: 'Any',148 id: alice.addressRaw,149 },150 }},151 },152 };153154 const assets = {155 V1: [156 {157 id: {158 Concrete: {159 parents: 0,160 interior: 'Here',161 },162 },163 fun: {164 Fungible: TRANSFER_AMOUNT,165 },166 },167 ],168 };169170 const feeAssetItem = 0;171 const weightLimit = 5_000_000_000;172173 await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, weightLimit);174 });175 176 });177178 itSub('Should connect and send USDT from Statemine to Quartz', async ({helper}) => {179 await usingStateminePlaygrounds(statemineUrl, async (helper) => {180 const dest = {181 V1: {182 parents: 1,183 interior: {X1: {184 Parachain: QUARTZ_CHAIN,185 },186 },187 }};188189 const beneficiary = {190 V1: {191 parents: 0,192 interior: {X1: {193 AccountId32: {194 network: 'Any',195 id: alice.addressRaw,196 },197 }},198 },199 };200201 const assets = {202 V1: [203 {204 id: {205 Concrete: {206 parents: 0,207 interior: {208 X2: [209 {210 PalletInstance: STATEMINE_PALLET_INSTANCE,211 },212 {213 GeneralIndex: USDT_ASSET_ID,214 }, 215 ]},216 },217 },218 fun: {219 Fungible: TRANSFER_AMOUNT,220 },221 },222 ],223 };224225 const feeAssetItem = 0;226 const weightLimit = 5000000000;227228 balanceStmnBefore = await helper.balance.getSubstrate(alice.address);229 await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, weightLimit);230231 balanceStmnAfter = await helper.balance.getSubstrate(alice.address);232233 // common good parachain take commission in it native token234 console.log(235 '[Quartz -> Statemine] transaction fees on Statemine: %s WND',236 helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, STATEMINE_DECIMALS),237 );238 expect(balanceStmnBefore > balanceStmnAfter).to.be.true;239240 });241242243 // ensure that asset has been delivered244 await helper.wait.newBlocks(3);245246 // expext collection id will be with id 1247 const free = await helper.ft.getBalance(1, {Substrate: alice.address});248249 balanceQuartzAfter = await helper.balance.getSubstrate(alice.address);250251 // commission has not paid in USDT token252 expect(free == TRANSFER_AMOUNT).to.be.true;253 console.log(254 '[Quartz -> Statemine] transaction fees on Quartz: %s USDT',255 helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free),256 );257 // ... and parachain native token258 expect(balanceQuartzAfter == balanceQuartzBefore).to.be.true;259 console.log(260 '[Quartz -> Statemine] transaction fees on Quartz: %s WND',261 helper.util.bigIntToDecimals(balanceQuartzAfter - balanceQuartzBefore, STATEMINE_DECIMALS),262 ); 263 });264265 itSub('Should connect and send USDT from Quartz to Statemine back', async ({helper}) => {266 const destination = {267 V1: {268 parents: 1,269 interior: {X2: [270 {271 Parachain: STATEMINE_CHAIN,272 },273 {274 AccountId32: {275 network: 'Any',276 id: alice.addressRaw,277 },278 },279 ]},280 },281 };282283 const currencies: [any, bigint][] = [284 [285 {286 ForeignAssetId: 0,287 },288 //10_000_000_000_000_000n,289 TRANSFER_AMOUNT,290 ], 291 [292 {293 NativeAssetId: 'Parent',294 },295 400_000_000_000_000n,296 ],297 ];298299 const feeItem = 1;300 const destWeight = 500000000000;301302 await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, destWeight);303 304 // the commission has been paid in parachain native token305 balanceQuartzFinal = await helper.balance.getSubstrate(alice.address);306 expect(balanceQuartzAfter > balanceQuartzFinal).to.be.true;307308 await usingStateminePlaygrounds(statemineUrl, async (helper) => {309 await helper.wait.newBlocks(3);310 311 // The USDT token never paid fees. Its amount not changed from begin value.312 // Also check that xcm transfer has been succeeded 313 expect((await helper.assets.account(USDT_ASSET_ID, alice.address))! == TRANSFER_AMOUNT).to.be.true;314 });315 });316317 itSub('Should connect and send Relay token to Quartz', async ({helper}) => {318 balanceBobBefore = await helper.balance.getSubstrate(bob.address);319 balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});320321 // Providing the relay currency to the unique sender account322 await usingRelayPlaygrounds(relayUrl, async (helper) => {323 const destination = {324 V1: {325 parents: 0,326 interior: {X1: {327 Parachain: QUARTZ_CHAIN,328 },329 },330 }};331332 const beneficiary = {333 V1: {334 parents: 0,335 interior: {X1: {336 AccountId32: {337 network: 'Any',338 id: bob.addressRaw,339 },340 }},341 },342 };343344 const assets = {345 V1: [346 {347 id: {348 Concrete: {349 parents: 0,350 interior: 'Here',351 },352 },353 fun: {354 Fungible: TRANSFER_AMOUNT,355 },356 },357 ],358 };359360 const feeAssetItem = 0;361 const weightLimit = 5_000_000_000;362363 await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, weightLimit);364 });365 366 await helper.wait.newBlocks(3);367368 balanceBobAfter = await helper.balance.getSubstrate(bob.address); 369 balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});370371 const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT - balanceBobRelayTokenBefore; 372 console.log(373 '[Relay (Westend) -> Quartz] transaction fees: %s QTZ',374 helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),375 );376 console.log(377 '[Relay (Westend) -> Quartz] transaction fees: %s WND',378 helper.util.bigIntToDecimals(wndFee, STATEMINE_DECIMALS),379 );380 expect(balanceBobBefore == balanceBobAfter).to.be.true;381 expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;382 });383384 itSub('Should connect and send Relay token back', async ({helper}) => {385 const destination = {386 V1: {387 parents: 1,388 interior: {X2: [389 {390 Parachain: STATEMINE_CHAIN,391 },392 {393 AccountId32: {394 network: 'Any',395 id: bob.addressRaw,396 },397 },398 ]},399 },400 };401402 const currencies: any = [403 [404 {405 NativeAssetId: 'Parent',406 },407 TRANSFER_AMOUNT,408 ],409 ];410411 const feeItem = 0;412 const destWeight = 500000000000;413414 await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, destWeight);415416 balanceBobFinal = await helper.balance.getSubstrate(bob.address);417 console.log('[Relay (Westend) to Quartz] transaction fees: %s QTZ', balanceBobAfter - balanceBobFinal);418 });419});3442035describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {421describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {36 let alice: IKeyringPair;422 let alice: IKeyringPair;249 },635 },250 },636 },251 fun: {637 fun: {252 Fungible: 50_000_000_000_000_000n,638 Fungible: TRANSFER_AMOUNT,253 },639 },254 },640 },255 ],641 ],