From 9a2e5478a54471f06968f72fe7c2a3b47a859591 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 12 Nov 2024 11:57:31 +0100 Subject: [PATCH] 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 --- tests/integration/testproofs.nim | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/integration/testproofs.nim b/tests/integration/testproofs.nim index fb09a09b..0d8b9bd3 100644 --- a/tests/integration/testproofs.nim +++ b/tests/integration/testproofs.nim @@ -158,8 +158,7 @@ marketplacesuite "Simulate invalid proofs": ): let client0 = clients()[0].client let expiry = 10.periods - # In 2 periods you cannot have enough invalid proofs submitted: - let duration = expiry + 2.periods + let duration = expiry + 10.periods let data = await RandomChunker.example(blocks=8) 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 - 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 proc onSlotFreed(event: SlotFreed) = if event.requestId == requestId: slotWasFreed = true + let freedSubscription = await marketplace.subscribe(SlotFreed, onSlotFreed) - let subscription = await marketplace.subscribe(SlotFreed, onSlotFreed) - - # check not freed - await sleepAsync((duration - expiry).int.seconds) + # In 2 periods you cannot have enough invalid proofs submitted: + await sleepAsync(2.periods.int.seconds) check not slotWasFreed - await subscription.unsubscribe() + await filledSubscription.unsubscribe() + await freedSubscription.unsubscribe() # TODO: uncomment once fixed # test "host that submits invalid proofs is paid out less", NodeConfigs(