Export contract deployment custom error assert into a function

This commit is contained in:
Arnaud 2025-04-15 15:37:23 +02:00
parent ec47be2685
commit f2757067f6
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
3 changed files with 24 additions and 22 deletions

View File

@ -41,6 +41,7 @@ const {
} = require("./evm") } = require("./evm")
const { getBytes } = require("ethers") const { getBytes } = require("ethers")
const MarketplaceModule = require("../ignition/modules/marketplace") const MarketplaceModule = require("../ignition/modules/marketplace")
const { assertDeploymentRejectedWithCustomError } = require("./util")
const ACCOUNT_STARTING_BALANCE = 1_000_000_000_000_000n 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 assertDeploymentRejectedWithCustomError(expectedError, promise)
expect(error)
.to.have.property("message")
.that.contains(
expectedError,
`Expected error ${expectedError}, but got ${error.message}`
)
}) })
} }
@ -101,13 +96,10 @@ describe("Marketplace constructor", function () {
}, },
}) })
const error = await expect(promise).to.be.rejected assertDeploymentRejectedWithCustomError(
expect(error) "Marketplace_MaximumSlashingTooHigh",
.to.have.property("message") promise,
.that.contains( )
expectedError,
`Expected error ${expectedError}, but got ${error.message}`
)
}) })
}) })

View File

@ -1,5 +1,6 @@
const { expect } = require("chai") const { expect } = require("chai")
const PeriodsModule = require("../ignition/modules/periods") const PeriodsModule = require("../ignition/modules/periods")
const { assertDeploymentRejectedWithCustomError } = require("./util")
describe("Periods", function () { describe("Periods", function () {
it("should revert when secondsPerPeriod is 0", async 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 assertDeploymentRejectedWithCustomError(
expect(error) "Periods_InvalidSecondsPerPeriod",
.to.have.property("message") promise,
.that.contains( )
expectedError,
`Expected error ${expectedError}, but got ${error.message}`,
)
}) })
it("should not revert when secondsPerPeriod more than 0", async function () { it("should not revert when secondsPerPeriod more than 0", async function () {

13
test/util.js Normal file
View File

@ -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}`,
)
}