git.delta.rocks / unique-network / refs/commits / 355fa3f6ae5c

difftreelog

feat(test xcm) added generic `low level` xcm tests

PraetorP2023-09-25parent: #f2a1159.patch.diff
in: master

4 files changed

modifiedtests/package.jsondiffbeforeafterboth
112 "testCollators": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collator-selection/**.*test.ts --timeout 49999999",112 "testCollators": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collator-selection/**.*test.ts --timeout 49999999",
113 "testCollatorSelection": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collatorSelection.*test.ts --timeout 49999999",113 "testCollatorSelection": "RUN_COLLATOR_TESTS=1 yarn _test ./**/collatorSelection.*test.ts --timeout 49999999",
114 "testIdentity": "RUN_COLLATOR_TESTS=1 yarn _test ./**/identity.*test.ts --timeout 49999999",114 "testIdentity": "RUN_COLLATOR_TESTS=1 yarn _test ./**/identity.*test.ts --timeout 49999999",
115 "testLowLevelXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/lowLevelXcmUnique.test.ts",
115 "testXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmUnique.test.ts",116 "testXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmUnique.test.ts",
116 "testXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmQuartz.test.ts",117 "testXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmQuartz.test.ts",
117 "testXcmOpal": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmOpal.test.ts",118 "testXcmOpal": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmOpal.test.ts",
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
458 session: SessionGroup;458 session: SessionGroup;
459 testUtils: TestUtilGroup;459 testUtils: TestUtilGroup;
460 foreignAssets: ForeignAssetsGroup;460 foreignAssets: ForeignAssetsGroup;
461 xcm: XcmGroup<UniqueHelper>;461 xcm: XcmGroup<DevUniqueHelper>;
462 xTokens: XTokensGroup<UniqueHelper>;462 xTokens: XTokensGroup<DevUniqueHelper>;
463 tokens: TokensGroup<UniqueHelper>;463 tokens: TokensGroup<DevUniqueHelper>;
464 scheduler: SchedulerGroup;464 scheduler: SchedulerGroup;
465 collatorSelection: CollatorSelectionGroup;465 collatorSelection: CollatorSelectionGroup;
466 council: ICollectiveGroup;466 council: ICollectiveGroup;
627 super(logger, options);627 super(logger, options);
628 this.wait = new WaitGroup(this);628 this.wait = new WaitGroup(this);
629 }629 }
630 getSudo<T extends AcalaHelper>() {630 getSudo() {
631 // eslint-disable-next-line @typescript-eslint/naming-convention631 // eslint-disable-next-line @typescript-eslint/naming-convention
632 const SudoHelperType = SudoHelper(this.helperBase);632 const SudoHelperType = SudoHelper(this.helperBase);
633 return this.clone(SudoHelperType) as T;633 return this.clone(SudoHelperType) as DevAcalaHelper;
634 }634 }
635}635}
636636
643 this.wait = new WaitGroup(this);643 this.wait = new WaitGroup(this);
644 }644 }
645645
646 getSudo<T extends PolkadexHelper>() {646 getSudo() {
647 // eslint-disable-next-line @typescript-eslint/naming-convention647 // eslint-disable-next-line @typescript-eslint/naming-convention
648 const SudoHelperType = SudoHelper(this.helperBase);648 const SudoHelperType = SudoHelper(this.helperBase);
649 return this.clone(SudoHelperType) as T;649 return this.clone(SudoHelperType) as DevPolkadexHelper;
650 }650 }
651}651}
652652
1290 } else if(maxBlocksToWait > 0) {1290 } else if(maxBlocksToWait > 0) {
1291 maxBlocksToWait--;1291 maxBlocksToWait--;
1292 } else {1292 } else {
1293 this.helper.logger.log(`Eligible event \`${eventIdStr}\` is NOT found`);1293 this.helper.logger.log(`Eligible event \`${eventIdStr}\` is NOT found.
1294 The wait lasted until block ${blockNumber} inclusive`);
1294 unsubscribe();1295 unsubscribe();
1295 resolve(null);1296 resolve(null);
1296 }1297 }
addedtests/src/xcm/lowLevelXcmUnique.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
18import config from '../config';18import config from '../config';
19import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds, usingStatemintPlaygrounds, usingAstarPlaygrounds, usingPolkadexPlaygrounds} from '../util';19import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds, usingStatemintPlaygrounds, usingAstarPlaygrounds, usingPolkadexPlaygrounds} from '../util';
20import {DevUniqueHelper, Event} from '../util/playgrounds/unique.dev';20import {DevUniqueHelper, Event} from '../util/playgrounds/unique.dev';
21import {nToBigInt} from '@polkadot/util';21import {hexToString, nToBigInt} from '@polkadot/util';
2222
23const UNIQUE_CHAIN = +(process.env.RELAY_UNIQUE_ID || 2037);23const UNIQUE_CHAIN = +(process.env.RELAY_UNIQUE_ID || 2037);
24const STATEMINT_CHAIN = +(process.env.RELAY_STATEMINT_ID || 1000);24const STATEMINT_CHAIN = +(process.env.RELAY_STATEMINT_ID || 1000);
58const SAFE_XCM_VERSION = 2;58const SAFE_XCM_VERSION = 2;
59const maxWaitBlocks = 6;59const maxWaitBlocks = 6;
60
61const uniqueMultilocation = {
62 V2: {
63 parents: 1,
64 interior: {
65 X1: {
66 Parachain: UNIQUE_CHAIN,
67 },
68 },
69 },
70};
71
60const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {72const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {
61 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash73 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash
509 decimals: 18,521 decimals: 18,
510 minimalBalance: 1250000000000000000n,522 minimalBalance: 1250000000000000000n,
511 };523 };
512524 const assets = (await (helper.callRpc('api.query.assetRegistry.assetMetadatas.entries'))).map(([_k, v] : [any, any]) =>
525 hexToString(v.toJSON()['symbol'])) as string[];
526
527 if(!assets.includes('UNQ')) {
513 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);528 await helper.getSudo().assetRegistry.registerForeignAsset(alice, destination, metadata);
529 } else {
530 console.log('UNQ token already registered on Acala assetRegistry pallet');
531 }
514 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);532 await helper.balance.transferToSubstrate(alice, randomAccount.address, 10000000000000n);
515 balanceAcalaTokenInit = await helper.balance.getSubstrate(randomAccount.address);
516 balanceUniqueForeignTokenInit = await helper.tokens.accounts(randomAccount.address, {ForeignAsset: 0});
517 });533 });
518534
519 await usingPlaygrounds(async (helper) => {535 await usingPlaygrounds(async (helper) => {
670 let targetAccountBalance = 0n;686 let targetAccountBalance = 0n;
671 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);687 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
672
673 const uniqueMultilocation = {
674 V2: {
675 parents: 1,
676 interior: {
677 X1: {Parachain: UNIQUE_CHAIN},
678 },
679 },
680 };
681688
682 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(689 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
683 targetAccount.addressRaw,690 targetAccount.addressRaw,
925932
926 itSub('Should connect to Polkadex and send UNQ back', async ({helper}) => {933 itSub('Should connect to Polkadex and send UNQ back', async ({helper}) => {
927
928 const uniqueMultilocation = {
929 V2: {
930 parents: 1,
931 interior: {
932 X1: {Parachain: UNIQUE_CHAIN},
933 },
934 },
935 };
936934
937 const xcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(935 const xcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
938 randomAccount.addressRaw,936 randomAccount.addressRaw,
971969
972 const targetAccount = helper.arrange.createEmptyAccount();970 const targetAccount = helper.arrange.createEmptyAccount();
973
974 const uniqueMultilocation = {
975 V2: {
976 parents: 1,
977 interior: {
978 X1: {Parachain: UNIQUE_CHAIN},
979 },
980 },
981 };
982971
983 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(972 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
984 targetAccount.addressRaw,973 targetAccount.addressRaw,
1304 const unitsPerSecond = 1n;1293 const unitsPerSecond = 1n;
1305 const numAssetsWeightHint = 0;1294 const numAssetsWeightHint = 0;
13061295
1296 if((await helper.assetManager.assetTypeId(uniqueAssetLocation)).toJSON) {
1297 console.log('Unique asset is already registered on MoonBeam');
1298 } else {
1307 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({1299 const encodedProposal = helper.assetManager.makeRegisterForeignAssetProposal({
1308 location: uniqueAssetLocation,1300 location: uniqueAssetLocation,
1309 metadata: uniqueAssetMetadata,1301 metadata: uniqueAssetMetadata,
13241316
1325 console.log('UNQ asset ID is %s', assetId);1317 console.log('UNQ asset ID is %s', assetId);
1326 console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');1318 console.log('Acquire Unique AssetId Info on Moonbeam.......DONE');
1319 }
1327 // >>> Acquire Unique AssetId Info on Moonbeam >>>1320 // >>> Acquire Unique AssetId Info on Moonbeam >>>
13281321
1329 // >>> Sponsoring random Account >>>1322 // >>> Sponsoring random Account >>>
1456 let targetAccountBalance = 0n;1449 let targetAccountBalance = 0n;
1457 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);1450 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
1458
1459 const uniqueMultilocation = {
1460 V2: {
1461 parents: 1,
1462 interior: {
1463 X1: {Parachain: UNIQUE_CHAIN},
1464 },
1465 },
1466 };
14671451
1468 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1452 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1469 targetAccount.addressRaw,1453 targetAccount.addressRaw,
1527 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);1511 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
1528 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);1512 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
1529
1530 const uniqueMultilocation = {
1531 V2: {
1532 parents: 1,
1533 interior: {
1534 X1: {
1535 Parachain: UNIQUE_CHAIN,
1536 },
1537 },
1538 },
1539 };
15401513
1541 const maliciousXcmProgramFullId = helper.arrange.makeXcmProgramReserveAssetDeposited(1514 const maliciousXcmProgramFullId = helper.arrange.makeXcmProgramReserveAssetDeposited(
1542 targetAccount.addressRaw,1515 targetAccount.addressRaw,
1634 });1607 });
16351608
1636 await usingAstarPlaygrounds(astarUrl, async (helper) => {1609 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1610 if(!(await helper.callRpc('api.query.assets.asset', [UNQ_ASSET_ID_ON_ASTAR])).toJSON()) {
1637 console.log('1. Create foreign asset and metadata');1611 console.log('1. Create foreign asset and metadata');
1638 // TODO update metadata with values from production1612 // TODO update metadata with values from production
1639 await helper.assets.create(1613 await helper.assets.create(
16671641
1668 console.log('3. Set UNQ payment for XCM execution on Astar');1642 console.log('3. Set UNQ payment for XCM execution on Astar');
1669 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);1643 await helper.getSudo().executeExtrinsic(alice, 'api.tx.xcAssetConfig.setAssetUnitsPerSecond', [assetLocation, unitsPerSecond]);
16701644 }
1671 console.log('4. Transfer 1 ASTR to recipient to create the account (needed due to existential balance)');1645 console.log('4. Transfer 1 ASTR to recipient to create the account (needed due to existential balance)');
1672 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);1646 await helper.balance.transferToSubstrate(alice, randomAccount.address, astarInitialBalance);
1673 });1647 });
1825 let targetAccountBalance = 0n;1799 let targetAccountBalance = 0n;
1826 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);1800 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
1827
1828 const uniqueMultilocation = {
1829 V2: {
1830 parents: 1,
1831 interior: {
1832 X1: {Parachain: UNIQUE_CHAIN},
1833 },
1834 },
1835 };
18361801
1837 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1802 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1838 targetAccount.addressRaw,1803 targetAccount.addressRaw,
1888 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);1853 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
1889 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);1854 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
1890
1891 const uniqueMultilocation = {
1892 V2: {
1893 parents: 1,
1894 interior: {
1895 X1: {
1896 Parachain: UNIQUE_CHAIN,
1897 },
1898 },
1899 },
1900 };
19011855
1902 const maliciousXcmProgramFullId = helper.arrange.makeXcmProgramReserveAssetDeposited(1856 const maliciousXcmProgramFullId = helper.arrange.makeXcmProgramReserveAssetDeposited(
1903 targetAccount.addressRaw,1857 targetAccount.addressRaw,