refactors a bit to get the tests back to work

This commit is contained in:
Marcin Czenko 2024-09-27 23:53:02 +02:00
parent 8186842784
commit c089000033
No known key found for this signature in database
GPG Key ID: 33DEA0C8E30937C0
4 changed files with 13 additions and 9 deletions

View File

@ -481,11 +481,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
@ -494,6 +492,6 @@ method queryPastEvents*[T: MarketplaceEvent](
let fromBlock = BlockTag.init(blockNumberForEpoch)
return await contract.queryFilter(T,
return await contract.queryFilter(SlotFilled,
fromBlock,
BlockTag.latest)

View File

@ -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")

View File

@ -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)

View File

@ -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)