import std/sequtils import pkg/asynctest import pkg/chronos import pkg/libp2p import pkg/questionable import pkg/questionable/results import pkg/codex/erasure import pkg/codex/manifest import pkg/codex/stores import pkg/codex/blocktype as bt import pkg/codex/rng import ./helpers suite "Erasure encode/decode": const dataSetSize = BlockSize * 123 # weird geometry var rng: Rng var chunker: Chunker var manifest: Manifest var store: BlockStore var erasure: Erasure setup: rng = Rng.instance() chunker = RandomChunker.new(rng, size = dataSetSize, chunkSize = BlockSize) manifest = !Manifest.new(blockSize = BlockSize) store = CacheStore.new(cacheSize = (dataSetSize * 2), chunkSize = BlockSize) erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider) while ( let chunk = await chunker.getBytes(); chunk.len > 0): let blk = bt.Block.new(chunk).tryGet() manifest.add(blk.cid) (await store.putBlock(blk)).tryGet() proc encode(buffers, parity: int): Future[Manifest] {.async.} = let encoded = (await erasure.encode( manifest, buffers, parity)).tryGet() check: encoded.len mod (buffers + parity) == 0 encoded.rounded == (manifest.len + (buffers - (manifest.len mod buffers))) encoded.steps == encoded.rounded div buffers return encoded test "Should tolerate loosing M data blocks in a single random column": const buffers = 20 parity = 10 let encoded = await encode(buffers, parity) var column = rng.rand(encoded.len div encoded.steps) # random column dropped: seq[Cid] for _ in 0..