Skip to content

Commit

Permalink
tests: update after sendAsPara refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pLabarta committed Feb 13, 2025
1 parent e3a278a commit 82e65a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import "@moonbeam-network/api-augment";
import { afterEach, beforeAll, describeSuite, type DevModeContext, expect } from "@moonwall/cli";
import { afterEach, beforeAll, describeSuite, expect } from "@moonwall/cli";

import { sovereignAccountOfSibling, sendCallAsPara } from "../../../../helpers/xcm.js";
import { fundAccount } from "../../../../helpers/balances.js";
import { expectEvent, expectNoEvent } from "../../../../helpers/expect.js";
import { PalletMoonbeamForeignAssetsAssetStatus } from "@polkadot/types/lookup";
import { AnyJson } from "@polkadot/types-codec/types";

describeSuite({
Expand Down Expand Up @@ -115,8 +114,8 @@ describeSuite({
const changeLocationCall = context
.polkadotJs()
.tx.evmForeignAssets.changeXcmLocation(assetId, anotherParaLocation);
const { block } = await sendCallAsPara(changeLocationCall, 5002, context, fundAmount / 20n);
await expectNoEvent(context, block.hash as `0x${string}`, "ForeignAssetXcmLocationChanged");
const { block, errorName } = await sendCallAsPara(changeLocationCall, 5002, context, fundAmount / 20n, true);
expect(errorName).to.eq("BadOrigin");
},
});

Expand All @@ -127,8 +126,8 @@ describeSuite({
const changeLocationCall = context
.polkadotJs()
.tx.evmForeignAssets.changeXcmLocation(assetId, anotherParaLocation);
const { block } = await sendCallAsPara(changeLocationCall, 5001, context, fundAmount / 20n);
await expectNoEvent(context, block.hash as `0x${string}`, "ForeignAssetXcmLocationChanged");
const { block, errorName } = await sendCallAsPara(changeLocationCall, 5001, context, fundAmount / 20n, true);
expect(errorName).to.eq("LocationOutsideOfOrigin");
},
});

Expand Down Expand Up @@ -159,8 +158,8 @@ describeSuite({
const changeLocationCall = context
.polkadotJs()
.tx.evmForeignAssets.changeXcmLocation(255, anotherParaLocation);
const { block } = await sendCallAsPara(changeLocationCall, 5001, context, fundAmount / 20n);
await expectNoEvent(context, block.hash as `0x${string}`, "ForeignAssetXcmLocationChanged");
const { block, errorName } = await sendCallAsPara(changeLocationCall, 5001, context, fundAmount / 20n, true);
expect(errorName).to.eq("AssetDoesNotExist");
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ describeSuite({
);
await expectEvent(context, block1.hash as `0x${string}`, "ForeignAssetFrozen");

const { block: block2 } = await sendCallAsPara(
const { block: block2, errorName } = await sendCallAsPara(
freezeForeignAssetCall,
3000,
context,
fundAmount / 20n
fundAmount / 20n,
true
);
await expectNoEvent(context, block2.hash as `0x${string}`, "ForeignAssetFrozen");
expect(errorName).to.eq("AssetAlreadyFrozen");

const unfreezeForeignAssetCall = context
.polkadotJs()
Expand All @@ -94,42 +95,14 @@ describeSuite({
);
await expectEvent(context, block3.hash as `0x${string}`, "ForeignAssetUnfrozen");

const { block: block4 } = await sendCallAsPara(
const { block: block4, errorName: error2 } = await sendCallAsPara(
unfreezeForeignAssetCall,
3000,
context,
fundAmount / 20n
fundAmount / 20n,
true
);
await expectNoEvent(context, block4.hash as `0x${string}`, "ForeignAssetUnfrozen");
},
});

it({
id: "T02",
title: "Should not be able to freeze/unfreeze if already frozen via Sudo/Gov",
test: async function () {
const freezeForeignAssetCall = context
.polkadotJs()
.tx.evmForeignAssets.freezeForeignAsset(assetId, false);

const sudoCall1 = context.polkadotJs().tx.sudo.sudo(freezeForeignAssetCall);
const { block: block1 } = await context.createBlock(sudoCall1);
await expectEvent(context, block1.hash as `0x${string}`, "ForeignAssetFrozen");

const sudoCall2 = context.polkadotJs().tx.sudo.sudo(freezeForeignAssetCall);
const { block: block2 } = await context.createBlock(sudoCall2);
await expectNoEvent(context, block2.hash as `0x${string}`, "ForeignAssetFrozen");

const unfreezeForeignAssetCall = context
.polkadotJs()
.tx.evmForeignAssets.unfreezeForeignAsset(assetId);
const sudoCall3 = context.polkadotJs().tx.sudo.sudo(unfreezeForeignAssetCall);
const { block: block3 } = await context.createBlock(sudoCall3);
await expectEvent(context, block3.hash as `0x${string}`, "ForeignAssetUnfrozen");

const sudoCall4 = context.polkadotJs().tx.sudo.sudo(unfreezeForeignAssetCall);
const { block: block4 } = await context.createBlock(sudoCall4);
await expectNoEvent(context, block4.hash as `0x${string}`, "ForeignAssetUnfrozen");
expect(error2).to.eq("AssetNotFrozen");
},
});

Expand All @@ -141,20 +114,21 @@ describeSuite({
.polkadotJs()
.tx.evmForeignAssets.freezeForeignAsset(255, false);

const { block } = await sendCallAsPara(freezeForeignAssetCall, 3000, context, fundAmount / 20n);
await expectNoEvent(context, block.hash as `0x${string}`, "ForeignAssetFrozen");
const { block, errorName: error1} = await sendCallAsPara(freezeForeignAssetCall, 3000, context, fundAmount / 20n, true);
expect(error1).to.eq("AssetDoesNotExist");

const unfreezeForeignAssetCall = context
.polkadotJs()
.tx.evmForeignAssets.unfreezeForeignAsset(255);

const { block: block2 } = await sendCallAsPara(
const { block: block2, errorName: error2 } = await sendCallAsPara(
unfreezeForeignAssetCall,
3000,
context,
fundAmount / 20n
fundAmount / 20n,
true
);
await expectNoEvent(context, block2.hash as `0x${string}`, "ForeignAssetUnfrozen");
expect(error2).to.eq("AssetDoesNotExist");
},
});

Expand All @@ -166,20 +140,21 @@ describeSuite({
.polkadotJs()
.tx.evmForeignAssets.freezeForeignAsset(assetId, false);

const { block } = await sendCallAsPara(freezeForeignAssetCall, 4000, context, fundAmount / 20n);
await expectNoEvent(context, block.hash as `0x${string}`, "ForeignAssetFrozen");
const { block, errorName: error1 } = await sendCallAsPara(freezeForeignAssetCall, 4000, context, fundAmount / 20n, true);
expect(error1).to.eq("BadOrigin");

const unfreezeForeignAssetCall = context
.polkadotJs()
.tx.evmForeignAssets.unfreezeForeignAsset(assetId);

const { block: block2 } = await sendCallAsPara(
const { block: block2, errorName: error2 } = await sendCallAsPara(
unfreezeForeignAssetCall,
4000,
context,
fundAmount / 20n
fundAmount / 20n,
true
);
await expectNoEvent(context, block2.hash as `0x${string}`, "ForeignAssetUnfrozen");
expect(error2).to.eq("BadOrigin");
},
});
},
Expand Down

0 comments on commit 82e65a2

Please sign in to comment.