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
before · tests/package.json
1{2  "name": "unique-tests",3  "version": "1.0.0",4  "description": "Unique Chain Tests",5  "main": "",6  "devDependencies": {7    "@polkadot/dev": "0.63.18",8    "@polkadot/ts": "0.4.12",9    "@polkadot/typegen": "6.6.2-5",10    "@types/chai": "^4.2.22",11    "@types/chai-as-promised": "^7.1.4",12    "@types/mocha": "^9.0.0",13    "@types/node": "^16.11.6",14    "@typescript-eslint/eslint-plugin": "^5.3.0",15    "@typescript-eslint/parser": "^5.3.0",16    "chai": "^4.3.4",17    "eslint": "^8.1.0",18    "mocha": "^9.1.3",19    "ts-node": "^10.4.0",20    "tslint": "^6.1.3",21    "typescript": "^4.4.4"22  },23  "mocha": {24    "timeout": 9999999,25    "require": "ts-node/register"26  },27  "scripts": {28    "lint": "eslint --ext .ts,.js src/",29    "fix": "eslint --ext .ts,.js src/ --fix",30    "test": "mocha --timeout 9999999 -r ts-node/register './**/*.test.ts'",31    "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",32    "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",33    "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",34    "loadTransfer": "ts-node src/transfer.nload.ts",35    "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",36    "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",37    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",38    "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",39    "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",40    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",41    "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",42    "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",43    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",44    "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",45    "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",46    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",47    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",48    "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",49    "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",50    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",51    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",52    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",53    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",54    "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",55    "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",56    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",57    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",58    "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",59    "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",60    "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",61    "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",62    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",63    "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",64    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",65    "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",66    "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",67    "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",68    "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",69    "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",70    "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --input src/interfaces/ --package .",71    "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint ws://localhost:9944 --output src/interfaces/ --package .",72    "polkadot-types": "yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"73  },74  "author": "",75  "license": "SEE LICENSE IN ../LICENSE",76  "homepage": "",77  "dependencies": {78    "@polkadot/api": "6.6.2-5",79    "@polkadot/api-contract": "6.6.2-5",80    "@polkadot/util-crypto": "^7.7.1",81    "bignumber.js": "^9.0.1",82    "chai-as-promised": "^7.1.1",83    "solc": "^0.8.9",84    "web3": "^1.6.0"85  },86  "standard": {87    "globals": [88      "it",89      "assert",90      "beforeEach",91      "afterEach",92      "describe",93      "contract",94      "artifacts"95    ]96  }97}
after · tests/package.json
1{2  "name": "unique-tests",3  "version": "1.0.0",4  "description": "Unique Chain Tests",5  "main": "",6  "devDependencies": {7    "@polkadot/dev": "0.63.18",8    "@polkadot/ts": "0.4.12",9    "@polkadot/typegen": "6.6.2-5",10    "@types/chai": "^4.2.22",11    "@types/chai-as-promised": "^7.1.4",12    "@types/mocha": "^9.0.0",13    "@types/node": "^16.11.6",14    "@typescript-eslint/eslint-plugin": "^5.3.0",15    "@typescript-eslint/parser": "^5.3.0",16    "chai": "^4.3.4",17    "eslint": "^8.1.0",18    "mocha": "^9.1.3",19    "ts-node": "^10.4.0",20    "tslint": "^6.1.3",21    "typescript": "^4.4.4"22  },23  "mocha": {24    "timeout": 9999999,25    "require": "ts-node/register"26  },27  "scripts": {28    "lint": "eslint --ext .ts,.js src/",29    "fix": "eslint --ext .ts,.js src/ --fix",30    "test": "mocha --timeout 9999999 -r ts-node/register './**/*.test.ts'",31    "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",32    "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",33    "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",34    "loadTransfer": "ts-node src/transfer.nload.ts",35    "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",36    "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",37    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",38    "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",39    "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",40    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",41    "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",42    "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",43    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",44    "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",45    "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",46    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",47    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",48    "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",49    "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",50    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",51    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",52    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",53    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",54    "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",55    "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",56    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",57    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",58    "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",59    "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",60    "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",61    "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",62    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",63    "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",64    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",65    "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",66    "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",67    "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",68    "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",69    "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",70    "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",71    "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --input src/interfaces/ --package .",72    "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint ws://localhost:9944 --output src/interfaces/ --package .",73    "polkadot-types": "yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"74  },75  "author": "",76  "license": "SEE LICENSE IN ../LICENSE",77  "homepage": "",78  "dependencies": {79    "@polkadot/api": "6.6.2-5",80    "@polkadot/api-contract": "6.6.2-5",81    "@polkadot/util-crypto": "^7.7.1",82    "bignumber.js": "^9.0.1",83    "chai-as-promised": "^7.1.1",84    "solc": "^0.8.9",85    "web3": "^1.6.0"86  },87  "standard": {88    "globals": [89      "it",90      "assert",91      "beforeEach",92      "afterEach",93      "describe",94      "contract",95      "artifacts"96    ]97  }98}
addedtests/src/xcmTransfer.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/xcmTransfer.test.ts
@@ -0,0 +1,200 @@
+//
+// This file is subject to the terms and conditions defined in
+// file 'LICENSE', which is part of this source code package.
+//
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+
+import {WsProvider} from '@polkadot/api';
+import {ApiOptions} from '@polkadot/api/types';
+import {IKeyringPair} from '@polkadot/types/types';
+import privateKey from './substrate/privateKey';
+import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
+import {getGenericResult} from './util/helpers';
+import waitNewBlocks from './substrate/wait-new-blocks';
+import getBalance from './substrate/get-balance';
+import {alicesPublicKey} from './accounts';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+const UNIQUE_CHAIN = 1000;
+const KARURA_CHAIN = 2000;
+const KARURA_PORT = '9946';
+
+describe('Integration test: Exchanging QTZ/OPL with Karura', () => {
+  let alice: IKeyringPair;
+  
+  before(async () => {
+    await usingApi(async () => {
+      alice = privateKey('//Alice');
+    });
+
+    const karuraApiOptions: ApiOptions = {
+      provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT),
+    };
+
+    await usingApi(async (api) => {
+      const destination = {
+        V0: {
+          X2: [
+            'Parent',
+            {
+              Parachain: UNIQUE_CHAIN,
+            },
+          ],
+        },
+      };
+
+      const metadata =
+      {
+        name: 'OPL',
+        symbol: 'OPL',
+        decimals: 15,
+        minimalBalance: 1,
+      };
+
+      const tx = api.tx.assetRegistry.registerForeignAsset(destination, metadata);
+      const sudoTx = api.tx.sudo.sudo(tx as any);
+      const events = await submitTransactionAsync(alice, sudoTx);
+      const result = getGenericResult(events);
+      expect(result.success).to.be.true;
+    }, karuraApiOptions);
+  });
+
+  it('Should connect and send OPL to Karura', async () => {
+    let balanceOnKaruraBefore: bigint;
+    
+    await usingApi(async (api) => {
+      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+      balanceOnKaruraBefore = free;
+    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
+
+    await usingApi(async (api) => {
+      const destination = {
+        V0: {
+          X2: [
+            'Parent',
+            {
+              Parachain: KARURA_CHAIN,
+            },
+          ],
+        },
+      };
+
+      const beneficiary = {
+        V0: {
+          X1: {
+            AccountId32: {
+              network: 'Any',
+              id: alice.addressRaw,
+            },
+          },
+        },
+      };
+
+      const assets = {
+        V1: [
+          {
+            id: {
+              Concrete: {
+                parents: 0,
+                interior: 'Here',
+              },
+            },
+            fun: {
+              Fungible: 5000000000,
+            },
+          },
+        ],
+      };
+
+      const feeAssetItem = 0;
+
+      const weightLimit = {
+        Limited: 5000000000,
+      };
+
+      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getGenericResult(events);
+      expect(result.success).to.be.true;
+    });
+
+    await usingApi(async (api) => {
+      // todo do something about instant sealing, where there might not be any new blocks
+      await waitNewBlocks(api, 1);
+      const {free} = (await api.query.tokens.accounts(alice.addressRaw, {ForeignAsset: 0})).toJSON() as any;
+      expect(free > balanceOnKaruraBefore).to.be.true;
+    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
+  });
+
+  /// TODO Under construction. The test won't pass.
+  it.skip('Should connect to Karura and send OPL back', async () => {
+    let balanceBefore: bigint;
+    
+    await usingApi(async (api) => {
+      [balanceBefore] = await getBalance(api, [alicesPublicKey]);
+    });
+
+    await usingApi(async (api) => {
+      const destination = {
+        V0: {
+          X2: [
+            'Parent',
+            {
+              Parachain: UNIQUE_CHAIN,
+            },
+          ],
+        },
+      };
+
+      const beneficiary = {
+        V0: {
+          X1: {
+            AccountId32: {
+              network: 'Any',
+              id: alice.addressRaw,
+            },
+          },
+        },
+      };
+
+      const assets = {
+        V1: [
+          {
+            id: {
+              Concrete: {
+                parents: 0,
+                interior: 'Here',
+              },
+            },
+            fun: {
+              Fungible: 5000000000,
+            },
+          },
+        ],
+      };
+
+      const feeAssetItem = 0;
+
+      const weightLimit = {
+        Limited: 5000000000,
+      };
+
+      // todo The functionality to be tested is not complete yet. The metadata above are subject to change, as is the transaction below.
+      const tx = api.tx.polkadotXcm.limitedReserveTransferAssets(destination, beneficiary, assets, feeAssetItem, weightLimit);
+      const events = await submitTransactionAsync(alice, tx);
+      const result = getGenericResult(events);
+      expect(result.success).to.be.true;
+    }, {provider: new WsProvider('ws://127.0.0.1:' + KARURA_PORT)});
+
+    await usingApi(async (api) => {
+      // todo do something about instant sealing, where there might not be any new blocks
+      await waitNewBlocks(api, 1);
+      const [balanceAfter] = await getBalance(api, [alicesPublicKey]);
+      expect(balanceAfter > balanceBefore).to.be.true;
+    });
+  });
+});
\ No newline at end of file