difftreelog
fix qtz/unq reject foreign unregistered tokens
in: master
3 files changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -632,6 +632,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 {
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -19,6 +19,7 @@
import config from '../config';
import {XcmV2TraitsError} from '../interfaces';
import {itSub, expect, describeXCM, usingPlaygrounds, usingKaruraPlaygrounds, usingRelayPlaygrounds, usingMoonriverPlaygrounds, usingStateminePlaygrounds, usingShidenPlaygrounds} from '../util';
+import {DevUniqueHelper} from '../util/playgrounds/unique.dev';
const QUARTZ_CHAIN = 2095;
const STATEMINE_CHAIN = 1000;
@@ -643,61 +644,139 @@
});
});
-// 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: Quartz rejects non-native tokens', () => {
let alice: IKeyringPair;
+ let alith: IKeyringPair;
+
+ const testAmount = 100_000_000_000n;
+ let quartzParachainJunction;
+ let quartzAccountJunction;
+
+ let quartzParachainMultilocation: any;
+ let quartzAccountMultilocation: any;
+ let quartzCombinedMultilocation: 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);
- });
- });
+ quartzParachainJunction = {Parachain: QUARTZ_CHAIN};
+ quartzAccountJunction = {
+ AccountId32: {
+ network: 'Any',
+ id: alice.addressRaw,
+ },
+ };
- itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
- await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
- const destination = {
+ quartzParachainMultilocation = {
V1: {
parents: 1,
interior: {
- X2: [
- {Parachain: QUARTZ_CHAIN},
- {
- AccountId32: {
- network: 'Any',
- id: alice.addressRaw,
- },
- },
- ],
+ X1: quartzParachainJunction,
},
},
};
- const id = {
- Token: 'KAR',
+ quartzAccountMultilocation = {
+ V1: {
+ parents: 0,
+ interior: {
+ X1: quartzAccountJunction,
+ },
+ },
};
- await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');
+ quartzCombinedMultilocation = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [quartzParachainJunction, quartzAccountJunction],
+ },
+ },
+ };
+
+ // 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 usingMoonriverPlaygrounds(moonriverUrl, 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,
- '[Karura] 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,
- '[Karura] The XCM error should be `FailedToTransactAsset`',
+ xcmpQueueFailEvent!.isFailedToTransactAsset,
+ `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,
).to.be.true;
+ };
+
+ itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
+ await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
+ const id = {
+ Token: 'KAR',
+ };
+ const destination = quartzCombinedMultilocation;
+ await helper.xTokens.transfer(alice, id, testAmount, destination, 'Unlimited');
+ });
+
+ await expectFailedToTransact('KAR', helper);
+ });
+
+ itSub('Quartz rejects MOVR tokens from Moonriver', async ({helper}) => {
+ await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {
+ const id = 'SelfReserve';
+ const destination = quartzCombinedMultilocation;
+ await helper.xTokens.transfer(alith, id, testAmount, destination, 'Unlimited');
+ });
+
+ await expectFailedToTransact('MOVR', helper);
+ });
+
+ itSub('Quartz rejects SDN tokens from Shiden', async ({helper}) => {
+ await usingShidenPlaygrounds(shidenUrl, async (helper) => {
+ const destinationParachain = quartzParachainMultilocation;
+ const beneficiary = quartzAccountMultilocation;
+ 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('SDN', helper);
});
});
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth19import 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';222323const UNIQUE_CHAIN = 2037;24const UNIQUE_CHAIN = 2037;24const STATEMINT_CHAIN = 1000;25const STATEMINT_CHAIN = 1000;645 });646 });646});647});647648648// These tests are relevant only when the foreign asset pallet is disabled649// These tests are relevant only when650// the the corresponding foreign assets are not registered649describeXCM('[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;654655 const testAmount = 100_000_000_000n;656 let uniqueParachainJunction;657 let uniqueAccountJunction;658659 let uniqueParachainMultilocation: any;660 let uniqueAccountMultilocation: any;661 let uniqueCombinedMultilocation: any;651662652 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');666667 uniqueParachainJunction = {Parachain: UNIQUE_CHAIN};668 uniqueAccountJunction = {669 AccountId32: {670 network: 'Any',671 id: alice.addressRaw,672 },673 };674675 uniqueParachainMultilocation = {676 V1: {677 parents: 1,678 interior: {679 X1: uniqueParachainJunction,680 },681 },682 };683684 uniqueAccountMultilocation = {685 V1: {686 parents: 0,687 interior: {688 X1: uniqueAccountJunction,689 },690 },691 };692693 uniqueCombinedMultilocation = {694 V1: {695 parents: 1,696 interior: {697 X2: [uniqueParachainJunction, uniqueAccountJunction],698 },699 },700 };655701656 // 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 });705706 // eslint-disable-next-line require-await707 await usingMoonbeamPlaygrounds(moonbeamUrl, async (helper) => {708 alith = helper.account.alithAccount();709 });659 });710 });711712 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {713 const maxWaitBlocks = 3;714715 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(716 maxWaitBlocks,717 'xcmpQueue',718 'Fail',719 );720721 expect(722 xcmpQueueFailEvent != null,723 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,724 ).to.be.true;725726 expect(727 xcmpQueueFailEvent!.isFailedToTransactAsset,728 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,729 ).to.be.true;730 };731732 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 });740741 await expectFailedToTransact('ACA', helper);742 });743744 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 });750751 await expectFailedToTransact('GLMR', helper);752 });660753661 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 };679680 const id = {771 const feeAssetItem = 0;681 Token: 'ACA',682 };683772684 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 });686687 const maxWaitBlocks = 3;688780689 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');781 await expectFailedToTransact('ASTR', helper);690691 expect(692 xcmpQueueFailEvent != null,693 '[Acala] xcmpQueue.FailEvent event is expected',694 ).to.be.true;695696 const event = xcmpQueueFailEvent!.event;697 const outcome = event.data[1] as XcmV2TraitsError;698699 expect(700 outcome.isFailedToTransactAsset,701 '[Acala] The XCM error should be `FailedToTransactAsset`',702 ).to.be.true;703 });782 });704});783});705784