git.delta.rocks / unique-network / refs/commits / 253e15bbcbb5

difftreelog

feat(xcm-tests) sending is ready, receiving pending core functionality

Fahrrader2022-01-21parent: #1c8c05f.patch.diff
in: master

3 files changed

modifiedlaunch-config.jsondiffbeforeafterboth
--- a/launch-config.json
+++ b/launch-config.json
@@ -40,6 +40,15 @@
                 "flags": [
                     "-lparachain::candidate_validation=debug"
                 ]
+            },
+            {
+                "name": "eve",
+                "wsPort": 9888,
+                "rpcPort": 9887,
+                "port": 30888,
+                "flags": [
+                    "-lparachain::candidate_validation=debug"
+                ]
             }
         ],
         "genesis": {
@@ -94,8 +103,8 @@
 			"balance": "1000000000000000000000",
 			"nodes": [
 				{
-					"wsPort": 9988,
-					"port": 31200,
+					"wsPort": 9946,
+					"port": 31202,
 					"name": "alice",
                     "flags": [
                         "--rpc-cors=all",
@@ -105,7 +114,26 @@
                     ]
 				}
 			]
-		}
+		},
+        {
+            "bin": "../cumulus/target/release/polkadot-collator",
+            "id": "3000",
+            "chain": "statemint-dev",
+            "balance": "1000000000000000000000000",
+            "nodes": [
+                {
+                    "wsPort": 9947,
+                    "port": 31203,
+                    "name": "alice",
+                    "flags": [
+                        "--rpc-cors=all",
+                        "--unsafe-rpc-external",
+                        "--unsafe-ws-external",
+                        "-lxcm=trace"
+                    ]
+                }
+            ]
+        }
     ],
     "simpleParachains": [],
     "hrmpChannels": [
modifiedtests/package.jsondiffbeforeafterboth
--- a/tests/package.json
+++ b/tests/package.json
@@ -64,6 +64,7 @@
     "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",
     "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",
     "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",
+    "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",
     "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",
     "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",
     "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",
addedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
after · tests/src/xcmTransfer.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';89import {WsProvider} from '@polkadot/api';10import {ApiOptions} from '@polkadot/api/types';11import {IKeyringPair} from '@polkadot/types/types';12import privateKey from './substrate/privateKey';13import usingApi, {submitTransactionAsync} from './substrate/substrate-api';14import {getGenericResult} from './util/helpers';15import waitNewBlocks from './substrate/wait-new-blocks';16import getBalance from './substrate/get-balance';17import {alicesPublicKey} from './accounts';1819chai.use(chaiAsPromised);20const expect = chai.expect;2122const UNIQUE_CHAIN = 1000;23const KARURA_CHAIN = 2000;24const KARURA_PORT = '9946';2526describe('Integration test: Exchanging QTZ/OPL with Karura', () => {27  let alice: IKeyringPair;28  29  before(async () => {30    await usingApi(async () => {31      alice = privateKey('//Alice');32    });3334    const karuraApiOptions: ApiOptions = {35      provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT),36    };3738    await usingApi(async (api) => {39      const destination = {40        V0: {41          X2: [42            'Parent',43            {44              Parachain: UNIQUE_CHAIN,45            },46          ],47        },48      };4950      const metadata =51      {52        name: 'OPL',53        symbol: 'OPL',54        decimals: 15,55        minimalBalance: 1,56      };5758      const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);59      const sudoTx = api.tx.sudo.sudo(tx as any);60      const events = await submitTransactionAsync(alice, sudoTx);61      const result = getGenericResult(events);62      expect(result.success).to.be.true;63    }, karuraApiOptions);64  });6566  it('Should connect and send OPL to Karura', async () => {67    let balanceOnKaruraBefore: bigint;68    69    await usingApi(async (api) => {70      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;71      balanceOnKaruraBefore = free;72    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});7374    await usingApi(async (api) => {75      const destination = {76        V0: {77          X2: [78            'Parent',79            {80              Parachain: KARURA_CHAIN,81            },82          ],83        },84      };8586      const beneficiary = {87        V0: {88          X1: {89            AccountId32: {90              network: 'Any',91              id: alice.addressRaw,92            },93          },94        },95      };9697      const assets = {98        V1: [99          {100            id: {101              Concrete: {102                parents: 0,103                interior: 'Here',104              },105            },106            fun: {107              Fungible: 5000000000,108            },109          },110        ],111      };112113      const feeAssetItem = 0;114115      const weightLimit = {116        Limited: 5000000000,117      };118119      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);120      const events = await submitTransactionAsync(alice, tx);121      const result = getGenericResult(events);122      expect(result.success).to.be.true;123    });124125    await usingApi(async (api) => {126      // todo do something about instant sealing, where there might not be any new blocks127      await waitNewBlocks(api, 1);128      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;129      expect(free > balanceOnKaruraBefore).to.be.true;130    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});131  });132133  /// TODO Under construction. The test won't pass.134  it.skip('Should connect to Karura and send OPL back', async () => {135    let balanceBefore: bigint;136    137    await usingApi(async (api) => {138      [balanceBefore] = await getBalance(api, [alicesPublicKey]);139    });140141    await usingApi(async (api) => {142      const destination = {143        V0: {144          X2: [145            'Parent',146            {147              Parachain: UNIQUE_CHAIN,148            },149          ],150        },151      };152153      const beneficiary = {154        V0: {155          X1: {156            AccountId32: {157              network: 'Any',158              id: alice.addressRaw,159            },160          },161        },162      };163164      const assets = {165        V1: [166          {167            id: {168              Concrete: {169                parents: 0,170                interior: 'Here',171              },172            },173            fun: {174              Fungible: 5000000000,175            },176          },177        ],178      };179180      const feeAssetItem = 0;181182      const weightLimit = {183        Limited: 5000000000,184      };185186      // todo The functionality to be tested is not complete yet. The metadata above are subject to change, as is the transaction below.187      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);188      const events = await submitTransactionAsync(alice, tx);189      const result = getGenericResult(events);190      expect(result.success).to.be.true;191    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});192193    await usingApi(async (api) => {194      // todo do something about instant sealing, where there might not be any new blocks195      await waitNewBlocks(api, 1);196      const [balanceAfter] = await getBalance(api, [alicesPublicKey]);197      expect(balanceAfter > balanceBefore).to.be.true;198    });199  });200});