difftreelog
test untrusted reserve locations
in: master
4 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
@@ -421,18 +421,13 @@
return capture;
}
- makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, amount: bigint | string) {
+ makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, id: any, amount: bigint | string) {
return {
V2: [
{
WithdrawAsset: [
{
- id: {
- Concrete: {
- parents: 0,
- interior: 'Here',
- },
- },
+ id,
fun: {
Fungible: amount,
},
@@ -442,12 +437,54 @@
{
BuyExecution: {
fees: {
- id: {
- Concrete: {
- parents: 0,
- interior: 'Here',
+ id,
+ fun: {
+ Fungible: amount,
+ },
+ },
+ weightLimit: 'Unlimited'
+ },
+ },
+ {
+ DepositAsset: {
+ assets: {
+ Wild: 'All'
+ },
+ maxAssets: 1,
+ beneficiary: {
+ parents: 0,
+ interior: {
+ X1: {
+ AccountId32: {
+ network: 'Any',
+ id: beneficiary
+ },
},
},
+ },
+ },
+ },
+ ],
+ };
+ }
+
+ makeXcmProgramReserveAssetDeposited(beneficiary: Uint8Array, id: any, amount: bigint | string) {
+ return {
+ V2: [
+ {
+ ReserveAssetDeposited: [
+ {
+ id,
+ fun: {
+ Fungible: amount,
+ },
+ },
+ ],
+ },
+ {
+ BuyExecution: {
+ fees: {
+ id,
fun: {
Fungible: amount,
},
@@ -472,7 +509,7 @@
},
},
},
- }
+ },
},
],
};
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -3021,6 +3021,18 @@
await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);
}
+
+ async send(signer: IKeyringPair, destination: any, message: any) {
+ await this.helper.executeExtrinsic(
+ signer,
+ `api.tx.${this.palletName}.send`,
+ [
+ destination,
+ message,
+ ],
+ true,
+ );
+ }
}
class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {
@@ -3284,6 +3296,7 @@
assetRegistry: AcalaAssetRegistryGroup;
xTokens: XTokensGroup<AcalaHelper>;
tokens: TokensGroup<AcalaHelper>;
+ xcm: XcmGroup<AcalaHelper>;
constructor(logger?: ILogger, options: {[key: string]: any} = {}) {
super(logger, options.helperBase ?? AcalaHelper);
@@ -3292,6 +3305,7 @@
this.assetRegistry = new AcalaAssetRegistryGroup(this);
this.xTokens = new XTokensGroup(this);
this.tokens = new TokensGroup(this);
+ this.xcm = new XcmGroup(this, 'polkadotXcm');
}
getSudo<T extends AcalaHelper>() {
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth665665666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanKaruraHas);666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(667 targetAccount.addressRaw,668 {669 Concrete: {670 parents: 0,671 interior: 'Here',672 },673 },674 moreThanKaruraHas,675 );667676668 // Try to trick Quartz677 // Try to trick Quartz669 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {678 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {670 await helper.getSudo().executeExtrinsic(679 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);671 alice,672 'api.tx.polkadotXcm.send',673 [674 quartzMultilocation,675 maliciousXcmProgram,676 ],677 true,678 );679 });680 });680681703 const validTransferAmount = karuraBalance / 2n;704 const validTransferAmount = karuraBalance / 2n;704 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);705 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(706 targetAccount.addressRaw,707 {708 Concrete: {709 parents: 0,710 interior: 'Here',711 },712 },713 validTransferAmount,714 );705715706 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {716 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {707 await helper.getSudo().executeExtrinsic(717 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);708 alice,709 'api.tx.polkadotXcm.send',710 [721 expect(targetAccountBalance).to.be.equal(validTransferAmount);723 expect(targetAccountBalance).to.be.equal(validTransferAmount);722 });724 });725726 itSub('Should not accept reserve transfer of QTZ from Karura', async ({helper}) => {727 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);728 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);729730 const quartzMultilocation = {731 V1: {732 parents: 1,733 interior: {734 X1: {735 Parachain: QUARTZ_CHAIN,736 },737 },738 },739 };740741 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(742 targetAccount.addressRaw,743 {744 Concrete: {745 parents: 1,746 interior: {747 X1: {748 Parachain: QUARTZ_CHAIN,749 },750 },751 },752 },753 testAmount,754 );755756 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {757 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);758 });759760 const maxWaitBlocks = 3;761762 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(763 maxWaitBlocks,764 'xcmpQueue',765 'Fail',766 );767768 expect(769 xcmpQueueFailEvent != null,770 `'xcmpQueue.FailEvent' event is expected`,771 ).to.be.true;772773 expect(774 xcmpQueueFailEvent!.isUntrustedReserveLocation,775 `The XCM error should be 'isUntrustedReserveLocation'`,776 ).to.be.true;777778 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);779 expect(accountBalance).to.be.equal(0n);780 });723});781});724782725// These tests are relevant only when783// These tests are relevant only when1143 throw Error("Not yet implemented");1201 throw Error("Not yet implemented");1144 });1202 });12031204 itSub.skip('Should not accept reserve transfer of QTZ from Moonriver', async ({helper}) => {1205 throw Error("Not yet implemented");1206 });1145});1207});114612081147describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1209describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {137714391378 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);1440 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1441 targetAccount.addressRaw,1442 {1443 Concrete: {1444 parents: 0,1445 interior: 'Here',1446 },1447 },1448 moreThanShidenHas,1449 );137914501380 // Try to trick Quartz1451 // Try to trick Quartz1381 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1452 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1382 await helper.getSudo().executeExtrinsic(1453 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1383 alice,1384 'api.tx.polkadotXcm.send',1385 [1386 quartzMultilocation,1387 maliciousXcmProgram,1388 ],1389 true,1390 );1391 });1454 });139214551415 const validTransferAmount = shidenBalance / 2n;1478 const validTransferAmount = shidenBalance / 2n;1416 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);1479 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1480 targetAccount.addressRaw,1481 {1482 Concrete: {1483 parents: 0,1484 interior: 'Here',1485 },1486 },1487 validTransferAmount,1488 );141714891418 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1490 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1419 await helper.getSudo().executeExtrinsic(1491 await helper.getSudo().xcm.send(alice, quartzMultilocation, validXcmProgram);1420 alice,1421 'api.tx.polkadotXcm.send',1422 [1423 quartzMultilocation,1424 validXcmProgram,1425 ],1426 true,1427 );1428 });1492 });142914931433 expect(targetAccountBalance).to.be.equal(validTransferAmount);1497 expect(targetAccountBalance).to.be.equal(validTransferAmount);1434 });1498 });14991500 itSub('Should not accept reserve transfer of QTZ from Shiden', async ({helper}) => {1501 const testAmount = 10_000n * (10n ** QTZ_DECIMALS);1502 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);15031504 const quartzMultilocation = {1505 V1: {1506 parents: 1,1507 interior: {1508 X1: {1509 Parachain: QUARTZ_CHAIN,1510 },1511 },1512 },1513 };15141515 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(1516 targetAccount.addressRaw,1517 {1518 Concrete: {1519 parents: 1,1520 interior: {1521 X1: {1522 Parachain: QUARTZ_CHAIN,1523 },1524 },1525 },1526 },1527 testAmount,1528 );15291530 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1531 await helper.getSudo().xcm.send(alice, quartzMultilocation, maliciousXcmProgram);1532 });15331534 const maxWaitBlocks = 3;15351536 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1537 maxWaitBlocks,1538 'xcmpQueue',1539 'Fail',1540 );15411542 expect(1543 xcmpQueueFailEvent != null,1544 `'xcmpQueue.FailEvent' event is expected`,1545 ).to.be.true;15461547 expect(1548 xcmpQueueFailEvent!.isUntrustedReserveLocation,1549 `The XCM error should be 'isUntrustedReserveLocation'`,1550 ).to.be.true;15511552 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);1553 expect(accountBalance).to.be.equal(0n);1554 });1435});1555});14361556tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -665,19 +665,20 @@
},
};
- const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanAcalaHas);
+ const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ moreThanAcalaHas,
+ );
// Try to trick Unique
await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
- await helper.getSudo().executeExtrinsic(
- alice,
- 'api.tx.polkadotXcm.send',
- [
- uniqueMultilocation,
- maliciousXcmProgram,
- ],
- true,
- );
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
});
const maxWaitBlocks = 3;
@@ -703,18 +704,19 @@
// But Acala still can send the correct amount
const validTransferAmount = acalaBalance / 2n;
- const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);
+ const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ validTransferAmount,
+ );
await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
- await helper.getSudo().executeExtrinsic(
- alice,
- 'api.tx.polkadotXcm.send',
- [
- uniqueMultilocation,
- validXcmProgram,
- ],
- true,
- );
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
});
await helper.wait.newBlocks(maxWaitBlocks);
@@ -722,6 +724,62 @@
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(validTransferAmount);
});
+
+ itSub('Should not accept reserve transfer of UNQ from Acala', async ({helper}) => {
+ const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
+ const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
+
+ const uniqueMultilocation = {
+ V1: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: UNIQUE_CHAIN,
+ },
+ },
+ },
+ };
+
+ const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: UNIQUE_CHAIN,
+ },
+ },
+ },
+ },
+ testAmount,
+ );
+
+ await usingAcalaPlaygrounds(acalaUrl, async (helper) => {
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+ });
+
+ const maxWaitBlocks = 3;
+
+ const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+ maxWaitBlocks,
+ 'xcmpQueue',
+ 'Fail',
+ );
+
+ expect(
+ xcmpQueueFailEvent != null,
+ `'xcmpQueue.FailEvent' event is expected`,
+ ).to.be.true;
+
+ expect(
+ xcmpQueueFailEvent!.isUntrustedReserveLocation,
+ `The XCM error should be 'isUntrustedReserveLocation'`,
+ ).to.be.true;
+
+ const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
+ expect(accountBalance).to.be.equal(0n);
+ });
});
// These tests are relevant only when
@@ -1145,6 +1203,10 @@
itSub.skip('Moonbeam can send only up to its balance', async ({helper}) => {
throw Error("Not yet implemented");
});
+
+ itSub.skip('Should not accept reserve transfer of UNQ from Moonbeam', async ({helper}) => {
+ throw Error("Not yet implemented");
+ });
});
describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {
@@ -1356,63 +1418,7 @@
console.log(`UNQ Balance on Unique after XCM is: ${balanceUNQ}`);
expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);
});
-
- itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {
- await usingAstarPlaygrounds(astarUrl, async (helper) => {
- const destination = {
- V1: {
- parents: 1,
- interior: {
- X1: {
- Parachain: UNIQUE_CHAIN,
- },
- },
- },
- };
-
- const beneficiary = {
- V1: {
- parents: 0,
- interior: {
- X1: {
- AccountId32: {
- network: 'Any',
- id: randomAccount.addressRaw,
- },
- },
- },
- },
- };
- const assets = {
- V1: [
- {
- id: {
- Concrete: {
- parents: 1,
- interior: {
- X1: {
- Parachain: UNIQUE_CHAIN,
- },
- },
- },
- },
- fun: {
- Fungible: unqFromAstarTransfered,
- },
- },
- ],
- };
-
- // Initial balance is 1 ASTAR
- expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);
-
- const feeAssetItem = 0;
- // TODO: expect rejected:
- await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');
- });
- });
-
itSub('Astar can send only up to its balance', async ({helper}) => {
// set Astar's sovereign account's balance
const astarBalance = 10000n * (10n ** UNQ_DECIMALS);
@@ -1433,19 +1439,20 @@
},
};
- const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);
+ const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ moreThanShidenHas,
+ );
// Try to trick Unique
await usingAstarPlaygrounds(astarUrl, async (helper) => {
- await helper.getSudo().executeExtrinsic(
- alice,
- 'api.tx.polkadotXcm.send',
- [
- uniqueMultilocation,
- maliciousXcmProgram,
- ],
- true,
- );
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
});
const maxWaitBlocks = 3;
@@ -1471,18 +1478,19 @@
// But Astar still can send the correct amount
const validTransferAmount = astarBalance / 2n;
- const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);
+ const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 0,
+ interior: 'Here',
+ },
+ },
+ validTransferAmount,
+ );
await usingAstarPlaygrounds(astarUrl, async (helper) => {
- await helper.getSudo().executeExtrinsic(
- alice,
- 'api.tx.polkadotXcm.send',
- [
- uniqueMultilocation,
- validXcmProgram,
- ],
- true,
- );
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);
});
await helper.wait.newBlocks(maxWaitBlocks);
@@ -1490,4 +1498,61 @@
targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(validTransferAmount);
});
+
+ itSub('Should not accept reserve transfer of UNQ from Astar', async ({helper}) => {
+ const testAmount = 10_000n * (10n ** UNQ_DECIMALS);
+ const [targetAccount] = await helper.arrange.createAccounts([0n], alice);
+
+ const uniqueMultilocation = {
+ V1: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: UNIQUE_CHAIN,
+ },
+ },
+ },
+ };
+
+ const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(
+ targetAccount.addressRaw,
+ {
+ Concrete: {
+ parents: 1,
+ interior: {
+ X1: {
+ Parachain: UNIQUE_CHAIN,
+ },
+ },
+ },
+ },
+ testAmount,
+ );
+
+ await usingAstarPlaygrounds(astarUrl, async (helper) => {
+ await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);
+ });
+
+ const maxWaitBlocks = 3;
+
+ const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(
+ maxWaitBlocks,
+ 'xcmpQueue',
+ 'Fail',
+ );
+
+ expect(
+ xcmpQueueFailEvent != null,
+ `'xcmpQueue.FailEvent' event is expected`,
+ ).to.be.true;
+
+ expect(
+ xcmpQueueFailEvent!.isUntrustedReserveLocation,
+ `The XCM error should be 'isUntrustedReserveLocation'`,
+ ).to.be.true;
+
+ const accountBalance = await helper.balance.getSubstrate(targetAccount.address);
+ expect(accountBalance).to.be.equal(0n);
+ });
+
});