mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-21 15:08:33 +00:00
fix proof integration test
there were two logic errors in this test: - a slot is freed anyway at the end of the contract - when starting the request takes a long time, the first slot can already be freed because there were too many missing proofs
This commit is contained in:
parent
a5ec80b99f
commit
a901da89b7
@ -158,8 +158,7 @@ marketplacesuite "Simulate invalid proofs":
|
|||||||
):
|
):
|
||||||
let client0 = clients()[0].client
|
let client0 = clients()[0].client
|
||||||
let expiry = 5.periods
|
let expiry = 5.periods
|
||||||
# In 2 periods you cannot have enough invalid proofs submitted:
|
let duration = expiry + 10.periods
|
||||||
let duration = expiry + 2.periods
|
|
||||||
|
|
||||||
let data = await RandomChunker.example(blocks=8)
|
let data = await RandomChunker.example(blocks=8)
|
||||||
createAvailabilities(data.len * 2, duration) # TODO: better value for data.len
|
createAvailabilities(data.len * 2, duration) # TODO: better value for data.len
|
||||||
@ -176,20 +175,27 @@ marketplacesuite "Simulate invalid proofs":
|
|||||||
)
|
)
|
||||||
let requestId = client0.requestId(purchaseId).get
|
let requestId = client0.requestId(purchaseId).get
|
||||||
|
|
||||||
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
var slotWasFilled = false
|
||||||
|
proc onSlotFilled(event: SlotFilled) =
|
||||||
|
if event.requestId == requestId:
|
||||||
|
slotWasFilled = true
|
||||||
|
let filledSubscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
||||||
|
|
||||||
|
# wait for the first slot to be filled
|
||||||
|
check eventually(slotWasFilled, timeout = expiry.int * 1000)
|
||||||
|
|
||||||
var slotWasFreed = false
|
var slotWasFreed = false
|
||||||
proc onSlotFreed(event: SlotFreed) =
|
proc onSlotFreed(event: SlotFreed) =
|
||||||
if event.requestId == requestId:
|
if event.requestId == requestId:
|
||||||
slotWasFreed = true
|
slotWasFreed = true
|
||||||
|
let freedSubscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
||||||
|
|
||||||
let subscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
# In 2 periods you cannot have enough invalid proofs submitted:
|
||||||
|
await sleepAsync(2.periods.int.seconds)
|
||||||
# check not freed
|
|
||||||
await sleepAsync((duration - expiry).int.seconds)
|
|
||||||
check not slotWasFreed
|
check not slotWasFreed
|
||||||
|
|
||||||
await subscription.unsubscribe()
|
await filledSubscription.unsubscribe()
|
||||||
|
await freedSubscription.unsubscribe()
|
||||||
|
|
||||||
# TODO: uncomment once fixed
|
# TODO: uncomment once fixed
|
||||||
# test "host that submits invalid proofs is paid out less", NodeConfigs(
|
# test "host that submits invalid proofs is paid out less", NodeConfigs(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user