git.delta.rocks / unique-network / refs/commits / e02f22f362b0

difftreelog

Merge pull request #915 from UniqueNetwork/test/additional-xcm-tests

Yaroslav Bolyukin2023-04-12parents: #5de8270 #b836b20.patch.diff
in: master
Test/additional xcm tests

4 files changed

modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -420,6 +420,100 @@
 
     return capture;
   }
+
+  makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, id: any, amount: bigint) {
+    return {
+      V2: [
+        {
+          WithdrawAsset: [
+            {
+              id,
+              fun: {
+                Fungible: amount,
+              },
+            },
+          ],
+        },
+        {
+          BuyExecution: {
+            fees: {
+              id,
+              fun: {
+                Fungible: amount,
+              },
+            },
+            weightLimit: 'Unlimited',
+          },
+        },
+        {
+          DepositAsset: {
+            assets: {
+              Wild: 'All',
+            },
+            maxAssets: 1,
+            beneficiary: {
+              parents: 0,
+              interior: {
+                X1: {
+                  AccountId32: {
+                    network: 'Any',
+                    id: beneficiary,
+                  },
+                },
+              },
+            },
+          },
+        },
+      ],
+    };
+  }
+
+  makeXcmProgramReserveAssetDeposited(beneficiary: Uint8Array, id: any, amount: bigint) {
+    return {
+      V2: [
+        {
+          ReserveAssetDeposited: [
+            {
+              id,
+              fun: {
+                Fungible: amount,
+              },
+            },
+          ],
+        },
+        {
+          BuyExecution: {
+            fees: {
+              id,
+              fun: {
+                Fungible: amount,
+              },
+            },
+            weightLimit: 'Unlimited',
+          },
+        },
+        {
+          DepositAsset: {
+            assets: {
+              Wild: 'All',
+            },
+            maxAssets: 1,
+            beneficiary: {
+              parents: 0,
+              interior: {
+                X1: {
+                  AccountId32: {
+                    network: 'Any',
+                    id: beneficiary,
+                  },
+                },
+              },
+            },
+          },
+        },
+      ],
+    };
+  }
 }
 
 class MoonbeamAccountGroup {
@@ -632,6 +726,19 @@
     });
     return promise;
   }
+
+  async eventOutcome<EventT>(maxBlocksToWait: number, eventSection: string, eventMethod: string) {
+    const eventRecord = await this.event(maxBlocksToWait, eventSection, eventMethod);
+
+    if (eventRecord == null) {
+      return null;
+    }
+
+    const event = eventRecord!.event;
+    const outcome = event.data[1] as EventT;
+
+    return outcome;
+  }
 }
 
 class SessionGroup {
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2446,6 +2446,10 @@
     return this.ethBalanceGroup.getEthereum(address);
   }
 
+  async setBalanceSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint, reservedAmount = 0n) {
+    await this.helper.executeExtrinsic(signer, 'api.tx.balances.setBalance', [address, amount, reservedAmount], true);
+  }
+
   /**
    * Transfer tokens to substrate address
    * @param signer keyring of signer
@@ -3017,6 +3021,18 @@
 
     await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);
   }
+
+  async send(signer: IKeyringPair, destination: any, message: any) {
+    await this.helper.executeExtrinsic(
+      signer,
+      `api.tx.${this.palletName}.send`,
+      [
+        destination,
+        message,
+      ],
+      true,
+    );
+  }
 }
 
 class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {
@@ -3280,6 +3296,7 @@
   assetRegistry: AcalaAssetRegistryGroup;
   xTokens: XTokensGroup<AcalaHelper>;
   tokens: TokensGroup<AcalaHelper>;
+  xcm: XcmGroup<AcalaHelper>;
 
   constructor(logger?: ILogger, options: {[key: string]: any} = {}) {
     super(logger, options.helperBase ?? AcalaHelper);
@@ -3288,6 +3305,7 @@
     this.assetRegistry = new AcalaAssetRegistryGroup(this);
     this.xTokens = new XTokensGroup(this);
     this.tokens = new TokensGroup(this);
+    this.xcm = new XcmGroup(this, 'polkadotXcm');
   }
 
   getSudo<T extends AcalaHelper>() {
modifiedtests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth
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, usingShidenPlaygrounds} from '../util';21import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';
22import {DevUniqueHelper} from '../util/playgrounds/unique.dev';
2223
23const QUARTZ_CHAIN = 2095;24const QUARTZ_CHAIN = 2095;
24const STATEMINE_CHAIN = 1000;25const STATEMINE_CHAIN = 1000;
642 expect(qtzFees == 0n).to.be.true;643 expect(qtzFees == 0n).to.be.true;
643 });644 });
645
646 itSub('Karura can send only up to its balance', async ({helper}) => {
647 // set Karura's sovereign account's balance
648 const karuraBalance = 10000n * (10n ** QTZ_DECIMALS);
649 const karuraSovereignAccount = helper.address.paraSiblingSovereignAccount(KARURA_CHAIN);
650 await helper.getSudo().balance.setBalanceSubstrate(alice, karuraSovereignAccount, karuraBalance);
651
652 const moreThanKaruraHas = karuraBalance * 2n;
653
654 let targetAccountBalance = 0n;
655 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
656
657 const quartzMultilocation = {
658 V1: {
659 parents: 1,
660 interior: {
661 X1: {Parachain: QUARTZ_CHAIN},
662 },
663 },
664 };
665
666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
667 targetAccount.addressRaw,
668 {
669 Concrete: {
670 parents: 0,
671 interior: 'Here',
672 },
673 },
674 moreThanKaruraHas,
675 );
676
677 // Try to trick Quartz
678 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
679 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
680 });
681
682 const maxWaitBlocks = 3;
683
684 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
685 maxWaitBlocks,
686 'xcmpQueue',
687 'Fail',
688 );
689
690 expect(
691 xcmpQueueFailEvent != null,
692 '\'xcmpQueue.FailEvent\' event is expected',
693 ).to.be.true;
694
695 expect(
696 xcmpQueueFailEvent!.isFailedToTransactAsset,
697 'The XCM error should be \'FailedToTransactAsset\'',
698 ).to.be.true;
699
700 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
701 expect(targetAccountBalance).to.be.equal(0n);
702
703 // But Karura still can send the correct amount
704 const validTransferAmount = karuraBalance / 2n;
705 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
706 targetAccount.addressRaw,
707 {
708 Concrete: {
709 parents: 0,
710 interior: 'Here',
711 },
712 },
713 validTransferAmount,
714 );
715
716 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
717 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);
718 });
719
720 await helper.wait.newBlocks(maxWaitBlocks);
721
722 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
723 expect(targetAccountBalance).to.be.equal(validTransferAmount);
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 });
644});781});
645782
646// These tests are relevant only when the foreign asset pallet is disabled783// These tests are relevant only when
784// the the corresponding foreign assets are not registered
647describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {785describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {
648 let alice: IKeyringPair;786 let alice: IKeyringPair;
787 let alith: IKeyringPair;
788
789 const testAmount = 100_000_000_000n;
790 let quartzParachainJunction;
791 let quartzAccountJunction;
792
793 let quartzParachainMultilocation: any;
794 let quartzAccountMultilocation: any;
795 let quartzCombinedMultilocation: any;
649796
650 before(async () => {797 before(async () => {
651 await usingPlaygrounds(async (helper, privateKey) => {798 await usingPlaygrounds(async (helper, privateKey) => {
652 alice = await privateKey('//Alice');799 alice = await privateKey('//Alice');
800
801 quartzParachainJunction = {Parachain: QUARTZ_CHAIN};
802 quartzAccountJunction = {
803 AccountId32: {
804 network: 'Any',
805 id: alice.addressRaw,
806 },
807 };
808
809 quartzParachainMultilocation = {
810 V1: {
811 parents: 1,
812 interior: {
813 X1: quartzParachainJunction,
814 },
815 },
816 };
817
818 quartzAccountMultilocation = {
819 V1: {
820 parents: 0,
821 interior: {
822 X1: quartzAccountJunction,
823 },
824 },
825 };
826
827 quartzCombinedMultilocation = {
828 V1: {
829 parents: 1,
830 interior: {
831 X2: [quartzParachainJunction, quartzAccountJunction],
832 },
833 },
834 };
653835
654 // Set the default version to wrap the first message to other chains.836 // Set the default version to wrap the first message to other chains.
655 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);837 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
656 });838 });
839
840 // eslint-disable-next-line require-await
841 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
842 alith = helper.account.alithAccount();
843 });
657 });844 });
845
846 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {
847 const maxWaitBlocks = 3;
848
849 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
850 maxWaitBlocks,
851 'xcmpQueue',
852 'Fail',
853 );
854
855 expect(
856 xcmpQueueFailEvent != null,
857 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,
858 ).to.be.true;
859
860 expect(
861 xcmpQueueFailEvent!.isFailedToTransactAsset,
862 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,
863 ).to.be.true;
864 };
865
866 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
867 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
868 const id = {
869 Token: 'KAR',
870 };
871 const destination = quartzCombinedMultilocation;
872 await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');
873 });
874
875 await expectFailedToTransact('KAR', helper);
876 });
877
878 itSub('Quartz rejects MOVR tokens from Moonriver', async ({helper}) => {
879 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
880 const id = 'SelfReserve';
881 const destination = quartzCombinedMultilocation;
882 await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');
883 });
884
885 await expectFailedToTransact('MOVR', helper);
886 });
658887
659 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {888 itSub('Quartz rejects SDN tokens from Shiden', async ({helper}) => {
660 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {889 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
890 const destinationParachain = quartzParachainMultilocation;
891 const beneficiary = quartzAccountMultilocation;
661 const destination = {892 const assets = {
662 V1: {893 V1: [{
894 id: {
895 Concrete: {
663 parents: 1,896 parents: 0,
664 interior: {897 interior: 'Here',
665 X2: [898 },
666 {Parachain: QUARTZ_CHAIN},899 },
667 {
668 AccountId32: {900 fun: {
669 network: 'Any',901 Fungible: testAmount,
670 id: alice.addressRaw,
671 },902 },
672 },
673 ],
674 },
675 },903 }],
676 };904 };
677
678 const id = {905 const feeAssetItem = 0;
679 Token: 'KAR',
680 };
681906
682 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');907 await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [
908 destinationParachain,
909 beneficiary,
910 assets,
911 feeAssetItem,
912 ]);
683 });913 });
684
685 const maxWaitBlocks = 3;
686914
687 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');915 await expectFailedToTransact('SDN', helper);
688
689 expect(
690 xcmpQueueFailEvent != null,
691 '[Karura] xcmpQueue.FailEvent event is expected',
692 ).to.be.true;
693
694 const event = xcmpQueueFailEvent!.event;
695 const outcome = event.data[1] as XcmV2TraitsError;
696
697 expect(
698 outcome.isFailedToTransactAsset,
699 '[Karura] The XCM error should be `FailedToTransactAsset`',
700 ).to.be.true;
701 });916 });
702});917});
703918
982 expect(qtzFees == 0n).to.be.true;1197 expect(qtzFees == 0n).to.be.true;
983 });1198 });
1199
1200 // eslint-disable-next-line require-await
1201 itSub.skip('Moonriver can send only up to its balance', async ({helper}) => {
1202 throw Error('Not yet implemented');
1203 });
1204
1205 // eslint-disable-next-line require-await
1206 itSub.skip('Should not accept reserve transfer of QTZ from Moonriver', async ({helper}) => {
1207 throw Error('Not yet implemented');
1208 });
984});1209});
9851210
986describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1211describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
1194 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);1419 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);
1195 });1420 });
1421
1422 itSub('Shiden can send only up to its balance', async ({helper}) => {
1423 // set Shiden's sovereign account's balance
1424 const shidenBalance = 10000n * (10n ** QTZ_DECIMALS);
1425 const shidenSovereignAccount = helper.address.paraSiblingSovereignAccount(SHIDEN_CHAIN);
1426 await helper.getSudo().balance.setBalanceSubstrate(alice, shidenSovereignAccount, shidenBalance);
1427
1428 const moreThanShidenHas = shidenBalance * 2n;
1429
1430 let targetAccountBalance = 0n;
1431 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
1432
1433 const quartzMultilocation = {
1434 V1: {
1435 parents: 1,
1436 interior: {
1437 X1: {Parachain: QUARTZ_CHAIN},
1438 },
1439 },
1440 };
1441
1442 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1443 targetAccount.addressRaw,
1444 {
1445 Concrete: {
1446 parents: 0,
1447 interior: 'Here',
1448 },
1449 },
1450 moreThanShidenHas,
1451 );
1452
1453 // Try to trick Quartz
1454 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1455 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);
1456 });
1457
1458 const maxWaitBlocks = 3;
1459
1460 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
1461 maxWaitBlocks,
1462 'xcmpQueue',
1463 'Fail',
1464 );
1465
1466 expect(
1467 xcmpQueueFailEvent != null,
1468 '\'xcmpQueue.FailEvent\' event is expected',
1469 ).to.be.true;
1470
1471 expect(
1472 xcmpQueueFailEvent!.isFailedToTransactAsset,
1473 'The XCM error should be \'FailedToTransactAsset\'',
1474 ).to.be.true;
1475
1476 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
1477 expect(targetAccountBalance).to.be.equal(0n);
1478
1479 // But Shiden still can send the correct amount
1480 const validTransferAmount = shidenBalance / 2n;
1481 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
1482 targetAccount.addressRaw,
1483 {
1484 Concrete: {
1485 parents: 0,
1486 interior: 'Here',
1487 },
1488 },
1489 validTransferAmount,
1490 );
1491
1492 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1493 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);
1494 });
1495
1496 await helper.wait.newBlocks(maxWaitBlocks);
1497
1498 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
1499 expect(targetAccountBalance).to.be.equal(validTransferAmount);
1500 });
1501
1502 itSub('Should not accept reserve transfer of QTZ from Shiden', async ({helper}) => {
1503 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);
1504 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
1505
1506 const quartzMultilocation = {
1507 V1: {
1508 parents: 1,
1509 interior: {
1510 X1: {
1511 Parachain: QUARTZ_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: QUARTZ_CHAIN,
1525 },
1526 },
1527 },
1528 },
1529 testAmount,
1530 );
1531
1532 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
1533 await helper.getSudo().xcm.send(alice, quartzMultilocation, 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 });
1196});1557});
11971558
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -19,6 +19,7 @@
 import config from '../config';
 import {XcmV2TraitsError} from '../interfaces';
 import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds, usingStatemintPlaygrounds, usingAstarPlaygrounds} from '../util';
+import {DevUniqueHelper} from '../util/playgrounds/unique.dev';
 
 const UNIQUE_CHAIN = 2037;
 const STATEMINT_CHAIN = 1000;
@@ -643,63 +644,277 @@
     console.log('[Acala -> Unique] transaction fees on Unique: %s UNQ', helper.util.bigIntToDecimals(unqFees));
     expect(unqFees == 0n).to.be.true;
   });
+
+  itSub('Acala can send only up to its balance', async ({helper}) => {
+    // set Acala's sovereign account's balance
+    const acalaBalance = 10000n * (10n ** UNQ_DECIMALS);
+    const acalaSovereignAccount = helper.address.paraSiblingSovereignAccount(ACALA_CHAIN);
+    await helper.getSudo().balance.setBalanceSubstrate(alice, acalaSovereignAccount, acalaBalance);
+
+    const moreThanAcalaHas = acalaBalance * 2n;
+
+    let targetAccountBalance = 0n;
+    const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
+
+    const uniqueMultilocation = {
+      V1: {
+        parents: 1,
+        interior: {
+          X1: {Parachain: UNIQUE_CHAIN},
+        },
+      },
+    };
+
+    const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 0,
+          interior: 'Here',
+        },
+      },
+      moreThanAcalaHas,
+    );
+
+    // Try to trick Unique
+    await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+    });
+
+    const maxWaitBlocks = 3;
+
+    const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+      maxWaitBlocks,
+      'xcmpQueue',
+      'Fail',
+    );
+
+    expect(
+      xcmpQueueFailEvent != null,
+      '\'xcmpQueue.FailEvent\' event is expected',
+    ).to.be.true;
+
+    expect(
+      xcmpQueueFailEvent!.isFailedToTransactAsset,
+      'The XCM error should be \'FailedToTransactAsset\'',
+    ).to.be.true;
+
+    targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(targetAccountBalance).to.be.equal(0n);
+
+    // But Acala still can send the correct amount
+    const validTransferAmount = acalaBalance / 2n;
+    const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 0,
+          interior: 'Here',
+        },
+      },
+      validTransferAmount,
+    );
+
+    await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
+    });
+
+    await helper.wait.newBlocks(maxWaitBlocks);
+
+    targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(targetAccountBalance).to.be.equal(validTransferAmount);
+  });
+
+  itSub('Should not accept reserve transfer of UNQ from Acala', async ({helper}) => {
+    const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
+    const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
+
+    const uniqueMultilocation = {
+      V1: {
+        parents: 1,
+        interior: {
+          X1: {
+            Parachain: UNIQUE_CHAIN,
+          },
+        },
+      },
+    };
+
+    const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 1,
+          interior: {
+            X1: {
+              Parachain: UNIQUE_CHAIN,
+            },
+          },
+        },
+      },
+      testAmount,
+    );
+
+    await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+    });
+
+    const maxWaitBlocks = 3;
+
+    const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+      maxWaitBlocks,
+      'xcmpQueue',
+      'Fail',
+    );
+
+    expect(
+      xcmpQueueFailEvent != null,
+      '\'xcmpQueue.FailEvent\' event is expected',
+    ).to.be.true;
+
+    expect(
+      xcmpQueueFailEvent!.isUntrustedReserveLocation,
+      'The XCM error should be \'isUntrustedReserveLocation\'',
+    ).to.be.true;
+
+    const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(accountBalance).to.be.equal(0n);
+  });
 });
 
-// These tests are relevant only when the foreign asset pallet is disabled
+// These tests are relevant only when
+// the the corresponding foreign assets are not registered
 describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => {
   let alice: IKeyringPair;
+  let alith: IKeyringPair;
+
+  const testAmount = 100_000_000_000n;
+  let uniqueParachainJunction;
+  let uniqueAccountJunction;
+
+  let uniqueParachainMultilocation: any;
+  let uniqueAccountMultilocation: any;
+  let uniqueCombinedMultilocation: any;
 
   before(async () => {
     await usingPlaygrounds(async (helper, privateKey) => {
       alice = await privateKey('//Alice');
 
-      // Set the default version to wrap the first message to other chains.
-      await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
-    });
-  });
+      uniqueParachainJunction = {Parachain: UNIQUE_CHAIN};
+      uniqueAccountJunction = {
+        AccountId32: {
+          network: 'Any',
+          id: alice.addressRaw,
+        },
+      };
 
-  itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
-    await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
-      const destination = {
+      uniqueParachainMultilocation = {
         V1: {
           parents: 1,
           interior: {
-            X2: [
-              {Parachain: UNIQUE_CHAIN},
-              {
-                AccountId32: {
-                  network: 'Any',
-                  id: alice.addressRaw,
-                },
-              },
-            ],
+            X1: uniqueParachainJunction,
+          },
+        },
+      };
+
+      uniqueAccountMultilocation = {
+        V1: {
+          parents: 0,
+          interior: {
+            X1: uniqueAccountJunction,
           },
         },
       };
 
-      const id = {
-        Token: 'ACA',
+      uniqueCombinedMultilocation = {
+        V1: {
+          parents: 1,
+          interior: {
+            X2: [uniqueParachainJunction, uniqueAccountJunction],
+          },
+        },
       };
 
-      await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');
+      // Set the default version to wrap the first message to other chains.
+      await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
     });
 
+    // eslint-disable-next-line require-await
+    await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
+      alith = helper.account.alithAccount();
+    });
+  });
+
+  const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {
     const maxWaitBlocks = 3;
 
-    const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');
+    const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+      maxWaitBlocks,
+      'xcmpQueue',
+      'Fail',
+    );
 
     expect(
       xcmpQueueFailEvent != null,
-      '[Acala] xcmpQueue.FailEvent event is expected',
+      `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,
     ).to.be.true;
-
-    const event = xcmpQueueFailEvent!.event;
-    const outcome = event.data[1] as XcmV2TraitsError;
 
     expect(
-      outcome.isFailedToTransactAsset,
-      '[Acala] The XCM error should be `FailedToTransactAsset`',
+      xcmpQueueFailEvent!.isFailedToTransactAsset,
+      `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,
     ).to.be.true;
+  };
+
+  itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
+    await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
+      const id = {
+        Token: 'ACA',
+      };
+      const destination = uniqueCombinedMultilocation;
+      await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');
+    });
+
+    await expectFailedToTransact('ACA', helper);
+  });
+
+  itSub('Unique rejects GLMR tokens from Moonbeam', async ({helper}) => {
+    await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
+      const id = 'SelfReserve';
+      const destination = uniqueCombinedMultilocation;
+      await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');
+    });
+
+    await expectFailedToTransact('GLMR', helper);
+  });
+
+  itSub('Unique rejects ASTR tokens from Astar', async ({helper}) => {
+    await usingAstarPlaygrounds(astarUrl, async (helper) => {
+      const destinationParachain = uniqueParachainMultilocation;
+      const beneficiary = uniqueAccountMultilocation;
+      const assets = {
+        V1: [{
+          id: {
+            Concrete: {
+              parents: 0,
+              interior: 'Here',
+            },
+          },
+          fun: {
+            Fungible: testAmount,
+          },
+        }],
+      };
+      const feeAssetItem = 0;
+
+      await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [
+        destinationParachain,
+        beneficiary,
+        assets,
+        feeAssetItem,
+      ]);
+    });
+
+    await expectFailedToTransact('ASTR', helper);
   });
 });
 
@@ -984,6 +1199,16 @@
     console.log('[Moonbeam -> Unique] transaction fees on Unique: %s UNQ', helper.util.bigIntToDecimals(unqFees));
     expect(unqFees == 0n).to.be.true;
   });
+
+  // eslint-disable-next-line require-await
+  itSub.skip('Moonbeam can send only up to its balance', async ({helper}) => {
+    throw Error('Not yet implemented');
+  });
+
+  // eslint-disable-next-line require-await
+  itSub.skip('Should not accept reserve transfer of UNQ from Moonbeam', async ({helper}) => {
+    throw Error('Not yet implemented');
+  });
 });
 
 describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {
@@ -1196,59 +1421,140 @@
     expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);
   });
 
-  itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
+  itSub('Astar can send only up to its balance', async ({helper}) => {
+    // set Astar's sovereign account's balance
+    const astarBalance = 10000n * (10n ** UNQ_DECIMALS);
+    const astarSovereignAccount = helper.address.paraSiblingSovereignAccount(ASTAR_CHAIN);
+    await helper.getSudo().balance.setBalanceSubstrate(alice, astarSovereignAccount, astarBalance);
+
+    const moreThanShidenHas = astarBalance * 2n;
+
+    let targetAccountBalance = 0n;
+    const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);
+
+    const uniqueMultilocation = {
+      V1: {
+        parents: 1,
+        interior: {
+          X1: {Parachain: UNIQUE_CHAIN},
+        },
+      },
+    };
+
+    const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 0,
+          interior: 'Here',
+        },
+      },
+      moreThanShidenHas,
+    );
+
+    // Try to trick Unique
+    await usingAstarPlaygrounds(astarUrl, async (helper) => {
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+    });
+
+    const maxWaitBlocks = 3;
+
+    const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+      maxWaitBlocks,
+      'xcmpQueue',
+      'Fail',
+    );
+
+    expect(
+      xcmpQueueFailEvent != null,
+      '\'xcmpQueue.FailEvent\' event is expected',
+    ).to.be.true;
+
+    expect(
+      xcmpQueueFailEvent!.isFailedToTransactAsset,
+      'The XCM error should be \'FailedToTransactAsset\'',
+    ).to.be.true;
+
+    targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(targetAccountBalance).to.be.equal(0n);
+
+    // But Astar still can send the correct amount
+    const validTransferAmount = astarBalance / 2n;
+    const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 0,
+          interior: 'Here',
+        },
+      },
+      validTransferAmount,
+    );
+
     await usingAstarPlaygrounds(astarUrl, async (helper) => {
-      const destination = {
-        V1: {
-          parents: 1,
-          interior: {
-            X1: {
-              Parachain: UNIQUE_CHAIN,
-            },
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
+    });
+
+    await helper.wait.newBlocks(maxWaitBlocks);
+
+    targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(targetAccountBalance).to.be.equal(validTransferAmount);
+  });
+
+  itSub('Should not accept reserve transfer of UNQ from Astar', async ({helper}) => {
+    const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
+    const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
+
+    const uniqueMultilocation = {
+      V1: {
+        parents: 1,
+        interior: {
+          X1: {
+            Parachain: UNIQUE_CHAIN,
           },
         },
-      };
+      },
+    };
 
-      const beneficiary = {
-        V1: {
-          parents: 0,
+    const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
+      targetAccount.addressRaw,
+      {
+        Concrete: {
+          parents: 1,
           interior: {
             X1: {
-              AccountId32: {
-                network: 'Any',
-                id: randomAccount.addressRaw,
-              },
+              Parachain: UNIQUE_CHAIN,
             },
           },
         },
-      };
+      },
+      testAmount,
+    );
 
-      const assets = {
-        V1: [
-          {
-            id: {
-              Concrete: {
-                parents: 1,
-                interior: {
-                  X1: {
-                    Parachain: UNIQUE_CHAIN,
-                  },
-                },
-              },
-            },
-            fun: {
-              Fungible: unqFromAstarTransfered,
-            },
-          },
-        ],
-      };
+    await usingAstarPlaygrounds(astarUrl, async (helper) => {
+      await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+    });
+
+    const maxWaitBlocks = 3;
 
-      // Initial balance is 1 ASTAR
-      expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);
+    const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+      maxWaitBlocks,
+      'xcmpQueue',
+      'Fail',
+    );
 
-      const feeAssetItem = 0;
-      // TODO: expect rejected:
-      await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
-    });
+    expect(
+      xcmpQueueFailEvent != null,
+      '\'xcmpQueue.FailEvent\' event is expected',
+    ).to.be.true;
+
+    expect(
+      xcmpQueueFailEvent!.isUntrustedReserveLocation,
+      'The XCM error should be \'isUntrustedReserveLocation\'',
+    ).to.be.true;
+
+    const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
+    expect(accountBalance).to.be.equal(0n);
   });
+
 });