mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-12 06:36:47 +00:00
* rework merkle tree support * rename merkletree -> codexmerkletree * treed and proof encoding/decoding * style * adding codex merkle and coders tests * use default hash codec * proof size changed * add from nodes test * shorte file names * wip poseidon tree * shorten file names * root returns a result * import poseidon tests * fix merge issues and cleanup a few warnings * setting up slot builder * Getting cids in slot * ensures blocks are devisable by number of slots * wip * Implements indexing strategies * Swaps in indexing strategy into erasure. * wires slot and indexing tests up * Fixes issue where indexing strategy stepped gives wrong values for smallest of ranges * debugs indexing strategies * Can select slot blocks * finding number of pad cells * Implements building slot tree * finishes implementing slot builder * Adds check that block size is a multiple of cell size * Cleanup slotbuilder * Review comments by Tomasz * Fixes issue where ecK was used as numberOfSlots. * rework merkle tree support * deps * rename merkletree -> codexmerkletree * treed and proof encoding/decoding * style * adding codex merkle and coders tests * remove new codecs for now * proof size changed * add from nodes test * shorte file names * wip poseidon tree * shorten file names * fix bad `elements` iter * bump * bump * wip * reworking slotbuilder * move out of manifest * expose getCidAndProof * import index strat... * remove getMHash * remove unused artifacts * alias zero * add digest for multihash * merge issues * remove unused hashes * add option to result converter * misc * fix tests * add helper to derive EC block count * rename method * misc * bump * extract slot root building into own proc * revert to manifest to accessor --------- Co-authored-by: benbierens <thatbenbierens@gmail.com>
66 lines
1.9 KiB
Nim
66 lines
1.9 KiB
Nim
import std/sequtils
|
|
import pkg/chronos
|
|
import pkg/asynctest
|
|
|
|
import ./helpers
|
|
|
|
import pkg/codex/indexingstrategy
|
|
|
|
for offset in @[0, 1, 2, 100]:
|
|
suite "Indexing strategies (Offset: " & $offset & ")":
|
|
let
|
|
firstIndex = 0 + offset
|
|
lastIndex = 12 + offset
|
|
nIters = 3
|
|
linear = LinearIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
|
stepped = SteppedIndexingStrategy.new(firstIndex, lastIndex, nIters)
|
|
|
|
test "linear":
|
|
check:
|
|
linear.getIndicies(0) == @[0, 1, 2, 3, 4].mapIt(it + offset)
|
|
linear.getIndicies(1) == @[5, 6, 7, 8, 9].mapIt(it + offset)
|
|
linear.getIndicies(2) == @[10, 11, 12].mapIt(it + offset)
|
|
|
|
test "stepped":
|
|
check:
|
|
stepped.getIndicies(0) == @[0, 3, 6, 9, 12].mapIt(it + offset)
|
|
stepped.getIndicies(1) == @[1, 4, 7, 10].mapIt(it + offset)
|
|
stepped.getIndicies(2) == @[2, 5, 8, 11].mapIt(it + offset)
|
|
|
|
suite "Indexing strategies":
|
|
let
|
|
linear = LinearIndexingStrategy.new(0, 10, 3)
|
|
stepped = SteppedIndexingStrategy.new(0, 10, 3)
|
|
|
|
test "smallest range 0":
|
|
let
|
|
l = LinearIndexingStrategy.new(0, 0, 1)
|
|
s = SteppedIndexingStrategy.new(0, 0, 1)
|
|
check:
|
|
l.getIndicies(0) == @[0]
|
|
s.getIndicies(0) == @[0]
|
|
|
|
test "smallest range 1":
|
|
let
|
|
l = LinearIndexingStrategy.new(0, 1, 1)
|
|
s = SteppedIndexingStrategy.new(0, 1, 1)
|
|
check:
|
|
l.getIndicies(0) == @[0, 1]
|
|
s.getIndicies(0) == @[0, 1]
|
|
|
|
test "first index must be smaller than last index":
|
|
expect AssertionDefect:
|
|
discard LinearIndexingStrategy.new(10, 0, 1)
|
|
|
|
test "numberOfIterations must be greater than zero":
|
|
expect AssertionDefect:
|
|
discard LinearIndexingStrategy.new(0, 10, 0)
|
|
|
|
test "linear - oob":
|
|
expect AssertionDefect:
|
|
discard linear.getIndicies(3)
|
|
|
|
test "stepped - oob":
|
|
expect AssertionDefect:
|
|
discard stepped.getIndicies(3)
|