From cc1c00e3ceb9d1212840ced848df02b93750cdf4 Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Tue, 25 Oct 2022 17:04:14 +1100 Subject: [PATCH] Implement myRequest() and getState() methods for OnChainMarket --- codex/contracts/market.nim | 7 +++++++ codex/contracts/storage.nim | 3 +++ tests/contracts/testMarket.nim | 16 ++++++++++++++++ vendor/dagger-contracts | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index b84f1c50..068851d8 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -28,6 +28,13 @@ func new*(_: type OnChainMarket, contract: Storage): OnChainMarket = method getSigner*(market: OnChainMarket): Future[Address] {.async.} = return await market.signer.getAddress() +method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} = + return await market.contract.myRequests + +method getState*(market: OnChainMarket, + requestId: RequestId): Future[RequestState] {.async.} = + return await market.contract.state(requestId) + method requestStorage(market: OnChainMarket, request: StorageRequest): Future[StorageRequest] {.async.} = diff --git a/codex/contracts/storage.nim b/codex/contracts/storage.nim index 2c1c0028..960001c4 100644 --- a/codex/contracts/storage.nim +++ b/codex/contracts/storage.nim @@ -41,6 +41,9 @@ proc payoutSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256) {.c proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.} proc getHost*(storage: Storage, id: SlotId): Address {.contract, view.} +proc myRequests*(storage: Storage): seq[RequestId] {.contract, view.} +proc state*(storage: Storage, requestId: RequestId): RequestState {.contract, view.} + proc proofPeriod*(storage: Storage): UInt256 {.contract, view.} proc proofTimeout*(storage: Storage): UInt256 {.contract, view.} diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index daeb0944..d5423ccd 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -191,3 +191,19 @@ ethersuite "On-Chain Market": test "request is none when unknown": check isNone await market.getRequest(request.id) + + test "can retrieve active requests": + await token.approve(storage.address, request.price) + discard await market.requestStorage(request) + var request2 = StorageRequest.example + request2.client = accounts[0] + await token.approve(storage.address, request2.price) + discard await market.requestStorage(request2) + check (await market.myRequests()) == @[request.id, request2.id] + + test "can retrieve request state": + await token.approve(storage.address, request.price) + discard await market.requestStorage(request) + for slotIndex in 0..