Skip to content

Commit

Permalink
Merge pull request #985 from UniqueNetwork/fix/xcm-release-60
Browse files Browse the repository at this point in the history
fix: xcm tests
  • Loading branch information
CertainLach authored Sep 6, 2023
2 parents 432eea3 + bf4df5f commit 33d4989
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .baedeker/xcm-quartz.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local moonriver = {
wantedKeys: 'para-nimbus',
legacyRpc: true,
},
for name in ['alice', 'bob']
for name in ['alith', 'baltathar']
},
};

Expand Down
2 changes: 1 addition & 1 deletion .baedeker/xcm-unique.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ local moonbeam = {
wantedKeys: 'para-nimbus',
legacyRpc: true,
},
for name in ['alice', 'bob']
for name in ['alith', 'baltathar']
},
};

Expand Down
42 changes: 25 additions & 17 deletions tests/src/xcm/xcmQuartz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
// 2 QTZ sent https://quartz.subscan.io/xcm_message/kusama-f60d821b049f8835a3005ce7102285006f5b61e9
// 1.919176000000000000 QTZ received (you can check Karura's chain state in the corresponding block)
const expectedKaruraIncomeFee = 2000000000000000000n - 1919176000000000000n;
const karuraEps = 8n * 10n ** 16n;

const KARURA_BACKWARD_TRANSFER_AMOUNT = TRANSFER_AMOUNT - expectedKaruraIncomeFee;
let karuraBackwardTransferAmount: bigint;

before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
Expand Down Expand Up @@ -569,6 +570,8 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {

const karFees = balanceKaruraTokenInit - balanceKaruraTokenMiddle;
const qtzIncomeTransfer = balanceQuartzForeignTokenMiddle - balanceQuartzForeignTokenInit;
karuraBackwardTransferAmount = qtzIncomeTransfer;

const karUnqFees = TRANSFER_AMOUNT - qtzIncomeTransfer;

console.log(
Expand All @@ -581,8 +584,11 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
);
console.log('[Quartz -> Karura] income %s QTZ', helper.util.bigIntToDecimals(qtzIncomeTransfer));
expect(karFees == 0n).to.be.true;

const bigintAbs = (n: bigint) => (n < 0n) ? -n : n;

expect(
karUnqFees == expectedKaruraIncomeFee,
bigintAbs(karUnqFees - expectedKaruraIncomeFee) < karuraEps,
'Karura took different income fee, check the Karura foreign asset config',
).to.be.true;
});
Expand Down Expand Up @@ -611,7 +617,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
ForeignAsset: 0,
};

await helper.xTokens.transfer(randomAccount, id, KARURA_BACKWARD_TRANSFER_AMOUNT, destination, 'Unlimited');
await helper.xTokens.transfer(randomAccount, id, karuraBackwardTransferAmount, destination, 'Unlimited');
balanceKaruraTokenFinal = await helper.balance.getSubstrate(randomAccount.address);
balanceQuartzForeignTokenFinal = await helper.tokens.accounts(randomAccount.address, id);

Expand All @@ -625,7 +631,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
console.log('[Karura -> Quartz] outcome %s QTZ', helper.util.bigIntToDecimals(qtzOutcomeTransfer));

expect(karFees > 0, 'Negative fees KAR, looks like nothing was transferred').to.be.true;
expect(qtzOutcomeTransfer == KARURA_BACKWARD_TRANSFER_AMOUNT).to.be.true;
expect(qtzOutcomeTransfer == karuraBackwardTransferAmount).to.be.true;
});

await helper.wait.newBlocks(3);
Expand All @@ -636,7 +642,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {

console.log('[Karura -> Quartz] actually delivered %s QTZ', helper.util.bigIntToDecimals(actuallyDelivered));

const qtzFees = KARURA_BACKWARD_TRANSFER_AMOUNT - actuallyDelivered;
const qtzFees = karuraBackwardTransferAmount - actuallyDelivered;
console.log('[Karura -> Quartz] transaction fees on Quartz: %s QTZ', helper.util.bigIntToDecimals(qtzFees));
expect(qtzFees == 0n).to.be.true;
});
Expand Down Expand Up @@ -673,7 +679,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
);

let maliciousXcmProgramSent: any;
const maxWaitBlocks = 3;
const maxWaitBlocks = 5;

// Try to trick Quartz
await usingKaruraPlaygrounds(karuraUrl, async (helper) => {
Expand All @@ -682,8 +688,10 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
maliciousXcmProgramSent = await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.XcmpMessageSent);
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramSent.messageHash
&& event.outcome().isFailedToTransactAsset);
await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => {
return event.messageHash == maliciousXcmProgramSent.messageHash
&& event.outcome.isFailedToTransactAsset;
});

targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
Expand Down Expand Up @@ -764,7 +772,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramFullIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand All @@ -777,7 +785,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Karura', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramHereIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand Down Expand Up @@ -853,7 +861,7 @@ describeXCM('[XCM] Integration test: Quartz rejects non-native tokens', () => {

const expectFailedToTransact = async (helper: DevUniqueHelper, messageSent: any) => {
await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == messageSent.messageHash
&& event.outcome().isFailedToTransactAsset);
&& event.outcome.isFailedToTransactAsset);
};

itSub('Quartz rejects KAR tokens from Karura', async ({helper}) => {
Expand Down Expand Up @@ -1165,7 +1173,7 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramSent.messageHash
&& event.outcome().isFailedToTransactAsset);
&& event.outcome.isFailedToTransactAsset);

targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
Expand Down Expand Up @@ -1254,7 +1262,7 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramFullIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand All @@ -1271,7 +1279,7 @@ describeXCM('[XCM] Integration test: Exchanging QTZ with Moonriver', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramHereIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand Down Expand Up @@ -1531,7 +1539,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramSent.messageHash
&& event.outcome().isFailedToTransactAsset);
&& event.outcome.isFailedToTransactAsset);

targetAccountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(targetAccountBalance).to.be.equal(0n);
Expand Down Expand Up @@ -1612,7 +1620,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramFullIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

let accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand All @@ -1625,7 +1633,7 @@ describeXCM('[XCM] Integration test: Exchanging tokens with Shiden', () => {
});

await helper.wait.expectEvent(maxWaitBlocks, Event.XcmpQueue.Fail, event => event.messageHash == maliciousXcmProgramHereIdSent.messageHash
&& event.outcome().isUntrustedReserveLocation);
&& event.outcome.isUntrustedReserveLocation);

accountBalance = await helper.balance.getSubstrate(targetAccount.address);
expect(accountBalance).to.be.equal(0n);
Expand Down
Loading

0 comments on commit 33d4989

Please sign in to comment.