difftreelog
Add constants to magic numbers
in: master
2 files changed
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -987,6 +987,9 @@
let alice: IKeyringPair;
let sender: IKeyringPair;
+ const QTZ_ASSET_ID_ON_SHIDEN = 1;
+ const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
+
// Quartz -> Shiden
const shidenInitialBalance = 1n * SHIDEN_DECIMALS; // 1 SHD, 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?
@@ -1008,22 +1011,23 @@
await usingShidenPlaygrounds(shidenUrl, async (helper) => {
console.log('1. Create foreign asset and metadata');
+ // TODO update metadata with values from production
await helper.assets.create(
alice,
- 1,
+ QTZ_ASSET_ID_ON_SHIDEN,
alice.address,
- 1n,
+ QTZ_MINIMAL_BALANCE_ON_SHIDEN,
);
await helper.assets.setMetadata(
alice,
- 1,
+ QTZ_ASSET_ID_ON_SHIDEN,
'Cross chain QTZ',
'xcQTZ',
- 18,
+ Number(QTZ_DECIMALS),
);
- console.log('2. Register asset location');
+ console.log('2. Register asset location on Shiden');
const assetLocation = {
V1: {
parents: 1,
@@ -1035,12 +1039,12 @@
},
};
- await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
+ await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, QTZ_ASSET_ID_ON_SHIDEN]);
- console.log('3. Set payment for computation');
+ console.log('3. Set QTZ payment for XCM execution on Shiden');
await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
- console.log('4. Transfer 1 SDN to recepient');
+ console.log('4. Transfer 1 SDN to recipient to create the account (needed due to existential balance)');
await helper.balance.transferToSubstrate(alice, sender.address, shidenInitialBalance);
});
});
@@ -1103,7 +1107,7 @@
await usingShidenPlaygrounds(shidenUrl, async (helper) => {
await helper.wait.newBlocks(3);
- const xcQTZbalance = await helper.assets.account(1, sender.address);
+ const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);
const shidenBalance = await helper.balance.getSubstrate(sender.address);
console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
@@ -1172,14 +1176,14 @@
await helper.executeExtrinsic(sender, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
// Balance after reserve transfer is less than 1 SDN
- const xcQTZbalance = await helper.assets.account(1, sender.address);
+ const xcQTZbalance = await helper.assets.account(QTZ_ASSET_ID_ON_SHIDEN, sender.address);
const balanceSDN = await helper.balance.getSubstrate(sender.address);
console.log(`xcQTZ balance on Shiden after XCM is: ${xcQTZbalance}`);
// Assert: xcQTZ balance correctly decreased
expect(xcQTZbalance).to.eq(qtzOnShidenLeft);
// Assert: SDN balance is 0.996...
- expect(balanceSDN / (10n ** 15n)).to.eq(996n);
+ expect(balanceSDN / (SHIDEN_DECIMALS - 3n)).to.eq(996n);
});
await helper.wait.newBlocks(3);
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth989 let alice: IKeyringPair;989 let alice: IKeyringPair;990 let randomAccount: IKeyringPair;990 let randomAccount: IKeyringPair;991992 const UNQ_ASSET_ID_ON_SHIDEN = 1;993 const UNQ_MINIMAL_BALANCE_ON_SHIDEN = 1n;991994992 // Unique -> Astar995 // Unique -> Astar993 const astarInitialBalance = 1n * ASTAR_DECIMALS; // 1 ASTR, existential deposit required to actually create the account on Shiden.996 const astarInitialBalance = 1n * ASTAR_DECIMALS; // 1 ASTR, existential deposit required to actually create the account on Shiden.101010131011 await usingAstarPlaygrounds(astarUrl, async (helper) => {1014 await usingAstarPlaygrounds(astarUrl, async (helper) => {1012 console.log('1. Create foreign asset and metadata');1015 console.log('1. Create foreign asset and metadata');1016 // TODO update metadata with values from production1013 await helper.assets.create(1017 await helper.assets.create(1014 alice,1018 alice,1015 1,1019 UNQ_ASSET_ID_ON_SHIDEN,1016 alice.address,1020 alice.address,1017 1n,1021 UNQ_MINIMAL_BALANCE_ON_SHIDEN,1018 );1022 );101910231020 await helper.assets.setMetadata(1024 await helper.assets.setMetadata(1021 alice,1025 alice,1022 1,1026 UNQ_ASSET_ID_ON_SHIDEN,1023 'Cross chain UNQ',1027 'Cross chain UNQ',1024 'xcUNQ',1028 'xcUNQ',1025 18,1029 Number(UNQ_DECIMALS),1026 );1030 );102710311028 console.log('2. Register asset location');1032 console.log('2. Register asset location on Astar');1029 const assetLocation = {1033 const assetLocation = {1030 V1: {1034 V1: {1031 parents: 1,1035 parents: 1,1037 },1041 },1038 };1042 };103910431040 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);1044 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, UNQ_ASSET_ID_ON_SHIDEN]);104110451042 console.log('3. Set payment for computation');1046 console.log('3. Set UNQ payment for XCM execution on Astar');1043 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1047 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);104410481045 console.log('4. Transfer 1 ASTR to recepient');1049 console.log('4. Transfer 1 ASTR to recipient to create the account (needed due to existential balance)');1046 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1050 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1047 });1051 });1048 });1052 });110511091106 await usingAstarPlaygrounds(astarUrl, async (helper) => {1110 await usingAstarPlaygrounds(astarUrl, async (helper) => {1107 await helper.wait.newBlocks(3);1111 await helper.wait.newBlocks(3);1108 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1112 const xcUNQbalance = await helper.assets.account(UNQ_ASSET_ID_ON_SHIDEN, randomAccount.address);1109 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);1113 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);111011141111 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);1115 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);1173 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw1177 // this is non-standard polkadotXcm extension for Astar only. It calls InitiateReserveWithdraw1174 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);1178 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);117511791176 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);1180 const xcUNQbalance = await helper.assets.account(UNQ_ASSET_ID_ON_SHIDEN, randomAccount.address);1177 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);1181 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);1178 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);1182 console.log(`xcUNQ balance on Astar after XCM is: ${xcUNQbalance}`);117911831180 // Assert: xcUNQ balance correctly decreased1184 // Assert: xcUNQ balance correctly decreased1181 expect(xcUNQbalance).to.eq(unqOnAstarLeft);1185 expect(xcUNQbalance).to.eq(unqOnAstarLeft);1182 // Assert: ASTR balance is 0.996...1186 // Assert: ASTR balance is 0.996...1183 expect(balanceAstar / (10n ** 15n)).to.eq(996n);1187 expect(balanceAstar / (ASTAR_DECIMALS - 3n)).to.eq(996n);1184 });1188 });118511891186 await helper.wait.newBlocks(3);1190 await helper.wait.newBlocks(3);