Skip to content

Commit

Permalink
refactors a bit to get the tests back to work
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinczenko committed Sep 27, 2024
1 parent ab7b87e commit 9e9882b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
8 changes: 3 additions & 5 deletions codex/contracts/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,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

Check warning on line 451 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L414-L451

Added lines #L414 - L451 were not covered by tests
Expand All @@ -456,6 +454,6 @@ method queryPastEvents*[T: MarketplaceEvent](

let fromBlock = BlockTag.init(blockNumberForEpoch)

Check warning on line 455 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L453-L455

Added lines #L453 - L455 were not covered by tests

return await contract.queryFilter(T,
return await contract.queryFilter(SlotFilled,
fromBlock,
BlockTag.latest)

Check warning on line 459 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L457-L459

Added lines #L457 - L459 were not covered by tests
5 changes: 2 additions & 3 deletions codex/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ method queryPastEvents*[T: MarketplaceEvent](
blocksAgo: int): Future[seq[T]] {.base, async.} =
raiseAssert("not implemented")

Check warning on line 227 in codex/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/market.nim#L227

Added line #L227 was not covered by tests
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")
2 changes: 1 addition & 1 deletion codex/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 135 in codex/validation.nim

View check run for this annotation

Codecov / codecov/patch

codex/validation.nim#L135

Added line #L135 was not covered by tests
Expand Down
7 changes: 7 additions & 0 deletions tests/codex/helpers/mockmarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,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)

Expand Down

0 comments on commit 9e9882b

Please sign in to comment.