import std/sequtils import pkg/asynctest import pkg/chronos import pkg/datastore 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 asyncchecksuite "Erasure encode/decode": const BlockSize = 1024'nb 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) store = CacheStore.new(cacheSize = (dataSetSize * 4), chunkSize = BlockSize) erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider) manifest = await storeDataGetManifest(store, chunker) proc encode(buffers, parity: int): Future[Manifest] {.async.} = let encoded = (await erasure.encode( manifest, buffers, parity)).tryGet() check: encoded.blocksCount mod (buffers + parity) == 0 encoded.rounded == (manifest.blocksCount + (buffers - (manifest.blocksCount mod buffers))) encoded.steps == encoded.rounded div buffers return encoded test "Should tolerate losing M data blocks in a single random column": const buffers = 20 parity = 10 let encoded = await encode(buffers, parity) var column = rng.rand((encoded.blocksCount - 1) div encoded.steps) # random column dropped: seq[int] for _ in 0..