Remove return value for reserveSlot

Not needed, as a slot that cannot be added due to already being included would revert anyway.
This commit is contained in:
Eric 2024-09-19 14:25:41 +10:00
parent b62c72b5e1
commit d2ba8693e7
No known key found for this signature in database
2 changed files with 6 additions and 12 deletions

View File

@ -11,11 +11,10 @@ contract SlotReservations {
uint8 private constant _MAX_RESERVATIONS = 3; uint8 private constant _MAX_RESERVATIONS = 3;
function reserveSlot(SlotId slotId) public returns (bool) { function reserveSlot(SlotId slotId) public {
address host = msg.sender; address host = msg.sender;
require(canReserveSlot(slotId), "Reservation not allowed"); require(canReserveSlot(slotId), "Reservation not allowed");
// returns false if set already contains address _reservations[slotId].add(host);
return _reservations[slotId].add(host);
} }
function canReserveSlot(SlotId slotId) public view returns (bool) { function canReserveSlot(SlotId slotId) public view returns (bool) {

View File

@ -8,6 +8,7 @@ describe("SlotReservations", function () {
let provider, address1, address2, address3 let provider, address1, address2, address3
let request let request
let slot let slot
let id // can't use slotId because it'll shadow the function slotId
beforeEach(async function () { beforeEach(async function () {
let SlotReservations = await ethers.getContractFactory( let SlotReservations = await ethers.getContractFactory(
@ -22,6 +23,8 @@ describe("SlotReservations", function () {
request: requestId(request), request: requestId(request),
index: request.ask.slots / 2, index: request.ask.slots / 2,
} }
id = slotId(slot)
}) })
function switchAccount(account) { function switchAccount(account) {
@ -29,13 +32,10 @@ describe("SlotReservations", function () {
} }
it("allows a slot to be reserved", async function () { it("allows a slot to be reserved", async function () {
let id = slotId(slot) expect(reservations.reserveSlot(id)).to.not.be.reverted
let reserved = await reservations.callStatic.reserveSlot(id)
expect(reserved).to.be.true
}) })
it("contains the correct addresses after reservation", async function () { it("contains the correct addresses after reservation", async function () {
let id = slotId(slot)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
expect(await reservations.contains(id, provider.address)).to.be.true expect(await reservations.contains(id, provider.address)).to.be.true
@ -45,7 +45,6 @@ describe("SlotReservations", function () {
}) })
it("has the correct number of addresses after reservation", async function () { it("has the correct number of addresses after reservation", async function () {
let id = slotId(slot)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
expect(await reservations.length(id)).to.equal(1) expect(await reservations.length(id)).to.equal(1)
@ -59,7 +58,6 @@ describe("SlotReservations", function () {
}) })
it("cannot reserve a slot more than once", async function () { it("cannot reserve a slot more than once", async function () {
let id = slotId(slot)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
await expect(reservations.reserveSlot(id)).to.be.revertedWith( await expect(reservations.reserveSlot(id)).to.be.revertedWith(
"Reservation not allowed" "Reservation not allowed"
@ -68,13 +66,11 @@ describe("SlotReservations", function () {
}) })
it("reports a slot cannot be reserved if already reserved", async function () { it("reports a slot cannot be reserved if already reserved", async function () {
let id = slotId(slot)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
expect(await reservations.canReserveSlot(id)).to.be.false expect(await reservations.canReserveSlot(id)).to.be.false
}) })
it("cannot reserve a slot if reservations are at capacity", async function () { it("cannot reserve a slot if reservations are at capacity", async function () {
let id = slotId(slot)
switchAccount(address1) switchAccount(address1)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
switchAccount(address2) switchAccount(address2)
@ -90,7 +86,6 @@ describe("SlotReservations", function () {
}) })
it("reports a slot cannot be reserved if reservations are at capacity", async function () { it("reports a slot cannot be reserved if reservations are at capacity", async function () {
let id = slotId(slot)
switchAccount(address1) switchAccount(address1)
await reservations.reserveSlot(id) await reservations.reserveSlot(id)
switchAccount(address2) switchAccount(address2)