git.delta.rocks / unique-network / refs/commits / 9d3aabb4c1a9

difftreelog

test(polkadex) added reserve malicious test

PraetorP2023-09-11parent: #683a128.patch.diff
in: master

2 files changed

modifiedtests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth
56const 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;
5757
58const 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.messageHash
62 && event.outcome.isFailedToTransactAsset);
63};
64const expectUntrustedReserveLocationFail = async (helper: DevUniqueHelper, messageSent: any) => {
65 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash
66 && 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;
895903
896 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {904 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {
905 /*
906 Since only the parachain part of the Polkadex
907 infrastructure is launched (without their
908 solochain validators), processing incoming
909 assets will lead to an error.
910 This error indicates that the Polkadex chain
911 received a message from the Unique network,
912 since the hash is being checked to ensure
913 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 });
976996
977 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramSent.messageHash);997 await expectFailedToTransact(helper, maliciousXcmProgramSent);
978998
979 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 });
1002
1003 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();
1006
1007 const uniqueMultilocation = {
1008 V2: {
1009 parents: 1,
1010 interior: {
1011 X1: {
1012 Parachain: UNIQUE_CHAIN,
1013 },
1014 },
1015 },
1016 };
1017
1018 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 );
1032
1033 const maliciousXcmProgramHereId = helper.arrange.makeXcmProgramReserveAssetDeposited(
1034 targetAccount.addressRaw,
1035 {
1036 Concrete: {
1037 parents: 0,
1038 interior: 'Here',
1039 },
1040 },
1041 testAmount,
1042 );
1043
1044 let maliciousXcmProgramFullIdSent: any;
1045 let maliciousXcmProgramHereIdSent: any;
1046 const maxWaitBlocks = 3;
1047
1048 // Try to trick Unique using full UNQ identification
1049 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {
1050 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramFullId);
1051
1052 maliciousXcmProgramFullIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
1053 });
1054
1055 await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramFullIdSent);
1056
1057 let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
1058 expect(accountBalance).to.be.equal(0n);
1059
1060 // Try to trick Unique using shortened UNQ identification
1061 await usingPolkadexPlaygrounds(polkadexUrl, async (helper) => {
1062 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgramHereId);
1063
1064 maliciousXcmProgramHereIdSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
1065 });
1066
1067 await expectUntrustedReserveLocationFail(helper, maliciousXcmProgramHereIdSent);
1068
1069 accountBalance = await helper.balance.getSubstrate(targetAccount.address);
1070 expect(accountBalance).to.be.equal(0n);
1071 });
982});1072});
9831073
984// These tests are relevant only when1074// These tests are relevant only when
1058 });1148 });
1059 });1149 });
10601150
1061 const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {1151
1062 await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash
1063 && event.outcome.isFailedToTransactAsset);
1064 };
10651152
1066 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) => {
addedvendor/baedeker-librarydiffbeforeafterboth

binary blob — no preview