[market] Add market.getRequest()
This commit is contained in:
parent
7c50d9f739
commit
b414ecd67e
|
@ -31,6 +31,14 @@ method requestStorage(market: OnChainMarket,
|
|||
await market.contract.requestStorage(request)
|
||||
return request
|
||||
|
||||
method getRequest(market: OnChainMarket,
|
||||
id: array[32, byte]): Future[?StorageRequest] {.async.} =
|
||||
let request = await market.contract.getRequest(id)
|
||||
if request != StorageRequest.default:
|
||||
return some request
|
||||
else:
|
||||
return none StorageRequest
|
||||
|
||||
method fulfillRequest(market: OnChainMarket,
|
||||
requestId: array[32, byte],
|
||||
proof: seq[byte]) {.async.} =
|
||||
|
|
|
@ -30,6 +30,7 @@ proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
|
|||
|
||||
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
|
||||
proc fulfillRequest*(storage: Storage, id: Id, proof: seq[byte]) {.contract.}
|
||||
proc getRequest*(storage: Storage, id: Id): StorageRequest {.contract, view.}
|
||||
|
||||
proc finishContract*(storage: Storage, id: Id) {.contract.}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import pkg/chronos
|
||||
import pkg/upraises
|
||||
import pkg/questionable
|
||||
import ./contracts/requests
|
||||
import ./contracts/offers
|
||||
|
||||
export chronos
|
||||
export questionable
|
||||
export requests
|
||||
export offers
|
||||
|
||||
|
@ -18,6 +20,11 @@ method requestStorage*(market: Market,
|
|||
Future[StorageRequest] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method getRequest*(market: Market,
|
||||
id: array[32, byte]):
|
||||
Future[?StorageRequest] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method fulfillRequest*(market: Market,
|
||||
requestId: array[32, byte],
|
||||
proof: seq[byte]) {.base, async.} =
|
||||
|
|
|
@ -30,6 +30,13 @@ method requestStorage*(market: MockMarket,
|
|||
subscription.callback(request.id, request.ask)
|
||||
return request
|
||||
|
||||
method getRequest(market: MockMarket,
|
||||
id: array[32, byte]): Future[?StorageRequest] {.async.} =
|
||||
for request in market.requested:
|
||||
if request.id == id:
|
||||
return some request
|
||||
return none StorageRequest
|
||||
|
||||
method fulfillRequest*(market: MockMarket,
|
||||
requestId: array[32, byte],
|
||||
proof: seq[byte]) {.async.} =
|
||||
|
|
|
@ -49,6 +49,12 @@ ethersuite "On-Chain Market":
|
|||
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.maxPrice)
|
||||
discard await market.requestStorage(request)
|
||||
check (await market.getRequest(request.id)) == some request
|
||||
|
||||
test "supports request subscriptions":
|
||||
var receivedIds: seq[array[32, byte]]
|
||||
var receivedAsks: seq[StorageAsk]
|
||||
|
|
Loading…
Reference in New Issue