Skip to content

Commit fbd378e

Browse files
committed
adapt existing tests to new data structures, remove vestigial tests
1 parent e18996e commit fbd378e

File tree

3 files changed

+51
-122
lines changed

3 files changed

+51
-122
lines changed

tests/codex/blockexchange/engine/testblockexc.nim

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,7 @@ asyncchecksuite "NetworkStore engine - 2 nodes":
9898
let blkFut = nodeCmps1.pendingBlocks.getWantHandle(blk.cid)
9999
(await nodeCmps2.localStore.putBlock(blk)).tryGet()
100100

101-
let entry = WantListEntry(
102-
address: blk.address,
103-
priority: 1,
104-
cancel: false,
105-
wantType: WantType.WantBlock,
106-
sendDontHave: false,
107-
)
108-
109-
peerCtx1.peerWants.add(entry)
101+
peerCtx1.wantedBlocks.incl(blk.address)
110102
check nodeCmps2.engine.taskQueue.pushOrUpdateNoWait(peerCtx1).isOk
111103

112104
check eventually (await nodeCmps1.localStore.hasBlock(blk.cid)).tryGet()

tests/codex/blockexchange/engine/testengine.nim

Lines changed: 47 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ asyncchecksuite "NetworkStore engine handlers":
174174
let ctx = await engine.taskQueue.pop()
175175
check ctx.id == peerId
176176
# only `wantBlock` scheduled
177-
check ctx.peerWants.mapIt(it.address.cidOrTreeCid) == blocks.mapIt(it.cid)
177+
check ctx.wantedBlocks == blocks.mapIt(it.address).toHashSet
178178

179179
let done = handler()
180180
await engine.wantListHandler(peerId, wantList)
@@ -579,130 +579,66 @@ asyncchecksuite "Task Handler":
579579

580580
engine.pricing = Pricing.example.some
581581

582-
test "Should send want-blocks in priority order":
583-
proc sendBlocksDelivery(
584-
id: PeerId, blocksDelivery: seq[BlockDelivery]
585-
) {.async: (raises: [CancelledError]).} =
586-
check blocksDelivery.len == 2
587-
check:
588-
blocksDelivery[1].address == blocks[0].address
589-
blocksDelivery[0].address == blocks[1].address
590-
591-
for blk in blocks:
592-
(await engine.localStore.putBlock(blk)).tryGet()
593-
engine.network.request.sendBlocksDelivery = sendBlocksDelivery
594-
595-
# second block to send by priority
596-
peersCtx[0].peerWants.add(
597-
WantListEntry(
598-
address: blocks[0].address,
599-
priority: 49,
600-
cancel: false,
601-
wantType: WantType.WantBlock,
602-
sendDontHave: false,
603-
)
604-
)
605-
606-
# first block to send by priority
607-
peersCtx[0].peerWants.add(
608-
WantListEntry(
609-
address: blocks[1].address,
610-
priority: 50,
611-
cancel: false,
612-
wantType: WantType.WantBlock,
613-
sendDontHave: false,
614-
)
615-
)
616-
617-
await engine.taskHandler(peersCtx[0])
582+
# FIXME: this is disabled for now: I've dropped block priorities to make
583+
# my life easier as I try to optimize the protocol, and also because
584+
# they were not being used anywhere.
585+
#
586+
# test "Should send want-blocks in priority order":
587+
# proc sendBlocksDelivery(
588+
# id: PeerId, blocksDelivery: seq[BlockDelivery]
589+
# ) {.async: (raises: [CancelledError]).} =
590+
# check blocksDelivery.len == 2
591+
# check:
592+
# blocksDelivery[1].address == blocks[0].address
593+
# blocksDelivery[0].address == blocks[1].address
594+
595+
# for blk in blocks:
596+
# (await engine.localStore.putBlock(blk)).tryGet()
597+
# engine.network.request.sendBlocksDelivery = sendBlocksDelivery
598+
599+
# # second block to send by priority
600+
# peersCtx[0].peerWants.add(
601+
# WantListEntry(
602+
# address: blocks[0].address,
603+
# priority: 49,
604+
# cancel: false,
605+
# wantType: WantType.WantBlock,
606+
# sendDontHave: false,
607+
# )
608+
# )
609+
610+
# # first block to send by priority
611+
# peersCtx[0].peerWants.add(
612+
# WantListEntry(
613+
# address: blocks[1].address,
614+
# priority: 50,
615+
# cancel: false,
616+
# wantType: WantType.WantBlock,
617+
# sendDontHave: false,
618+
# )
619+
# )
620+
621+
# await engine.taskHandler(peersCtx[0])
618622

619623
test "Should set in-flight for outgoing blocks":
620624
proc sendBlocksDelivery(
621625
id: PeerId, blocksDelivery: seq[BlockDelivery]
622626
) {.async: (raises: [CancelledError]).} =
623-
let blockAddress = peersCtx[0].peerWants[0].address
627+
let blockAddress = peersCtx[0].wantedBlocks.toSeq[0]
624628
check peersCtx[0].isInFlight(blockAddress)
625629

626630
for blk in blocks:
627631
(await engine.localStore.putBlock(blk)).tryGet()
628632
engine.network.request.sendBlocksDelivery = sendBlocksDelivery
629633

630-
peersCtx[0].peerWants.add(
631-
WantListEntry(
632-
address: blocks[0].address,
633-
priority: 50,
634-
cancel: false,
635-
wantType: WantType.WantBlock,
636-
sendDontHave: false,
637-
)
638-
)
634+
peersCtx[0].wantedBlocks.incl(blocks[0].address)
635+
639636
await engine.taskHandler(peersCtx[0])
640637

641638
test "Should clear in-flight when local lookup fails":
642-
peersCtx[0].peerWants.add(
643-
WantListEntry(
644-
address: blocks[0].address,
645-
priority: 50,
646-
cancel: false,
647-
wantType: WantType.WantBlock,
648-
sendDontHave: false,
649-
)
650-
)
639+
peersCtx[0].wantedBlocks.incl(blocks[0].address)
640+
651641
await engine.taskHandler(peersCtx[0])
652642

653-
let blockAddress = peersCtx[0].peerWants[0].address
643+
let blockAddress = peersCtx[0].wantedBlocks.toSeq[0]
654644
check not peersCtx[0].isInFlight(blockAddress)
655-
656-
test "Should send presence":
657-
let present = blocks
658-
let missing = @[Block.new("missing".toBytes).tryGet()]
659-
let price = (!engine.pricing).price
660-
661-
proc sendPresence(
662-
id: PeerId, presence: seq[BlockPresence]
663-
) {.async: (raises: [CancelledError]).} =
664-
check presence.mapIt(!Presence.init(it)) ==
665-
@[
666-
Presence(address: present[0].address, have: true, price: price),
667-
Presence(address: present[1].address, have: true, price: price),
668-
Presence(address: missing[0].address, have: false),
669-
]
670-
671-
for blk in blocks:
672-
(await engine.localStore.putBlock(blk)).tryGet()
673-
engine.network.request.sendPresence = sendPresence
674-
675-
# have block
676-
peersCtx[0].peerWants.add(
677-
WantListEntry(
678-
address: present[0].address,
679-
priority: 1,
680-
cancel: false,
681-
wantType: WantType.WantHave,
682-
sendDontHave: false,
683-
)
684-
)
685-
686-
# have block
687-
peersCtx[0].peerWants.add(
688-
WantListEntry(
689-
address: present[1].address,
690-
priority: 1,
691-
cancel: false,
692-
wantType: WantType.WantHave,
693-
sendDontHave: false,
694-
)
695-
)
696-
697-
# don't have block
698-
peersCtx[0].peerWants.add(
699-
WantListEntry(
700-
address: missing[0].address,
701-
priority: 1,
702-
cancel: false,
703-
wantType: WantType.WantHave,
704-
sendDontHave: false,
705-
)
706-
)
707-
708-
await engine.taskHandler(peersCtx[0])

tests/codex/blockexchange/testpeerctxstore.nim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ suite "Peer Context Store Peer Selection":
8181
)
8282
)
8383

84-
peerCtxs[0].peerWants = entries
85-
peerCtxs[5].peerWants = entries
84+
for address in addresses:
85+
peerCtxs[0].wantedBlocks.incl(address)
86+
peerCtxs[5].wantedBlocks.incl(address)
8687

8788
let peers = store.peersWant(addresses[4])
8889

0 commit comments

Comments
 (0)