import std/sequtils import std/sugar 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 pkg/codex/utils 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: let repoDs = SQLiteDatastore.new(Memory).tryGet() metaDs = SQLiteDatastore.new(Memory).tryGet() rng = Rng.instance() chunker = RandomChunker.new(rng, size = dataSetSize, chunkSize = BlockSize) store = RepoStore.new(repoDs, metaDs) 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 == roundUp(manifest.blocksCount, 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 div encoded.steps) - 1) # random column dropped: seq[int] for _ in 0..