difftreelog
Add constants to magic numbers
in: master
2 files changed
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth987 let alice: IKeyringPair;987 let alice: IKeyringPair;988 let sender: IKeyringPair;988 let sender: IKeyringPair;989990 const QTZ_ASSET_ID_ON_SHIDEN = 1;991 const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;989992990 // Quartz -> Shiden993 // Quartz -> Shiden991 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 Shiden100810111009 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 production1011 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 );101710211018 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 );102510291026 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 };103710411038 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]);103910431040 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]);104210461043 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 });110311071104 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);110811121109 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]);117311771174 // Balance after reserve transfer is less than 1 SDN1178 // Balance after reserve transfer is less than 1 SDN1175 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}`);117811821179 // Assert: xcQTZ balance correctly decreased1183 // Assert: xcQTZ balance correctly decreased1180 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 });118411881185 await helper.wait.newBlocks(3);1189 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);