From 0636c94b74acfa910b15aa69afab928e1396a133 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 4 Jul 2022 14:14:56 +0200 Subject: [PATCH] [market] Add market.getSigner() --- codex/contracts/market.nim | 3 +++ codex/market.nim | 3 +++ tests/codex/helpers/mockmarket.nim | 9 ++++++++- tests/contracts/testMarket.nim | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 1a8445f6..fdcebece 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -23,6 +23,9 @@ func new*(_: type OnChainMarket, contract: Storage): OnChainMarket = signer: signer, ) +method getSigner*(market: OnChainMarket): Future[Address] {.async.} = + return await market.signer.getAddress() + method requestStorage(market: OnChainMarket, request: StorageRequest): Future[StorageRequest] {.async.} = diff --git a/codex/market.nim b/codex/market.nim index 91a19299..c8b3f5d8 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -15,6 +15,9 @@ type OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.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, request: StorageRequest): Future[StorageRequest] {.base, async.} = diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 4e534ba3..0b782e9f 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -7,6 +7,7 @@ type MockMarket* = ref object of Market requested*: seq[StorageRequest] fulfilled*: seq[Fulfillment] + signer: Address subscriptions: Subscriptions Fulfillment* = object requestId: array[32, byte] @@ -23,6 +24,12 @@ type requestId: array[32, byte] 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, request: StorageRequest): Future[StorageRequest] {.async.} = @@ -58,7 +65,7 @@ proc fulfillRequest*(market: MockMarket, method fulfillRequest*(market: MockMarket, requestId: array[32, byte], proof: seq[byte]) {.async.} = - market.fulfillRequest(requestid, proof, Address.default) + market.fulfillRequest(requestid, proof, market.signer) method subscribeRequests*(market: MockMarket, callback: OnRequest): diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 9f75e286..613309e8 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -38,6 +38,9 @@ ethersuite "On-Chain Market": expect AssertionError: discard OnChainMarket.new(storageWithoutSigner) + test "knows signer address": + check (await market.getSigner()) == (await provider.getSigner().getAddress()) + test "supports storage requests": await token.approve(storage.address, request.ask.maxPrice) check (await market.requestStorage(request)) == request