git.delta.rocks / unique-network / refs/commits / 671f56ab5557

difftreelog

Add constants to magic numbers

Max Andreev2023-03-30parent: #647e949.patch.diff
in: master

2 files changed

modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
987 let alice: IKeyringPair;987 let alice: IKeyringPair;
988 let sender: IKeyringPair;988 let sender: IKeyringPair;
989
990 const QTZ_ASSET_ID_ON_SHIDEN = 1;
991 const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
989992
990 // Quartz -> Shiden993 // Quartz -> Shiden
991 const shidenInitialBalance = 1n * SHIDEN_DECIMALS; // 1 SHD, existential deposit required to actually create the account on Shiden994 const shidenInitialBalance = 1n * SHIDEN_DECIMALS; // 1 SHD, existential deposit required to actually create the account on Shiden
10081011
1009 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1012 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1010 console.log('1. Create foreign asset and metadata');1013 console.log('1. Create foreign asset and metadata');
1014 // TODO update metadata with values from production
1011 await helper.assets.create(1015 await helper.assets.create(
1012 alice,1016 alice,
1013 1,1017 QTZ_ASSET_ID_ON_SHIDEN,
1014 alice.address,1018 alice.address,
1015 1n,1019 QTZ_MINIMAL_BALANCE_ON_SHIDEN,
1016 );1020 );
10171021
1018 await helper.assets.setMetadata(1022 await helper.assets.setMetadata(
1019 alice,1023 alice,
1020 1,1024 QTZ_ASSET_ID_ON_SHIDEN,
1021 'Cross chain QTZ',1025 'Cross chain QTZ',
1022 'xcQTZ',1026 'xcQTZ',
1023 18,1027 Number(QTZ_DECIMALS),
1024 );1028 );
10251029
1026 console.log('2. Register asset location');1030 console.log('2. Register asset location on Shiden');
1027 const assetLocation = {1031 const assetLocation = {
1028 V1: {1032 V1: {
1029 parents: 1,1033 parents: 1,
1035 },1039 },
1036 };1040 };
10371041
1038 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);1042 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, QTZ_ASSET_ID_ON_SHIDEN]);
10391043
1040 console.log('3. Set payment for computation');1044 console.log('3. Set QTZ payment for XCM execution on Shiden');
1041 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1045 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
10421046
1043 console.log('4. Transfer 1 SDN to recepient');1047 console.log('4. Transfer 1 SDN to recipient to create the account (needed due to existential balance)');
1044 await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);1048 await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);
1045 });1049 });
1046 });1050 });
11031107
1104 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1108 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1105 await helper.wait.newBlocks(3);1109 await helper.wait.newBlocks(3);
1106 const xcQTZbalance = await helper.assets.account(1, sender.address);1110 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);
1107 const shidenBalance = await helper.balance.getSubstrate(sender.address);1111 const shidenBalance = await helper.balance.getSubstrate(sender.address);
11081112
1109 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);1113 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
1172 await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);1176 await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
11731177
1174 // Balance after reserve transfer is less than 1 SDN1178 // Balance after reserve transfer is less than 1 SDN
1175 const xcQTZbalance = await helper.assets.account(1, sender.address);1179 const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);
1176 const balanceSDN = await helper.balance.getSubstrate(sender.address);1180 const balanceSDN = await helper.balance.getSubstrate(sender.address);
1177 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);1181 console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
11781182
1179 // Assert: xcQTZ balance correctly decreased1183 // Assert: xcQTZ balance correctly decreased
1180 expect(xcQTZbalance).to.eq(qtzOnShidenLeft);1184 expect(xcQTZbalance).to.eq(qtzOnShidenLeft);
1181 // Assert: SDN balance is 0.996...1185 // Assert: SDN balance is 0.996...
1182 expect(balanceSDN / (10n ** 15n)).to.eq(996n);1186 expect(balanceSDN / (SHIDEN_DECIMALS - 3n)).to.eq(996n);
1183 });1187 });
11841188
1185 await helper.wait.newBlocks(3);1189 await helper.wait.newBlocks(3);
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -989,6 +989,9 @@
   let alice: IKeyringPair;
   let randomAccount: IKeyringPair;
 
+  const UNQ_ASSET_ID_ON_SHIDEN = 1;
+  const UNQ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
+
   // Unique -> Astar
   const astarInitialBalance = 1n * ASTAR_DECIMALS; // 1 ASTR, existential deposit required to actually create the account on Shiden.
   const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
@@ -1010,22 +1013,23 @@
 
     await usingAstarPlaygrounds(astarUrl, async (helper) => {
       console.log('1. Create foreign asset and metadata');
+      // TODO update metadata with values from production
       await helper.assets.create(
         alice,
-        1,
+        UNQ_ASSET_ID_ON_SHIDEN,
         alice.address,
-        1n,
+        UNQ_MINIMAL_BALANCE_ON_SHIDEN,
       );
 
       await helper.assets.setMetadata(
         alice,
-        1,
+        UNQ_ASSET_ID_ON_SHIDEN,
         'Cross chain UNQ',
         'xcUNQ',
-        18,
+        Number(UNQ_DECIMALS),
       );
 
-      console.log('2. Register asset location');
+      console.log('2. Register asset location on Astar');
       const assetLocation = {
         V1: {
           parents: 1,
@@ -1037,12 +1041,12 @@
         },
       };
 
-      await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
+      await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, UNQ_ASSET_ID_ON_SHIDEN]);
 
-      console.log('3. Set payment for computation');
+      console.log('3. Set UNQ payment for XCM execution on Astar');
       await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
 
-      console.log('4. Transfer 1 ASTR to recepient');
+      console.log('4. Transfer 1 ASTR to recipient to create the account (needed due to existential balance)');
       await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);
     });
   });
@@ -1105,7 +1109,7 @@
 
     await usingAstarPlaygrounds(astarUrl, async (helper) => {
       await helper.wait.newBlocks(3);
-      const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
+      const xcUNQbalance = await helper.assets.account(UNQ_ASSET_ID_ON_SHIDEN, randomAccount.address);
       const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
 
       console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
@@ -1173,14 +1177,14 @@
       // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw
       await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
 
-      const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
+      const xcUNQbalance = await helper.assets.account(UNQ_ASSET_ID_ON_SHIDEN, randomAccount.address);
       const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
       console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);
 
       // Assert: xcUNQ balance correctly decreased
       expect(xcUNQbalance).to.eq(unqOnAstarLeft);
       // Assert: ASTR balance is 0.996...
-      expect(balanceAstar / (10n ** 15n)).to.eq(996n);
+      expect(balanceAstar / (ASTAR_DECIMALS - 3n)).to.eq(996n);
     });
 
     await helper.wait.newBlocks(3);