mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-12 03:44:07 +00:00
3046b7636c
* integration: move REST API tests into their own module * integration: move upload and download tests into their own module * integration: move purchasing tests into their own module * integration: move marketplace tests to the right module * integration: mine a block *after* starting nodes To ensure that tests involving multiple nodes do not start with out-of-sync clocks * Fix: do not swallow CancellationErrors * integration: avoid underflow in UInt256 * network: remove unnecessary error handling No Exceptions can occur, only Defects, because everything is asyncSpawned. Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> * network: do not raise in asyncSpawned proc Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> --------- Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
45 lines
1.5 KiB
Nim
45 lines
1.5 KiB
Nim
import ../../conf
|
|
when codex_enable_proof_failures:
|
|
import std/strutils
|
|
import pkg/stint
|
|
import pkg/ethers
|
|
import pkg/ethers/testing
|
|
|
|
import ../../contracts/requests
|
|
import ../../logutils
|
|
import ../../market
|
|
import ../../utils/exceptions
|
|
import ../salescontext
|
|
import ./proving
|
|
|
|
logScope:
|
|
topics = "marketplace sales simulated-proving"
|
|
|
|
type
|
|
SaleProvingSimulated* = ref object of SaleProving
|
|
failEveryNProofs*: int
|
|
proofCount: int
|
|
|
|
proc onSubmitProofError(error: ref CatchableError, period: UInt256, slotId: SlotId) =
|
|
error "Submitting invalid proof failed", period, slotId, msg = error.msgDetail
|
|
|
|
method prove*(state: SaleProvingSimulated, slot: Slot, challenge: ProofChallenge, onProve: OnProve, market: Market, currentPeriod: Period) {.async.} =
|
|
trace "Processing proving in simulated mode"
|
|
state.proofCount += 1
|
|
if state.failEveryNProofs > 0 and
|
|
state.proofCount mod state.failEveryNProofs == 0:
|
|
state.proofCount = 0
|
|
|
|
try:
|
|
warn "Submitting INVALID proof", period = currentPeriod, slotId = slot.id
|
|
await market.submitProof(slot.id, Groth16Proof.default)
|
|
except MarketError as e:
|
|
if not e.msg.contains("Invalid proof"):
|
|
onSubmitProofError(e, currentPeriod, slot.id)
|
|
except CancelledError as error:
|
|
raise error
|
|
except CatchableError as e:
|
|
onSubmitProofError(e, currentPeriod, slot.id)
|
|
else:
|
|
await procCall SaleProving(state).prove(slot, challenge, onProve, market, currentPeriod)
|