feat: expose underlying nim-ethers errors to logs (#985)
* feat: expose underlying nim-ethers errors to logs * chore: bump nim-ethers * test: fix testproof compilation * test: raise defects on results error
This commit is contained in:
parent
3f510eb501
commit
0707446cdd
|
@ -1,5 +1,6 @@
|
||||||
import std/times
|
import std/times
|
||||||
import pkg/ethers
|
import pkg/ethers
|
||||||
|
import pkg/questionable
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/stint
|
import pkg/stint
|
||||||
import ../clock
|
import ../clock
|
||||||
|
@ -45,7 +46,11 @@ method start*(clock: OnChainClock) {.async.} =
|
||||||
if clock.started:
|
if clock.started:
|
||||||
return
|
return
|
||||||
|
|
||||||
proc onBlock(_: Block) =
|
proc onBlock(blckResult: ?!Block) =
|
||||||
|
if eventError =? blckResult.errorOption:
|
||||||
|
error "There was an error in block subscription", msg=eventError.msg
|
||||||
|
return
|
||||||
|
|
||||||
# ignore block parameter; hardhat may call this with pending blocks
|
# ignore block parameter; hardhat may call this with pending blocks
|
||||||
asyncSpawn clock.update()
|
asyncSpawn clock.update()
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,11 @@ method canReserveSlot*(
|
||||||
method subscribeRequests*(market: OnChainMarket,
|
method subscribeRequests*(market: OnChainMarket,
|
||||||
callback: OnRequest):
|
callback: OnRequest):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: StorageRequested) {.upraises:[].} =
|
proc onEvent(eventResult: ?!StorageRequested) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in Request subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId,
|
callback(event.requestId,
|
||||||
event.ask,
|
event.ask,
|
||||||
event.expiry)
|
event.expiry)
|
||||||
|
@ -289,7 +293,11 @@ method subscribeRequests*(market: OnChainMarket,
|
||||||
method subscribeSlotFilled*(market: OnChainMarket,
|
method subscribeSlotFilled*(market: OnChainMarket,
|
||||||
callback: OnSlotFilled):
|
callback: OnSlotFilled):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: SlotFilled) {.upraises:[].} =
|
proc onEvent(eventResult: ?!SlotFilled) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in SlotFilled subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId, event.slotIndex)
|
callback(event.requestId, event.slotIndex)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -311,7 +319,11 @@ method subscribeSlotFilled*(market: OnChainMarket,
|
||||||
method subscribeSlotFreed*(market: OnChainMarket,
|
method subscribeSlotFreed*(market: OnChainMarket,
|
||||||
callback: OnSlotFreed):
|
callback: OnSlotFreed):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: SlotFreed) {.upraises:[].} =
|
proc onEvent(eventResult: ?!SlotFreed) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in SlotFreed subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId, event.slotIndex)
|
callback(event.requestId, event.slotIndex)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -322,7 +334,11 @@ method subscribeSlotReservationsFull*(
|
||||||
market: OnChainMarket,
|
market: OnChainMarket,
|
||||||
callback: OnSlotReservationsFull): Future[MarketSubscription] {.async.} =
|
callback: OnSlotReservationsFull): Future[MarketSubscription] {.async.} =
|
||||||
|
|
||||||
proc onEvent(event: SlotReservationsFull) {.upraises:[].} =
|
proc onEvent(eventResult: ?!SlotReservationsFull) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in SlotReservationsFull subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId, event.slotIndex)
|
callback(event.requestId, event.slotIndex)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -332,7 +348,11 @@ method subscribeSlotReservationsFull*(
|
||||||
method subscribeFulfillment(market: OnChainMarket,
|
method subscribeFulfillment(market: OnChainMarket,
|
||||||
callback: OnFulfillment):
|
callback: OnFulfillment):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestFulfilled) {.upraises:[].} =
|
proc onEvent(eventResult: ?!RequestFulfilled) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestFulfillment subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -343,7 +363,11 @@ method subscribeFulfillment(market: OnChainMarket,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
callback: OnFulfillment):
|
callback: OnFulfillment):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestFulfilled) {.upraises:[].} =
|
proc onEvent(eventResult: ?!RequestFulfilled) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestFulfillment subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
if event.requestId == requestId:
|
if event.requestId == requestId:
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
|
@ -354,7 +378,11 @@ method subscribeFulfillment(market: OnChainMarket,
|
||||||
method subscribeRequestCancelled*(market: OnChainMarket,
|
method subscribeRequestCancelled*(market: OnChainMarket,
|
||||||
callback: OnRequestCancelled):
|
callback: OnRequestCancelled):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestCancelled) {.upraises:[].} =
|
proc onEvent(eventResult: ?!RequestCancelled) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestCancelled subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -365,7 +393,11 @@ method subscribeRequestCancelled*(market: OnChainMarket,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
callback: OnRequestCancelled):
|
callback: OnRequestCancelled):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestCancelled) {.upraises:[].} =
|
proc onEvent(eventResult: ?!RequestCancelled) {.upraises:[].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestCancelled subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
if event.requestId == requestId:
|
if event.requestId == requestId:
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
|
@ -376,7 +408,11 @@ method subscribeRequestCancelled*(market: OnChainMarket,
|
||||||
method subscribeRequestFailed*(market: OnChainMarket,
|
method subscribeRequestFailed*(market: OnChainMarket,
|
||||||
callback: OnRequestFailed):
|
callback: OnRequestFailed):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestFailed) {.upraises:[]} =
|
proc onEvent(eventResult: ?!RequestFailed) {.upraises:[]} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestFailed subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -387,7 +423,11 @@ method subscribeRequestFailed*(market: OnChainMarket,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
callback: OnRequestFailed):
|
callback: OnRequestFailed):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: RequestFailed) {.upraises:[]} =
|
proc onEvent(eventResult: ?!RequestFailed) {.upraises:[]} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in RequestFailed subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
if event.requestId == requestId:
|
if event.requestId == requestId:
|
||||||
callback(event.requestId)
|
callback(event.requestId)
|
||||||
|
|
||||||
|
@ -398,7 +438,11 @@ method subscribeRequestFailed*(market: OnChainMarket,
|
||||||
method subscribeProofSubmission*(market: OnChainMarket,
|
method subscribeProofSubmission*(market: OnChainMarket,
|
||||||
callback: OnProofSubmitted):
|
callback: OnProofSubmitted):
|
||||||
Future[MarketSubscription] {.async.} =
|
Future[MarketSubscription] {.async.} =
|
||||||
proc onEvent(event: ProofSubmitted) {.upraises: [].} =
|
proc onEvent(eventResult: ?!ProofSubmitted) {.upraises: [].} =
|
||||||
|
without event =? eventResult, eventErr:
|
||||||
|
error "There was an error in ProofSubmitted subscription", msg = eventErr.msg
|
||||||
|
return
|
||||||
|
|
||||||
callback(event.id)
|
callback(event.id)
|
||||||
|
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
|
|
@ -33,8 +33,9 @@ marketplacesuite "Bug #821 - node crashes during erasure coding":
|
||||||
let cid = clientApi.upload(data).get
|
let cid = clientApi.upload(data).get
|
||||||
|
|
||||||
var requestId = none RequestId
|
var requestId = none RequestId
|
||||||
proc onStorageRequested(event: StorageRequested) {.raises:[].} =
|
proc onStorageRequested(eventResult: ?!StorageRequested)=
|
||||||
requestId = event.requestId.some
|
assert not eventResult.isErr
|
||||||
|
requestId = some (!eventResult).requestId
|
||||||
|
|
||||||
let subscription = await marketplace.subscribe(StorageRequested, onStorageRequested)
|
let subscription = await marketplace.subscribe(StorageRequested, onStorageRequested)
|
||||||
|
|
||||||
|
|
|
@ -135,8 +135,9 @@ marketplacesuite "Marketplace payouts":
|
||||||
let cid = clientApi.upload(data).get
|
let cid = clientApi.upload(data).get
|
||||||
|
|
||||||
var slotIdxFilled = none UInt256
|
var slotIdxFilled = none UInt256
|
||||||
proc onSlotFilled(event: SlotFilled) =
|
proc onSlotFilled(eventResult: ?!SlotFilled) =
|
||||||
slotIdxFilled = some event.slotIndex
|
assert not eventResult.isErr
|
||||||
|
slotIdxFilled = some (!eventResult).slotIndex
|
||||||
|
|
||||||
let subscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
let subscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from std/times import inMilliseconds
|
from std/times import inMilliseconds
|
||||||
|
import pkg/questionable
|
||||||
import pkg/codex/logutils
|
import pkg/codex/logutils
|
||||||
import pkg/stew/byteutils
|
import pkg/stew/byteutils
|
||||||
import ../contracts/time
|
import ../contracts/time
|
||||||
|
@ -54,8 +55,8 @@ marketplacesuite "Hosts submit regular proofs":
|
||||||
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
||||||
|
|
||||||
var proofWasSubmitted = false
|
var proofWasSubmitted = false
|
||||||
proc onProofSubmitted(event: ProofSubmitted) =
|
proc onProofSubmitted(event: ?!ProofSubmitted) =
|
||||||
proofWasSubmitted = true
|
proofWasSubmitted = event.isOk
|
||||||
|
|
||||||
let subscription = await marketplace.subscribe(ProofSubmitted, onProofSubmitted)
|
let subscription = await marketplace.subscribe(ProofSubmitted, onProofSubmitted)
|
||||||
|
|
||||||
|
@ -120,8 +121,8 @@ marketplacesuite "Simulate invalid proofs":
|
||||||
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
check eventually(client0.purchaseStateIs(purchaseId, "started"), timeout = expiry.int * 1000)
|
||||||
|
|
||||||
var slotWasFreed = false
|
var slotWasFreed = false
|
||||||
proc onSlotFreed(event: SlotFreed) =
|
proc onSlotFreed(event: ?!SlotFreed) =
|
||||||
if event.requestId == requestId:
|
if event.isOk and event.value.requestId == requestId:
|
||||||
slotWasFreed = true
|
slotWasFreed = true
|
||||||
|
|
||||||
let subscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
let subscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
||||||
|
@ -176,7 +177,10 @@ marketplacesuite "Simulate invalid proofs":
|
||||||
let requestId = client0.requestId(purchaseId).get
|
let requestId = client0.requestId(purchaseId).get
|
||||||
|
|
||||||
var slotWasFilled = false
|
var slotWasFilled = false
|
||||||
proc onSlotFilled(event: SlotFilled) =
|
proc onSlotFilled(eventResult: ?!SlotFilled) =
|
||||||
|
assert not eventResult.isErr
|
||||||
|
let event = !eventResult
|
||||||
|
|
||||||
if event.requestId == requestId:
|
if event.requestId == requestId:
|
||||||
slotWasFilled = true
|
slotWasFilled = true
|
||||||
let filledSubscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
let filledSubscription = await marketplace.subscribe(SlotFilled, onSlotFilled)
|
||||||
|
@ -185,8 +189,8 @@ marketplacesuite "Simulate invalid proofs":
|
||||||
check eventually(slotWasFilled, timeout = expiry.int * 1000)
|
check eventually(slotWasFilled, timeout = expiry.int * 1000)
|
||||||
|
|
||||||
var slotWasFreed = false
|
var slotWasFreed = false
|
||||||
proc onSlotFreed(event: SlotFreed) =
|
proc onSlotFreed(event: ?!SlotFreed) =
|
||||||
if event.requestId == requestId:
|
if event.isOk and event.value.requestId == requestId:
|
||||||
slotWasFreed = true
|
slotWasFreed = true
|
||||||
let freedSubscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
let freedSubscription = await marketplace.subscribe(SlotFreed, onSlotFreed)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1ae2cd4a35aa7c7ca21ca750fb7f951b3a6a97c0
|
Subproject commit 2808a05488152c8b438d947dc871445164fa1278
|
Loading…
Reference in New Issue