difftreelog
test(polkadex) added reserve malicious test
in: master
2 files changed
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth56const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;56const USDT_ASSET_AMOUNT = 10_000_000_000_000_000_000_000_000n;575758const SAFE_XCM_VERSION = 2;58const SAFE_XCM_VERSION = 2;5959const maxWaitBlocks = 6;60const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {61 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash62 && event.outcome.isFailedToTransactAsset);63};64const expectUntrustedReserveLocationFail = async (helper: DevUniqueHelper, messageSent: any) => {65 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash66 && event.outcome.isUntrustedReserveLocation);67};60describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => {68describeXCM('[XCM] Integration test: Exchanging USDT with Statemint', () => {61 let alice: IKeyringPair;69 let alice: IKeyringPair;62 let bob: IKeyringPair;70 let bob: IKeyringPair;894 expect(unqFees > 0n, 'Negative fees UNQ, looks like nothing was transferred').to.be.true;902 expect(unqFees > 0n, 'Negative fees UNQ, looks like nothing was transferred').to.be.true;895903896 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {904 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {905 /*906 Since only the parachain part of the Polkadex907 infrastructure is launched (without their908 solochain validators), processing incoming909 assets will lead to an error.910 This error indicates that the Polkadex chain911 received a message from the Unique network,912 since the hash is being checked to ensure913 it matches what was sent.914 */897 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash);915 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash);898 });916 });899 });917 });914 randomAccount.addressRaw,932 randomAccount.addressRaw,915 {933 {916 Concrete: {934 Concrete: {917 parents: 0,935 parents: 1,918 interior: 'Here',936 interior: {937 X1: {Parachain: UNIQUE_CHAIN},938 },919 },939 },920 },940 },921 TRANSFER_AMOUNT,941 TRANSFER_AMOUNT,974 maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);994 maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);975 });995 });976996977 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramSent.messageHash);997 await expectFailedToTransact(helper, maliciousXcmProgramSent);978998979 const targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);999 const targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);980 expect(targetAccountBalance).to.be.equal(0n);1000 expect(targetAccountBalance).to.be.equal(0n);981 });1001 });10021003 itSub('Should not accept reserve transfer of UNQ from Acala', async ({helper}) => {1004 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);1005 const targetAccount = helper.arrange.createEmptyAccount();10061007 const uniqueMultilocation = {1008 V2: {1009 parents: 1,1010 interior: {1011 X1: {1012 Parachain: UNIQUE_CHAIN,1013 },1014 },1015 },1016 };10171018 const maliciousXcmProgramFullId = helper.arrange.makeXcmProgramReserveAssetDeposited(1019 targetAccount.addressRaw,1020 {1021 Concrete: {1022 parents: 1,1023 interior: {1024 X1: {1025 Parachain: UNIQUE_CHAIN,1026 },1027 },1028 },1029 },1030 testAmount,1031 );10321033 const maliciousXcmProgramHereId = helper.arrange.makeXcmProgramReserveAssetDeposited(1034 targetAccount.addressRaw,1035 {1036 Concrete: {1037 parents: 0,1038 interior: 'Here',1039 },1040 },1041 testAmount,1042 );10431044 let maliciousXcmProgramFullIdSent: any;1045 let maliciousXcmProgramHereIdSent: any;1046 const maxWaitBlocks = 3;10471048 // Try to trick Unique using full UNQ identification1049 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {1050 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramFullId);10511052 maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);1053 });10541055 await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramFullIdSent);10561057 let accountBalance = await helper.balance.getSubstrate(targetAccount.address);1058 expect(accountBalance).to.be.equal(0n);10591060 // Try to trick Unique using shortened UNQ identification1061 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {1062 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramHereId);10631064 maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);1065 });10661067 await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramHereIdSent);10681069 accountBalance = await helper.balance.getSubstrate(targetAccount.address);1070 expect(accountBalance).to.be.equal(0n);1071 });982});1072});9831073984// These tests are relevant only when1074// These tests are relevant only when1058 });1148 });1059 });1149 });106011501061 const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {11511062 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash1063 && event.outcome.isFailedToTransactAsset);1064 };106511521066 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {1153 itSub('Unique rejects ACA tokens from Acala', async ({helper}) => {1067 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {1154 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {vendor/baedeker-librarydiffbeforeafterbothbinary blob — no preview