mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-10 09:23:12 +00:00
Stop the test when the request fails
This commit is contained in:
parent
6a8445d7af
commit
881a32f929
@ -40,7 +40,8 @@ marketplacesuite(name = "Marketplace"):
|
||||
# As we use in tests ethProvider.currentTime() which uses block timestamp this can lead to synchronization issues.
|
||||
await ethProvider.advanceTime(1.u256)
|
||||
|
||||
test "nodes negotiate contracts on the marketplace", marketplaceConfig:
|
||||
test "nodes negotiate contracts on the marketplace",
|
||||
marketplaceConfig, stopOnRequestFail = true:
|
||||
# host makes storage available
|
||||
let availability = (
|
||||
await host.postAvailability(
|
||||
@ -83,7 +84,7 @@ marketplacesuite(name = "Marketplace"):
|
||||
check slot.request.id == purchase.requestId
|
||||
|
||||
test "node slots gets paid out and rest of tokens are returned to client",
|
||||
marketplaceConfig:
|
||||
marketplaceConfig, stopOnRequestFail = true:
|
||||
var providerRewardEvent = newAsyncEvent()
|
||||
var clientFundsEvent = newAsyncEvent()
|
||||
var transferEvent = newAsyncEvent()
|
||||
@ -177,7 +178,8 @@ marketplacesuite(name = "Marketplace"):
|
||||
# .withLogFile()
|
||||
# .withLogTopics("marketplace", "sales", "statemachine","slotqueue", "reservations")
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
var requestId: RequestId
|
||||
|
||||
# We create an avavilability allowing the first SP to host the 3 slots.
|
||||
@ -254,7 +256,8 @@ marketplacesuite(name = "Marketplace payouts"):
|
||||
# "node", "marketplace", "sales", "reservations", "node", "statemachine"
|
||||
# )
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client = clients()[0]
|
||||
let provider = providers()[0]
|
||||
let clientApi = client.client
|
||||
@ -365,7 +368,8 @@ marketplacesuite(name = "Marketplace payouts"):
|
||||
# "node", "marketplace", "sales", "reservations", "statemachine"
|
||||
# )
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0]
|
||||
let provider0 = providers()[0]
|
||||
let provider1 = providers()[1]
|
||||
|
||||
@ -34,7 +34,8 @@ marketplacesuite(name = "Hosts submit regular proofs"):
|
||||
# .withLogFile() # uncomment to output log file to tests/integration/logs/<start_datetime> <suite_name>/<test_name>/<node_role>_<node_idx>.log
|
||||
# .withLogTopics("marketplace", "sales", "reservations", "node", "clock")
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0].client
|
||||
let expiry = 10.periods
|
||||
let duration = expiry + 5.periods
|
||||
@ -118,7 +119,8 @@ marketplacesuite(name = "Simulate invalid proofs"):
|
||||
# uncomment to output log file to tests/integration/logs/<start_datetime> <suite_name>/<test_name>/<node_role>_<node_idx>.log
|
||||
# .withLogTopics("validator", "onchain", "ethers", "clock")
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0].client
|
||||
let expiry = 10.periods
|
||||
let duration = expiry + 10.periods
|
||||
@ -162,7 +164,8 @@ marketplacesuite(name = "Simulate invalid proofs"):
|
||||
# .withLogFile() # uncomment to output log file to tests/integration/logs/<start_datetime> <suite_name>/<test_name>/<node_role>_<node_idx>.log
|
||||
# .withLogTopics("validator", "onchain", "ethers", "clock")
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0].client
|
||||
let expiry = 10.periods
|
||||
let duration = expiry + 10.periods
|
||||
|
||||
@ -4,7 +4,7 @@ import ../../contracts/time
|
||||
import ../../contracts/deployment
|
||||
import ../../codex/helpers
|
||||
import ../../examples
|
||||
import ../marketplacesuite
|
||||
import ../marketplacesuite as marketplacesuite
|
||||
import ../nodeconfigs
|
||||
|
||||
export logutils
|
||||
@ -75,7 +75,8 @@ marketplacesuite(name = "SP Slot Repair"):
|
||||
# .debug()
|
||||
# .withLogFile()
|
||||
# .withLogTopics("validator").some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0]
|
||||
let provider0 = providers()[0]
|
||||
let provider1 = providers()[1]
|
||||
@ -154,7 +155,8 @@ marketplacesuite(name = "SP Slot Repair"):
|
||||
# .debug()
|
||||
.withLogFile()
|
||||
.withLogTopics("marketplace", "sales", "statemachine", "reservations").some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0]
|
||||
let provider0 = providers()[0]
|
||||
let provider1 = providers()[1]
|
||||
@ -236,7 +238,8 @@ marketplacesuite(name = "SP Slot Repair"):
|
||||
# .withLogFile()
|
||||
# .withLogTopics("marketplace", "sales", "statemachine", "reservations")
|
||||
.some,
|
||||
):
|
||||
),
|
||||
stopOnRequestFail = true:
|
||||
let client0 = clients()[0]
|
||||
let provider0 = providers()[0]
|
||||
let provider1 = providers()[1]
|
||||
|
||||
@ -34,7 +34,7 @@ marketplacesuite(name = "Sales"):
|
||||
host = providers()[0].client
|
||||
client = clients()[0].client
|
||||
|
||||
test "node handles new storage availability", salesConfig:
|
||||
test "node handles new storage availability", salesConfig, stopOnRequestFail = true:
|
||||
let availability1 = (
|
||||
await host.postAvailability(
|
||||
totalSize = 1.uint64,
|
||||
@ -53,7 +53,7 @@ marketplacesuite(name = "Sales"):
|
||||
).get
|
||||
check availability1 != availability2
|
||||
|
||||
test "node lists storage that is for sale", salesConfig:
|
||||
test "node lists storage that is for sale", salesConfig, stopOnRequestFail = true:
|
||||
let availability = (
|
||||
await host.postAvailability(
|
||||
totalSize = 1.uint64,
|
||||
@ -64,7 +64,7 @@ marketplacesuite(name = "Sales"):
|
||||
).get
|
||||
check availability in (await host.getAvailabilities()).get
|
||||
|
||||
test "updating availability", salesConfig:
|
||||
test "updating availability", salesConfig, stopOnRequestFail = true:
|
||||
let availability = (
|
||||
await host.postAvailability(
|
||||
totalSize = 140000.uint64,
|
||||
@ -95,7 +95,8 @@ marketplacesuite(name = "Sales"):
|
||||
check updatedAvailability.enabled == false
|
||||
check updatedAvailability.until == until
|
||||
|
||||
test "updating availability - updating totalSize", salesConfig:
|
||||
test "updating availability - updating totalSize",
|
||||
salesConfig, stopOnRequestFail = true:
|
||||
let availability = (
|
||||
await host.postAvailability(
|
||||
totalSize = 140000.uint64,
|
||||
@ -112,7 +113,7 @@ marketplacesuite(name = "Sales"):
|
||||
check updatedAvailability.freeSize == 100000
|
||||
|
||||
test "updating availability - updating totalSize does not allow bellow utilized",
|
||||
salesConfig:
|
||||
salesConfig, stopOnRequestFail = true:
|
||||
let originalSize = 0xFFFFFF.uint64
|
||||
let minPricePerBytePerSecond = 3.u256
|
||||
let collateralPerByte = 1.u256
|
||||
@ -157,7 +158,8 @@ marketplacesuite(name = "Sales"):
|
||||
check newUpdatedAvailability.totalSize == originalSize + 20000
|
||||
check newUpdatedAvailability.freeSize - updatedAvailability.freeSize == 20000
|
||||
|
||||
test "updating availability fails with until negative", salesConfig:
|
||||
test "updating availability fails with until negative",
|
||||
salesConfig, stopOnRequestFail = true:
|
||||
let availability = (
|
||||
await host.postAvailability(
|
||||
totalSize = 140000.uint64,
|
||||
@ -174,7 +176,7 @@ marketplacesuite(name = "Sales"):
|
||||
(await response.body) == "Cannot set until to a negative value"
|
||||
|
||||
test "returns an error when trying to update the until date before an existing a request is finished",
|
||||
salesConfig:
|
||||
salesConfig, stopOnRequestFail = true:
|
||||
let size = 0xFFFFFF.uint64
|
||||
let duration = 20 * 60.uint64
|
||||
let expiry = 10 * 60.uint64
|
||||
|
||||
@ -23,6 +23,56 @@ template marketplacesuite*(name: string, body: untyped) =
|
||||
var token {.inject, used.}: Erc20Token
|
||||
var subscriptions: seq[Subscription] = @[]
|
||||
var tokenSubscription: Subscription
|
||||
var requestFailedEvent: AsyncEvent
|
||||
|
||||
template test(tname, startNodeConfigs, stopOnRequestFail, tbody) =
|
||||
test tname, startNodeConfigs:
|
||||
stopOnRequestFailed:
|
||||
tbody
|
||||
|
||||
template stopOnRequestFailed(tbody: untyped) =
|
||||
let completed = newAsyncEvent()
|
||||
let requestFailedEvent = newAsyncEvent()
|
||||
|
||||
proc onRequestFailed(eventResult: ?!RequestFailed) {.raises: [].} =
|
||||
assert not eventResult.isErr
|
||||
requestFailedEvent.fire()
|
||||
|
||||
let sub = await marketplace.subscribe(RequestFailed, onRequestFailed)
|
||||
subscriptions.add(sub)
|
||||
|
||||
let mainFut = (
|
||||
proc(): Future[void] {.async.} =
|
||||
try:
|
||||
tbody
|
||||
completed.fire()
|
||||
except CancelledError as e:
|
||||
raise e
|
||||
except CatchableError as e:
|
||||
completed.fire()
|
||||
raise e
|
||||
)()
|
||||
|
||||
let fastFailFut = (
|
||||
proc(): Future[void] {.async.} =
|
||||
try:
|
||||
await requestFailedEvent.wait().wait(timeout = chronos.seconds(60))
|
||||
completed.fire()
|
||||
raise newException(TestFailedError, "storage request has failed")
|
||||
except AsyncTimeoutError:
|
||||
discard
|
||||
)()
|
||||
|
||||
await completed.wait().wait(timeout = chronos.seconds(60 * 30))
|
||||
|
||||
if not fastFailFut.completed:
|
||||
await fastFailFut.cancelAndWait()
|
||||
|
||||
if mainFut.failed:
|
||||
raise mainFut.error
|
||||
|
||||
if fastFailFut.failed:
|
||||
raise fastFailFut.error
|
||||
|
||||
proc check(cond: bool, reason = "Check failed"): void =
|
||||
if not cond:
|
||||
@ -215,6 +265,7 @@ template marketplacesuite*(name: string, body: untyped) =
|
||||
period = config.proofs.period
|
||||
periodicity = Periodicity(seconds: period)
|
||||
subscriptions = @[]
|
||||
requestFailedEvent = newAsyncEvent()
|
||||
teardown:
|
||||
for subscription in subscriptions:
|
||||
await subscription.unsubscribe()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user