From b26386f631302693e67c3876f0038b79f51acef6 Mon Sep 17 00:00:00 2001 From: gmega Date: Tue, 16 Jan 2024 17:51:30 -0300 Subject: [PATCH] update asynctest package, async signatures, add back toSeq from botched merge --- codex/erasure/erasure.nim | 14 +++++++------- codex/indexingstrategy.nim | 4 ++-- tests/codex/node/helpers.nim | 9 ++++++--- tests/codex/node/testcontracts.nim | 4 ++-- tests/codex/node/testnode.nim | 4 ++-- tests/codex/testindexingstrategy.nim | 20 ++++++++++---------- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/codex/erasure/erasure.nim b/codex/erasure/erasure.nim index cd84c376..96411f47 100644 --- a/codex/erasure/erasure.nim +++ b/codex/erasure/erasure.nim @@ -91,13 +91,13 @@ func indexToPos(steps, idx, step: int): int {.inline.} = proc getPendingBlocks( self: Erasure, manifest: Manifest, - indicies: seq[int]): AsyncIter[(?!bt.Block, int)] = + indices: seq[int]): AsyncIter[(?!bt.Block, int)] = ## Get pending blocks iterator ## var # request blocks from the store - pendingBlocks = indicies.map( (i: int) => + pendingBlocks = indices.map( (i: int) => self.store.getBlock( BlockAddress.init(manifest.treeCid, i) ).map((r: ?!bt.Block) => (r, i)) # Get the data blocks (first K) @@ -135,8 +135,8 @@ proc prepareEncodingData( lastIndex = params.rounded - 1, numberOfIterations = params.steps ) - indicies = strategy.getIndices(step) - pendingBlocksIter = self.getPendingBlocks(manifest, indicies.filterIt(it < manifest.blocksCount)) + indices = toSeq(strategy.getIndices(step)) + pendingBlocksIter = self.getPendingBlocks(manifest, indices.filterIt(it < manifest.blocksCount)) var resolved = 0 for fut in pendingBlocksIter: @@ -151,7 +151,7 @@ proc prepareEncodingData( resolved.inc() - for idx in indicies.filterIt(it >= manifest.blocksCount): + for idx in indices.filterIt(it >= manifest.blocksCount): let pos = indexToPos(params.steps, idx, step) trace "Padding with empty block", idx shallowCopy(data[pos], emptyBlock) @@ -184,8 +184,8 @@ proc prepareDecodingData( lastIndex = encoded.blocksCount - 1, numberOfIterations = encoded.steps ) - indicies = strategy.getIndices(step) - pendingBlocksIter = self.getPendingBlocks(encoded, indicies) + indices = toSeq(strategy.getIndices(step)) + pendingBlocksIter = self.getPendingBlocks(encoded, indices) var dataPieces = 0 diff --git a/codex/indexingstrategy.nim b/codex/indexingstrategy.nim index 7b854ee9..ba3fd8be 100644 --- a/codex/indexingstrategy.nim +++ b/codex/indexingstrategy.nim @@ -63,7 +63,7 @@ proc getIter(first, last, step: int): Iter[int] = Iter.new(get, isFinished) -method getIndicies*( +method getIndices*( self: LinearIndexingStrategy, iteration: int): Iter[int] {.raises: [IndexingError].} = @@ -75,7 +75,7 @@ method getIndicies*( getIter(first, last, 1) -method getIndicies*( +method getIndices*( self: SteppedIndexingStrategy, iteration: int): Iter[int] {.raises: [IndexingError].} = diff --git a/tests/codex/node/helpers.nim b/tests/codex/node/helpers.nim index 0501de18..dd441601 100644 --- a/tests/codex/node/helpers.nim +++ b/tests/codex/node/helpers.nim @@ -3,7 +3,7 @@ import std/times import pkg/libp2p import pkg/chronos -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/codex/codextypes import pkg/codex/chunker @@ -13,7 +13,7 @@ proc toTimesDuration*(d: chronos.Duration): times.Duration = proc drain*( stream: LPStream | Result[lpstream.LPStream, ref CatchableError]): - Future[seq[byte]] {.async.} = + Future[seq[byte]] {.async: (handleException: true, raises: [AsyncExceptionError]).} = let stream = @@ -36,7 +36,10 @@ proc drain*( data -proc pipeChunker*(stream: BufferStream, chunker: Chunker) {.async.} = +proc pipeChunker*( + stream: BufferStream, + chunker: Chunker +) {.async: (handleException: true, raises: [AsyncExceptionError]).} = try: while ( let chunk = await chunker.getBytes(); diff --git a/tests/codex/node/testcontracts.nim b/tests/codex/node/testcontracts.nim index 601912f1..4ddb35bf 100644 --- a/tests/codex/node/testcontracts.nim +++ b/tests/codex/node/testcontracts.nim @@ -5,7 +5,7 @@ import std/times import std/sequtils import std/importutils -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stew/byteutils import pkg/datastore @@ -129,7 +129,7 @@ asyncchecksuite "Test Node - Host contracts": (await onStore(request, 1.u256, onBlocks)).tryGet() check fetchedBytes == 786432 - for index in builder.slotIndicies(1): + for index in !builder.slotIndices(1): let blk = (await localStore.getBlock(verifiable.treeCid, index)).tryGet expiryKey = (createBlockExpirationMetadataKey(blk.cid)).tryGet diff --git a/tests/codex/node/testnode.nim b/tests/codex/node/testnode.nim index 51dd7e0d..6f1ee30a 100644 --- a/tests/codex/node/testnode.nim +++ b/tests/codex/node/testnode.nim @@ -5,7 +5,7 @@ import std/times import std/sequtils import std/importutils -import pkg/asynctest +import pkg/asynctest/chronos/unittest import pkg/chronos import pkg/stew/byteutils import pkg/datastore @@ -69,7 +69,7 @@ asyncchecksuite "Test Node - Basic": (await node.fetchBatched( manifest, batchSize = batchSize, - proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async.} = + proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async: (handleException: true).} = check blocks.len > 0 and blocks.len <= batchSize return success() )).tryGet() diff --git a/tests/codex/testindexingstrategy.nim b/tests/codex/testindexingstrategy.nim index 14541892..f7a8f67d 100644 --- a/tests/codex/testindexingstrategy.nim +++ b/tests/codex/testindexingstrategy.nim @@ -19,15 +19,15 @@ for offset in @[0, 1, 2, 100]: test "linear": check: - linear.getIndices(0) == @[0, 1, 2, 3, 4].mapIt(it + offset) - linear.getIndices(1) == @[5, 6, 7, 8, 9].mapIt(it + offset) - linear.getIndices(2) == @[10, 11, 12].mapIt(it + offset) + toSeq(linear.getIndices(0)) == @[0, 1, 2, 3, 4].mapIt(it + offset) + toSeq(linear.getIndices(1)) == @[5, 6, 7, 8, 9].mapIt(it + offset) + toSeq(linear.getIndices(2)) == @[10, 11, 12].mapIt(it + offset) test "stepped": check: - stepped.getIndices(0) == @[0, 3, 6, 9, 12].mapIt(it + offset) - stepped.getIndices(1) == @[1, 4, 7, 10].mapIt(it + offset) - stepped.getIndices(2) == @[2, 5, 8, 11].mapIt(it + offset) + toSeq(stepped.getIndices(0)) == @[0, 3, 6, 9, 12].mapIt(it + offset) + toSeq(stepped.getIndices(1)) == @[1, 4, 7, 10].mapIt(it + offset) + toSeq(stepped.getIndices(2)) == @[2, 5, 8, 11].mapIt(it + offset) suite "Indexing strategies": let @@ -39,16 +39,16 @@ suite "Indexing strategies": l = LinearIndexingStrategy.new(0, 0, 1) s = SteppedIndexingStrategy.new(0, 0, 1) check: - l.getIndices(0) == @[0] - s.getIndices(0) == @[0] + toSeq(l.getIndices(0)) == @[0] + toSeq(s.getIndices(0)) == @[0] test "smallest range 1": let l = LinearIndexingStrategy.new(0, 1, 1) s = SteppedIndexingStrategy.new(0, 1, 1) check: - l.getIndices(0) == @[0, 1] - s.getIndices(0) == @[0, 1] + toSeq(l.getIndices(0)) == @[0, 1] + toSeq(s.getIndices(0)) == @[0, 1] test "first index must be smaller than last index": expect IndexingWrongIndexError: