mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-04-18 02:33:10 +00:00
Reduce the number of requests for asserts in tests
This commit is contained in:
parent
98b42f4319
commit
1663bd224f
@ -35,3 +35,14 @@ proc allFuturesThrowing*[T, E]( # https://github.com/nim-lang/Nim/issues/23432
|
|||||||
futs: varargs[InternalRaisesFuture[T, E]]
|
futs: varargs[InternalRaisesFuture[T, E]]
|
||||||
): Future[void] =
|
): Future[void] =
|
||||||
allFuturesThrowing(futs.mapIt(FutureBase(it)))
|
allFuturesThrowing(futs.mapIt(FutureBase(it)))
|
||||||
|
|
||||||
|
template safeEventually*(expression: untyped, waitingTime = 250, timeout = 5000): bool =
|
||||||
|
proc safeEventually(): Future[bool] {.async.} =
|
||||||
|
let endTime = getTime() + initDuration(milliseconds = timeout)
|
||||||
|
while not expression:
|
||||||
|
if endTime < getTime():
|
||||||
|
return false
|
||||||
|
await sleepAsync(waitingTime)
|
||||||
|
return true
|
||||||
|
|
||||||
|
await safeEventually()
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import ../../contracts/deployment
|
|||||||
import ./../marketplacesuite
|
import ./../marketplacesuite
|
||||||
import ../twonodes
|
import ../twonodes
|
||||||
import ../nodeconfigs
|
import ../nodeconfigs
|
||||||
|
from ../../helpers import safeEventually
|
||||||
|
|
||||||
marketplacesuite(name = "Marketplace", stopOnRequestFail = true):
|
marketplacesuite(name = "Marketplace", stopOnRequestFail = true):
|
||||||
let marketplaceConfig = NodeConfigs(
|
let marketplaceConfig = NodeConfigs(
|
||||||
@ -122,11 +123,11 @@ marketplacesuite(name = "Marketplace", stopOnRequestFail = true):
|
|||||||
# Checking that the hosting node received reward for at least the time between <expiry;end>
|
# Checking that the hosting node received reward for at least the time between <expiry;end>
|
||||||
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
|
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
|
||||||
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
|
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
|
||||||
check eventually (await token.balanceOf(hostAccount)) - startBalanceHost >=
|
check safeEventually (await token.balanceOf(hostAccount)) - startBalanceHost >=
|
||||||
(duration - 5 * 60).u256 * pricePerSlotPerSecond * ecNodes.u256
|
(duration - 5 * 60).u256 * pricePerSlotPerSecond * ecNodes.u256
|
||||||
|
|
||||||
# Checking that client node receives some funds back that were not used for the host nodes
|
# Checking that client node receives some funds back that were not used for the host nodes
|
||||||
check eventually(
|
check safeEventually(
|
||||||
(await token.balanceOf(clientAccount)) - clientBalanceBeforeFinished > 0,
|
(await token.balanceOf(clientAccount)) - clientBalanceBeforeFinished > 0,
|
||||||
timeout = 10 * 1000, # give client a bit of time to withdraw its funds
|
timeout = 10 * 1000, # give client a bit of time to withdraw its funds
|
||||||
)
|
)
|
||||||
@ -296,12 +297,12 @@ marketplacesuite(name = "Marketplace payouts", stopOnRequestFail = true):
|
|||||||
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
|
let slotSize = slotSize(blocks, ecNodes, ecTolerance)
|
||||||
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
|
let pricePerSlotPerSecond = minPricePerBytePerSecond * slotSize
|
||||||
|
|
||||||
check eventually (
|
check safeEventually (
|
||||||
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))
|
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))
|
||||||
endBalanceProvider > startBalanceProvider and
|
endBalanceProvider > startBalanceProvider and
|
||||||
endBalanceProvider < startBalanceProvider + expiry.u256 * pricePerSlotPerSecond
|
endBalanceProvider < startBalanceProvider + expiry.u256 * pricePerSlotPerSecond
|
||||||
)
|
)
|
||||||
check eventually(
|
check safeEventually(
|
||||||
(
|
(
|
||||||
let endBalanceClient = (await token.balanceOf(client.ethAccount))
|
let endBalanceClient = (await token.balanceOf(client.ethAccount))
|
||||||
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))
|
let endBalanceProvider = (await token.balanceOf(provider.ethAccount))
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import ../../codex/helpers
|
|||||||
import ../../examples
|
import ../../examples
|
||||||
import ../marketplacesuite
|
import ../marketplacesuite
|
||||||
import ../nodeconfigs
|
import ../nodeconfigs
|
||||||
|
from ../../helpers import safeEventually
|
||||||
|
|
||||||
export logutils
|
export logutils
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import ../../contracts/time
|
|||||||
import ../codexconfig
|
import ../codexconfig
|
||||||
import ../codexclient
|
import ../codexclient
|
||||||
import ../nodeconfigs
|
import ../nodeconfigs
|
||||||
|
from ../../helpers import safeEventually
|
||||||
import ../marketplacesuite
|
import ../marketplacesuite
|
||||||
|
|
||||||
proc findItem[T](items: seq[T], item: T): ?!T =
|
proc findItem[T](items: seq[T], item: T): ?!T =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user