Simplify test
This commit is contained in:
parent
c57ecde046
commit
0a28338136
|
@ -339,18 +339,15 @@ suite "Task Handler":
|
||||||
await engine.taskHandler(peersCtx[0])
|
await engine.taskHandler(peersCtx[0])
|
||||||
|
|
||||||
test "Should send presence":
|
test "Should send presence":
|
||||||
proc sendPresence(
|
let present = blocks
|
||||||
id: PeerID,
|
let missing = @[bt.Block.new("missing".toBytes)]
|
||||||
presence: seq[BlockPresence]) {.gcsafe.} =
|
|
||||||
check presence.len == 3
|
|
||||||
check:
|
|
||||||
presence[0].cid == blocks[0].cid.data.buffer
|
|
||||||
presence[0].`type` == BlockPresenceType.presenceHave
|
|
||||||
|
|
||||||
presence[1].cid == blocks[1].cid.data.buffer
|
proc sendPresence(id: PeerID, presence: seq[BlockPresence]) =
|
||||||
presence[1].`type` == BlockPresenceType.presenceHave
|
check presence.mapIt(!Presence.init(it)) == @[
|
||||||
|
Presence(cid: present[0].cid, have: true),
|
||||||
presence[2].`type` == BlockPresenceType.presenceDontHave
|
Presence(cid: present[1].cid, have: true),
|
||||||
|
Presence(cid: missing[0].cid, have: false)
|
||||||
|
]
|
||||||
|
|
||||||
engine.localStore.putBlocks(blocks)
|
engine.localStore.putBlocks(blocks)
|
||||||
engine.request.sendPresence = sendPresence
|
engine.request.sendPresence = sendPresence
|
||||||
|
@ -358,7 +355,7 @@ suite "Task Handler":
|
||||||
# have block
|
# have block
|
||||||
peersCtx[0].peerWants.add(
|
peersCtx[0].peerWants.add(
|
||||||
Entry(
|
Entry(
|
||||||
`block`: blocks[0].cid.data.buffer,
|
`block`: present[0].cid.data.buffer,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
cancel: false,
|
cancel: false,
|
||||||
wantType: WantType.wantHave,
|
wantType: WantType.wantHave,
|
||||||
|
@ -368,7 +365,7 @@ suite "Task Handler":
|
||||||
# have block
|
# have block
|
||||||
peersCtx[0].peerWants.add(
|
peersCtx[0].peerWants.add(
|
||||||
Entry(
|
Entry(
|
||||||
`block`: blocks[1].cid.data.buffer,
|
`block`: present[1].cid.data.buffer,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
cancel: false,
|
cancel: false,
|
||||||
wantType: WantType.wantHave,
|
wantType: WantType.wantHave,
|
||||||
|
@ -378,7 +375,7 @@ suite "Task Handler":
|
||||||
# don't have block
|
# don't have block
|
||||||
peersCtx[0].peerWants.add(
|
peersCtx[0].peerWants.add(
|
||||||
Entry(
|
Entry(
|
||||||
`block`: bt.Block.new("Block 1".toBytes).cid.data.buffer,
|
`block`: missing[0].cid.data.buffer,
|
||||||
priority: 1,
|
priority: 1,
|
||||||
cancel: false,
|
cancel: false,
|
||||||
wantType: WantType.wantHave,
|
wantType: WantType.wantHave,
|
||||||
|
|
Loading…
Reference in New Issue