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.tsdiffbeforeafterboth19import 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';222323const QUARTZ_CHAIN = 2095;24const QUARTZ_CHAIN = 2095;24const STATEMINE_CHAIN = 1000;25const STATEMINE_CHAIN = 1000;643 });644 });644});645});645646646// These tests are relevant only when the foreign asset pallet is disabled647// These tests are relevant only when648// the the corresponding foreign assets are not registered647describeXCM('[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;652653 const testAmount = 100_000_000_000n;654 let quartzParachainJunction;655 let quartzAccountJunction;656657 let quartzParachainMultilocation: any;658 let quartzAccountMultilocation: any;659 let quartzCombinedMultilocation: any;649660650 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');664665 quartzParachainJunction = {Parachain: QUARTZ_CHAIN};666 quartzAccountJunction = {667 AccountId32: {668 network: 'Any',669 id: alice.addressRaw,670 },671 };672673 quartzParachainMultilocation = {674 V1: {675 parents: 1,676 interior: {677 X1: quartzParachainJunction,678 },679 },680 };681682 quartzAccountMultilocation = {683 V1: {684 parents: 0,685 interior: {686 X1: quartzAccountJunction,687 },688 },689 };690691 quartzCombinedMultilocation = {692 V1: {693 parents: 1,694 interior: {695 X2: [quartzParachainJunction, quartzAccountJunction],696 },697 },698 };653699654 // 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 });703704 // eslint-disable-next-line require-await705 await usingMoonriverPlaygrounds(moonriverUrl, async (helper) => {706 alith = helper.account.alithAccount();707 });657 });708 });709710 const expectFailedToTransact = async (network: string, helper: DevUniqueHelper) => {711 const maxWaitBlocks = 3;712713 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(714 maxWaitBlocks,715 'xcmpQueue',716 'Fail',717 );718719 expect(720 xcmpQueueFailEvent != null,721 `[reject ${network} tokens] 'xcmpQueue.FailEvent' event is expected`,722 ).to.be.true;723724 expect(725 xcmpQueueFailEvent!.isFailedToTransactAsset,726 `[reject ${network} tokens] The XCM error should be 'FailedToTransactAsset'`,727 ).to.be.true;728 };729730 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 });738739 await expectFailedToTransact('KAR', helper);740 });741742 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 });748749 await expectFailedToTransact('MOVR', helper);750 });658751659 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 };677678 const id = {769 const feeAssetItem = 0;679 Token: 'KAR',680 };681770682 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 });684685 const maxWaitBlocks = 3;686778687 const xcmpQueueFailEvent = await helper.wait.event(maxWaitBlocks, 'xcmpQueue', 'Fail');779 await expectFailedToTransact('SDN', helper);688689 expect(690 xcmpQueueFailEvent != null,691 '[Karura] xcmpQueue.FailEvent event is expected',692 ).to.be.true;693694 const event = xcmpQueueFailEvent!.event;695 const outcome = event.data[1] as XcmV2TraitsError;696697 expect(698 outcome.isFailedToTransactAsset,699 '[Karura] The XCM error should be `FailedToTransactAsset`',700 ).to.be.true;701 });780 });702});781});703782tests/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;
@@ -645,61 +646,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: 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,
},
},
};
- const id = {
- Token: 'ACA',
+ uniqueAccountMultilocation = {
+ V1: {
+ parents: 0,
+ interior: {
+ X1: uniqueAccountJunction,
+ },
+ },
};
- await helper.xTokens.transfer(alice, id, 100_000_000_000n, destination, 'Unlimited');
+ uniqueCombinedMultilocation = {
+ V1: {
+ parents: 1,
+ interior: {
+ X2: [uniqueParachainJunction, uniqueAccountJunction],
+ },
+ },
+ };
+
+ // 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);
});
});