fix(tests): maximum gas deviation for reserveSlot

Maximum gas deviation is 25%, not 1%. Previously the test didn't
exercise the scenario where the number of reservations is full.
This commit is contained in:
Mark Spanbroek 2025-06-17 14:42:19 +02:00 committed by Adam Uhlíř
parent 78334edccf
commit 3ce91a51ab
No known key found for this signature in database
GPG Key ID: 1D17A9E81F76155B

View File

@ -32,7 +32,9 @@ describe("Marketplace gas estimates", function () {
async function setupToken() { async function setupToken() {
const Token = await ethers.getContractFactory("TestToken") const Token = await ethers.getContractFactory("TestToken")
const token = await Token.deploy() const token = await Token.deploy()
for (let signer of await ethers.getSigners()) {
await token.mint(signer.address, 1_000_000_000_000_000) await token.mint(signer.address, 1_000_000_000_000_000)
}
return token return token
} }
@ -79,20 +81,25 @@ describe("Marketplace gas estimates", function () {
}) })
describe("reserveSlot", function () { describe("reserveSlot", function () {
it("has at most 1% deviation in gas usage", async function () { it("has at most 25% deviation in gas usage", async function () {
const request = await requestStorage() const request = await requestStorage()
const id = requestId(request) const id = requestId(request)
const gasUsage = [] const gasUsage = []
for (let signer of await ethers.getSigners()) {
marketplace = marketplace.connect(signer)
for (let i = 0; i < request.ask.slots; i++) { for (let i = 0; i < request.ask.slots; i++) {
try {
const transaction = await marketplace.reserveSlot(id, i) const transaction = await marketplace.reserveSlot(id, i)
const receipt = await transaction.wait() const receipt = await transaction.wait()
gasUsage.push(receipt.gasUsed.toNumber()) gasUsage.push(receipt.gasUsed.toNumber())
await token.approve(marketplace.address, collateralPerSlot(request)) } catch (exception) {
await marketplace.fillSlot(id, i, exampleProof()) // ignore: reservations can be full
}
}
} }
const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0 const deviation = Math.max(...gasUsage) / Math.min(...gasUsage) - 1.0
expect(deviation).to.be.gt(0) expect(deviation).to.be.gt(0)
expect(deviation).to.be.lte(0.01) expect(deviation).to.be.lte(0.25)
}) })
}) })