use tryGet, which is more informative than get (#45)
This commit is contained in:
parent
b315c759bb
commit
68a45d8f57
|
@ -41,14 +41,14 @@ suite "NetworkStore engine - 2 nodes":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks1.add(bt.Block.init(chunk).get())
|
||||
blocks1.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
while true:
|
||||
let chunk = await chunker2.getBytes()
|
||||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks2.add(bt.Block.init(chunk).get())
|
||||
blocks2.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
switch1 = newStandardSwitch()
|
||||
switch2 = newStandardSwitch()
|
||||
|
@ -119,7 +119,7 @@ suite "NetworkStore engine - 2 nodes":
|
|||
check peerCtx2.account.?address == pricing2.address.some
|
||||
|
||||
test "should send want-have for block":
|
||||
let blk = bt.Block.init("Block 1".toBytes).get()
|
||||
let blk = bt.Block.init("Block 1".toBytes).tryGet()
|
||||
check await blockexc2.engine.localStore.putBlock(blk)
|
||||
|
||||
let entry = Entry(
|
||||
|
@ -144,7 +144,7 @@ suite "NetworkStore engine - 2 nodes":
|
|||
check blocks.mapIt( !it.read ) == blocks2
|
||||
|
||||
test "remote should send blocks when available":
|
||||
let blk = bt.Block.init("Block 1".toBytes).get()
|
||||
let blk = bt.Block.init("Block 1".toBytes).tryGet()
|
||||
|
||||
# should fail retrieving block from remote
|
||||
check not await blockexc1.getBlock(blk.cid)
|
||||
|
@ -183,7 +183,7 @@ suite "NetworkStore - multiple nodes":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
for e in generateNodes(5):
|
||||
switch.add(e.switch)
|
||||
|
|
|
@ -19,8 +19,8 @@ import ../examples
|
|||
suite "NetworkStore engine basic":
|
||||
let
|
||||
rng = Rng.instance()
|
||||
seckey = PrivateKey.random(rng[]).get()
|
||||
peerId = PeerID.init(seckey.getPublicKey().get()).get()
|
||||
seckey = PrivateKey.random(rng[]).tryGet()
|
||||
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
||||
chunker = RandomChunker.new(Rng.instance(), size = 1024, chunkSize = 256)
|
||||
wallet = WalletRef.example
|
||||
|
||||
|
@ -34,7 +34,7 @@ suite "NetworkStore engine basic":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
done = newFuture[void]()
|
||||
|
||||
|
@ -86,8 +86,8 @@ suite "NetworkStore engine basic":
|
|||
suite "NetworkStore engine handlers":
|
||||
let
|
||||
rng = Rng.instance()
|
||||
seckey = PrivateKey.random(rng[]).get()
|
||||
peerId = PeerID.init(seckey.getPublicKey().get()).get()
|
||||
seckey = PrivateKey.random(rng[]).tryGet()
|
||||
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
||||
chunker = RandomChunker.new(Rng.instance(), size = 1024, chunkSize = 256)
|
||||
wallet = WalletRef.example
|
||||
|
||||
|
@ -103,7 +103,7 @@ suite "NetworkStore engine handlers":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
done = newFuture[void]()
|
||||
engine = BlockExcEngine.new(MemoryStore.new(), wallet, BlockExcNetwork())
|
||||
|
@ -227,15 +227,15 @@ suite "Task Handler":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
done = newFuture[void]()
|
||||
engine = BlockExcEngine.new(MemoryStore.new(), wallet, BlockExcNetwork())
|
||||
peersCtx = @[]
|
||||
|
||||
for i in 0..3:
|
||||
let seckey = PrivateKey.random(rng[]).get()
|
||||
peers.add(PeerID.init(seckey.getPublicKey().get()).get())
|
||||
let seckey = PrivateKey.random(rng[]).tryGet()
|
||||
peers.add(PeerID.init(seckey.getPublicKey().tryGet()).tryGet())
|
||||
|
||||
peersCtx.add(BlockExcPeerCtx(
|
||||
id: peers[i]
|
||||
|
@ -281,7 +281,7 @@ suite "Task Handler":
|
|||
|
||||
test "Should send presence":
|
||||
let present = blocks
|
||||
let missing = @[bt.Block.init("missing".toBytes).get()]
|
||||
let missing = @[bt.Block.init("missing".toBytes).tryGet()]
|
||||
let price = (!engine.pricing).price
|
||||
|
||||
proc sendPresence(id: PeerID, presence: seq[BlockPresence]) =
|
||||
|
|
|
@ -18,8 +18,8 @@ import ../examples
|
|||
suite "NetworkStore network":
|
||||
let
|
||||
rng = Rng.instance()
|
||||
seckey = PrivateKey.random(rng[]).get()
|
||||
peerId = PeerID.init(seckey.getPublicKey().get()).get()
|
||||
seckey = PrivateKey.random(rng[]).tryGet()
|
||||
peerId = PeerID.init(seckey.getPublicKey().tryGet()).tryGet()
|
||||
chunker = RandomChunker.new(Rng.instance(), size = 1024, chunkSize = 256)
|
||||
|
||||
var
|
||||
|
@ -38,7 +38,7 @@ suite "NetworkStore network":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
done = newFuture[void]()
|
||||
buffer = BufferStream.new()
|
||||
|
@ -154,7 +154,7 @@ suite "NetworkStore Network - e2e":
|
|||
if chunk.len <= 0:
|
||||
break
|
||||
|
||||
blocks.add(bt.Block.init(chunk).get())
|
||||
blocks.add(bt.Block.init(chunk).tryGet())
|
||||
|
||||
done = newFuture[void]()
|
||||
switch1 = newStandardSwitch()
|
||||
|
|
|
@ -42,7 +42,7 @@ proc example*(_: type Pricing): Pricing =
|
|||
proc example*(_: type Block): Block =
|
||||
let length = rand(4096)
|
||||
let bytes = newSeqWith(length, rand(uint8))
|
||||
Block.init(bytes).get()
|
||||
Block.init(bytes).tryGet()
|
||||
|
||||
proc example*(_: type PeerId): PeerID =
|
||||
let key = PrivateKey.random(Rng.instance[]).get
|
||||
|
|
|
@ -21,7 +21,7 @@ suite "FS Store":
|
|||
var
|
||||
store: FSStore
|
||||
repoDir: string
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
|
||||
setup:
|
||||
repoDir = path.parentDir / "repo"
|
||||
|
|
|
@ -11,7 +11,7 @@ import ../helpers
|
|||
suite "Memory Store tests":
|
||||
test "putBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new()
|
||||
|
||||
check await store.putBlock(newBlock)
|
||||
|
@ -19,7 +19,7 @@ suite "Memory Store tests":
|
|||
|
||||
test "getBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new(@[newBlock])
|
||||
|
||||
let blk = await store.getBlock(newBlock.cid)
|
||||
|
@ -28,7 +28,7 @@ suite "Memory Store tests":
|
|||
|
||||
test "fail getBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new(@[])
|
||||
|
||||
let blk = await store.getBlock(newBlock.cid)
|
||||
|
@ -36,21 +36,21 @@ suite "Memory Store tests":
|
|||
|
||||
test "hasBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new(@[newBlock])
|
||||
|
||||
check store.hasBlock(newBlock.cid)
|
||||
|
||||
test "fail hasBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new(@[])
|
||||
|
||||
check not store.hasBlock(newBlock.cid)
|
||||
|
||||
test "delBlock":
|
||||
let
|
||||
newBlock = Block.init("New Block".toBytes()).get()
|
||||
newBlock = Block.init("New Block".toBytes()).tryGet()
|
||||
store = MemoryStore.new(@[newBlock])
|
||||
|
||||
check await store.delBlock(newBlock.cid)
|
||||
|
|
|
@ -19,7 +19,7 @@ proc toSortedSeq[T](h: AsyncHeapQueue[T], queueType = QueueType.Min): seq[T] =
|
|||
for d in h:
|
||||
check tmp.pushNoWait(d).isOk
|
||||
while tmp.len > 0:
|
||||
result.add(popNoWait(tmp).get())
|
||||
result.add(popNoWait(tmp).tryGet())
|
||||
|
||||
suite "synchronous tests":
|
||||
test "test pushNoWait - Min":
|
||||
|
@ -189,7 +189,7 @@ suite "asynchronous tests":
|
|||
check heap[0] == ("b", 3) # sanity check for order
|
||||
|
||||
let fut = heap.pushOrUpdate(("c", 2)) # attempt to push a non existen item but block
|
||||
check heap.popNoWait().get() == ("b", 3) # pop one off
|
||||
check heap.popNoWait().tryGet() == ("b", 3) # pop one off
|
||||
await fut # wait for push to complete
|
||||
|
||||
check heap[0] == (name: "c", priority: 2) # check order again
|
||||
|
|
|
@ -17,13 +17,13 @@ suite "Manifest":
|
|||
test "Should produce valid tree hash checksum":
|
||||
without var manifest =? BlocksManifest.init(
|
||||
blocks = @[
|
||||
Block.init("Block 1".toBytes).get().cid,
|
||||
Block.init("Block 2".toBytes).get().cid,
|
||||
Block.init("Block 3".toBytes).get().cid,
|
||||
Block.init("Block 4".toBytes).get().cid,
|
||||
Block.init("Block 5".toBytes).get().cid,
|
||||
Block.init("Block 6".toBytes).get().cid,
|
||||
Block.init("Block 7".toBytes).get().cid,
|
||||
Block.init("Block 1".toBytes).tryGet().cid,
|
||||
Block.init("Block 2".toBytes).tryGet().cid,
|
||||
Block.init("Block 3".toBytes).tryGet().cid,
|
||||
Block.init("Block 4".toBytes).tryGet().cid,
|
||||
Block.init("Block 5".toBytes).tryGet().cid,
|
||||
Block.init("Block 6".toBytes).tryGet().cid,
|
||||
Block.init("Block 7".toBytes).tryGet().cid,
|
||||
]):
|
||||
fail()
|
||||
|
||||
|
@ -35,22 +35,22 @@ suite "Manifest":
|
|||
82, 184, 85]
|
||||
|
||||
var mh: MultiHash
|
||||
check MultiHash.decode(checksum, mh).get() > 0
|
||||
check MultiHash.decode(checksum, mh).tryGet() > 0
|
||||
|
||||
let checkSumCid = Cid.init(manifest.version, manifest.codec, mh).get()
|
||||
check checkSumCid == manifest.cid.get()
|
||||
let checkSumCid = Cid.init(manifest.version, manifest.codec, mh).tryGet()
|
||||
check checkSumCid == manifest.cid.tryGet()
|
||||
|
||||
test "Should encode/decode to/from manifest":
|
||||
let
|
||||
blocks = (0..<1000).mapIt(
|
||||
Block.init(("Block " & $it).toBytes).get().cid
|
||||
Block.init(("Block " & $it).toBytes).tryGet().cid
|
||||
)
|
||||
|
||||
var
|
||||
manifest = BlocksManifest.init(blocks).get()
|
||||
manifest = BlocksManifest.init(blocks).tryGet()
|
||||
|
||||
let
|
||||
e = manifest.encode().get()
|
||||
(cid, decoded) = BlocksManifest.decode(e).get()
|
||||
e = manifest.encode().tryGet()
|
||||
(cid, decoded) = BlocksManifest.decode(e).tryGet()
|
||||
|
||||
check decoded == blocks
|
||||
|
|
|
@ -55,27 +55,27 @@ suite "Test Node":
|
|||
storeFut = node.store(stream)
|
||||
|
||||
var
|
||||
manifest = BlocksManifest.init().get()
|
||||
manifest = BlocksManifest.init().tryGet()
|
||||
|
||||
try:
|
||||
while (
|
||||
let chunk = await chunker.getBytes();
|
||||
chunk.len > 0):
|
||||
await stream.pushData(chunk)
|
||||
manifest.put(bt.Block.init(chunk).get().cid)
|
||||
manifest.put(bt.Block.init(chunk).tryGet().cid)
|
||||
finally:
|
||||
await stream.pushEof()
|
||||
await stream.close()
|
||||
|
||||
let
|
||||
manifestCid = (await storeFut).get()
|
||||
manifestCid = (await storeFut).tryGet()
|
||||
|
||||
check:
|
||||
manifestCid in localStore
|
||||
|
||||
var
|
||||
manifestBlock = (await localStore.getBlock(manifestCid)).get()
|
||||
localManifest = BlocksManifest.init(manifestBlock).get()
|
||||
manifestBlock = (await localStore.getBlock(manifestCid)).tryGet()
|
||||
localManifest = BlocksManifest.init(manifestBlock).tryGet()
|
||||
|
||||
check:
|
||||
manifest.len == localManifest.len
|
||||
|
@ -83,7 +83,7 @@ suite "Test Node":
|
|||
|
||||
test "Retrieve Data Stream":
|
||||
var
|
||||
manifest = BlocksManifest.init().get()
|
||||
manifest = BlocksManifest.init().tryGet()
|
||||
original: seq[byte]
|
||||
|
||||
while (
|
||||
|
@ -91,7 +91,7 @@ suite "Test Node":
|
|||
chunk.len > 0):
|
||||
|
||||
let
|
||||
blk = bt.Block.init(chunk).get()
|
||||
blk = bt.Block.init(chunk).tryGet()
|
||||
|
||||
original &= chunk
|
||||
check await localStore.putBlock(blk)
|
||||
|
@ -99,8 +99,8 @@ suite "Test Node":
|
|||
|
||||
let
|
||||
manifestBlock = bt.Block.init(
|
||||
manifest.encode().get(),
|
||||
codec = ManifestCodec).get()
|
||||
manifest.encode().tryGet(),
|
||||
codec = ManifestCodec).tryGet()
|
||||
|
||||
check await localStore.putBlock(manifestBlock)
|
||||
|
||||
|
@ -124,7 +124,7 @@ suite "Test Node":
|
|||
test "Retrieve One Block":
|
||||
let
|
||||
testString = "Block 1"
|
||||
blk = bt.Block.init(testString.toBytes).get()
|
||||
blk = bt.Block.init(testString.toBytes).tryGet()
|
||||
|
||||
var
|
||||
stream = BufferStream.new()
|
||||
|
|
Loading…
Reference in New Issue