fix tests

This commit is contained in:
Dmitriy Ryajov 2022-03-29 17:27:27 -06:00
parent 5ebc32764f
commit 800d6e52fa
No known key found for this signature in database
GPG Key ID: DA8C680CE7C657A4
2 changed files with 7 additions and 14 deletions

View File

@ -35,7 +35,7 @@ suite "Test Node":
setup: setup:
file = open(path.splitFile().dir /../ "fixtures" / "test.jpg") file = open(path.splitFile().dir /../ "fixtures" / "test.jpg")
chunker = FileChunker.new(file = file) chunker = FileChunker.new(file = file, chunkSize = BlockSize)
switch = newStandardSwitch() switch = newStandardSwitch()
wallet = WalletRef.new(EthPrivateKey.random()) wallet = WalletRef.new(EthPrivateKey.random())
network = BlockExcNetwork.new(switch) network = BlockExcNetwork.new(switch)
@ -106,19 +106,15 @@ suite "Test Node":
check await localStore.putBlock(manifestBlock) check await localStore.putBlock(manifestBlock)
let stream = BufferStream.new() let stream = (await node.retrieve(manifestBlock.cid)).tryGet()
check (await node.retrieve(stream, manifestBlock.cid)).isOk
var data: seq[byte] var data: seq[byte]
while true: while not stream.atEof:
var var
buf = newSeq[byte](BlockSize) buf = newSeq[byte](BlockSize)
res = await stream.readOnce(addr buf[0], buf.len) res = await stream.readOnce(addr buf[0], BlockSize div 2)
if res <= 0:
break
buf.setLen(res) buf.setLen(res)
data &= buf data &= buf
check data == original check data == original
@ -128,11 +124,8 @@ suite "Test Node":
testString = "Block 1" testString = "Block 1"
blk = bt.Block.new(testString.toBytes).tryGet() blk = bt.Block.new(testString.toBytes).tryGet()
var
stream = BufferStream.new()
check (await localStore.putBlock(blk)) check (await localStore.putBlock(blk))
check (await node.retrieve(stream, blk.cid)).isOk let stream = (await node.retrieve(blk.cid)).tryGet()
var data = newSeq[byte](testString.len) var data = newSeq[byte](testString.len)
await stream.readExactly(addr data[0], data.len) await stream.readExactly(addr data[0], data.len)

View File

@ -33,7 +33,7 @@ suite "StoreStream":
setup: setup:
store = CacheStore.new() store = CacheStore.new()
manifest = Manifest.new(blockSize = 10).tryGet() manifest = Manifest.new(blockSize = 10).tryGet()
stream = StoreStream.init(store, manifest) stream = StoreStream.new(store, manifest)
for d in data: for d in data:
let let