safeEventually > eventuallySafe

This commit is contained in:
Eric 2025-03-24 13:28:12 +11:00
parent 93832a6ef1
commit 866d754de6
No known key found for this signature in database
4 changed files with 11 additions and 11 deletions

View File

@ -36,13 +36,13 @@ proc allFuturesThrowing*[T, E]( # https://github.com/nim-lang/Nim/issues/23432
): Future[void] =
allFuturesThrowing(futs.mapIt(FutureBase(it)))
template safeEventually*(expression: untyped, waitingTime = 250, timeout = 5000): bool =
proc safeEventually(): Future[bool] {.async.} =
template eventuallySafe*(expression: untyped, timeout=5000, pollInterval=1000)): bool =
proc eventuallySafe(): Future[bool] {.async.} =
let endTime = getTime() + initDuration(milliseconds = timeout)
while not expression:
if endTime < getTime():
return false
await sleepAsync(waitingTime)
await sleepAsync(pollInterval)
return true
await safeEventually()
await eventuallySafe()

View File

@ -6,7 +6,7 @@ import ../../contracts/deployment
import ./../marketplacesuite
import ../twonodes
import ../nodeconfigs
from ../../helpers import safeEventually
from ../../helpers import eventuallySafe
marketplacesuite(name = "Marketplace", stopOnRequestFail = true):
let marketplaceConfig = NodeConfigs(
@ -123,11 +123,11 @@ marketplacesuite(name = "Marketplace", stopOnRequestFail = true):
# Checking that the hosting node received reward for at least the time between <expiry;end>
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
check safeEventually (await token.balanceOf(hostAccount)) - startBalanceHost >=
check eventuallySafe (await token.balanceOf(hostAccount)) - startBalanceHost >=
(duration - 5 * 60).u256 * pricePerSlotPerSecond * ecNodes.u256
# Checking that client node receives some funds back that were not used for the host nodes
check safeEventually(
check eventuallySafe(
(await token.balanceOf(clientAccount)) - clientBalanceBeforeFinished > 0,
timeout = 10 * 1000, # give client a bit of time to withdraw its funds
)
@ -297,12 +297,12 @@ marketplacesuite(name = "Marketplace payouts", stopOnRequestFail = true):
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
check safeEventually (
check eventuallySafe (
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))
endBalanceProvider > startBalanceProvider and
endBalanceProvider < startBalanceProvider + expiry.u256 * pricePerSlotPerSecond
)
check safeEventually(
check eventuallySafe(
(
let endBalanceClient = (await token.balanceOf(client.ethAccount))
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))

View File

@ -7,7 +7,7 @@ import ../../codex/helpers
import ../../examples
import ../marketplacesuite
import ../nodeconfigs
from ../../helpers import safeEventually
from ../../helpers import eventuallySafe
export logutils

View File

@ -8,7 +8,7 @@ import ../../contracts/time
import ../codexconfig
import ../codexclient
import ../nodeconfigs
from ../../helpers import safeEventually
from ../../helpers import eventuallySafe
import ../marketplacesuite
proc findItem[T](items: seq[T], item: T): ?!T =