mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-11 09:53:12 +00:00
safeEventually > eventuallySafe
This commit is contained in:
parent
cb20b54213
commit
8b192df271
@ -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()
|
||||
|
||||
@ -6,7 +6,7 @@ import ../contracts/deployment
|
||||
import ./marketplacesuite
|
||||
import ./twonodes
|
||||
import ./nodeconfigs
|
||||
from ../helpers import safeEventually
|
||||
from ../helpers import eventuallySafe
|
||||
|
||||
marketplacesuite "Marketplace":
|
||||
let marketplaceConfig = NodeConfigs(
|
||||
@ -62,7 +62,7 @@ marketplacesuite "Marketplace":
|
||||
tolerance = ecTolerance,
|
||||
)
|
||||
|
||||
check safeEventually(
|
||||
check eventuallySafe(
|
||||
await client.purchaseStateIs(id, "started"), timeout = 10 * 60 * 1000
|
||||
)
|
||||
let purchase = (await client.getPurchase(id)).get
|
||||
@ -109,7 +109,7 @@ marketplacesuite "Marketplace":
|
||||
tolerance = ecTolerance,
|
||||
)
|
||||
|
||||
check safeEventually(
|
||||
check eventuallySafe(
|
||||
await client.purchaseStateIs(id, "started"), timeout = 10 * 60 * 1000
|
||||
)
|
||||
let purchase = (await client.getPurchase(id)).get
|
||||
@ -125,11 +125,11 @@ marketplacesuite "Marketplace":
|
||||
# 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
|
||||
)
|
||||
@ -299,12 +299,12 @@ marketplacesuite "Marketplace payouts":
|
||||
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))
|
||||
|
||||
@ -7,7 +7,7 @@ import ../codex/helpers
|
||||
import ../examples
|
||||
import ./marketplacesuite
|
||||
import ./nodeconfigs
|
||||
from ../helpers import safeEventually
|
||||
from ../helpers import eventuallySafe
|
||||
|
||||
export logutils
|
||||
|
||||
@ -65,7 +65,7 @@ marketplacesuite "Hosts submit regular proofs":
|
||||
|
||||
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
|
||||
|
||||
check safeEventually(
|
||||
check eventuallySafe(
|
||||
await client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000
|
||||
)
|
||||
|
||||
@ -141,7 +141,7 @@ marketplacesuite "Simulate invalid proofs":
|
||||
)
|
||||
let requestId = (await client0.requestId(purchaseId)).get
|
||||
|
||||
check safeEventually(
|
||||
check eventuallySafe(
|
||||
await client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000
|
||||
)
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import ../contracts/time
|
||||
import ./codexconfig
|
||||
import ./codexclient
|
||||
import ./nodeconfigs
|
||||
from ../helpers import safeEventually
|
||||
from ../helpers import eventuallySafe
|
||||
|
||||
proc findItem[T](items: seq[T], item: T): ?!T =
|
||||
for tmp in items:
|
||||
@ -142,7 +142,7 @@ multinodesuite "Sales":
|
||||
)
|
||||
).get
|
||||
|
||||
check safeEventually(
|
||||
check eventuallySafe(
|
||||
await client.purchaseStateIs(id, "started"), timeout = 10 * 60 * 1000
|
||||
)
|
||||
let updatedAvailability =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user