fix(Marketplace): ensure requests include ask with sufficient slots

There is a missing check in `requestStorage()` on whether the `Request`
contains an `Ask` where its `slots` is `> 0`.

This allows for making storage request without slots. Not harmful but
not a valid state of the system either.

This commit adds that check and a test with batteries included.
This commit is contained in:
r4bbit 2024-08-23 09:46:28 +02:00
parent 6d319c76b9
commit cc0b2732ad
2 changed files with 8 additions and 0 deletions

View File

@ -95,6 +95,7 @@ contract Marketplace is Proofs, StateRetrieval, Endian {
request.expiry > 0 && request.expiry < request.ask.duration, request.expiry > 0 && request.expiry < request.ask.duration,
"Expiry not in range" "Expiry not in range"
); );
require(request.ask.slots > 0, "Insufficient slots");
require( require(
request.ask.maxSlotLoss <= request.ask.slots, request.ask.maxSlotLoss <= request.ask.slots,
"maxSlotLoss exceeds slots" "maxSlotLoss exceeds slots"

View File

@ -211,6 +211,13 @@ describe("Marketplace", function () {
) )
}) })
it("is rejected with insufficient slots ", async function () {
request.ask.slots = 0
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"Insufficient slots"
)
})
it("is rejected when maxSlotLoss exceeds slots", async function () { it("is rejected when maxSlotLoss exceeds slots", async function () {
request.ask.maxSlotLoss = request.ask.slots + 1 request.ask.maxSlotLoss = request.ask.slots + 1
await expect(marketplace.requestStorage(request)).to.be.revertedWith( await expect(marketplace.requestStorage(request)).to.be.revertedWith(