git.delta.rocks / unique-network / refs/commits / 1550f8cc5eba

difftreelog

Add Quartz-Shiden tests

Max Andreev2023-03-29parent: #955fd21.patch.diff
in: master
+ fix send-back test

2 files changed

modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
18import {blake2AsHex} from '@polkadot/util-crypto';18import {blake2AsHex} from '@polkadot/util-crypto';
19import config from '../config';19import config from '../config';
20import {XcmV2TraitsError} from '../interfaces';20import {XcmV2TraitsError} from '../interfaces';
21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds} from '../util';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingAstarPlaygrounds} from '../util';
2222
23const QUARTZ_CHAIN = 2095;23const QUARTZ_CHAIN = 2095;
24const STATEMINE_CHAIN = 1000;24const STATEMINE_CHAIN = 1000;
25const KARURA_CHAIN = 2000;25const KARURA_CHAIN = 2000;
26const MOONRIVER_CHAIN = 2023;26const MOONRIVER_CHAIN = 2023;
27const SHIDEN_CHAIN = 2007;
2728
28const STATEMINE_PALLET_INSTANCE = 50;29const STATEMINE_PALLET_INSTANCE = 50;
2930
30const relayUrl = config.relayUrl;31const relayUrl = config.relayUrl;
31const statemineUrl = config.statemineUrl;32const statemineUrl = config.statemineUrl;
32const karuraUrl = config.karuraUrl;33const karuraUrl = config.karuraUrl;
33const moonriverUrl = config.moonriverUrl;34const moonriverUrl = config.moonriverUrl;
35const shidenUrl = config.shidenUrl;
3436
35const RELAY_DECIMALS = 12;37const RELAY_DECIMALS = 12;
36const STATEMINE_DECIMALS = 12;38const STATEMINE_DECIMALS = 12;
979 });981 });
980});982});
983
984describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
985 let alice: IKeyringPair;
986 let randomAccount: IKeyringPair;
987
988 const shidenInitialBalance = 1n * (10n ** 18n);
989 const qtzToShidenAmount = 10n * (10n ** 18n);
990
991 before(async () => {
992 await usingPlaygrounds(async (helper, privateKey) => {
993 alice = await privateKey('//Alice');
994 [randomAccount] = await helper.arrange.createAccounts([100n], alice);
995 console.log('randomAccount', randomAccount.address);
996 });
997
998 await usingAstarPlaygrounds(shidenUrl, async (helper) => {
999 console.log('1. Create foreign asset and metadata');
1000 await helper.assets.create(
1001 alice,
1002 1,
1003 alice.address,
1004 1n,
1005 );
1006
1007 await helper.assets.setMetadata(
1008 alice,
1009 1,
1010 'Cross chain QTZ',
1011 'xcQTZ',
1012 18,
1013 );
1014
1015 console.log('2. Register asset location');
1016 const assetLocation = {
1017 V1: {
1018 parents: 1,
1019 interior: {
1020 X1: {
1021 Parachain: QUARTZ_CHAIN,
1022 },
1023 },
1024 },
1025 };
1026
1027 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.registerAssetLocation', [assetLocation, 1]);
1028
1029 console.log('3. Set payment for computation');
1030 // TODO this is Phala's price, what price will be for Unique?
1031 const unitsPerSecond = 228_000_000_000n;
1032 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
1033
1034 console.log('4. Transfer 1 SDN to recepient');
1035 await helper.balance.transferToSubstrate(alice, randomAccount.address, shidenInitialBalance);
1036 });
1037 });
1038
1039 itSub.only('Should connect and send QTZ to Shiden', async ({helper}) => {
1040 const destination = {
1041 V1: {
1042 parents: 1,
1043 interior: {
1044 X1: {
1045 Parachain: SHIDEN_CHAIN,
1046 },
1047 },
1048 },
1049 };
1050
1051 const beneficiary = {
1052 V1: {
1053 parents: 0,
1054 interior: {
1055 X1: {
1056 AccountId32: {
1057 network: 'Any',
1058 id: randomAccount.addressRaw,
1059 },
1060 },
1061 },
1062 },
1063 };
1064
1065 const assets = {
1066 V1: [
1067 {
1068 id: {
1069 Concrete: {
1070 parents: 0,
1071 interior: 'Here',
1072 },
1073 },
1074 fun: {
1075 Fungible: qtzToShidenAmount,
1076 },
1077 },
1078 ],
1079 };
1080
1081 // Initial balance is 100 UNQ
1082 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(100n * (10n ** 18n));
1083
1084 const feeAssetItem = 0;
1085 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
1086
1087 // Balance after reserve transfer is less than 90
1088 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(89_941967662676666465n);
1089
1090 await usingAstarPlaygrounds(shidenUrl, async (helper) => {
1091 await helper.wait.newBlocks(3);
1092 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1093 const astarBalance = await helper.balance.getSubstrate(randomAccount.address);
1094
1095 expect(xcUNQbalance).to.eq(9_999_999_999_088_000_000n);
1096 // Astar balance does not changed
1097 expect(astarBalance).to.eq(1_000_000_000_000_000_000n);
1098 });
1099 });
1100
1101 itSub.only('Should connect to Shiden and send QTZ back', async ({helper}) => {
1102 await usingAstarPlaygrounds(shidenUrl, async (helper) => {
1103 const destination = {
1104 V1: {
1105 parents: 1,
1106 interior: {
1107 X1: {
1108 Parachain: QUARTZ_CHAIN,
1109 },
1110 },
1111 },
1112 };
1113
1114 const beneficiary = {
1115 V1: {
1116 parents: 0,
1117 interior: {
1118 X1: {
1119 AccountId32: {
1120 network: 'Any',
1121 id: randomAccount.addressRaw,
1122 },
1123 },
1124 },
1125 },
1126 };
1127
1128 const assets = {
1129 V1: [
1130 {
1131 id: {
1132 Concrete: {
1133 parents: 1,
1134 interior: {
1135 X1: {
1136 Parachain: QUARTZ_CHAIN,
1137 },
1138 },
1139 },
1140 },
1141 fun: {
1142 Fungible: 5_000_000_000_000_000_000n,
1143 },
1144 },
1145 ],
1146 };
1147
1148 // Initial balance is 1 SDN
1149 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
1150
1151 const feeAssetItem = 0;
1152 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
1153
1154 // Balance after reserve transfer is less than 1 SDN
1155 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1156 const balanceSDN = await helper.balance.getSubstrate(randomAccount.address);
1157
1158 // Assert: xcQTZ balance decreased
1159 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
1160 // Assert: SDN balance is 0.996...
1161 expect(balanceSDN / (10n ** 15n)).to.eq(996n);
1162 });
1163
1164 await helper.wait.newBlocks(3);
1165 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
1166 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
1167 });
1168});
9811169
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
1003 alice,1003 alice,
1004 1,1004 1,
1005 alice.address,1005 alice.address,
1006 1n, // TODO set correct minimal balance1006 1n,
1007 );1007 );
10081008
1009 await helper.assets.setMetadata(1009 await helper.assets.setMetadata(
1033 const unitsPerSecond = 228_000_000_000n;1033 const unitsPerSecond = 228_000_000_000n;
1034 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1034 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
10351035
1036 console.log('4. Transfer 1 ASTAR for recepient');1036 console.log('4. Transfer 1 ASTR to recepient');
1037 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1037 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);
1038 });1038 });
1039 });1039 });
1100 });1100 });
1101 });1101 });
1102
1103 itSub.only('Should connect to Astar and send UNQ back', async ({helper}) => {
1104 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1105 const destination = {
1106 V1: {
1107 parents: 1,
1108 interior: {
1109 X1: {
1110 Parachain: UNIQUE_CHAIN,
1111 },
1112 },
1113 },
1114 };
1115
1116 const beneficiary = {
1117 V1: {
1118 parents: 0,
1119 interior: {
1120 X1: {
1121 AccountId32: {
1122 network: 'Any',
1123 id: randomAccount.addressRaw,
1124 },
1125 },
1126 },
1127 },
1128 };
1129
1130 const assets = {
1131 V1: [
1132 {
1133 id: {
1134 Concrete: {
1135 parents: 1,
1136 interior: {
1137 X1: {
1138 Parachain: UNIQUE_CHAIN,
1139 },
1140 },
1141 },
1142 },
1143 fun: {
1144 Fungible: 5_000_000_000_000_000_000n,
1145 },
1146 },
1147 ],
1148 };
1149
1150 // Initial balance is 1 ASTR
1151 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(1_000_000_000_000_000_000n);
1152
1153 const feeAssetItem = 0;
1154 await helper.executeExtrinsic(randomAccount, 'api.tx.polkadotXcm.reserveWithdrawAssets', [destination, beneficiary, assets, feeAssetItem]);
1155
1156 const xcUNQbalance = await helper.assets.account(1, randomAccount.address);
1157 const balanceAstar = await helper.balance.getSubstrate(randomAccount.address);
1158
1159 // Assert: xcUNQ balance decreased
1160 expect(xcUNQbalance).to.eq(4_999_999_999_088_000_000n);
1161 // Assert: ASTR balance is 0.996...
1162 expect(balanceAstar / (10n ** 15n)).to.eq(996n);
1163 });
1164
1165 await helper.wait.newBlocks(3);
1166 const balanceUNQ = await helper.balance.getSubstrate(randomAccount.address);
1167 expect(balanceUNQ).to.eq(89_941967662676666465n + 5_000_000_000_000_000_000n);
1168 });
11021169
1103 itSub.only('Should connect to Astar and send UNQ back', async ({helper}) => {1170 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
1104 await usingAstarPlaygrounds(astarUrl, async (helper) => {1171 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1105 const destination = {1172 const destination = {
1106 V1: {1173 V1: {