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

difftreelog

fix qtz/unq reject foreign unregistered tokens

Daniel Shiposha2023-04-11parent: #5de8270.patch.diff
in: master

3 files changed

modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
633 return promise;633 return promise;
634 }634 }
635
636 async eventOutcome<EventT>(maxBlocksToWait: number, eventSection: string, eventMethod: string) {
637 const eventRecord = await this.event(maxBlocksToWait, eventSection, eventMethod);
638
639 if (eventRecord == null) {
640 return null;
641 }
642
643 const event = eventRecord!.event;
644 const outcome = event.data[1] as EventT;
645
646 return outcome;
647 }
635}648}
636649
637class SessionGroup {650class SessionGroup {
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;
643 });644 });
644});645});
645646
646// These tests are relevant only when the foreign asset pallet is disabled647// These tests are relevant only when
648// the the corresponding foreign assets are not registered
647describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {649describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {
648 let alice: IKeyringPair;650 let alice: IKeyringPair;
651 let alith: IKeyringPair;
652
653 const testAmount = 100_000_000_000n;
654 let quartzParachainJunction;
655 let quartzAccountJunction;
656
657 let quartzParachainMultilocation: any;
658 let quartzAccountMultilocation: any;
659 let quartzCombinedMultilocation: any;
649660
650 before(async () => {661 before(async () => {
651 await usingPlaygrounds(async (helper, privateKey) => {662 await usingPlaygrounds(async (helper, privateKey) => {
652 alice = await privateKey('//Alice');663 alice = await privateKey('//Alice');
664
665 quartzParachainJunction = {Parachain: QUARTZ_CHAIN};
666 quartzAccountJunction = {
667 AccountId32: {
668 network: 'Any',
669 id: alice.addressRaw,
670 },
671 };
672
673 quartzParachainMultilocation = {
674 V1: {
675 parents: 1,
676 interior: {
677 X1: quartzParachainJunction,
678 },
679 },
680 };
681
682 quartzAccountMultilocation = {
683 V1: {
684 parents: 0,
685 interior: {
686 X1: quartzAccountJunction,
687 },
688 },
689 };
690
691 quartzCombinedMultilocation = {
692 V1: {
693 parents: 1,
694 interior: {
695 X2: [quartzParachainJunction, quartzAccountJunction],
696 },
697 },
698 };
653699
654 // Set the default version to wrap the first message to other chains.700 // Set the default version to wrap the first message to other chains.
655 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);701 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
656 });702 });
703
704 // eslint-disable-next-line require-await
705 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
706 alith = helper.account.alithAccount();
707 });
657 });708 });
709
710 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {
711 const maxWaitBlocks = 3;
712
713 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
714 maxWaitBlocks,
715 'xcmpQueue',
716 'Fail',
717 );
718
719 expect(
720 xcmpQueueFailEvent != null,
721 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,
722 ).to.be.true;
723
724 expect(
725 xcmpQueueFailEvent!.isFailedToTransactAsset,
726 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,
727 ).to.be.true;
728 };
729
730 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
731 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
732 const id = {
733 Token: 'KAR',
734 };
735 const destination = quartzCombinedMultilocation;
736 await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');
737 });
738
739 await expectFailedToTransact('KAR', helper);
740 });
741
742 itSub('Quartz rejects MOVR tokens from Moonriver', async ({helper}) => {
743 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
744 const id = 'SelfReserve';
745 const destination = quartzCombinedMultilocation;
746 await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');
747 });
748
749 await expectFailedToTransact('MOVR', helper);
750 });
658751
659 itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {752 itSub('Quartz rejects SDN tokens from Shiden', async ({helper}) => {
660 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {753 await usingShidenPlaygrounds(shidenUrl, async (helper) => {
754 const destinationParachain = quartzParachainMultilocation;
755 const beneficiary = quartzAccountMultilocation;
661 const destination = {756 const assets = {
662 V1: {757 V1: [{
758 id: {
759 Concrete: {
663 parents: 1,760 parents: 0,
664 interior: {761 interior: 'Here',
665 X2: [762 },
666 {Parachain: QUARTZ_CHAIN},763 },
667 {
668 AccountId32: {764 fun: {
669 network: 'Any',765 Fungible: testAmount,
670 id: alice.addressRaw,
671 },766 },
672 },
673 ],
674 },
675 },767 }],
676 };768 };
677
678 const id = {769 const feeAssetItem = 0;
679 Token: 'KAR',
680 };
681770
682 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');771 await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [
772 destinationParachain,
773 beneficiary,
774 assets,
775 feeAssetItem,
776 ]);
683 });777 });
684
685 const maxWaitBlocks = 3;
686778
687 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');779 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 });780 });
702});781});
703782
modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
19import config from '../config';19import config from '../config';
20import {XcmV2TraitsError} from '../interfaces';20import {XcmV2TraitsError} from '../interfaces';
21import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds, usingStatemintPlaygrounds, usingAstarPlaygrounds} from '../util';21import {itSub, expect, describeXCM, usingPlaygrounds, usingAcalaPlaygrounds, usingRelayPlaygrounds, usingMoonbeamPlaygrounds, usingStatemintPlaygrounds, usingAstarPlaygrounds} from '../util';
22import {DevUniqueHelper} from '../util/playgrounds/unique.dev';
2223
23const UNIQUE_CHAIN = 2037;24const UNIQUE_CHAIN = 2037;
24const STATEMINT_CHAIN = 1000;25const STATEMINT_CHAIN = 1000;
645 });646 });
646});647});
647648
648// These tests are relevant only when the foreign asset pallet is disabled649// These tests are relevant only when
650// the the corresponding foreign assets are not registered
649describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => {651describeXCM('[XCM] Integration test: Unique rejects non-native tokens', () => {
650 let alice: IKeyringPair;652 let alice: IKeyringPair;
653 let alith: IKeyringPair;
654
655 const testAmount = 100_000_000_000n;
656 let uniqueParachainJunction;
657 let uniqueAccountJunction;
658
659 let uniqueParachainMultilocation: any;
660 let uniqueAccountMultilocation: any;
661 let uniqueCombinedMultilocation: any;
651662
652 before(async () => {663 before(async () => {
653 await usingPlaygrounds(async (helper, privateKey) => {664 await usingPlaygrounds(async (helper, privateKey) => {
654 alice = await privateKey('//Alice');665 alice = await privateKey('//Alice');
666
667 uniqueParachainJunction = {Parachain: UNIQUE_CHAIN};
668 uniqueAccountJunction = {
669 AccountId32: {
670 network: 'Any',
671 id: alice.addressRaw,
672 },
673 };
674
675 uniqueParachainMultilocation = {
676 V1: {
677 parents: 1,
678 interior: {
679 X1: uniqueParachainJunction,
680 },
681 },
682 };
683
684 uniqueAccountMultilocation = {
685 V1: {
686 parents: 0,
687 interior: {
688 X1: uniqueAccountJunction,
689 },
690 },
691 };
692
693 uniqueCombinedMultilocation = {
694 V1: {
695 parents: 1,
696 interior: {
697 X2: [uniqueParachainJunction, uniqueAccountJunction],
698 },
699 },
700 };
655701
656 // Set the default version to wrap the first message to other chains.702 // Set the default version to wrap the first message to other chains.
657 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);703 await helper.getSudo().xcm.setSafeXcmVersion(alice, SAFE_XCM_VERSION);
658 });704 });
705
706 // eslint-disable-next-line require-await
707 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
708 alith = helper.account.alithAccount();
709 });
659 });710 });
711
712 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {
713 const maxWaitBlocks = 3;
714
715 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
716 maxWaitBlocks,
717 'xcmpQueue',
718 'Fail',
719 );
720
721 expect(
722 xcmpQueueFailEvent != null,
723 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,
724 ).to.be.true;
725
726 expect(
727 xcmpQueueFailEvent!.isFailedToTransactAsset,
728 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,
729 ).to.be.true;
730 };
731
732 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {
733 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
734 const id = {
735 Token: 'ACA',
736 };
737 const destination = uniqueCombinedMultilocation;
738 await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');
739 });
740
741 await expectFailedToTransact('ACA', helper);
742 });
743
744 itSub('Unique rejects GLMR tokens from Moonbeam', async ({helper}) => {
745 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {
746 const id = 'SelfReserve';
747 const destination = uniqueCombinedMultilocation;
748 await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');
749 });
750
751 await expectFailedToTransact('GLMR', helper);
752 });
660753
661 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {754 itSub('Unique rejects ASTR tokens from Astar', async ({helper}) => {
662 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {755 await usingAstarPlaygrounds(astarUrl, async (helper) => {
756 const destinationParachain = uniqueParachainMultilocation;
757 const beneficiary = uniqueAccountMultilocation;
663 const destination = {758 const assets = {
664 V1: {759 V1: [{
760 id: {
761 Concrete: {
665 parents: 1,762 parents: 0,
666 interior: {763 interior: 'Here',
667 X2: [764 },
668 {Parachain: UNIQUE_CHAIN},765 },
669 {
670 AccountId32: {766 fun: {
671 network: 'Any',767 Fungible: testAmount,
672 id: alice.addressRaw,
673 },768 },
674 },
675 ],
676 },
677 },769 }],
678 };770 };
679
680 const id = {771 const feeAssetItem = 0;
681 Token: 'ACA',
682 };
683772
684 await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');773 await helper.executeExtrinsic(alice, 'api.tx.polkadotXcm.reserveWithdrawAssets', [
774 destinationParachain,
775 beneficiary,
776 assets,
777 feeAssetItem,
778 ]);
685 });779 });
686
687 const maxWaitBlocks = 3;
688780
689 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');781 await expectFailedToTransact('ASTR', helper);
690
691 expect(
692 xcmpQueueFailEvent != null,
693 '[Acala] xcmpQueue.FailEvent event is expected',
694 ).to.be.true;
695
696 const event = xcmpQueueFailEvent!.event;
697 const outcome = event.data[1] as XcmV2TraitsError;
698
699 expect(
700 outcome.isFailedToTransactAsset,
701 '[Acala] The XCM error should be `FailedToTransactAsset`',
702 ).to.be.true;
703 });782 });
704});783});
705784