difftreelog
Add Quartz-Shiden tests
in: master
+ fix send-back test
2 files changed
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -18,12 +18,13 @@
import {blake2AsHex} from '@polkadot/util-crypto';
import config from '../config';
import {XcmV2TraitsError} from '../interfaces';
-import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds} from '../util';
+import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingAstarPlaygrounds} from '../util';
const QUARTZ_CHAIN = 2095;
const STATEMINE_CHAIN = 1000;
const KARURA_CHAIN = 2000;
const MOONRIVER_CHAIN = 2023;
+const SHIDEN_CHAIN = 2007;
const STATEMINE_PALLET_INSTANCE = 50;
@@ -31,6 +32,7 @@
const statemineUrl = config.statemineUrl;
const karuraUrl = config.karuraUrl;
const moonriverUrl = config.moonriverUrl;
+const shidenUrl = config.shidenUrl;
const RELAY_DECIMALS = 12;
const STATEMINE_DECIMALS = 12;
@@ -978,3 +980,189 @@
expect(qtzFees == 0n).to.be.true;
});
});
+
+describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
+ let alice: IKeyringPair;
+ let randomAccount: IKeyringPair;
+
+ const shidenInitialBalance = 1n * (10n ** 18n);
+ const qtzToShidenAmount = 10n * (10n ** 18n);
+
+ before(async () => {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ alice = await privateKey('//Alice');
+ [randomAccount] = await helper.arrange.createAccounts([100n], alice);
+ console.log('randomAccount', randomAccount.address);
+ });
+
+ await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ console.log('1. Create foreign asset and metadata');
+ await helper.assets.create(
+ alice,
+ 1,
+ alice.address,
+ 1n,
+ );
+
+ await helper.assets.setMetadata(
+ alice,
+ 1,
+ 'Cross chain QTZ',
+ 'xcQTZ',
+ 18,
+ );
+
+ console.log('2. Register asset location');
+ const assetLocation = {
+ V1: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: QUARTZ_CHAIN,
+ },
+ },
+ },
+ };
+
+ await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
+
+ console.log('3. Set payment for computation');
+ // TODO this is Phala's price, what price will be for Unique?
+ const unitsPerSecond = 228_000_000_000n;
+ await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
+
+ console.log('4. Transfer 1 SDN to recepient');
+ await helper.balance.transferToSubstrate(alice, randomAccount.address, shidenInitialBalance);
+ });
+ });
+
+ itSub.only('Should connect and send QTZ to Shiden', async ({helper}) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: SHIDEN_CHAIN,
+ },
+ },
+ },
+ };
+
+ const beneficiary = {
+ V1: {
+ parents: 0,
+ interior: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
+ },
+ },
+ },
+ };
+
+ const assets = {
+ V1: [
+ {
+ id: {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ fun: {
+ Fungible: qtzToShidenAmount,
+ },
+ },
+ ],
+ };
+
+ // Initial balance is 100 UNQ
+ expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));
+
+ const feeAssetItem = 0;
+ await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
+
+ // Balance after reserve transfer is less than 90
+ expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);
+
+ await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ await helper.wait.newBlocks(3);
+ const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
+ const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
+
+ expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);
+ // Astar balance does not changed
+ expect(astarBalance).to.eq(1_000_000_000_000_000_000n);
+ });
+ });
+
+ itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {
+ await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+ const destination = {
+ V1: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: QUARTZ_CHAIN,
+ },
+ },
+ },
+ };
+
+ const beneficiary = {
+ V1: {
+ parents: 0,
+ interior: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: randomAccount.addressRaw,
+ },
+ },
+ },
+ },
+ };
+
+ const assets = {
+ V1: [
+ {
+ id: {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: QUARTZ_CHAIN,
+ },
+ },
+ },
+ },
+ fun: {
+ Fungible: 5_000_000_000_000_000_000n,
+ },
+ },
+ ],
+ };
+
+ // Initial balance is 1 SDN
+ expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
+
+ const feeAssetItem = 0;
+ await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
+
+ // Balance after reserve transfer is less than 1 SDN
+ const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
+ const balanceSDN = await helper.balance.getSubstrate(randomAccount.address);
+
+ // Assert: xcQTZ balance decreased
+ expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
+ // Assert: SDN balance is 0.996...
+ expect(balanceSDN / (10n ** 15n)).to.eq(996n);
+ });
+
+ await helper.wait.newBlocks(3);
+ const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
+ expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
+ });
+});
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth1003 alice,1003 alice,1004 1,1004 1,1005 alice.address,1005 alice.address,1006 1n, // TODO set correct minimal balance1006 1n,1007 );1007 );100810081009 await helper.assets.setMetadata(1009 await helper.assets.setMetadata(1033 const unitsPerSecond = 228_000_000_000n;1033 const unitsPerSecond = 228_000_000_000n;1034 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1034 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);103510351036 console.log('4. Transfer 1 ASTAR for recepient');1036 console.log('4. Transfer 1 ASTR to recepient');1037 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1037 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1038 });1038 });1039 });1039 });1100 });1100 });1101 });1101 });11021103 itSub.only('Should connect to Astar and send UNQ back', async ({helper}) => {1104 await usingAstarPlaygrounds(astarUrl, async (helper) => {1105 const destination = {1106 V1: {1107 parents: 1,1108 interior: {1109 X1: {1110 Parachain: UNIQUE_CHAIN,1111 },1112 },1113 },1114 };11151116 const beneficiary = {1117 V1: {1118 parents: 0,1119 interior: {1120 X1: {1121 AccountId32: {1122 network: 'Any',1123 id: randomAccount.addressRaw,1124 },1125 },1126 },1127 },1128 };11291130 const assets = {1131 V1: [1132 {1133 id: {1134 Concrete: {1135 parents: 1,1136 interior: {1137 X1: {1138 Parachain: UNIQUE_CHAIN,1139 },1140 },1141 },1142 },1143 fun: {1144 Fungible: 5_000_000_000_000_000_000n,1145 },1146 },1147 ],1148 };11491150 // Initial balance is 1 ASTR1151 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);11521153 const feeAssetItem = 0;1154 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);11551156 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1157 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);11581159 // Assert: xcUNQ balance decreased1160 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);1161 // Assert: ASTR balance is 0.996...1162 expect(balanceAstar / (10n ** 15n)).to.eq(996n);1163 });11641165 await helper.wait.newBlocks(3);1166 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);1167 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);1168 });110211691103 itSub.only('Should connect to Astar and send UNQ back', async ({helper}) => {1170 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {1104 await usingAstarPlaygrounds(astarUrl, async (helper) => {1171 await usingAstarPlaygrounds(astarUrl, async (helper) => {1105 const destination = {1172 const destination = {1106 V1: {1173 V1: {