import pkg/chronos import pkg/questionable/results import pkg/codex/[ streams, stores, indexingstrategy, manifest, blocktype as bt] import ../asynctest import ./examples import ./helpers asyncchecksuite "StoreStream": var manifest: Manifest store: BlockStore stream: StoreStream # Check that `buf` contains `size` bytes with values start, start+1... proc sequentialBytes(buf: seq[byte], size: int, start: int): bool = for i in 0.. blockSize": var buf = newSeq[byte](11) n = 0 while not stream.atEof: let read = (await stream.readOnce(addr buf[0], buf.len)) if not stream.atEof: check read == 11 else: check read == 1 check sequentialBytes(buf,read,n) n += read test "Read exact bytes within block boundary": var buf = newSeq[byte](5) await stream.readExactly(addr buf[0], 5) check sequentialBytes(buf,5,0) test "Read exact bytes outside of block boundary": var buf = newSeq[byte](15) await stream.readExactly(addr buf[0], 15) check sequentialBytes(buf,15,0) suite "StoreStream - Size Tests": var stream: StoreStream teardown: await stream.close() test "Should return dataset size as stream size": let manifest = Manifest.new( treeCid = Cid.example, datasetSize = 80.NBytes, blockSize = 10.NBytes ) stream = StoreStream.new(CacheStore.new(), manifest) check stream.size == 80 test "Should not count parity/padding bytes as part of stream size": let protectedManifest = Manifest.new( treeCid = Cid.example, datasetSize = 120.NBytes, # size including parity bytes blockSize = 10.NBytes, version = CIDv1, hcodec = Sha256HashCodec, codec = BlockCodec, ecK = 2, ecM = 1, originalTreeCid = Cid.example, originalDatasetSize = 80.NBytes, # size without parity bytes strategy = StrategyType.SteppedStrategy ) stream = StoreStream.new(CacheStore.new(), protectedManifest) check stream.size == 80