git.delta.rocks / unique-network / refs/commits / b75652834f32

difftreelog

fix opal xcm logs in test

Daniel Shiposha2022-12-21parent: #29cb492.patch.diff
in: master

1 file changed

modifiedtests/src/xcm/xcmOpal.test.tsdiffbeforeafterboth
before · tests/src/xcm/xcmOpal.test.ts
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 config from '../config';19import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util';2021const STATEMINE_CHAIN = 1000;22const UNIQUE_CHAIN = 2095;2324const relayUrl = config.relayUrl;25const westmintUrl = config.westmintUrl;2627const STATEMINE_PALLET_INSTANCE = 50;28const ASSET_ID = 100;29const ASSET_METADATA_DECIMALS = 18;30const ASSET_METADATA_NAME = 'USDT';31const ASSET_METADATA_DESCRIPTION = 'USDT';32const ASSET_METADATA_MINIMAL_BALANCE = 1n;3334const WESTMINT_DECIMALS = 12;3536const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;3738// 10,000.00 (ten thousands) USDT39const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 4041describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => {42  let alice: IKeyringPair;43  let bob: IKeyringPair;44  45  let balanceStmnBefore: bigint;46  let balanceStmnAfter: bigint;4748  let balanceOpalBefore: bigint;49  let balanceOpalAfter: bigint;50  let balanceOpalFinal: bigint;5152  let balanceBobBefore: bigint;53  let balanceBobAfter: bigint;54  let balanceBobFinal: bigint;5556  let balanceBobRelayTokenBefore: bigint;57  let balanceBobRelayTokenAfter: bigint;585960  before(async () => {61    await usingPlaygrounds(async (_helper, privateKey) => {62      alice = await privateKey('//Alice');63      bob = await privateKey('//Bob'); // funds donor64    });6566    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {67      // 350.00 (three hundred fifty) DOT68      const fundingAmount = 3_500_000_000_000n; 6970      await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);71      await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);72      await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);7374      // funding parachain sovereing account (Parachain: 2095)75      const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);76      await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);77    });787980    await usingPlaygrounds(async (helper) => {81      const location = {82        V1: {83          parents: 1,84          interior: {X3: [85            {86              Parachain: STATEMINE_CHAIN,87            },88            {89              PalletInstance: STATEMINE_PALLET_INSTANCE,90            },91            {92              GeneralIndex: ASSET_ID,93            },94          ]},95        },96      };9798      const metadata =99      {100        name: ASSET_ID,101        symbol: ASSET_METADATA_NAME,102        decimals: ASSET_METADATA_DECIMALS,103        minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,104      };105      await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);106      balanceOpalBefore = await helper.balance.getSubstrate(alice.address);107    });108109110    // Providing the relay currency to the unique sender account111    await usingRelayPlaygrounds(relayUrl, async (helper) => {112      const destination = {113        V1: {114          parents: 0,115          interior: {X1: {116            Parachain: UNIQUE_CHAIN,117          },118          },119        }};120121      const beneficiary = {122        V1: {123          parents: 0,124          interior: {X1: {125            AccountId32: {126              network: 'Any',127              id: alice.addressRaw,128            },129          }},130        },131      };132133      const assets = {134        V1: [135          {136            id: {137              Concrete: {138                parents: 0,139                interior: 'Here',140              },141            },142            fun: {143              Fungible: 50_000_000_000_000_000n,144            },145          },146        ],147      };148149      const feeAssetItem = 0;150151      await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});152    });153  154  });155156  itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {157    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {158      const dest = {159        V1: {160          parents: 1,161          interior: {X1: {162            Parachain: UNIQUE_CHAIN,163          },164          },165        }};166167      const beneficiary = {168        V1: {169          parents: 0,170          interior: {X1: {171            AccountId32: {172              network: 'Any',173              id: alice.addressRaw,174            },175          }},176        },177      };178179      const assets = {180        V1: [181          {182            id: {183              Concrete: {184                parents: 0,185                interior: {186                  X2: [187                    {188                      PalletInstance: STATEMINE_PALLET_INSTANCE,189                    },190                    {191                      GeneralIndex: ASSET_ID,192                    }, 193                  ]},194              },195            },196            fun: {197              Fungible: TRANSFER_AMOUNT,198            },199          },200        ],201      };202203      const feeAssetItem = 0;204205      balanceStmnBefore = await helper.balance.getSubstrate(alice.address);206      await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, {Unlimited: null});207208      balanceStmnAfter = await helper.balance.getSubstrate(alice.address);209210      // common good parachain take commission in it native token211      console.log(212        'Opal to Westmint transaction fees on Westmint: %s WND',213        helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),214      );215      expect(balanceStmnBefore > balanceStmnAfter).to.be.true;216217    });218219220    // ensure that asset has been delivered221    await helper.wait.newBlocks(3);222223    // expext collection id will be with id 1224    const free = await helper.ft.getBalance(1, {Substrate: alice.address});225226    balanceOpalAfter = await helper.balance.getSubstrate(alice.address);227228    // commission has not paid in USDT token229    expect(free == TRANSFER_AMOUNT).to.be.true;230    console.log(231      'Opal to Westmint transaction fees on Opal: %s USDT',232      helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free),233    );234    // ... and parachain native token235    expect(balanceOpalAfter == balanceOpalBefore).to.be.true;236    console.log(237      'Opal to Westmint transaction fees on Opal: %s WND',238      helper.util.bigIntToDecimals(balanceOpalAfter - balanceOpalBefore, WESTMINT_DECIMALS),239    );    240  });241242  itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {243    const destination = {244      V1: {245        parents: 1,246        interior: {X2: [247          {248            Parachain: STATEMINE_CHAIN,249          },250          {251            AccountId32: {252              network: 'Any',253              id: alice.addressRaw,254            },255          },256        ]},257      },258    };259260    const currencies: [any, bigint][] = [261      [262        {263          ForeignAssetId: 0,264        },265        //10_000_000_000_000_000n,266        TRANSFER_AMOUNT,267      ], 268      [269        {270          NativeAssetId: 'Parent',271        },272        400_000_000_000_000n,273      ],274    ];275276    const feeItem = 1;277278    await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, {Unlimited: null});279    280    // the commission has been paid in parachain native token281    balanceOpalFinal = await helper.balance.getSubstrate(alice.address);282    expect(balanceOpalAfter > balanceOpalFinal).to.be.true;283284    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {285      await helper.wait.newBlocks(3);286      287      // The USDT token never paid fees. Its amount not changed from begin value.288      // Also check that xcm transfer has been succeeded 289      expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;290    });291  });292293  itSub('Should connect and send Relay token to Unique', async ({helper}) => {294    const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;295296    balanceBobBefore = await helper.balance.getSubstrate(bob.address);297    balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});298299    // Providing the relay currency to the unique sender account300    await usingRelayPlaygrounds(relayUrl, async (helper) => {301      const destination = {302        V1: {303          parents: 0,304          interior: {X1: {305            Parachain: UNIQUE_CHAIN,306          },307          },308        }};309310      const beneficiary = {311        V1: {312          parents: 0,313          interior: {X1: {314            AccountId32: {315              network: 'Any',316              id: bob.addressRaw,317            },318          }},319        },320      };321322      const assets = {323        V1: [324          {325            id: {326              Concrete: {327                parents: 0,328                interior: 'Here',329              },330            },331            fun: {332              Fungible: TRANSFER_AMOUNT_RELAY,333            },334          },335        ],336      };337338      const feeAssetItem = 0;339340      await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});341    });342  343    await helper.wait.newBlocks(3);344345    balanceBobAfter = await helper.balance.getSubstrate(bob.address);  346    balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});347348    const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 349    console.log(350      'Relay (Westend) to Opal transaction fees: %s OPL',351      helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),352    );353    console.log(354      'Relay (Westend) to Opal transaction fees: %s WND',355      helper.util.bigIntToDecimals(wndFee, WESTMINT_DECIMALS),356    );357    expect(balanceBobBefore == balanceBobAfter).to.be.true;358    expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;359  });360361  itSub('Should connect and send Relay token back', async ({helper}) => {362    const destination = {363      V1: {364        parents: 1,365        interior: {X2: [366          {367            Parachain: STATEMINE_CHAIN,368          },369          {370            AccountId32: {371              network: 'Any',372              id: bob.addressRaw,373            },374          },375        ]},376      },377    };378379    const currencies: any = [380      [381        {382          NativeAssetId: 'Parent',383        },384        50_000_000_000_000_000n,385      ],386    ];387388    const feeItem = 0;389390    await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, {Unlimited: null});391392    balanceBobFinal = await helper.balance.getSubstrate(bob.address);393    console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);394  });395});
after · tests/src/xcm/xcmOpal.test.ts
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 config from '../config';19import {itSub, expect, describeXCM, usingPlaygrounds, usingWestmintPlaygrounds, usingRelayPlaygrounds} from '../util';2021const STATEMINE_CHAIN = 1000;22const UNIQUE_CHAIN = 2095;2324const relayUrl = config.relayUrl;25const westmintUrl = config.westmintUrl;2627const STATEMINE_PALLET_INSTANCE = 50;28const ASSET_ID = 100;29const ASSET_METADATA_DECIMALS = 18;30const ASSET_METADATA_NAME = 'USDT';31const ASSET_METADATA_DESCRIPTION = 'USDT';32const ASSET_METADATA_MINIMAL_BALANCE = 1n;3334const WESTMINT_DECIMALS = 12;3536const TRANSFER_AMOUNT = 1_000_000_000_000_000_000n;3738// 10,000.00 (ten thousands) USDT39const ASSET_AMOUNT = 1_000_000_000_000_000_000_000n; 4041describeXCM('[XCM] Integration test: Exchanging USDT with Westmint', () => {42  let alice: IKeyringPair;43  let bob: IKeyringPair;44  45  let balanceStmnBefore: bigint;46  let balanceStmnAfter: bigint;4748  let balanceOpalBefore: bigint;49  let balanceOpalAfter: bigint;50  let balanceOpalFinal: bigint;5152  let balanceBobBefore: bigint;53  let balanceBobAfter: bigint;54  let balanceBobFinal: bigint;5556  let balanceBobRelayTokenBefore: bigint;57  let balanceBobRelayTokenAfter: bigint;585960  before(async () => {61    await usingPlaygrounds(async (_helper, privateKey) => {62      alice = await privateKey('//Alice');63      bob = await privateKey('//Bob'); // funds donor64    });6566    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {67      // 350.00 (three hundred fifty) DOT68      const fundingAmount = 3_500_000_000_000n; 6970      await helper.assets.create(alice, ASSET_ID, alice.address, ASSET_METADATA_MINIMAL_BALANCE);71      await helper.assets.setMetadata(alice, ASSET_ID, ASSET_METADATA_NAME, ASSET_METADATA_DESCRIPTION, ASSET_METADATA_DECIMALS);72      await helper.assets.mint(alice, ASSET_ID, alice.address, ASSET_AMOUNT);7374      // funding parachain sovereing account (Parachain: 2095)75      const parachainSovereingAccount = helper.address.paraSiblingSovereignAccount(UNIQUE_CHAIN);76      await helper.balance.transferToSubstrate(bob, parachainSovereingAccount, fundingAmount);77    });787980    await usingPlaygrounds(async (helper) => {81      const location = {82        V1: {83          parents: 1,84          interior: {X3: [85            {86              Parachain: STATEMINE_CHAIN,87            },88            {89              PalletInstance: STATEMINE_PALLET_INSTANCE,90            },91            {92              GeneralIndex: ASSET_ID,93            },94          ]},95        },96      };9798      const metadata =99      {100        name: ASSET_ID,101        symbol: ASSET_METADATA_NAME,102        decimals: ASSET_METADATA_DECIMALS,103        minimalBalance: ASSET_METADATA_MINIMAL_BALANCE,104      };105      await helper.getSudo().foreignAssets.register(alice, alice.address, location, metadata);106      balanceOpalBefore = await helper.balance.getSubstrate(alice.address);107    });108109110    // Providing the relay currency to the unique sender account111    await usingRelayPlaygrounds(relayUrl, async (helper) => {112      const destination = {113        V1: {114          parents: 0,115          interior: {X1: {116            Parachain: UNIQUE_CHAIN,117          },118          },119        }};120121      const beneficiary = {122        V1: {123          parents: 0,124          interior: {X1: {125            AccountId32: {126              network: 'Any',127              id: alice.addressRaw,128            },129          }},130        },131      };132133      const assets = {134        V1: [135          {136            id: {137              Concrete: {138                parents: 0,139                interior: 'Here',140              },141            },142            fun: {143              Fungible: 50_000_000_000_000_000n,144            },145          },146        ],147      };148149      const feeAssetItem = 0;150151      await helper.xcm.limitedReserveTransferAssets(alice, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});152    });153  154  });155156  itSub('Should connect and send USDT from Westmint to Opal', async ({helper}) => {157    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {158      const dest = {159        V1: {160          parents: 1,161          interior: {X1: {162            Parachain: UNIQUE_CHAIN,163          },164          },165        }};166167      const beneficiary = {168        V1: {169          parents: 0,170          interior: {X1: {171            AccountId32: {172              network: 'Any',173              id: alice.addressRaw,174            },175          }},176        },177      };178179      const assets = {180        V1: [181          {182            id: {183              Concrete: {184                parents: 0,185                interior: {186                  X2: [187                    {188                      PalletInstance: STATEMINE_PALLET_INSTANCE,189                    },190                    {191                      GeneralIndex: ASSET_ID,192                    }, 193                  ]},194              },195            },196            fun: {197              Fungible: TRANSFER_AMOUNT,198            },199          },200        ],201      };202203      const feeAssetItem = 0;204205      balanceStmnBefore = await helper.balance.getSubstrate(alice.address);206      await helper.xcm.limitedReserveTransferAssets(alice, dest, beneficiary, assets, feeAssetItem, {Unlimited: null});207208      balanceStmnAfter = await helper.balance.getSubstrate(alice.address);209210      // common good parachain take commission in it native token211      console.log(212        'Opal to Westmint transaction fees on Westmint: %s WND',213        helper.util.bigIntToDecimals(balanceStmnBefore - balanceStmnAfter, WESTMINT_DECIMALS),214      );215      expect(balanceStmnBefore > balanceStmnAfter).to.be.true;216217    });218219220    // ensure that asset has been delivered221    await helper.wait.newBlocks(3);222223    // expext collection id will be with id 1224    const free = await helper.ft.getBalance(1, {Substrate: alice.address});225226    balanceOpalAfter = await helper.balance.getSubstrate(alice.address);227228    console.log(229      'Opal to Westmint transaction fees on Opal: %s USDT',230      helper.util.bigIntToDecimals(TRANSFER_AMOUNT - free, ASSET_METADATA_DECIMALS),231    );232    console.log(233      'Opal to Westmint transaction fees on Opal: %s OPL',234      helper.util.bigIntToDecimals(balanceOpalAfter - balanceOpalBefore),235    );236237    // commission has not paid in USDT token238    expect(free == TRANSFER_AMOUNT).to.be.true;239    // ... and parachain native token240    expect(balanceOpalAfter == balanceOpalBefore).to.be.true;241  });242243  itSub('Should connect and send USDT from Unique to Statemine back', async ({helper}) => {244    const destination = {245      V1: {246        parents: 1,247        interior: {X2: [248          {249            Parachain: STATEMINE_CHAIN,250          },251          {252            AccountId32: {253              network: 'Any',254              id: alice.addressRaw,255            },256          },257        ]},258      },259    };260261    const currencies: [any, bigint][] = [262      [263        {264          ForeignAssetId: 0,265        },266        //10_000_000_000_000_000n,267        TRANSFER_AMOUNT,268      ], 269      [270        {271          NativeAssetId: 'Parent',272        },273        400_000_000_000_000n,274      ],275    ];276277    const feeItem = 1;278279    await helper.xTokens.transferMulticurrencies(alice, currencies, feeItem, destination, {Unlimited: null});280    281    // the commission has been paid in parachain native token282    balanceOpalFinal = await helper.balance.getSubstrate(alice.address);283    expect(balanceOpalAfter > balanceOpalFinal).to.be.true;284285    await usingWestmintPlaygrounds(westmintUrl, async (helper) => {286      await helper.wait.newBlocks(3);287      288      // The USDT token never paid fees. Its amount not changed from begin value.289      // Also check that xcm transfer has been succeeded 290      expect((await helper.assets.account(ASSET_ID, alice.address))! == ASSET_AMOUNT).to.be.true;291    });292  });293294  itSub('Should connect and send Relay token to Unique', async ({helper}) => {295    const TRANSFER_AMOUNT_RELAY = 50_000_000_000_000_000n;296297    balanceBobBefore = await helper.balance.getSubstrate(bob.address);298    balanceBobRelayTokenBefore = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});299300    // Providing the relay currency to the unique sender account301    await usingRelayPlaygrounds(relayUrl, async (helper) => {302      const destination = {303        V1: {304          parents: 0,305          interior: {X1: {306            Parachain: UNIQUE_CHAIN,307          },308          },309        }};310311      const beneficiary = {312        V1: {313          parents: 0,314          interior: {X1: {315            AccountId32: {316              network: 'Any',317              id: bob.addressRaw,318            },319          }},320        },321      };322323      const assets = {324        V1: [325          {326            id: {327              Concrete: {328                parents: 0,329                interior: 'Here',330              },331            },332            fun: {333              Fungible: TRANSFER_AMOUNT_RELAY,334            },335          },336        ],337      };338339      const feeAssetItem = 0;340341      await helper.xcm.limitedReserveTransferAssets(bob, destination, beneficiary, assets, feeAssetItem, {Unlimited: null});342    });343  344    await helper.wait.newBlocks(3);345346    balanceBobAfter = await helper.balance.getSubstrate(bob.address);  347    balanceBobRelayTokenAfter = await helper.tokens.accounts(bob.address, {NativeAssetId: 'Parent'});348349    const wndFee = balanceBobRelayTokenAfter - TRANSFER_AMOUNT_RELAY - balanceBobRelayTokenBefore; 350    console.log(351      'Relay (Westend) to Opal transaction fees: %s OPL',352      helper.util.bigIntToDecimals(balanceBobAfter - balanceBobBefore),353    );354    console.log(355      'Relay (Westend) to Opal transaction fees: %s WND',356      helper.util.bigIntToDecimals(wndFee, WESTMINT_DECIMALS),357    );358    expect(balanceBobBefore == balanceBobAfter).to.be.true;359    expect(balanceBobRelayTokenBefore < balanceBobRelayTokenAfter).to.be.true;360  });361362  itSub('Should connect and send Relay token back', async ({helper}) => {363    const destination = {364      V1: {365        parents: 1,366        interior: {X2: [367          {368            Parachain: STATEMINE_CHAIN,369          },370          {371            AccountId32: {372              network: 'Any',373              id: bob.addressRaw,374            },375          },376        ]},377      },378    };379380    const currencies: any = [381      [382        {383          NativeAssetId: 'Parent',384        },385        50_000_000_000_000_000n,386      ],387    ];388389    const feeItem = 0;390391    await helper.xTokens.transferMulticurrencies(bob, currencies, feeItem, destination, {Unlimited: null});392393    balanceBobFinal = await helper.balance.getSubstrate(bob.address);394    console.log('Relay (Westend) to Opal transaction fees: %s OPL', balanceBobAfter - balanceBobFinal);395  });396});