[WIP sales] fulfill request

This commit is contained in:
Mark Spanbroek 2022-07-05 10:37:55 +02:00 committed by markspanbroek
parent 5abd5dd674
commit a2570f9380
3 changed files with 14 additions and 4 deletions

View File

@ -147,6 +147,7 @@ proc start(negotiation: Negotiation) {.async.} =
await retrieve(request.content.cid)
let proof = await prove(request.content.cid)
await market.fulfillRequest(request.id, proof)
await negotiation.sendOffer()
await negotiation.subscribeSelect()

View File

@ -10,9 +10,9 @@ type
signer: Address
subscriptions: Subscriptions
Fulfillment* = object
requestId: array[32, byte]
proof: seq[byte]
host: Address
requestId*: array[32, byte]
proof*: seq[byte]
host*: Address
Subscriptions = object
onRequest: seq[RequestSubscription]
onFulfillment: seq[FulfillmentSubscription]

View File

@ -23,6 +23,7 @@ suite "Sales":
cid: "some cid"
)
)
let proof = seq[byte].example
var sales: Sales
var market: MockMarket
@ -33,7 +34,7 @@ suite "Sales":
clock = MockClock.new()
sales = Sales.new(market, clock)
sales.retrieve = proc(_: string) {.async.} = discard
sales.prove = proc(_: string): Future[seq[byte]] {.async.} = discard
sales.prove = proc(_: string): Future[seq[byte]] {.async.} = return proof
await sales.start()
teardown:
@ -94,6 +95,14 @@ suite "Sales":
discard await market.requestStorage(request)
check provingCid == request.content.cid
test "fulfills request":
sales.add(availability)
discard await market.requestStorage(request)
check market.fulfilled.len == 1
check market.fulfilled[0].requestId == request.id
check market.fulfilled[0].proof == proof
check market.fulfilled[0].host == await market.getSigner()
# test "calls onSale when offer is selected":
# var sold: StorageOffer
# sales.onSale = proc(offer: StorageOffer) =