mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-13 16:15:23 +00:00
7efa9177df
* extra utilities and tweaks * add atlas lock * update ignores * break build into it's own script * update url rules * base off codexdht's * compile fixes for Nim 1.6.14 * update submodules * convert mapFailure to procs to work around type resolution issues * add toml parser for multiaddress * change error type on keyutils * bump nimbus build to use 1.6.14 * update gitignore * adding new deps submodules * bump nim ci version * even more fixes * more libp2p changes * update keys * fix eventually function * adding coverage test file * move coverage to build.nims * use nimcache/coverage * move libp2p import for tests into helper.nim * remove named bin * bug fixes for networkpeers (from Dmitriy) --------- Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
82 lines
2.3 KiB
Nim
82 lines
2.3 KiB
Nim
import std/sequtils
|
|
import std/algorithm
|
|
|
|
import pkg/chronos
|
|
import pkg/asynctest
|
|
import pkg/stew/byteutils
|
|
|
|
import pkg/codex/blocktype as bt
|
|
import pkg/codex/blockexchange
|
|
|
|
import ../helpers
|
|
|
|
checksuite "Pending Blocks":
|
|
test "Should add want handle":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blk = bt.Block.new("Hello".toBytes).tryGet
|
|
|
|
discard pendingBlocks.getWantHandle(blk.cid)
|
|
|
|
check pendingBlocks.pending(blk.cid)
|
|
|
|
test "Should resolve want handle":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blk = bt.Block.new("Hello".toBytes).tryGet
|
|
handle = pendingBlocks.getWantHandle(blk.cid)
|
|
|
|
check blk.cid in pendingBlocks
|
|
pendingBlocks.resolve(@[blk])
|
|
check (await handle) == blk
|
|
check blk.cid notin pendingBlocks
|
|
|
|
test "Should cancel want handle":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blk = bt.Block.new("Hello".toBytes).tryGet
|
|
handle = pendingBlocks.getWantHandle(blk.cid)
|
|
|
|
check blk.cid in pendingBlocks
|
|
await handle.cancelAndWait()
|
|
check blk.cid notin pendingBlocks
|
|
|
|
test "Should expire want handle":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blk = bt.Block.new("Hello".toBytes).tryGet
|
|
handle = pendingBlocks.getWantHandle(blk.cid, 1.millis)
|
|
|
|
check blk.cid in pendingBlocks
|
|
|
|
await sleepAsync(10.millis)
|
|
expect AsyncTimeoutError:
|
|
discard await handle
|
|
|
|
check blk.cid notin pendingBlocks
|
|
|
|
test "Should get wants list":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blks = (0..9).mapIt( bt.Block.new(("Hello " & $it).toBytes).tryGet )
|
|
|
|
discard blks.mapIt( pendingBlocks.getWantHandle( it.cid ) )
|
|
|
|
check:
|
|
blks.mapIt( $it.cid ).sorted(cmp[string]) ==
|
|
toSeq(pendingBlocks.wantList).mapIt( $it ).sorted(cmp[string])
|
|
|
|
test "Should get want handles list":
|
|
let
|
|
pendingBlocks = PendingBlocksManager.new()
|
|
blks = (0..9).mapIt( bt.Block.new(("Hello " & $it).toBytes).tryGet )
|
|
handles = blks.mapIt( pendingBlocks.getWantHandle( it.cid ) )
|
|
wantHandles = toSeq(pendingBlocks.wantHandles)
|
|
|
|
check wantHandles.len == handles.len
|
|
pendingBlocks.resolve(blks)
|
|
|
|
check:
|
|
(await allFinished(wantHandles)).mapIt( $it.read.cid ).sorted(cmp[string]) ==
|
|
(await allFinished(handles)).mapIt( $it.read.cid ).sorted(cmp[string])
|