mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-01-14 08:37:19 +00:00
fix: reset missed counter when slot is freed (#48)
This commit is contained in:
parent
dfdbd16d5b
commit
8b39ef8f4a
@ -152,6 +152,7 @@ contract Marketplace is Proofs, StateRetrieval {
|
|||||||
delete _slots[slotId];
|
delete _slots[slotId];
|
||||||
context.slotsFilled -= 1;
|
context.slotsFilled -= 1;
|
||||||
emit SlotFreed(requestId, slotId);
|
emit SlotFreed(requestId, slotId);
|
||||||
|
resetMissingProofs(slotId);
|
||||||
|
|
||||||
Request storage request = _requests[requestId];
|
Request storage request = _requests[requestId];
|
||||||
uint256 slotsLost = request.ask.slots - context.slotsFilled;
|
uint256 slotsLost = request.ask.slots - context.slotsFilled;
|
||||||
|
@ -25,6 +25,10 @@ abstract contract Proofs is Periods {
|
|||||||
return _missed[slotId];
|
return _missed[slotId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetMissingProofs(SlotId slotId) internal {
|
||||||
|
_missed[slotId] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function _startRequiringProofs(SlotId id, uint256 probability) internal {
|
function _startRequiringProofs(SlotId id, uint256 probability) internal {
|
||||||
_slotStarts[id] = block.timestamp;
|
_slotStarts[id] = block.timestamp;
|
||||||
_probabilities[id] = probability;
|
_probabilities[id] = probability;
|
||||||
|
@ -777,6 +777,24 @@ describe("Marketplace", function () {
|
|||||||
expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free)
|
expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free)
|
||||||
expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte(minimum)
|
expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte(minimum)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("free slot when minimum reached and resets missed proof counter", async function () {
|
||||||
|
const minimum = config.collateral.minimumAmount
|
||||||
|
await waitUntilStarted(marketplace, request, proof, token)
|
||||||
|
let missedProofs = 0
|
||||||
|
while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) {
|
||||||
|
expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.gt(minimum)
|
||||||
|
await waitUntilProofIsRequired(slotId(slot))
|
||||||
|
const missedPeriod = periodOf(await currentTime())
|
||||||
|
await advanceTime(period)
|
||||||
|
expect(await marketplace.missingProofs(slotId(slot))).to.equal(missedProofs)
|
||||||
|
await marketplace.markProofAsMissing(slotId(slot), missedPeriod)
|
||||||
|
missedProofs += 1
|
||||||
|
}
|
||||||
|
expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free)
|
||||||
|
expect(await marketplace.missingProofs(slotId(slot))).to.equal(0)
|
||||||
|
expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte(minimum)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("list of active requests", function () {
|
describe("list of active requests", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user