From 156cd5ba73eb0e4997596bd516eb45ef2cb7053e Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 20 Jul 2022 15:59:07 +0200 Subject: [PATCH] [market] Replace fulfillRequest() by fillSlot() --- codex/contracts/market.nim | 6 +++++ codex/market.nim | 6 +++++ tests/contracts/examples.nim | 2 +- tests/contracts/testMarket.nim | 46 +++++++++++++++++++--------------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index fdcebece..e2c92751 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -55,6 +55,12 @@ method fulfillRequest(market: OnChainMarket, proof: seq[byte]) {.async.} = await market.contract.fulfillRequest(requestId, proof) +method fillSlot(market: OnChainMarket, + requestId: array[32, byte], + slotIndex: UInt256, + proof: seq[byte]) {.async.} = + await market.contract.fillSlot(requestId, slotIndex, proof) + method subscribeRequests(market: OnChainMarket, callback: OnRequest): Future[MarketSubscription] {.async.} = diff --git a/codex/market.nim b/codex/market.nim index cb0ee362..f4cb7ede 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -35,6 +35,12 @@ method fulfillRequest*(market: Market, proof: seq[byte]) {.base, async.} = raiseAssert("not implemented") +method fillSlot*(market: Market, + requestId: array[32, byte], + slotIndex: UInt256, + proof: seq[byte]) {.base, async.} = + raiseAssert("not implemented") + method subscribeRequests*(market: Market, callback: OnRequest): Future[Subscription] {.base, async.} = diff --git a/tests/contracts/examples.nim b/tests/contracts/examples.nim index af504259..ed3c6c46 100644 --- a/tests/contracts/examples.nim +++ b/tests/contracts/examples.nim @@ -17,7 +17,7 @@ proc example*(_: type StorageRequest): StorageRequest = duration: (10 * 60 * 60).u256, # 10 hours proofProbability: 4.u256, # require a proof roughly once every 4 periods reward: 84.u256, - slots: 42 + slots: 4 ), content: StorageContent( cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob", diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index a9b2f40c..bcf884b4 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -12,12 +12,13 @@ ethersuite "On-Chain Market": var storage: Storage var token: TestToken var request: StorageRequest + var slotIndex: UInt256 setup: let deployment = deployment() storage = Storage.new(!deployment.address(Storage), provider.getSigner()) token = TestToken.new(!deployment.address(TestToken), provider.getSigner()) - await token.mint(accounts[0], 1000.u256) + await token.mint(accounts[0], 1_000_000_000.u256) let collateral = await storage.collateralAmount() await token.approve(storage.address, collateral) @@ -28,6 +29,8 @@ ethersuite "On-Chain Market": request = StorageRequest.example request.client = accounts[0] + slotIndex = (request.ask.slots div 2).u256 + test "fails to instantiate when contract does not have a signer": let storageWithoutSigner = storage.connect(provider) expect AssertionError: @@ -37,19 +40,19 @@ ethersuite "On-Chain Market": check (await market.getSigner()) == (await provider.getSigner().getAddress()) test "supports storage requests": - await token.approve(storage.address, request.ask.reward) + await token.approve(storage.address, request.price) check (await market.requestStorage(request)) == request test "sets client address when submitting storage request": var requestWithoutClient = request requestWithoutClient.client = Address.default - await token.approve(storage.address, request.ask.reward) + await token.approve(storage.address, request.price) let submitted = await market.requestStorage(requestWithoutClient) check submitted.client == accounts[0] test "can retrieve previously submitted requests": check (await market.getRequest(request.id)) == none StorageRequest - await token.approve(storage.address, request.ask.reward) + await token.approve(storage.address, request.price) discard await market.requestStorage(request) check (await market.getRequest(request.id)) == some request @@ -60,42 +63,43 @@ ethersuite "On-Chain Market": receivedIds.add(id) receivedAsks.add(ask) let subscription = await market.subscribeRequests(onRequest) - await token.approve(storage.address, request.ask.reward) + await token.approve(storage.address, request.price) discard await market.requestStorage(request) check receivedIds == @[request.id] check receivedAsks == @[request.ask] await subscription.unsubscribe() - test "supports fulfilling of requests": - await token.approve(storage.address, request.ask.reward) + test "supports filling of slots": + await token.approve(storage.address, request.price) discard await market.requestStorage(request) - await market.fulfillRequest(request.id, proof) + await market.fillSlot(request.id, slotIndex, proof) - test "can retrieve host that fulfilled request": - await token.approve(storage.address, request.ask.reward) + test "can retrieve host that filled slot": + await token.approve(storage.address, request.price) discard await market.requestStorage(request) - check (await market.getHost(request.id)) == none Address - await market.fulfillRequest(request.id, proof) - check (await market.getHost(request.id)) == some accounts[0] + check (await market.getHost(request.slotId(slotIndex))) == none Address + await market.fillSlot(request.id, slotIndex, proof) + check (await market.getHost(request.slotId(slotIndex))) == some accounts[0] test "support fulfillment subscriptions": - await token.approve(storage.address, request.ask.reward) + await token.approve(storage.address, request.price) discard await market.requestStorage(request) var receivedIds: seq[array[32, byte]] proc onFulfillment(id: array[32, byte]) = receivedIds.add(id) let subscription = await market.subscribeFulfillment(request.id, onFulfillment) - await market.fulfillRequest(request.id, proof) + for slotIndex in 0..