From a2570f9380bb32f5933fbe9b6fca34350e1a53f5 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 5 Jul 2022 10:37:55 +0200 Subject: [PATCH] [WIP sales] fulfill request --- codex/sales.nim | 1 + tests/codex/helpers/mockmarket.nim | 6 +++--- tests/codex/testsales.nim | 11 ++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/codex/sales.nim b/codex/sales.nim index f62253af..7bacb0a6 100644 --- a/codex/sales.nim +++ b/codex/sales.nim @@ -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() diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 0b782e9f..c257d4c3 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -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] diff --git a/tests/codex/testsales.nim b/tests/codex/testsales.nim index 280a383f..212986a4 100644 --- a/tests/codex/testsales.nim +++ b/tests/codex/testsales.nim @@ -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) =