Implement myRequest() and getState() methods for OnChainMarket

This commit is contained in:
Eric Mastro 2022-10-25 17:04:14 +11:00
parent 79f6f81766
commit cc1c00e3ce
No known key found for this signature in database
GPG Key ID: 141E3048D95A4E63
4 changed files with 27 additions and 1 deletions

View File

@ -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.} =

View File

@ -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.}

View File

@ -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..<request.ask.slots:
await market.fillSlot(request.id, slotIndex.u256, proof)
check (await market.getState(request.id)) == RequestState.Started

@ -1 +1 @@
Subproject commit 087c13a7fc2b44a5ad52b8a624f51b711a10d783
Subproject commit 2ac6c0b2deecd8060ae326301bf625d64115cc09