[marketplace] fix tests
Fix tests based from two changes: - Addition of the Reservations module - ContractInteractions split into ClientInteractions and HostInteractions
This commit is contained in:
parent
cff2ca93d8
commit
8444b1b967
|
@ -47,8 +47,8 @@ proc new*(_: type ClientInteractions,
|
||||||
ClientInteractions.new("ws://localhost:8545", account)
|
ClientInteractions.new("ws://localhost:8545", account)
|
||||||
|
|
||||||
proc start*(self: ClientInteractions) {.async.} =
|
proc start*(self: ClientInteractions) {.async.} =
|
||||||
await self.purchasing.start()
|
|
||||||
await procCall ContractInteractions(self).start()
|
await procCall ContractInteractions(self).start()
|
||||||
|
await self.purchasing.start()
|
||||||
|
|
||||||
proc stop*(self: ClientInteractions) {.async.} =
|
proc stop*(self: ClientInteractions) {.async.} =
|
||||||
await self.purchasing.stop()
|
await self.purchasing.stop()
|
||||||
|
|
|
@ -57,9 +57,9 @@ proc new*(_: type HostInteractions,
|
||||||
HostInteractions.new("ws://localhost:8545", account, repo)
|
HostInteractions.new("ws://localhost:8545", account, repo)
|
||||||
|
|
||||||
method start*(self: HostInteractions) {.async.} =
|
method start*(self: HostInteractions) {.async.} =
|
||||||
|
await procCall ContractInteractions(self).start()
|
||||||
await self.sales.start()
|
await self.sales.start()
|
||||||
await self.proving.start()
|
await self.proving.start()
|
||||||
await procCall ContractInteractions(self).start()
|
|
||||||
|
|
||||||
method stop*(self: HostInteractions) {.async.} =
|
method stop*(self: HostInteractions) {.async.} =
|
||||||
await self.sales.stop()
|
await self.sales.stop()
|
||||||
|
|
|
@ -38,8 +38,8 @@ proc prepare*(
|
||||||
|
|
||||||
return success((signer, deploy))
|
return success((signer, deploy))
|
||||||
|
|
||||||
method start*(interactions: ContractInteractions) {.async, base.} =
|
method start*(self: ContractInteractions) {.async, base.} =
|
||||||
await interactions.clock.start()
|
await self.clock.start()
|
||||||
|
|
||||||
method stop*(interactions: ContractInteractions) {.async, base.} =
|
method stop*(self: ContractInteractions) {.async, base.} =
|
||||||
await interactions.clock.stop()
|
await self.clock.stop()
|
||||||
|
|
|
@ -372,9 +372,16 @@ proc start*(node: CodexNodeRef) {.async.} =
|
||||||
try:
|
try:
|
||||||
await contracts.start()
|
await contracts.start()
|
||||||
except CatchableError as error:
|
except CatchableError as error:
|
||||||
error "Unable to start contract interactions: ", error=error.msg
|
error "Unable to start host contract interactions: ", error=error.msg
|
||||||
node.contracts.host = HostInteractions.none
|
node.contracts.host = HostInteractions.none
|
||||||
|
|
||||||
|
if contracts =? node.contracts.client:
|
||||||
|
try:
|
||||||
|
await contracts.start()
|
||||||
|
except CatchableError as error:
|
||||||
|
error "Unable to start client contract interactions: ", error=error.msg
|
||||||
|
node.contracts.client = ClientInteractions.none
|
||||||
|
|
||||||
node.networkId = node.switch.peerInfo.peerId
|
node.networkId = node.switch.peerInfo.peerId
|
||||||
notice "Started codex node", id = $node.networkId, addrs = node.switch.peerInfo.addrs
|
notice "Started codex node", id = $node.networkId, addrs = node.switch.peerInfo.addrs
|
||||||
|
|
||||||
|
|
|
@ -247,7 +247,10 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf): RestRouter =
|
||||||
without contracts =? node.contracts.host:
|
without contracts =? node.contracts.host:
|
||||||
return RestApiResponse.error(Http503, "Sales unavailable")
|
return RestApiResponse.error(Http503, "Sales unavailable")
|
||||||
|
|
||||||
let json = %contracts.sales.available
|
without unused =? (await contracts.sales.reservations.unused), err:
|
||||||
|
return RestApiResponse.error(Http500, err.msg)
|
||||||
|
|
||||||
|
let json = %unused
|
||||||
return RestApiResponse.response($json)
|
return RestApiResponse.response($json)
|
||||||
|
|
||||||
router.rawApi(
|
router.rawApi(
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
## those terms.
|
## those terms.
|
||||||
|
|
||||||
import std/typetraits
|
import std/typetraits
|
||||||
|
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/chronicles
|
import pkg/chronicles
|
||||||
import pkg/upraises
|
import pkg/upraises
|
||||||
|
@ -274,6 +275,18 @@ proc availabilities*(
|
||||||
iter.next = next
|
iter.next = next
|
||||||
return success iter
|
return success iter
|
||||||
|
|
||||||
|
proc unused*(r: Reservations): Future[?!seq[Availability]] {.async.} =
|
||||||
|
var ret: seq[Availability] = @[]
|
||||||
|
|
||||||
|
without availabilities =? (await r.availabilities), err:
|
||||||
|
return failure(err)
|
||||||
|
|
||||||
|
for a in availabilities:
|
||||||
|
if availability =? (await a) and not availability.used:
|
||||||
|
ret.add availability
|
||||||
|
|
||||||
|
return success(ret)
|
||||||
|
|
||||||
proc find*(
|
proc find*(
|
||||||
self: Reservations,
|
self: Reservations,
|
||||||
size, duration, minPrice: UInt256,
|
size, duration, minPrice: UInt256,
|
||||||
|
|
Loading…
Reference in New Issue