git.delta.rocks / unique-network / refs/commits / 1b19b1f3b608

difftreelog

test untrusted reserve locations

Daniel Shiposha2023-04-12parent: #abe0498.patch.diff
in: master

4 files changed

modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
421 return capture;421 return capture;
422 }422 }
423423
424 makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, amount: bigint | string) {424 makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, id: any, amount: bigint | string) {
425 return {425 return {
426 V2: [426 V2: [
427 {427 {
428 WithdrawAsset: [428 WithdrawAsset: [
429 {429 {
430 id: {430 id,
431 Concrete: {
432 parents: 0,
433 interior: 'Here',
434 },
435 },
436 fun: {431 fun: {
437 Fungible: amount,432 Fungible: amount,
438 },433 },
442 {437 {
443 BuyExecution: {438 BuyExecution: {
444 fees: {439 fees: {
445 id: {440 id,
446 Concrete: {
447 parents: 0,
448 interior: 'Here',
449 },
450 },
451 fun: {441 fun: {
452 Fungible: amount,442 Fungible: amount,
453 },443 },
478 };468 };
479 }469 }
470
471 makeXcmProgramReserveAssetDeposited(beneficiary: Uint8Array, id: any, amount: bigint | string) {
472 return {
473 V2: [
474 {
475 ReserveAssetDeposited: [
476 {
477 id,
478 fun: {
479 Fungible: amount,
480 },
481 },
482 ],
483 },
484 {
485 BuyExecution: {
486 fees: {
487 id,
488 fun: {
489 Fungible: amount,
490 },
491 },
492 weightLimit: 'Unlimited'
493 },
494 },
495 {
496 DepositAsset: {
497 assets: {
498 Wild: 'All'
499 },
500 maxAssets: 1,
501 beneficiary: {
502 parents: 0,
503 interior: {
504 X1: {
505 AccountId32: {
506 network: 'Any',
507 id: beneficiary
508 },
509 },
510 },
511 },
512 },
513 },
514 ],
515 };
516 }
480}517}
481518
482class MoonbeamAccountGroup {519class MoonbeamAccountGroup {
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
3022 await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);3022 await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);
3023 }3023 }
3024
3025 async send(signer: IKeyringPair, destination: any, message: any) {
3026 await this.helper.executeExtrinsic(
3027 signer,
3028 `api.tx.${this.palletName}.send`,
3029 [
3030 destination,
3031 message,
3032 ],
3033 true,
3034 );
3035 }
3024}3036}
30253037
3026class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {3038class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {
3284 assetRegistry: AcalaAssetRegistryGroup;3296 assetRegistry: AcalaAssetRegistryGroup;
3285 xTokens: XTokensGroup<AcalaHelper>;3297 xTokens: XTokensGroup<AcalaHelper>;
3286 tokens: TokensGroup<AcalaHelper>;3298 tokens: TokensGroup<AcalaHelper>;
3299 xcm: XcmGroup<AcalaHelper>;
32873300
3288 constructor(logger?: ILogger, options: {[key: string]: any} = {}) {3301 constructor(logger?: ILogger, options: {[key: string]: any} = {}) {
3289 super(logger, options.helperBase ?? AcalaHelper);3302 super(logger, options.helperBase ?? AcalaHelper);
3292 this.assetRegistry = new AcalaAssetRegistryGroup(this);3305 this.assetRegistry = new AcalaAssetRegistryGroup(this);
3293 this.xTokens = new XTokensGroup(this);3306 this.xTokens = new XTokensGroup(this);
3294 this.tokens = new TokensGroup(this);3307 this.tokens = new TokensGroup(this);
3308 this.xcm = new XcmGroup(this, 'polkadotXcm');
3295 }3309 }
32963310
3297 getSudo<T extends AcalaHelper>() {3311 getSudo<T extends AcalaHelper>() {
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
665665
666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanKaruraHas);666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
667 targetAccount.addressRaw,
668 {
669 Concrete: {
670 parents: 0,
671 interior: 'Here',
672 },
673 },
674 moreThanKaruraHas,
675 );
667676
668 // Try to trick Quartz677 // Try to trick Quartz
669 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {678 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
670 await helper.getSudo().executeExtrinsic(679 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
671 alice,
672 'api.tx.polkadotXcm.send',
673 [
674 quartzMultilocation,
675 maliciousXcmProgram,
676 ],
677 true,
678 );
679 });680 });
680681
703 const validTransferAmount = karuraBalance / 2n;704 const validTransferAmount = karuraBalance / 2n;
704 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);705 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
706 targetAccount.addressRaw,
707 {
708 Concrete: {
709 parents: 0,
710 interior: 'Here',
711 },
712 },
713 validTransferAmount,
714 );
705715
706 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {716 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
707 await helper.getSudo().executeExtrinsic(717 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);
708 alice,
709 'api.tx.polkadotXcm.send',
710 [
721 expect(targetAccountBalance).to.be.equal(validTransferAmount);723 expect(targetAccountBalance).to.be.equal(validTransferAmount);
722 });724 });
725
726 itSub('Should not accept reserve transfer of QTZ from Karura', async ({helper}) => {
727 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);
728 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
729
730 const quartzMultilocation = {
731 V1: {
732 parents: 1,
733 interior: {
734 X1: {
735 Parachain: QUARTZ_CHAIN,
736 },
737 },
738 },
739 };
740
741 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
742 targetAccount.addressRaw,
743 {
744 Concrete: {
745 parents: 1,
746 interior: {
747 X1: {
748 Parachain: QUARTZ_CHAIN,
749 },
750 },
751 },
752 },
753 testAmount,
754 );
755
756 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
757 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
758 });
759
760 const maxWaitBlocks = 3;
761
762 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
763 maxWaitBlocks,
764 'xcmpQueue',
765 'Fail',
766 );
767
768 expect(
769 xcmpQueueFailEvent != null,
770 `'xcmpQueue.FailEvent' event is expected`,
771 ).to.be.true;
772
773 expect(
774 xcmpQueueFailEvent!.isUntrustedReserveLocation,
775 `The XCM error should be 'isUntrustedReserveLocation'`,
776 ).to.be.true;
777
778 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
779 expect(accountBalance).to.be.equal(0n);
780 });
723});781});
724782
725// These tests are relevant only when783// These tests are relevant only when
1143 throw Error("Not yet implemented");1201 throw Error("Not yet implemented");
1144 });1202 });
1203
1204 itSub.skip('Should not accept reserve transfer of QTZ from Moonriver', async ({helper}) => {
1205 throw Error("Not yet implemented");
1206 });
1145});1207});
11461208
1147describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1209describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
13771439
1378 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);1440 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1441 targetAccount.addressRaw,
1442 {
1443 Concrete: {
1444 parents: 0,
1445 interior: 'Here',
1446 },
1447 },
1448 moreThanShidenHas,
1449 );
13791450
1380 // Try to trick Quartz1451 // Try to trick Quartz
1381 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1452 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1382 await helper.getSudo().executeExtrinsic(1453 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
1383 alice,
1384 'api.tx.polkadotXcm.send',
1385 [
1386 quartzMultilocation,
1387 maliciousXcmProgram,
1388 ],
1389 true,
1390 );
1391 });1454 });
13921455
1415 const validTransferAmount = shidenBalance / 2n;1478 const validTransferAmount = shidenBalance / 2n;
1416 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);1479 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1480 targetAccount.addressRaw,
1481 {
1482 Concrete: {
1483 parents: 0,
1484 interior: 'Here',
1485 },
1486 },
1487 validTransferAmount,
1488 );
14171489
1418 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1490 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1419 await helper.getSudo().executeExtrinsic(1491 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);
1420 alice,
1421 'api.tx.polkadotXcm.send',
1422 [
1423 quartzMultilocation,
1424 validXcmProgram,
1425 ],
1426 true,
1427 );
1428 });1492 });
14291493
1433 expect(targetAccountBalance).to.be.equal(validTransferAmount);1497 expect(targetAccountBalance).to.be.equal(validTransferAmount);
1434 });1498 });
1499
1500 itSub('Should not accept reserve transfer of QTZ from Shiden', async ({helper}) => {
1501 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);
1502 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
1503
1504 const quartzMultilocation = {
1505 V1: {
1506 parents: 1,
1507 interior: {
1508 X1: {
1509 Parachain: QUARTZ_CHAIN,
1510 },
1511 },
1512 },
1513 };
1514
1515 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
1516 targetAccount.addressRaw,
1517 {
1518 Concrete: {
1519 parents: 1,
1520 interior: {
1521 X1: {
1522 Parachain: QUARTZ_CHAIN,
1523 },
1524 },
1525 },
1526 },
1527 testAmount,
1528 );
1529
1530 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1531 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
1532 });
1533
1534 const maxWaitBlocks = 3;
1535
1536 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
1537 maxWaitBlocks,
1538 'xcmpQueue',
1539 'Fail',
1540 );
1541
1542 expect(
1543 xcmpQueueFailEvent != null,
1544 `'xcmpQueue.FailEvent' event is expected`,
1545 ).to.be.true;
1546
1547 expect(
1548 xcmpQueueFailEvent!.isUntrustedReserveLocation,
1549 `The XCM error should be 'isUntrustedReserveLocation'`,
1550 ).to.be.true;
1551
1552 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
1553 expect(accountBalance).to.be.equal(0n);
1554 });
1435});1555});
14361556
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
667667
668 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanAcalaHas);668 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
669 targetAccount.addressRaw,
670 {
671 Concrete: {
672 parents: 0,
673 interior: 'Here',
674 },
675 },
676 moreThanAcalaHas,
677 );
669678
670 // Try to trick Unique679 // Try to trick Unique
671 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {680 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
672 await helper.getSudo().executeExtrinsic(681 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
673 alice,
674 'api.tx.polkadotXcm.send',
675 [
676 uniqueMultilocation,
677 maliciousXcmProgram,
678 ],
679 true,
680 );
681 });682 });
682683
705 const validTransferAmount = acalaBalance / 2n;706 const validTransferAmount = acalaBalance / 2n;
706 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);707 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
708 targetAccount.addressRaw,
709 {
710 Concrete: {
711 parents: 0,
712 interior: 'Here',
713 },
714 },
715 validTransferAmount,
716 );
707717
708 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {718 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
709 await helper.getSudo().executeExtrinsic(719 await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
710 alice,
711 'api.tx.polkadotXcm.send',
712 [
723 expect(targetAccountBalance).to.be.equal(validTransferAmount);725 expect(targetAccountBalance).to.be.equal(validTransferAmount);
724 });726 });
727
728 itSub('Should not accept reserve transfer of UNQ from Acala', async ({helper}) => {
729 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
730 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
731
732 const uniqueMultilocation = {
733 V1: {
734 parents: 1,
735 interior: {
736 X1: {
737 Parachain: UNIQUE_CHAIN,
738 },
739 },
740 },
741 };
742
743 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
744 targetAccount.addressRaw,
745 {
746 Concrete: {
747 parents: 1,
748 interior: {
749 X1: {
750 Parachain: UNIQUE_CHAIN,
751 },
752 },
753 },
754 },
755 testAmount,
756 );
757
758 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
759 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
760 });
761
762 const maxWaitBlocks = 3;
763
764 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
765 maxWaitBlocks,
766 'xcmpQueue',
767 'Fail',
768 );
769
770 expect(
771 xcmpQueueFailEvent != null,
772 `'xcmpQueue.FailEvent' event is expected`,
773 ).to.be.true;
774
775 expect(
776 xcmpQueueFailEvent!.isUntrustedReserveLocation,
777 `The XCM error should be 'isUntrustedReserveLocation'`,
778 ).to.be.true;
779
780 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
781 expect(accountBalance).to.be.equal(0n);
782 });
725});783});
726784
727// These tests are relevant only when785// These tests are relevant only when
1146 throw Error("Not yet implemented");1204 throw Error("Not yet implemented");
1147 });1205 });
1206
1207 itSub.skip('Should not accept reserve transfer of UNQ from Moonbeam', async ({helper}) => {
1208 throw Error("Not yet implemented");
1209 });
1148});1210});
11491211
1150describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {1212describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {
1357 expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);1419 expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);
1358 });1420 });
1359
1360 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
1361 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1362 const destination = {
1363 V1: {
1364 parents: 1,
1365 interior: {
1366 X1: {
1367 Parachain: UNIQUE_CHAIN,
1368 },
1369 },
1370 },
1371 };
1372
1373 const beneficiary = {
1374 V1: {
1375 parents: 0,
1376 interior: {
1377 X1: {
1378 AccountId32: {
1379 network: 'Any',
1380 id: randomAccount.addressRaw,
1381 },
1382 },
1383 },
1384 },
1385 };
1386
1387 const assets = {
1388 V1: [
1389 {
1390 id: {
1391 Concrete: {
1392 parents: 1,
1393 interior: {
1394 X1: {
1395 Parachain: UNIQUE_CHAIN,
1396 },
1397 },
1398 },
1399 },
1400 fun: {
1401 Fungible: unqFromAstarTransfered,
1402 },
1403 },
1404 ],
1405 };
1406
1407 // Initial balance is 1 ASTAR
1408 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);
1409
1410 const feeAssetItem = 0;
1411 // TODO: expect rejected:
1412 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
1413 });
1414 });
14151421
1416 itSub('Astar can send only up to its balance', async ({helper}) => {1422 itSub('Astar can send only up to its balance', async ({helper}) => {
1417 // set Astar's sovereign account's balance1423 // set Astar's sovereign account's balance
14351441
1436 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);1442 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1443 targetAccount.addressRaw,
1444 {
1445 Concrete: {
1446 parents: 0,
1447 interior: 'Here',
1448 },
1449 },
1450 moreThanShidenHas,
1451 );
14371452
1438 // Try to trick Unique1453 // Try to trick Unique
1439 await usingAstarPlaygrounds(astarUrl, async (helper) => {1454 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1440 await helper.getSudo().executeExtrinsic(1455 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
1441 alice,
1442 'api.tx.polkadotXcm.send',
1443 [
1444 uniqueMultilocation,
1445 maliciousXcmProgram,
1446 ],
1447 true,
1448 );
1449 });1456 });
14501457
1473 const validTransferAmount = astarBalance / 2n;1480 const validTransferAmount = astarBalance / 2n;
1474 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);1481 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1482 targetAccount.addressRaw,
1483 {
1484 Concrete: {
1485 parents: 0,
1486 interior: 'Here',
1487 },
1488 },
1489 validTransferAmount,
1490 );
14751491
1476 await usingAstarPlaygrounds(astarUrl, async (helper) => {1492 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1477 await helper.getSudo().executeExtrinsic(1493 await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
1478 alice,
1479 'api.tx.polkadotXcm.send',
1480 [
1481 uniqueMultilocation,
1482 validXcmProgram,
1483 ],
1484 true,
1485 );
1486 });1494 });
14871495
1491 expect(targetAccountBalance).to.be.equal(validTransferAmount);1499 expect(targetAccountBalance).to.be.equal(validTransferAmount);
1492 });1500 });
1501
1502 itSub('Should not accept reserve transfer of UNQ from Astar', async ({helper}) => {
1503 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
1504 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
1505
1506 const uniqueMultilocation = {
1507 V1: {
1508 parents: 1,
1509 interior: {
1510 X1: {
1511 Parachain: UNIQUE_CHAIN,
1512 },
1513 },
1514 },
1515 };
1516
1517 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
1518 targetAccount.addressRaw,
1519 {
1520 Concrete: {
1521 parents: 1,
1522 interior: {
1523 X1: {
1524 Parachain: UNIQUE_CHAIN,
1525 },
1526 },
1527 },
1528 },
1529 testAmount,
1530 );
1531
1532 await usingAstarPlaygrounds(astarUrl, async (helper) => {
1533 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
1534 });
1535
1536 const maxWaitBlocks = 3;
1537
1538 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
1539 maxWaitBlocks,
1540 'xcmpQueue',
1541 'Fail',
1542 );
1543
1544 expect(
1545 xcmpQueueFailEvent != null,
1546 `'xcmpQueue.FailEvent' event is expected`,
1547 ).to.be.true;
1548
1549 expect(
1550 xcmpQueueFailEvent!.isUntrustedReserveLocation,
1551 `The XCM error should be 'isUntrustedReserveLocation'`,
1552 ).to.be.true;
1553
1554 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
1555 expect(accountBalance).to.be.equal(0n);
1556 });
1557
1493});1558});
14941559