difftreelog
feat(xcm-tests) sending is ready, receiving pending core functionality
in: master
3 files changed
launch-config.jsondiffbeforeafterboth1{2 "relaychain": {3 "bin": "../polkadot/target/release/polkadot",4 "chain": "rococo-local",5 "nodes": [6 {7 "name": "alice",8 "wsPort": 9844,9 "rpcPort": 9843,10 "port": 30444,11 "flags": [12 "-lparachain::candidate_validation=debug",13 "-lxcm=trace"14 ]15 },16 {17 "name": "bob",18 "wsPort": 9855,19 "rpcPort": 9854,20 "port": 30555,21 "flags": [22 "-lparachain::candidate_validation=debug",23 "-lxcm=trace"24 ]25 },26 {27 "name": "charlie",28 "wsPort": 9866,29 "rpcPort": 9865,30 "port": 30666,31 "flags": [32 "-lparachain::candidate_validation=debug"33 ]34 },35 {36 "name": "dave",37 "wsPort": 9877,38 "rpcPort": 9876,39 "port": 30777,40 "flags": [41 "-lparachain::candidate_validation=debug"42 ]43 }44 ],45 "genesis": {46 "runtime": {47 "runtime_genesis_config": {48 "parachainsConfiguration": {49 "config": {50 "validation_upgrade_frequency": 1,51 "validation_upgrade_delay": 152 }53 }54 }55 }56 }57 },58 "parachains": [59 {60 "bin": "../unique-chain/target/release/unique-collator",61 "id": "1000",62 "balance": "1000000000000000000000000",63 "nodes": [64 {65 "port": 31200,66 "wsPort": 9944,67 "rpcPort": 9933,68 "name": "alice",69 "flags": [70 "--rpc-cors=all",71 "--unsafe-rpc-external",72 "--unsafe-ws-external",73 "-lxcm=trace"74 ]75 },76 {77 "port": 31201,78 "wsPort": 9945,79 "rpcPort": 9934,80 "name": "bob",81 "flags": [82 "--rpc-cors=all",83 "--unsafe-rpc-external",84 "--unsafe-ws-external",85 "-lxcm=trace"86 ]87 }88 ]89 },90 {91 "bin": "../Acala/target/release/acala",92 "id": "2000",93 "chain": "karura-dev",94 "balance": "1000000000000000000000",95 "nodes": [96 {97 "wsPort": 9988,98 "port": 31200,99 "name": "alice",100 "flags": [101 "--rpc-cors=all",102 "--unsafe-rpc-external",103 "--unsafe-ws-external",104 "-lxcm=trace"105 ]106 }107 ]108 }109 ],110 "simpleParachains": [],111 "hrmpChannels": [112 {113 "sender": 2000,114 "recipient": 1000,115 "maxCapacity": 8,116 "maxMessageSize": 512117 },118 {119 "sender": 1000,120 "recipient": 2000,121 "maxCapacity": 8,122 "maxMessageSize": 512123 }124 ],125 "finalization": false126}1{2 "relaychain": {3 "bin": "../polkadot/target/release/polkadot",4 "chain": "rococo-local",5 "nodes": [6 {7 "name": "alice",8 "wsPort": 9844,9 "rpcPort": 9843,10 "port": 30444,11 "flags": [12 "-lparachain::candidate_validation=debug",13 "-lxcm=trace"14 ]15 },16 {17 "name": "bob",18 "wsPort": 9855,19 "rpcPort": 9854,20 "port": 30555,21 "flags": [22 "-lparachain::candidate_validation=debug",23 "-lxcm=trace"24 ]25 },26 {27 "name": "charlie",28 "wsPort": 9866,29 "rpcPort": 9865,30 "port": 30666,31 "flags": [32 "-lparachain::candidate_validation=debug"33 ]34 },35 {36 "name": "dave",37 "wsPort": 9877,38 "rpcPort": 9876,39 "port": 30777,40 "flags": [41 "-lparachain::candidate_validation=debug"42 ]43 },44 {45 "name": "eve",46 "wsPort": 9888,47 "rpcPort": 9887,48 "port": 30888,49 "flags": [50 "-lparachain::candidate_validation=debug"51 ]52 }53 ],54 "genesis": {55 "runtime": {56 "runtime_genesis_config": {57 "parachainsConfiguration": {58 "config": {59 "validation_upgrade_frequency": 1,60 "validation_upgrade_delay": 161 }62 }63 }64 }65 }66 },67 "parachains": [68 {69 "bin": "../unique-chain/target/release/unique-collator",70 "id": "1000",71 "balance": "1000000000000000000000000",72 "nodes": [73 {74 "port": 31200,75 "wsPort": 9944,76 "rpcPort": 9933,77 "name": "alice",78 "flags": [79 "--rpc-cors=all",80 "--unsafe-rpc-external",81 "--unsafe-ws-external",82 "-lxcm=trace"83 ]84 },85 {86 "port": 31201,87 "wsPort": 9945,88 "rpcPort": 9934,89 "name": "bob",90 "flags": [91 "--rpc-cors=all",92 "--unsafe-rpc-external",93 "--unsafe-ws-external",94 "-lxcm=trace"95 ]96 }97 ]98 },99 {100 "bin": "../Acala/target/release/acala",101 "id": "2000",102 "chain": "karura-dev",103 "balance": "1000000000000000000000",104 "nodes": [105 {106 "wsPort": 9946,107 "port": 31202,108 "name": "alice",109 "flags": [110 "--rpc-cors=all",111 "--unsafe-rpc-external",112 "--unsafe-ws-external",113 "-lxcm=trace"114 ]115 }116 ]117 },118 {119 "bin": "../cumulus/target/release/polkadot-collator",120 "id": "3000",121 "chain": "statemint-dev",122 "balance": "1000000000000000000000000",123 "nodes": [124 {125 "wsPort": 9947,126 "port": 31203,127 "name": "alice",128 "flags": [129 "--rpc-cors=all",130 "--unsafe-rpc-external",131 "--unsafe-ws-external",132 "-lxcm=trace"133 ]134 }135 ]136 }137 ],138 "simpleParachains": [],139 "hrmpChannels": [140 {141 "sender": 2000,142 "recipient": 1000,143 "maxCapacity": 8,144 "maxMessageSize": 512145 },146 {147 "sender": 1000,148 "recipient": 2000,149 "maxCapacity": 8,150 "maxMessageSize": 512151 }152 ],153 "finalization": false154}tests/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",
tests/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