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

difftreelog

Fixes after review

Max Andreev2023-03-29parent: #1550f8c.patch.diff
in: master

6 files changed

modified.docker/xcm-config/launch-config-xcm-quartz.j2diffbeforeafterboth
--- a/.docker/xcm-config/launch-config-xcm-quartz.j2
+++ b/.docker/xcm-config/launch-config-xcm-quartz.j2
@@ -169,7 +169,7 @@
         {
             "bin": "/astar/target/release/astar",
             "id": "2007",
-            "chain": "astar-dev",
+            "chain": "shiden-dev",
             "balance": "1000000000000000000000000",
             "nodes": [
                 {
@@ -224,12 +224,12 @@
         },
         {
             "sender": 2007,
-            "recipient": 1000,
+            "recipient": 2095,
             "maxCapacity": 8,
             "maxMessageSize": 512
         },
         {
-            "sender": 1000,
+            "sender": 2095,
             "recipient": 2007,
             "maxCapacity": 8,
             "maxMessageSize": 512
modified.docker/xcm-config/launch-config-xcm-unique.j2diffbeforeafterboth
--- a/.docker/xcm-config/launch-config-xcm-unique.j2
+++ b/.docker/xcm-config/launch-config-xcm-unique.j2
@@ -224,12 +224,12 @@
         },
         {
             "sender": 2006,
-            "recipient": 1000,
+            "recipient": 2037,
             "maxCapacity": 8,
             "maxMessageSize": 512
         },
         {
-            "sender": 1000,
+            "sender": 2037,
             "recipient": 2006,
             "maxCapacity": 8,
             "maxMessageSize": 512
modifiedtests/src/util/index.tsdiffbeforeafterboth
--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -11,7 +11,7 @@
 import config from '../config';
 import {ChainHelperBase} from './playgrounds/unique';
 import {ILogger} from './playgrounds/types';
-import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper} from './playgrounds/unique.dev';
+import {DevUniqueHelper, SilentLogger, SilentConsole, DevMoonbeamHelper, DevMoonriverHelper, DevAcalaHelper, DevKaruraHelper, DevRelayHelper, DevWestmintHelper, DevStatemineHelper, DevStatemintHelper, DevAstarHelper, DevShidenHelper} from './playgrounds/unique.dev';
 import {dirname} from 'path';
 import {fileURLToPath} from 'url';
 
@@ -105,6 +105,9 @@
   return usingPlaygroundsGeneral<DevAstarHelper>(DevAstarHelper, url, code);
 };
 
+export const usingShidenPlaygrounds = (url: string, code: (helper: DevShidenHelper, privateKey: (seed: string) => Promise<IKeyringPair>) => Promise<void>) => {
+  return usingPlaygroundsGeneral<DevShidenHelper>(DevShidenHelper, url, code);
+};
 
 export const MINIMUM_DONOR_FUND = 100_000n;
 export const DONOR_FUNDING = 2_000_000n;
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -184,6 +184,17 @@
   }
 }
 
+export class DevShidenHelper extends AstarHelper {
+  wait: WaitGroup;
+
+  constructor(logger: { log: (msg: any, level: any) => void, level: any }, options: {[key: string]: any} = {}) {
+    options.helperBase = options.helperBase ?? DevShidenHelper;
+
+    super(logger, options);
+    this.wait = new WaitGroup(this);
+  }
+}
+
 export class DevAcalaHelper extends AcalaHelper {
   wait: WaitGroup;
 
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -18,7 +18,7 @@
 import {blake2AsHex} from '@polkadot/util-crypto';
 import config from '../config';
 import {XcmV2TraitsError} from '../interfaces';
-import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingAstarPlaygrounds} from '../util';
+import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';
 
 const QUARTZ_CHAIN = 2095;
 const STATEMINE_CHAIN = 1000;
@@ -983,19 +983,28 @@
 
 describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
   let alice: IKeyringPair;
-  let randomAccount: IKeyringPair;
+  let sender: IKeyringPair;
+
+  // Quartz -> Shiden
+  const shidenInitialBalance = 1n * (10n ** 18n); // 1 SHD, existencial deposit required in order to perform XCM call
+  const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+  const qtzToShidenTransferred = 10n * (10n ** 18n); // 10 QTZ
+  const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens
+  const senderIinitialBalanceQTZ = 100n * (10n ** 18n); // How many QTZ sender has initially
+  const senderBalanceAfterXCM = 89_941967662676666465n; // 89.94... QTZ after XCM call
 
-  const shidenInitialBalance = 1n * (10n ** 18n);
-  const qtzToShidenAmount = 10n * (10n ** 18n);
+  // Shiden -> Quartz
+  const qtzFromShidenTransfered = 5n * (10n ** 18n); // 5 QTZ
+  const qtzOnShidenLeft = qtzToShidenArrived - qtzFromShidenTransfered; // 4.999_999_999_088_000_000n QTZ
 
   before(async () => {
     await usingPlaygrounds(async (helper, privateKey) => {
       alice = await privateKey('//Alice');
-      [randomAccount] = await helper.arrange.createAccounts([100n], alice);
-      console.log('randomAccount', randomAccount.address);
+      [sender] = await helper.arrange.createAccounts([100n], alice);
+      console.log('sender', sender.address);
     });
 
-    await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+    await usingShidenPlaygrounds(shidenUrl, async (helper) => {
       console.log('1. Create foreign asset and metadata');
       await helper.assets.create(
         alice,
@@ -1027,12 +1036,10 @@
       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);
+      await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);
     });
   });
 
@@ -1055,7 +1062,7 @@
           X1: {
             AccountId32: {
               network: 'Any',
-              id: randomAccount.addressRaw,
+              id: sender.addressRaw,
             },
           },
         },
@@ -1072,34 +1079,42 @@
             },
           },
           fun: {
-            Fungible: qtzToShidenAmount,
+            Fungible: qtzToShidenTransferred,
           },
         },
       ],
     };
 
-    // Initial balance is 100 UNQ
-    expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));
+    // Initial balance is 100 QTZ
+    const balanceBefore = await helper.balance.getSubstrate(sender.address);
+    console.log(`Initial balance is: ${balanceBefore}`);
+    expect(balanceBefore).to.eq(senderIinitialBalanceQTZ);
 
     const feeAssetItem = 0;
-    await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
+    await helper.xcm.limitedReserveTransferAssets(sender, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
 
     // Balance after reserve transfer is less than 90
-    expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);
+    const balanceAfter = await helper.balance.getSubstrate(sender.address);
+    console.log(`QTZ Balance on Quartz after XCM is: ${balanceAfter}`);
+    console.log(`Quartz's QTZ commission is: ${balanceBefore - balanceAfter}`);
+    expect(balanceAfter).to.eq(senderBalanceAfterXCM);
 
-    await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+    await usingShidenPlaygrounds(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);
+      const xcQTZbalance = await helper.assets.account(1, sender.address);
+      const shidenBalance = await helper.balance.getSubstrate(sender.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);
+      console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
+      console.log(`Shiden's QTZ commission is: ${qtzToShidenTransferred - xcQTZbalance!}`);
+
+      expect(xcQTZbalance).to.eq(qtzToShidenArrived);
+      // SHD balance does not changed:
+      expect(shidenBalance).to.eq(shidenInitialBalance);
     });
   });
 
   itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {
-    await usingAstarPlaygrounds(shidenUrl, async (helper) => {
+    await usingShidenPlaygrounds(shidenUrl, async (helper) => {
       const destination = {
         V1: {
           parents: 1,
@@ -1118,7 +1133,7 @@
             X1: {
               AccountId32: {
                 network: 'Any',
-                id: randomAccount.addressRaw,
+                id: sender.addressRaw,
               },
             },
           },
@@ -1139,30 +1154,35 @@
               },
             },
             fun: {
-              Fungible: 5_000_000_000_000_000_000n,
+              Fungible: qtzFromShidenTransfered,
             },
           },
         ],
       };
 
       // Initial balance is 1 SDN
-      expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
+      const balanceSDNbefore = await helper.balance.getSubstrate(sender.address);
+      console.log(`SDN balance is: ${balanceSDNbefore}, it does not changed`);
+      expect(balanceSDNbefore).to.eq(shidenInitialBalance);
 
       const feeAssetItem = 0;
-      await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
+      // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw
+      await helper.executeExtrinsic(sender, '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);
+      const xcQTZbalance = await helper.assets.account(1, sender.address);
+      const balanceSDN = await helper.balance.getSubstrate(sender.address);
+      console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
 
-      // Assert: xcQTZ balance decreased
-      expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
+      // Assert: xcQTZ balance correctly decreased
+      expect(xcQTZbalance).to.eq(qtzOnShidenLeft);
       // 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);
+    const balanceQTZ = await helper.balance.getSubstrate(sender.address);
+    console.log(`QTZ Balance on Quartz after XCM is: ${balanceQTZ}`);
+    expect(balanceQTZ).to.eq(senderBalanceAfterXCM + qtzFromShidenTransfered);
   });
 });
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
987 let alice: IKeyringPair;987 let alice: IKeyringPair;
988 let randomAccount: IKeyringPair;988 let randomAccount: IKeyringPair;
989989
990 // Unique -> Astar
990 const astarInitialBalance = 1n * (10n ** 18n);991 const astarInitialBalance = 1n * (10n ** 18n); // 1 ASTR. Existencial deposit required in order to perform XCM call
992 const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
991 const unqToAstarAmount = 10n * (10n ** 18n);993 const unqToAstarTransferred = 10n * (10n ** 18n); // 10 UNQ
994 const unqToAstarArrived = 9_999_999_999_088_000_000n; // 9.999 ... UNQ, Shiden takes a commision in foreign tokens
995 const senderIinitialBalanceUNQ = 100n * (10n ** 18n); // How many UNQ sender has initially
996 const senderBalanceAfterXCM = 89_941967662676666465n; // 89.94... UNQ after XCM call
997
998 // Astar -> Unique
999 const unqFromAstarTransfered = 5n * (10n ** 18n); // 5 UNQ
1000 const unqOnAstarLeft = unqToAstarArrived - unqFromAstarTransfered; // 4.999_999_999_088_000_000n UNQ
9921001
993 before(async () => {1002 before(async () => {
994 await usingPlaygrounds(async (helper, privateKey) => {1003 await usingPlaygrounds(async (helper, privateKey) => {
1029 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);1038 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
10301039
1031 console.log('3. Set payment for computation');1040 console.log('3. Set payment for computation');
1032 // TODO this is Phala's price, what price will be for Unique?
1033 const unitsPerSecond = 228_000_000_000n;
1034 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1041 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
10351042
1036 console.log('4. Transfer 1 ASTR to recepient');1043 console.log('4. Transfer 1 ASTR to recepient');
1074 },1081 },
1075 },1082 },
1076 fun: {1083 fun: {
1077 Fungible: unqToAstarAmount,1084 Fungible: unqToAstarTransferred,
1078 },1085 },
1079 },1086 },
1080 ],1087 ],
1081 };1088 };
10821089
1083 // Initial balance is 100 UNQ1090 // Initial balance is 100 UNQ
1084 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));1091 const balanceBefore = await helper.balance.getSubstrate(randomAccount.address);
1092 console.log(`Initial balance is: ${balanceBefore}`);
1093 expect(balanceBefore).to.eq(senderIinitialBalanceUNQ);
10851094
1086 const feeAssetItem = 0;1095 const feeAssetItem = 0;
1087 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');1096 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
10881097
1089 // Balance after reserve transfer is less than 901098 // Balance after reserve transfer is less than 90
1090 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);1099 const balanceAfter = await helper.balance.getSubstrate(randomAccount.address);
1100 console.log(`UNQ Balance on Unique after XCM is: ${balanceAfter}`);
1101 console.log(`Unique's UNQ commission is: ${balanceBefore - balanceAfter}`);
1102 expect(balanceAfter).to.eq(senderBalanceAfterXCM);
10911103
1092 await usingAstarPlaygrounds(astarUrl, async (helper) => {1104 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1093 await helper.wait.newBlocks(3);1105 await helper.wait.newBlocks(3);
1094 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1106 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1095 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);1107 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
1108
1109 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
1110 console.log(`Astar's UNQ commission is: ${unqToAstarTransferred - xcUNQbalance!}`);
10961111
1097 expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);1112 expect(xcUNQbalance).to.eq(unqToAstarArrived);
1098 // Astar balance does not changed1113 // Astar balance does not changed
1099 expect(astarBalance).to.eq(1_000_000_000_000_000_000n);1114 expect(astarBalance).to.eq(astarInitialBalance);
1100 });1115 });
1101 });1116 });
11021117
1141 },1156 },
1142 },1157 },
1143 fun: {1158 fun: {
1144 Fungible: 5_000_000_000_000_000_000n,1159 Fungible: unqFromAstarTransfered,
1145 },1160 },
1146 },1161 },
1147 ],1162 ],
1148 };1163 };
11491164
1150 // Initial balance is 1 ASTR1165 // Initial balance is 1 ASTR
1151 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);1166 const balanceASTRbefore = await helper.balance.getSubstrate(randomAccount.address);
1167 console.log(`ASTR balance is: ${balanceASTRbefore}, it does not changed`);
1168 expect(balanceASTRbefore).to.eq(astarInitialBalance);
11521169
1153 const feeAssetItem = 0;1170 const feeAssetItem = 0;
1171 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw
1154 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);1172 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
11551173
1156 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1174 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1157 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);1175 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
1176 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
11581177
1159 // Assert: xcUNQ balance decreased1178 // Assert: xcUNQ balance correctly decreased
1160 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);1179 expect(xcUNQbalance).to.eq(unqOnAstarLeft);
1161 // Assert: ASTR balance is 0.996...1180 // Assert: ASTR balance is 0.996...
1162 expect(balanceAstar / (10n ** 15n)).to.eq(996n);1181 expect(balanceAstar / (10n ** 15n)).to.eq(996n);
1163 });1182 });
11641183
1165 await helper.wait.newBlocks(3);1184 await helper.wait.newBlocks(3);
1166 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);1185 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
1186 console.log(`UNQ Balance on Unique after XCM is: ${balanceUNQ}`);
1167 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);1187 expect(balanceUNQ).to.eq(senderBalanceAfterXCM + unqFromAstarTransfered);
1168 });1188 });
11691189
1170 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {1190 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
1208 },1228 },
1209 },1229 },
1210 fun: {1230 fun: {
1211 Fungible: 5_000_000_000_000_000_000n, // TODO set another value1231 Fungible: unqFromAstarTransfered,
1212 },1232 },
1213 },1233 },
1214 ],1234 ],
1215 };1235 };
12161236
1217 // Initial balance is 1 ASTAR1237 // Initial balance is 1 ASTAR
1218 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);1238 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);
12191239
1220 const feeAssetItem = 0;1240 const feeAssetItem = 0;
1241 // TODO: expect rejected:
1221 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');1242 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
1222
1223 // Balance after reserve transfer is less than 1 ASTAR
1224 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1225 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
1226
1227 // xcUNQ balance decreased
1228 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
1229 // Astar balance is 0.997...
1230 expect(balanceAstar / (10n ** 15n)).to.eq(997n);
1231 });1243 });
1232
1233 await helper.wait.newBlocks(3);
1234 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
1235 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
1236 });1244 });
1237});1245});
12381246