From 3d9eb198557dacc8863d7001ae33e291b99ac508 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Mon, 6 Nov 2023 13:10:23 +1100 Subject: [PATCH] All integration tests working --- codex/contracts/clock.nim | 5 - codex/sales.nim | 1 + tests/integration/codexclient.nim | 3 - tests/integration/marketplacesuite.nim | 24 -- tests/integration/multinodes.nim | 2 - tests/integration/testproofs.nim | 536 ++++++++----------------- 6 files changed, 160 insertions(+), 411 deletions(-) diff --git a/codex/contracts/clock.nim b/codex/contracts/clock.nim index 315bbe78..763dc579 100644 --- a/codex/contracts/clock.nim +++ b/codex/contracts/clock.nim @@ -24,14 +24,12 @@ proc new*(_: type OnChainClock, provider: Provider): OnChainClock = method start*(clock: OnChainClock) {.async.} = if clock.started: return - trace "starting on chain clock" clock.started = true proc onBlock(blck: Block) {.upraises:[].} = let blockTime = initTime(blck.timestamp.truncate(int64), 0) let computerTime = getTime() clock.offset = blockTime - computerTime - trace "new block received, updated clock offset", blockTime, computerTime, offset = clock.offset clock.newBlock.fire() if latestBlock =? (await clock.provider.getBlock(BlockTag.latest)): @@ -42,7 +40,6 @@ method start*(clock: OnChainClock) {.async.} = method stop*(clock: OnChainClock) {.async.} = if not clock.started: return - trace "stopping on chain clock" clock.started = false await clock.subscription.unsubscribe() @@ -58,8 +55,6 @@ method lastBlockTimestamp*(clock: OnChainClock): Future[UInt256] {.async.} = return blk.timestamp method waitUntil*(clock: OnChainClock, time: SecondsSince1970) {.async.} = - trace "waiting until", time while (let difference = time - (await clock.lastBlockTimestamp).truncate(int64); difference > 0): clock.newBlock.clear() discard await clock.newBlock.wait().withTimeout(chronos.seconds(difference)) - trace "waiting for time unblocked" diff --git a/codex/sales.nim b/codex/sales.nim index 53b5860b..28c3e50d 100644 --- a/codex/sales.nim +++ b/codex/sales.nim @@ -492,6 +492,7 @@ proc start*(sales: Sales) {.async.} = await sales.load() await sales.startSlotQueue() await sales.subscribe() + sales.running = true proc stop*(sales: Sales) {.async.} = trace "stopping sales" diff --git a/tests/integration/codexclient.nim b/tests/integration/codexclient.nim index 285d365f..87bd55b6 100644 --- a/tests/integration/codexclient.nim +++ b/tests/integration/codexclient.nim @@ -110,14 +110,11 @@ proc getPurchase*(client: CodexClient, purchaseId: PurchaseId): ?!RestPurchase = proc getSalesAgent*(client: CodexClient, slotId: SlotId): ?!RestSalesAgent = let url = client.baseurl & "/sales/slots/" & slotId.toHex - echo "getting sales agent for id, ", slotId.toHex try: let body = client.http.getContent(url) - echo "get sales agent body: ", body let json = ? parseJson(body).catch return RestSalesAgent.fromJson(json) except CatchableError as e: - echo "[client.getSalesAgent] error getting agent: ", e.msg return failure e.msg proc getSlots*(client: CodexClient): ?!seq[Slot] = diff --git a/tests/integration/marketplacesuite.nim b/tests/integration/marketplacesuite.nim index 6068653c..f72e4b2a 100644 --- a/tests/integration/marketplacesuite.nim +++ b/tests/integration/marketplacesuite.nim @@ -24,43 +24,20 @@ template marketplacesuite*(name: string, startNodes: Nodes, body: untyped) = let periodicity = Periodicity(seconds: period.u256) let currentPeriod = periodicity.periodOf(await ethProvider.currentTime()) let endOfPeriod = periodicity.periodEnd(currentPeriod) - echo "advancing to next period start at ", endOfPeriod + 1 await ethProvider.advanceTimeTo(endOfPeriod + 1) proc timeUntil(period: Period): Future[times.Duration] {.async.} = let currentPeriod = await getCurrentPeriod() - echo "[timeUntil] currentPeriod: ", currentPeriod - echo "[timeUntil] waiting until period: ", period let endOfCurrPeriod = periodicity.periodEnd(currentPeriod) let endOfLastPeriod = periodicity.periodEnd(period) let endOfCurrPeriodTime = initTime(endOfCurrPeriod.truncate(int64), 0) let endOfLastPeriodTime = initTime(endOfLastPeriod.truncate(int64), 0) let r = endOfLastPeriodTime - endOfCurrPeriodTime - echo "[timeUntil] diff between end of current period and now: ", r return r - # echo "advancing to next period start at ", endOfPeriod + 1 - # await ethProvider.advanceTimeTo(endOfPeriod + 1) proc periods(p: int): uint64 = p.uint64 * period - template eventuallyP(condition: untyped, totalProofs: int, sleep: int): bool = - proc e: Future[bool] {.async.} = - for i in 0.. (await token.balanceOf(!provider0.address)) ) - echo "provider1 balance: ", (await token.balanceOf(!provider1.address)) - echo "provider0 balance: ", (await token.balanceOf(!provider0.address)) await subscription.unsubscribe()