[market] Add market.getSigner()

This commit is contained in:
Mark Spanbroek 2022-07-04 14:14:56 +02:00 committed by markspanbroek
parent 03b92a2067
commit 0636c94b74
4 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,9 @@ func new*(_: type OnChainMarket, contract: Storage): OnChainMarket =
signer: signer, signer: signer,
) )
method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
return await market.signer.getAddress()
method requestStorage(market: OnChainMarket, method requestStorage(market: OnChainMarket,
request: StorageRequest): request: StorageRequest):
Future[StorageRequest] {.async.} = Future[StorageRequest] {.async.} =

View File

@ -15,6 +15,9 @@ type
OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.gcsafe, upraises:[].} OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.gcsafe, upraises:[].}
OnFulfillment* = proc(requestId: array[32, byte]) {.gcsafe, upraises: [].} OnFulfillment* = proc(requestId: array[32, byte]) {.gcsafe, upraises: [].}
method getSigner*(market: Market): Future[Address] {.base, async.} =
raiseAssert("not implemented")
method requestStorage*(market: Market, method requestStorage*(market: Market,
request: StorageRequest): request: StorageRequest):
Future[StorageRequest] {.base, async.} = Future[StorageRequest] {.base, async.} =

View File

@ -7,6 +7,7 @@ type
MockMarket* = ref object of Market MockMarket* = ref object of Market
requested*: seq[StorageRequest] requested*: seq[StorageRequest]
fulfilled*: seq[Fulfillment] fulfilled*: seq[Fulfillment]
signer: Address
subscriptions: Subscriptions subscriptions: Subscriptions
Fulfillment* = object Fulfillment* = object
requestId: array[32, byte] requestId: array[32, byte]
@ -23,6 +24,12 @@ type
requestId: array[32, byte] requestId: array[32, byte]
callback: OnFulfillment callback: OnFulfillment
proc new*(_: type MockMarket): MockMarket =
MockMarket(signer: Address.example)
method getSigner*(market: MockMarket): Future[Address] {.async.} =
return market.signer
method requestStorage*(market: MockMarket, method requestStorage*(market: MockMarket,
request: StorageRequest): request: StorageRequest):
Future[StorageRequest] {.async.} = Future[StorageRequest] {.async.} =
@ -58,7 +65,7 @@ proc fulfillRequest*(market: MockMarket,
method fulfillRequest*(market: MockMarket, method fulfillRequest*(market: MockMarket,
requestId: array[32, byte], requestId: array[32, byte],
proof: seq[byte]) {.async.} = proof: seq[byte]) {.async.} =
market.fulfillRequest(requestid, proof, Address.default) market.fulfillRequest(requestid, proof, market.signer)
method subscribeRequests*(market: MockMarket, method subscribeRequests*(market: MockMarket,
callback: OnRequest): callback: OnRequest):

View File

@ -38,6 +38,9 @@ ethersuite "On-Chain Market":
expect AssertionError: expect AssertionError:
discard OnChainMarket.new(storageWithoutSigner) discard OnChainMarket.new(storageWithoutSigner)
test "knows signer address":
check (await market.getSigner()) == (await provider.getSigner().getAddress())
test "supports storage requests": test "supports storage requests":
await token.approve(storage.address, request.ask.maxPrice) await token.approve(storage.address, request.ask.maxPrice)
check (await market.requestStorage(request)) == request check (await market.requestStorage(request)) == request