mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-16 14:57:54 +00:00
Implement myRequest() and getState() methods for OnChainMarket
This commit is contained in:
parent
79f6f81766
commit
cc1c00e3ce
@ -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.} =
|
||||
|
@ -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.}
|
||||
|
||||
|
@ -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
|
||||
|
2
vendor/dagger-contracts
vendored
2
vendor/dagger-contracts
vendored
@ -1 +1 @@
|
||||
Subproject commit 087c13a7fc2b44a5ad52b8a624f51b711a10d783
|
||||
Subproject commit 2ac6c0b2deecd8060ae326301bf625d64115cc09
|
Loading…
x
Reference in New Issue
Block a user