From 14d703a1a6f28cd06b7fe74e6db726ea6ecd3722 Mon Sep 17 00:00:00 2001 From: Marcin Czenko Date: Fri, 27 Sep 2024 23:53:02 +0200 Subject: [PATCH] refactors a bit to get the tests back to work --- codex/contracts/market.nim | 8 +++----- codex/market.nim | 5 ++--- codex/validation.nim | 2 +- tests/codex/helpers/mockmarket.nim | 7 +++++++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index e04c9743..2ba8adba 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -470,11 +470,9 @@ proc blockNumberForEpoch(epochTime: int64, provider: Provider): Future[UInt256] except ValueError as e: raise newException(EthersError, fmt"Conversion error: {e.msg}") -method queryPastEvents*[T: MarketplaceEvent]( +method queryPastSlotFilledEvents*( market: OnChainMarket, - _: type T, - fromTime: int64): Future[seq[T]] {.async.} = - + fromTime: int64): Future[seq[SlotFilled]] {.async.} = convertEthersError: let contract = market.contract let provider = contract.provider @@ -483,6 +481,6 @@ method queryPastEvents*[T: MarketplaceEvent]( let fromBlock = BlockTag.init(blockNumberForEpoch) - return await contract.queryFilter(T, + return await contract.queryFilter(SlotFilled, fromBlock, BlockTag.latest) diff --git a/codex/market.nim b/codex/market.nim index 12971c1b..73522c39 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -249,8 +249,7 @@ method queryPastEvents*[T: MarketplaceEvent]( blocksAgo: int): Future[seq[T]] {.base, async.} = raiseAssert("not implemented") -method queryPastEvents*[T: MarketplaceEvent]( +method queryPastSlotFilledEvents*( market: Market, - _: type T, - fromTime: int64): Future[seq[T]] {.base, async.} = + fromTime: int64): Future[seq[SlotFilled]] {.base, async.} = raiseAssert("not implemented") diff --git a/codex/validation.nim b/codex/validation.nim index 80e15c8f..ac1a9400 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -129,7 +129,7 @@ proc epochForDurationBackFromNow(duration: times.Duration): int64 = proc restoreHistoricalState(validation: Validation) {.async} = let startTimeEpoch = epochForDurationBackFromNow(MaxStorageRequestDuration) - let slotFilledEvents = await validation.market.queryPastEvents(SlotFilled, + let slotFilledEvents = await validation.market.queryPastSlotFilledEvents( fromTime = startTimeEpoch) for event in slotFilledEvents: let slotId = slotId(event.requestId, event.slotIndex) diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index d19f0c21..928641c8 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -485,6 +485,13 @@ method queryPastEvents*[T: MarketplaceEvent]( SlotFilled(requestId: slot.requestId, slotIndex: slot.slotIndex) ) +method queryPastSlotFilledEvents*( + market: MockMarket, + fromTime: int64): Future[seq[SlotFilled]] {.async.} = + return market.filled.map(slot => + SlotFilled(requestId: slot.requestId, slotIndex: slot.slotIndex) + ) + method unsubscribe*(subscription: RequestSubscription) {.async.} = subscription.market.subscriptions.onRequest.keepItIf(it != subscription)