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
989 let alice: IKeyringPair;989 let alice: IKeyringPair;
990 let randomAccount: IKeyringPair;990 let randomAccount: IKeyringPair;
991
992 const UNQ_ASSET_ID_ON_SHIDEN = 1;
993 const UNQ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
991994
992 // Unique -> Astar995 // Unique -> Astar
993 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.
10101013
1011 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 production
1013 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 );
10191023
1020 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 );
10271031
1028 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 };
10391043
1040 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]);
10411045
1042 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]);
10441048
1045 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 });
11051109
1106 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);
11101114
1111 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 InitiateReserveWithdraw
1174 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]);
11751179
1176 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}`);
11791183
1180 // Assert: xcUNQ balance correctly decreased1184 // Assert: xcUNQ balance correctly decreased
1181 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 });
11851189
1186 await helper.wait.newBlocks(3);1190 await helper.wait.newBlocks(3);