@@ -14,6 +14,7 @@ from pkg/ethers import BlockTag
1414import codex/ clock
1515
1616import ../ examples
17+ import ./ mockclock
1718
1819export market
1920export tables
5152 errorOnFillSlot* : ? (ref MarketError )
5253 errorOnFreeSlot* : ? (ref MarketError )
5354 errorOnGetHost* : ? (ref MarketError )
54- clock: ? Clock
55+ clock: Clock
5556
5657 Fulfillment * = object
5758 requestId* : RequestId
6364 host* : Address
6465 slotIndex* : uint64
6566 proof* : Groth16Proof
66- timestamp: ? SecondsSince1970
67+ timestamp: SecondsSince1970
6768 collateral* : UInt256
6869
6970 Subscriptions = object
@@ -119,7 +120,7 @@ proc hash*(address: Address): Hash =
119120proc hash * (requestId: RequestId ): Hash =
120121 hash (requestId.toArray)
121122
122- proc new * (_: type MockMarket , clock: ? Clock = Clock .none ): MockMarket =
123+ proc new * (_: type MockMarket , clock: Clock = MockClock . new () ): MockMarket =
123124 # # Create a new mocked Market instance
124125 # #
125126 let config = MarketplaceConfig (
@@ -181,10 +182,15 @@ method getPointer*(market: MockMarket, slotId: SlotId): Future[uint8] {.async.}
181182method requestStorage * (
182183 market: MockMarket , request: StorageRequest
183184) {.async : (raises: [CancelledError , MarketError ]).} =
185+ let now = market.clock.now ()
186+ let requestExpiresAt = now + request.expiry.toSecondsSince1970
187+ let requestEndsAt = now + request.ask.duration.toSecondsSince1970
184188 market.requested.add (request)
189+ market.requestExpiry[request.id] = requestExpiresAt
190+ market.requestEnds[request.id] = requestEndsAt
185191 var subscriptions = market.subscriptions.onRequest
186192 for subscription in subscriptions:
187- subscription.callback (request.id, request.ask, request.expiry )
193+ subscription.callback (request.id, request.ask, requestExpiresAt. uint64 )
188194
189195method myRequests * (market: MockMarket ): Future [seq [RequestId ]] {.async .} =
190196 return market.activeRequests[market.signer]
@@ -308,7 +314,7 @@ proc fillSlot*(
308314 slotIndex: slotIndex,
309315 proof: proof,
310316 host: host,
311- timestamp: market.clock .? now,
317+ timestamp: market.clock. now,
312318 collateral: collateral,
313319 )
314320 market.filled.add (slot)
@@ -541,15 +547,23 @@ method queryPastStorageRequestedEvents*(
541547): Future [seq [StorageRequested ]] {.async .} =
542548 return market.requested.map (
543549 request =>
544- StorageRequested (requestId: request.id, ask: request.ask, expiry: request.expiry)
550+ StorageRequested (
551+ requestId: request.id,
552+ ask: request.ask,
553+ expiry: market.requestExpiry[request.id].uint64 ,
554+ )
545555 )
546556
547557method queryPastStorageRequestedEvents * (
548558 market: MockMarket , blocksAgo: int
549559): Future [seq [StorageRequested ]] {.async .} =
550560 return market.requested.map (
551561 request =>
552- StorageRequested (requestId: request.id, ask: request.ask, expiry: request.expiry)
562+ StorageRequested (
563+ requestId: request.id,
564+ ask: request.ask,
565+ expiry: market.requestExpiry[request.id].uint64 ,
566+ )
553567 )
554568
555569method queryPastSlotFilledEvents * (
@@ -571,10 +585,7 @@ method queryPastSlotFilledEvents*(
571585): Future [seq [SlotFilled ]] {.async .} =
572586 let filtered = market.filled.filter (
573587 proc (slot: MockSlot ): bool =
574- if timestamp =? slot.timestamp:
575- return timestamp >= fromTime
576- else :
577- true
588+ return slot.timestamp >= fromTime
578589 )
579590 return filtered.map (
580591 slot => SlotFilled (requestId: slot.requestId, slotIndex: slot.slotIndex)
0 commit comments