difftreelog
test other chains can spend only up to balance
in: master
4 files changed
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth421 return capture;421 return capture;422 }422 }423424 makeXcmProgramWithdrawDeposit(beneficiary: Uint8Array, amount: bigint | string) {425 return {426 V2: [427 {428 WithdrawAsset: [429 {430 id: {431 Concrete: {432 parents: 0,433 interior: 'Here',434 },435 },436 fun: {437 Fungible: amount,438 },439 },440 ],441 },442 {443 BuyExecution: {444 fees: {445 id: {446 Concrete: {447 parents: 0,448 interior: 'Here',449 },450 },451 fun: {452 Fungible: amount,453 },454 },455 weightLimit: 'Unlimited'456 },457 },458 {459 DepositAsset: {460 assets: {461 Wild: 'All'462 },463 maxAssets: 1,464 beneficiary: {465 parents: 0,466 interior: {467 X1: {468 AccountId32: {469 network: 'Any',470 id: beneficiary471 },472 },473 },474 },475 }476 },477 ],478 };479 }423}480}424481425class MoonbeamAccountGroup {482class MoonbeamAccountGroup {tests/src/util/playgrounds/unique.tsdiffbeforeafterboth2446 return this.ethBalanceGroup.getEthereum(address);2446 return this.ethBalanceGroup.getEthereum(address);2447 }2447 }24482449 async setBalanceSubstrate(signer: TSigner, address: TSubstrateAccount, amount: bigint | string, reservedAmount: bigint | string = 0n) {2450 await this.helper.executeExtrinsic(signer, 'api.tx.balances.setBalance', [address, amount, reservedAmount], true);2451 }244824522449 /**2453 /**2450 * Transfer tokens to substrate address2454 * Transfer tokens to substrate addresstests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth643 expect(qtzFees == 0n).to.be.true;643 expect(qtzFees == 0n).to.be.true;644 });644 });645646 itSub('Karura can send only up to its balance', async ({helper}) => {647 // set Karura's sovereign account's balance648 const karuraBalance = 10000n * (10n ** QTZ_DECIMALS);649 const karuraSovereignAccount = helper.address.paraSiblingSovereignAccount(KARURA_CHAIN);650 await helper.getSudo().balance.setBalanceSubstrate(alice, karuraSovereignAccount, karuraBalance);651652 const moreThanKaruraHas = karuraBalance * 2n;653654 let targetAccountBalance = 0n;655 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);656657 const quartzMultilocation = {658 V1: {659 parents: 1,660 interior: {661 X1: {Parachain: QUARTZ_CHAIN},662 },663 },664 };665666 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanKaruraHas);667668 // Try to trick Quartz669 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {670 await helper.getSudo().executeExtrinsic(671 alice,672 'api.tx.polkadotXcm.send',673 [674 quartzMultilocation,675 maliciousXcmProgram,676 ],677 true,678 );679 });680681 const maxWaitBlocks = 3;682683 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(684 maxWaitBlocks,685 'xcmpQueue',686 'Fail',687 );688689 expect(690 xcmpQueueFailEvent != null,691 `'xcmpQueue.FailEvent' event is expected`,692 ).to.be.true;693694 expect(695 xcmpQueueFailEvent!.isFailedToTransactAsset,696 `The XCM error should be 'FailedToTransactAsset'`,697 ).to.be.true;698699 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);700 expect(targetAccountBalance).to.be.equal(0n);701702 // But Karura still can send the correct amount703 const validTransferAmount = karuraBalance / 2n;704 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);705706 await usingKaruraPlaygrounds(karuraUrl, async (helper) => {707 await helper.getSudo().executeExtrinsic(708 alice,709 'api.tx.polkadotXcm.send',710 [711 quartzMultilocation,712 validXcmProgram,713 ],714 true,715 );716 });717718 await helper.wait.newBlocks(maxWaitBlocks);719720 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);721 expect(targetAccountBalance).to.be.equal(validTransferAmount);722 });645});723});646724647// These tests are relevant only when725// These tests are relevant only when1061 expect(qtzFees == 0n).to.be.true;1139 expect(qtzFees == 0n).to.be.true;1062 });1140 });11411142 itSub.skip('Moonriver can send only up to its balance', async ({helper}) => {1143 throw Error("Not yet implemented");1144 });1063});1145});106411461065describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1147describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {1273 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);1355 expect(balanceQTZ).to.eq(balanceAfterQuartzToShidenXCM + qtzFromShidenTransfered);1274 });1356 });13571358 itSub('Shiden can send only up to its balance', async ({helper}) => {1359 // set Shiden's sovereign account's balance1360 const shidenBalance = 10000n * (10n ** QTZ_DECIMALS);1361 const shidenSovereignAccount = helper.address.paraSiblingSovereignAccount(SHIDEN_CHAIN);1362 await helper.getSudo().balance.setBalanceSubstrate(alice, shidenSovereignAccount, shidenBalance);13631364 const moreThanShidenHas = shidenBalance * 2n;13651366 let targetAccountBalance = 0n;1367 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);13681369 const quartzMultilocation = {1370 V1: {1371 parents: 1,1372 interior: {1373 X1: {Parachain: QUARTZ_CHAIN},1374 },1375 },1376 };13771378 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);13791380 // Try to trick Quartz1381 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1382 await helper.getSudo().executeExtrinsic(1383 alice,1384 'api.tx.polkadotXcm.send',1385 [1386 quartzMultilocation,1387 maliciousXcmProgram,1388 ],1389 true,1390 );1391 });13921393 const maxWaitBlocks = 3;13941395 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1396 maxWaitBlocks,1397 'xcmpQueue',1398 'Fail',1399 );14001401 expect(1402 xcmpQueueFailEvent != null,1403 `'xcmpQueue.FailEvent' event is expected`,1404 ).to.be.true;14051406 expect(1407 xcmpQueueFailEvent!.isFailedToTransactAsset,1408 `The XCM error should be 'FailedToTransactAsset'`,1409 ).to.be.true;14101411 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1412 expect(targetAccountBalance).to.be.equal(0n);14131414 // But Shiden still can send the correct amount1415 const validTransferAmount = shidenBalance / 2n;1416 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);14171418 await usingShidenPlaygrounds(shidenUrl, async (helper) => {1419 await helper.getSudo().executeExtrinsic(1420 alice,1421 'api.tx.polkadotXcm.send',1422 [1423 quartzMultilocation,1424 validXcmProgram,1425 ],1426 true,1427 );1428 });14291430 await helper.wait.newBlocks(maxWaitBlocks);14311432 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1433 expect(targetAccountBalance).to.be.equal(validTransferAmount);1434 });1275});1435});12761436tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth645 expect(unqFees == 0n).to.be.true;645 expect(unqFees == 0n).to.be.true;646 });646 });647648 itSub('Acala can send only up to its balance', async ({helper}) => {649 // set Acala's sovereign account's balance650 const acalaBalance = 10000n * (10n ** UNQ_DECIMALS);651 const acalaSovereignAccount = helper.address.paraSiblingSovereignAccount(ACALA_CHAIN);652 await helper.getSudo().balance.setBalanceSubstrate(alice, acalaSovereignAccount, acalaBalance);653654 const moreThanAcalaHas = acalaBalance * 2n;655656 let targetAccountBalance = 0n;657 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);658659 const uniqueMultilocation = {660 V1: {661 parents: 1,662 interior: {663 X1: {Parachain: UNIQUE_CHAIN},664 },665 },666 };667668 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanAcalaHas);669670 // Try to trick Unique671 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {672 await helper.getSudo().executeExtrinsic(673 alice,674 'api.tx.polkadotXcm.send',675 [676 uniqueMultilocation,677 maliciousXcmProgram,678 ],679 true,680 );681 });682683 const maxWaitBlocks = 3;684685 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(686 maxWaitBlocks,687 'xcmpQueue',688 'Fail',689 );690691 expect(692 xcmpQueueFailEvent != null,693 `'xcmpQueue.FailEvent' event is expected`,694 ).to.be.true;695696 expect(697 xcmpQueueFailEvent!.isFailedToTransactAsset,698 `The XCM error should be 'FailedToTransactAsset'`,699 ).to.be.true;700701 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);702 expect(targetAccountBalance).to.be.equal(0n);703704 // But Acala still can send the correct amount705 const validTransferAmount = acalaBalance / 2n;706 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);707708 await usingAcalaPlaygrounds(acalaUrl, async (helper) => {709 await helper.getSudo().executeExtrinsic(710 alice,711 'api.tx.polkadotXcm.send',712 [713 uniqueMultilocation,714 validXcmProgram,715 ],716 true,717 );718 });719720 await helper.wait.newBlocks(maxWaitBlocks);721722 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);723 expect(targetAccountBalance).to.be.equal(validTransferAmount);724 });647});725});648726649// These tests are relevant only when727// These tests are relevant only when1064 expect(unqFees == 0n).to.be.true;1142 expect(unqFees == 0n).to.be.true;1065 });1143 });11441145 itSub.skip('Moonbeam can send only up to its balance', async ({helper}) => {1146 throw Error("Not yet implemented");1147 });1066});1148});106711491068describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {1150describeXCM('[XCM] Integration test: Exchanging tokens with Astar', () => {1331 });1413 });1332 });1414 });14151416 itSub('Astar can send only up to its balance', async ({helper}) => {1417 // set Astar's sovereign account's balance1418 const astarBalance = 10000n * (10n ** UNQ_DECIMALS);1419 const astarSovereignAccount = helper.address.paraSiblingSovereignAccount(ASTAR_CHAIN);1420 await helper.getSudo().balance.setBalanceSubstrate(alice, astarSovereignAccount, astarBalance);14211422 const moreThanShidenHas = astarBalance * 2n;14231424 let targetAccountBalance = 0n;1425 const [targetAccount] = await helper.arrange.createAccounts([targetAccountBalance], alice);14261427 const uniqueMultilocation = {1428 V1: {1429 parents: 1,1430 interior: {1431 X1: {Parachain: UNIQUE_CHAIN},1432 },1433 },1434 };14351436 const maliciousXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, moreThanShidenHas);14371438 // Try to trick Unique1439 await usingAstarPlaygrounds(astarUrl, async (helper) => {1440 await helper.getSudo().executeExtrinsic(1441 alice,1442 'api.tx.polkadotXcm.send',1443 [1444 uniqueMultilocation,1445 maliciousXcmProgram,1446 ],1447 true,1448 );1449 });14501451 const maxWaitBlocks = 3;14521453 const xcmpQueueFailEvent = await helper.wait.eventOutcome<XcmV2TraitsError>(1454 maxWaitBlocks,1455 'xcmpQueue',1456 'Fail',1457 );14581459 expect(1460 xcmpQueueFailEvent != null,1461 `'xcmpQueue.FailEvent' event is expected`,1462 ).to.be.true;14631464 expect(1465 xcmpQueueFailEvent!.isFailedToTransactAsset,1466 `The XCM error should be 'FailedToTransactAsset'`,1467 ).to.be.true;14681469 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1470 expect(targetAccountBalance).to.be.equal(0n);14711472 // But Astar still can send the correct amount1473 const validTransferAmount = astarBalance / 2n;1474 const validXcmProgram = helper.arrange.makeXcmProgramWithdrawDeposit(targetAccount.addressRaw, validTransferAmount);14751476 await usingAstarPlaygrounds(astarUrl, async (helper) => {1477 await helper.getSudo().executeExtrinsic(1478 alice,1479 'api.tx.polkadotXcm.send',1480 [1481 uniqueMultilocation,1482 validXcmProgram,1483 ],1484 true,1485 );1486 });14871488 await helper.wait.newBlocks(maxWaitBlocks);14891490 targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);1491 expect(targetAccountBalance).to.be.equal(validTransferAmount);1492 });1333});1493});13341494