difftreelog
test untrusted reserve locations
in: master
4 files changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth421 return capture;421 return capture;422 }422 }423423424 makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, amount: bigint | string) {424 makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, id: any, amount: bigint | string) {425 return {425 return {426 V2: [426 V2: [427 {427 {428 WithdrawAsset: [428 WithdrawAsset: [429 {429 {430 id: {430 id,431 Concrete: {432 parents: 0,433 interior: 'Here',434 },435 },436 fun: {431 fun: {437 Fungible: amount,432 Fungible: amount,438 },433 },442 {437 {443 BuyExecution: {438 BuyExecution: {444 fees: {439 fees: {445 id: {440 id,446 Concrete: {447 parents: 0,448 interior: 'Here',449 },450 },451 fun: {441 fun: {452 Fungible: amount,442 Fungible: amount,453 },443 },478 };468 };479 }469 }470471 makeXcmProgramReserveAssetDeposited(beneficiary: Uint8Array, id: any, amount: bigint | string) {472 return {473 V2: [474 {475 ReserveAssetDeposited: [476 {477 id,478 fun: {479 Fungible: amount,480 },481 },482 ],483 },484 {485 BuyExecution: {486 fees: {487 id,488 fun: {489 Fungible: amount,490 },491 },492 weightLimit: 'Unlimited'493 },494 },495 {496 DepositAsset: {497 assets: {498 Wild: 'All'499 },500 maxAssets: 1,501 beneficiary: {502 parents: 0,503 interior: {504 X1: {505 AccountId32: {506 network: 'Any',507 id: beneficiary508 },509 },510 },511 },512 },513 },514 ],515 };516 }480}517}481518482class MoonbeamAccountGroup {519class MoonbeamAccountGroup {tests/src/util/playgrounds/unique.tsdiffbeforeafterboth3022 await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);3022 await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);3023 }3023 }30243025 async send(signer: IKeyringPair, destination: any, message: any) {3026 await this.helper.executeExtrinsic(3027 signer,3028 `api.tx.${this.palletName}.send`,3029 [3030 destination,3031 message,3032 ],3033 true,3034 ); 3035 }3024}3036}302530373026class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {3038class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {3284 assetRegistry: AcalaAssetRegistryGroup;3296 assetRegistry: AcalaAssetRegistryGroup;3285 xTokens: XTokensGroup<AcalaHelper>;3297 xTokens: XTokensGroup<AcalaHelper>;3286 tokens: TokensGroup<AcalaHelper>;3298 tokens: TokensGroup<AcalaHelper>;3299 xcm: XcmGroup<AcalaHelper>;328733003288 constructor(logger?: ILogger, options: {[key: string]: any} = {}) {3301 constructor(logger?: ILogger, options: {[key: string]: any} = {}) {3289 super(logger, options.helperBase ?? AcalaHelper);3302 super(logger, options.helperBase ?? AcalaHelper);3292 this.assetRegistry = new AcalaAssetRegistryGroup(this);3305 this.assetRegistry = new AcalaAssetRegistryGroup(this);3293 this.xTokens = new XTokensGroup(this);3306 this.xTokens = new XTokensGroup(this);3294 this.tokens = new TokensGroup(this);3307 this.tokens = new TokensGroup(this);3308 this.xcm = new XcmGroup(this, 'polkadotXcm');3295 }3309 }329633103297 getSudo<T extends AcalaHelper>() {3311 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.tsdiffbeforeafterboth667667668 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanAcalaHas);668 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(669 targetAccount.addressRaw,670 {671 Concrete: {672 parents: 0,673 interior: 'Here',674 },675 },676 moreThanAcalaHas,677 );669678670 // Try to trick Unique679 // Try to trick Unique671 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {680 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {672 await helper.getSudo().executeExtrinsic(681 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);673 alice,674 'api.tx.polkadotXcm.send',675 [676 uniqueMultilocation,677 maliciousXcmProgram,678 ],679 true,680 );681 });682 });682683705 const validTransferAmount = acalaBalance / 2n;706 const validTransferAmount = acalaBalance / 2n;706 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);707 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(708 targetAccount.addressRaw,709 {710 Concrete: {711 parents: 0,712 interior: 'Here',713 },714 },715 validTransferAmount,716 );707717708 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {718 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {709 await helper.getSudo().executeExtrinsic(719 await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);710 alice,711 'api.tx.polkadotXcm.send',712 [723 expect(targetAccountBalance).to.be.equal(validTransferAmount);725 expect(targetAccountBalance).to.be.equal(validTransferAmount);724 });726 });727728 itSub('Should not accept reserve transfer of UNQ from Acala', async ({helper}) => {729 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);730 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);731732 const uniqueMultilocation = {733 V1: {734 parents: 1,735 interior: {736 X1: {737 Parachain: UNIQUE_CHAIN,738 },739 },740 },741 };742743 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(744 targetAccount.addressRaw,745 {746 Concrete: {747 parents: 1,748 interior: {749 X1: {750 Parachain: UNIQUE_CHAIN,751 },752 },753 },754 },755 testAmount,756 );757758 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {759 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);760 });761762 const maxWaitBlocks = 3;763764 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(765 maxWaitBlocks,766 'xcmpQueue',767 'Fail',768 );769770 expect(771 xcmpQueueFailEvent != null,772 `'xcmpQueue.FailEvent' event is expected`,773 ).to.be.true;774775 expect(776 xcmpQueueFailEvent!.isUntrustedReserveLocation,777 `The XCM error should be 'isUntrustedReserveLocation'`,778 ).to.be.true;779780 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);781 expect(accountBalance).to.be.equal(0n);782 });725});783});726784727// These tests are relevant only when785// These tests are relevant only when1146 throw Error("Not yet implemented");1204 throw Error("Not yet implemented");1147 });1205 });12061207 itSub.skip('Should not accept reserve transfer of UNQ from Moonbeam', async ({helper}) => {1208 throw Error("Not yet implemented");1209 });1148});1210});114912111150describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {1212describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {1357 expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);1419 expect(balanceUNQ).to.eq(balanceAfterUniqueToAstarXCM + unqFromAstarTransfered);1358 });1420 });13591360 itSub.skip('Should not accept limitedReserveTransfer of UNQ from ASTAR', async ({helper}) => {1361 await usingAstarPlaygrounds(astarUrl, async (helper) => {1362 const destination = {1363 V1: {1364 parents: 1,1365 interior: {1366 X1: {1367 Parachain: UNIQUE_CHAIN,1368 },1369 },1370 },1371 };13721373 const beneficiary = {1374 V1: {1375 parents: 0,1376 interior: {1377 X1: {1378 AccountId32: {1379 network: 'Any',1380 id: randomAccount.addressRaw,1381 },1382 },1383 },1384 },1385 };13861387 const assets = {1388 V1: [1389 {1390 id: {1391 Concrete: {1392 parents: 1,1393 interior: {1394 X1: {1395 Parachain: UNIQUE_CHAIN,1396 },1397 },1398 },1399 },1400 fun: {1401 Fungible: unqFromAstarTransfered,1402 },1403 },1404 ],1405 };14061407 // Initial balance is 1 ASTAR1408 expect(await helper.balance.getSubstrate(randomAccount.address)).to.eq(astarInitialBalance);14091410 const feeAssetItem = 0;1411 // TODO: expect rejected:1412 await helper.xcm.limitedReserveTransferAssets(randomAccount, destination, beneficiary, assets, feeAssetItem, 'Unlimited');1413 });1414 });141514211416 itSub('Astar can send only up to its balance', async ({helper}) => {1422 itSub('Astar can send only up to its balance', async ({helper}) => {1417 // set Astar's sovereign account's balance1423 // set Astar's sovereign account's balance143514411436 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);1442 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1443 targetAccount.addressRaw,1444 {1445 Concrete: {1446 parents: 0,1447 interior: 'Here',1448 },1449 },1450 moreThanShidenHas,1451 );143714521438 // Try to trick Unique1453 // Try to trick Unique1439 await usingAstarPlaygrounds(astarUrl, async (helper) => {1454 await usingAstarPlaygrounds(astarUrl, async (helper) => {1440 await helper.getSudo().executeExtrinsic(1455 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);1441 alice,1442 'api.tx.polkadotXcm.send',1443 [1444 uniqueMultilocation,1445 maliciousXcmProgram,1446 ],1447 true,1448 );1449 });1456 });145014571473 const validTransferAmount = astarBalance / 2n;1480 const validTransferAmount = astarBalance / 2n;1474 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);1481 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(1482 targetAccount.addressRaw,1483 {1484 Concrete: {1485 parents: 0,1486 interior: 'Here',1487 },1488 },1489 validTransferAmount,1490 );147514911476 await usingAstarPlaygrounds(astarUrl, async (helper) => {1492 await usingAstarPlaygrounds(astarUrl, async (helper) => {1477 await helper.getSudo().executeExtrinsic(1493 await helper.getSudo().xcm.send(alice, uniqueMultilocation, validXcmProgram);1478 alice,1479 'api.tx.polkadotXcm.send',1480 [1481 uniqueMultilocation,1482 validXcmProgram,1483 ],1484 true,1485 );1486 });1494 });148714951491 expect(targetAccountBalance).to.be.equal(validTransferAmount);1499 expect(targetAccountBalance).to.be.equal(validTransferAmount);1492 });1500 });15011502 itSub('Should not accept reserve transfer of UNQ from Astar', async ({helper}) => {1503 const testAmount = 10_000n * (10n ** UNQ_DECIMALS);1504 const [targetAccount] = await helper.arrange.createAccounts([0n], alice);15051506 const uniqueMultilocation = {1507 V1: {1508 parents: 1,1509 interior: {1510 X1: {1511 Parachain: UNIQUE_CHAIN,1512 },1513 },1514 },1515 };15161517 const maliciousXcmProgram = helper.arrange.makeXcmProgramReserveAssetDeposited(1518 targetAccount.addressRaw,1519 {1520 Concrete: {1521 parents: 1,1522 interior: {1523 X1: {1524 Parachain: UNIQUE_CHAIN,1525 },1526 },1527 },1528 },1529 testAmount,1530 );15311532 await usingAstarPlaygrounds(astarUrl, async (helper) => {1533 await helper.getSudo().xcm.send(alice, uniqueMultilocation, maliciousXcmProgram);1534 });15351536 const maxWaitBlocks = 3;15371538 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1539 maxWaitBlocks,1540 'xcmpQueue',1541 'Fail',1542 );15431544 expect(1545 xcmpQueueFailEvent != null,1546 `'xcmpQueue.FailEvent' event is expected`,1547 ).to.be.true;15481549 expect(1550 xcmpQueueFailEvent!.isUntrustedReserveLocation,1551 `The XCM error should be 'isUntrustedReserveLocation'`,1552 ).to.be.true;15531554 const accountBalance = await helper.balance.getSubstrate(targetAccount.address);1555 expect(accountBalance).to.be.equal(0n);1556 });15571493});1558});14941559