Update Vault tests for ignition

This commit is contained in:
Arnaud 2025-05-16 20:37:20 +02:00
parent 110ac8197a
commit 0807f7d52c
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
4 changed files with 391 additions and 203 deletions

View File

@ -98,7 +98,7 @@ describe("Marketplace constructor", function () {
assertDeploymentRejectedWithCustomError(
"Marketplace_MaximumSlashingTooHigh",
promise,
promise
)
})
})
@ -109,7 +109,6 @@ describe("Marketplace", function () {
let marketplace
let token
let verifier
let client,
clientWithdrawRecipient,
host,
@ -672,7 +671,7 @@ describe("Marketplace", function () {
// Make a reservation from another host
switchAccount(host2)
collateral = collateralPerSlot(request)
await token.approve(marketplace.address, collateral)
await token.approve(await marketplace.getAddress(), collateral)
await marketplace.reserveSlot(slot.request, slot.index)
// Switch host and free the slot
@ -687,7 +686,7 @@ describe("Marketplace", function () {
await marketplace.reserveSlot(slot.request, slot.index)
let currPeriod = periodOf(await currentTime())
await advanceTimeTo(periodEnd(currPeriod) + 1)
await token.approve(marketplace.address, collateral)
await token.approve(await marketplace.getAddress(), collateral)
await marketplace.fillSlot(slot.request, slot.index, proof)
})
})
@ -1130,10 +1129,8 @@ describe("Marketplace", function () {
clientWithdrawRecipient.address
)
const endBalance = await token.balanceOf(clientWithdrawRecipient.address)
expect(endBalance - ACCOUNT_STARTING_BALANCE).to.equal(
maxPrice(request) - expectedPartialhostRewardRecipient
expect(endBalance - startBalance).to.equal(
maxPrice(request) - expectedPartialhostRewardRecipient,
maxPrice(request) - expectedPartialhostRewardRecipient
)
})

File diff suppressed because it is too large Load Diff

View File

@ -2,27 +2,32 @@ const {
time,
mine,
takeSnapshot,
setNextBlockTimestamp,
} = require("@nomicfoundation/hardhat-network-helpers")
const hre = require("hardhat")
const provider = hre.network.provider
const snapshots = []
async function snapshot() {
const snapshot = await takeSnapshot()
const automine = await ethers.provider.send("hardhat_getAutomine")
const time = await currentTime()
const automine = await provider.send("hardhat_getAutomine")
snapshots.push({ snapshot, automine, time })
}
async function revert() {
const { snapshot, time, automine } = snapshots.pop()
if (snapshot) {
setNextBlockTimestamp(time)
await ethers.provider.send("evm_setAutomine", [automine])
return snapshot.restore()
await snapshot.restore()
await setNextBlockTimestamp(time)
await provider.send("evm_setAutomine", [automine])
}
}
async function setAutomine(enabled) {
await provider.send("evm_setAutomine", [enabled])
}
async function ensureMinimumBlockHeight(height) {
while ((await time.latestBlock()) < height) {
await mine()

View File

@ -1,13 +1,15 @@
export async function assertDeploymentRejectedWithCustomError(
customError,
deploymentPromise,
) {
const error = await expect(deploymentPromise).to.be.rejected
module.exports = {
assertDeploymentRejectedWithCustomError: async function (
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}`,
)
expect(error)
.to.have.property("message")
.that.contains(
customError,
`Expected error ${expectedError}, but got ${error.message}`,
)
},
}