[market] subscribe to offers for a certain request
This commit is contained in:
parent
0cee79b1a2
commit
5ea64522d8
|
@ -43,6 +43,7 @@ method subscribeOffers(market: OnChainMarket,
|
||||||
callback: OnOffer):
|
callback: OnOffer):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: StorageOffered) {.upraises:[].} =
|
proc onEvent(event: StorageOffered) {.upraises:[].} =
|
||||||
|
if event.requestId == requestId:
|
||||||
callback(event.offer)
|
callback(event.offer)
|
||||||
let subscription = await market.contract.subscribe(StorageOffered, onEvent)
|
let subscription = await market.contract.subscribe(StorageOffered, onEvent)
|
||||||
return OnChainMarketSubscription(eventSubscription: subscription)
|
return OnChainMarketSubscription(eventSubscription: subscription)
|
||||||
|
|
|
@ -93,3 +93,29 @@ ethersuite "On-Chain Market":
|
||||||
await market.offerStorage(offerWithoutHost)
|
await market.offerStorage(offerWithoutHost)
|
||||||
|
|
||||||
check submitted.host == accounts[0]
|
check submitted.host == accounts[0]
|
||||||
|
|
||||||
|
test "subscribes only to offers for a certain request":
|
||||||
|
var otherRequest = StorageRequest.example
|
||||||
|
var otherOffer = StorageOffer.example
|
||||||
|
otherRequest.client = accounts[0]
|
||||||
|
otherOffer.host = accounts[0]
|
||||||
|
otherOffer.requestId = otherRequest.id
|
||||||
|
otherOffer.price = otherRequest.maxPrice
|
||||||
|
|
||||||
|
await token.approve(storage.address, request.maxPrice)
|
||||||
|
await market.requestStorage(request)
|
||||||
|
await token.approve(storage.address, otherRequest.maxPrice)
|
||||||
|
await market.requestStorage(otherRequest)
|
||||||
|
|
||||||
|
var submitted: seq[StorageOffer]
|
||||||
|
proc onOffer(offer: StorageOffer) =
|
||||||
|
submitted.add(offer)
|
||||||
|
|
||||||
|
let subscription = await market.subscribeOffers(request.id, onOffer)
|
||||||
|
|
||||||
|
await market.offerStorage(offer)
|
||||||
|
await market.offerStorage(otherOffer)
|
||||||
|
|
||||||
|
check submitted == @[offer]
|
||||||
|
|
||||||
|
await subscription.unsubscribe()
|
||||||
|
|
Loading…
Reference in New Issue