mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-05 23:45:02 +00:00
15ff87a8bb
* fix: createReservation lock (#825) * fix: createReservation lock * fix: additional locking places * fix: acquire lock * chore: feedback Co-authored-by: markspanbroek <mark@spanbroek.net> Signed-off-by: Adam Uhlíř <adam@uhlir.dev> * feat: withLock template and fixed tests * fix: use proc for MockReservations constructor * chore: feedback Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com> Signed-off-by: Adam Uhlíř <adam@uhlir.dev> * chore: feedback implementation --------- Signed-off-by: Adam Uhlíř <adam@uhlir.dev> Co-authored-by: markspanbroek <mark@spanbroek.net> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com> * Block deletion with ref count & repostore refactor (#631) * Fix StoreStream so it doesn't return parity bytes (#838) * fix storestream so it doesn\'t return parity bits for protected/verifiable manifests * use Cid.example instead of creating a mock manually * Fix verifiable manifest initialization (#839) * fix verifiable manifest initialization * fix linearstrategy, use verifiableStrategy to select blocks for slots * check for both strategies in attribute inheritance test * ci: add verify_circuit=true to the releases (#840) * provisional fix so EC errors do not crash the node on download (#841) --------- Signed-off-by: Adam Uhlíř <adam@uhlir.dev> Co-authored-by: Adam Uhlíř <adam@uhlir.dev> Co-authored-by: markspanbroek <mark@spanbroek.net> Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com> Co-authored-by: Tomasz Bekas <tomasz.bekas@gmail.com> Co-authored-by: Giuliano Mega <giuliano.mega@gmail.com>
53 lines
1.5 KiB
Nim
53 lines
1.5 KiB
Nim
## Nim-Codex
|
|
## Copyright (c) 2023 Status Research & Development GmbH
|
|
## Licensed under either of
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
## at your option.
|
|
## This file may not be copied, modified, or distributed except according to
|
|
## those terms.
|
|
|
|
import std/sequtils
|
|
import std/sugar
|
|
import pkg/chronos
|
|
import pkg/libp2p
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
import pkg/codex/stores/repostore
|
|
import pkg/codex/utils/asynciter
|
|
|
|
type
|
|
MockRepoStore* = ref object of RepoStore
|
|
delBlockCids*: seq[Cid]
|
|
getBeMaxNumber*: int
|
|
getBeOffset*: int
|
|
|
|
testBlockExpirations*: seq[BlockExpiration]
|
|
getBlockExpirationsThrows*: bool
|
|
|
|
method delBlock*(self: MockRepoStore, cid: Cid): Future[?!void] {.async.} =
|
|
self.delBlockCids.add(cid)
|
|
self.testBlockExpirations = self.testBlockExpirations.filterIt(it.cid != cid)
|
|
return success()
|
|
|
|
method getBlockExpirations*(self: MockRepoStore, maxNumber: int, offset: int): Future[?!AsyncIter[BlockExpiration]] {.async.} =
|
|
if self.getBlockExpirationsThrows:
|
|
raise new CatchableError
|
|
|
|
self.getBeMaxNumber = maxNumber
|
|
self.getBeOffset = offset
|
|
|
|
let
|
|
testBlockExpirationsCpy = @(self.testBlockExpirations)
|
|
limit = min(offset + maxNumber, len(testBlockExpirationsCpy))
|
|
|
|
let
|
|
iter1 = AsyncIter[int].new(offset..<limit)
|
|
iter2 = map[int, BlockExpiration](iter1,
|
|
proc (i: int): Future[BlockExpiration] {.async.} =
|
|
testBlockExpirationsCpy[i]
|
|
)
|
|
|
|
success(iter2)
|