import pkg/chronos import pkg/asynctest/chronos/unittest import pkg/questionable/results import ./helpers import pkg/codex/streams import pkg/codex/stores import pkg/codex/manifest import pkg/codex/blocktype as bt 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)