diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 00b0ece..6dd11a8 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -41,6 +41,7 @@ const { } = require("./evm") const { getBytes } = require("ethers") const MarketplaceModule = require("../ignition/modules/marketplace") +const { assertDeploymentRejectedWithCustomError } = require("./util") const ACCOUNT_STARTING_BALANCE = 1_000_000_000_000_000n @@ -67,13 +68,7 @@ describe("Marketplace constructor", function () { }, }) - const error = await expect(promise).to.be.rejected - expect(error) - .to.have.property("message") - .that.contains( - expectedError, - `Expected error ${expectedError}, but got ${error.message}` - ) + assertDeploymentRejectedWithCustomError(expectedError, promise) }) } @@ -101,13 +96,10 @@ describe("Marketplace constructor", function () { }, }) - const error = await expect(promise).to.be.rejected - expect(error) - .to.have.property("message") - .that.contains( - expectedError, - `Expected error ${expectedError}, but got ${error.message}` - ) + assertDeploymentRejectedWithCustomError( + "Marketplace_MaximumSlashingTooHigh", + promise, + ) }) }) diff --git a/test/Periods.test.js b/test/Periods.test.js index 49ac84d..1295140 100644 --- a/test/Periods.test.js +++ b/test/Periods.test.js @@ -1,5 +1,6 @@ const { expect } = require("chai") const PeriodsModule = require("../ignition/modules/periods") +const { assertDeploymentRejectedWithCustomError } = require("./util") describe("Periods", function () { it("should revert when secondsPerPeriod is 0", async function () { @@ -10,15 +11,11 @@ describe("Periods", function () { }, }, }) - const expectedError = "Periods_InvalidSecondsPerPeriod" - const error = await expect(promise).to.be.rejected - expect(error) - .to.have.property("message") - .that.contains( - expectedError, - `Expected error ${expectedError}, but got ${error.message}`, - ) + assertDeploymentRejectedWithCustomError( + "Periods_InvalidSecondsPerPeriod", + promise, + ) }) it("should not revert when secondsPerPeriod more than 0", async function () { diff --git a/test/util.js b/test/util.js new file mode 100644 index 0000000..46bc91d --- /dev/null +++ b/test/util.js @@ -0,0 +1,13 @@ +export async function assertDeploymentRejectedWithCustomError( + customError, + deploymentPromise, +) { + const error = await expect(deploymentPromise).to.be.rejected + + expect(error) + .to.have.property("message") + .that.contains( + customError, + `Expected error ${expectedError}, but got ${error.message}`, + ) +}