mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-25 00:33:11 +00:00
Removed modules: - sales (including reservations, slot queue, marketplace abstractions, state machines, etc) - purchasing - erasure coding - contract interactions - prover - slot builder - block exchange payments - sales/purchasing from REST api - removed persistence command and all config params from cli configuration - CI workflows (devnet, dist tests, cirdl build, start eth node, contracts version reporting) - unused modules from tests - marketplace integration tests, and starting provider/validator/hardhat nodes - unused manifest properties - integration tests using the above # Conflicts: # .github/workflows/ci-reusable.yml # .github/workflows/docker.yml # build.nims # codex/blockexchange/engine/payments.nim # codex/codex.nim # codex/conf.nim # codex/contracts/Readme.md # codex/erasure.nim # codex/erasure/backend.nim # codex/erasure/backends/leopard.nim # codex/erasure/erasure.nim # codex/rest/api.nim # codex/sales.nim # codex/sales/reservations.nim # codex/sales/states/filled.nim # codex/sales/states/preparing.nim # codex/sales/states/provingsimulated.nim # codex/slots/builder/builder.nim # codex/slots/converters.nim # codex/slots/proofs/backends/circomcompat.nim # codex/slots/proofs/backends/converters.nim # codex/slots/proofs/prover.nim # codex/slots/sampler/sampler.nim # codex/slots/sampler/utils.nim # codex/slots/types.nim # tests/integration/5_minutes/testrestapivalidation.nim # tests/integration/hardhatprocess.nim # tests/integration/multinodes.nim # tools/cirdl/cirdl.nim
109 lines
2.5 KiB
Nim
109 lines
2.5 KiB
Nim
import std/sugar
|
|
import std/sequtils
|
|
|
|
import pkg/unittest2
|
|
import pkg/libp2p
|
|
|
|
import pkg/codex/blockexchange/peers
|
|
import pkg/codex/blockexchange/protobuf/blockexc
|
|
import pkg/codex/blockexchange/protobuf/presence
|
|
|
|
import ../helpers
|
|
import ../examples
|
|
|
|
suite "Peer Context Store":
|
|
var
|
|
store: PeerCtxStore
|
|
peerCtx: BlockExcPeerCtx
|
|
|
|
setup:
|
|
store = PeerCtxStore.new()
|
|
peerCtx = BlockExcPeerCtx.example
|
|
store.add(peerCtx)
|
|
|
|
test "Should add peer":
|
|
check peerCtx.id in store
|
|
|
|
test "Should remove peer":
|
|
store.remove(peerCtx.id)
|
|
check peerCtx.id notin store
|
|
|
|
test "Should get peer":
|
|
check store.get(peerCtx.id) == peerCtx
|
|
|
|
suite "Peer Context Store Peer Selection":
|
|
var
|
|
store: PeerCtxStore
|
|
peerCtxs: seq[BlockExcPeerCtx]
|
|
addresses: seq[BlockAddress]
|
|
|
|
setup:
|
|
store = PeerCtxStore.new()
|
|
addresses = collect(newSeq):
|
|
for i in 0 ..< 10:
|
|
BlockAddress(leaf: false, cid: Cid.example)
|
|
|
|
peerCtxs = collect(newSeq):
|
|
for i in 0 ..< 10:
|
|
BlockExcPeerCtx.example
|
|
|
|
for p in peerCtxs:
|
|
store.add(p)
|
|
|
|
teardown:
|
|
store = nil
|
|
addresses = @[]
|
|
peerCtxs = @[]
|
|
|
|
test "Should select peers that have Cid":
|
|
peerCtxs[0].blocks = collect(initTable):
|
|
for i, a in addresses:
|
|
{a: Presence(address: a)}
|
|
|
|
peerCtxs[5].blocks = collect(initTable):
|
|
for i, a in addresses:
|
|
{a: Presence(address: a)}
|
|
|
|
let peers = store.peersHave(addresses[0])
|
|
|
|
check peers.len == 2
|
|
check peerCtxs[0] in peers
|
|
check peerCtxs[5] in peers
|
|
|
|
test "Should select peers that want Cid":
|
|
let entries = addresses.mapIt(
|
|
WantListEntry(
|
|
address: it,
|
|
priority: 1,
|
|
cancel: false,
|
|
wantType: WantType.WantBlock,
|
|
sendDontHave: false,
|
|
)
|
|
)
|
|
|
|
for address in addresses:
|
|
peerCtxs[0].wantedBlocks.incl(address)
|
|
peerCtxs[5].wantedBlocks.incl(address)
|
|
|
|
let peers = store.peersWant(addresses[4])
|
|
|
|
check peers.len == 2
|
|
check peerCtxs[0] in peers
|
|
check peerCtxs[5] in peers
|
|
|
|
test "Should return peers with and without block":
|
|
let address = addresses[2]
|
|
|
|
peerCtxs[1].blocks[address] = Presence(address: address)
|
|
peerCtxs[2].blocks[address] = Presence(address: address)
|
|
|
|
let peers = store.getPeersForBlock(address)
|
|
|
|
for i, pc in peerCtxs:
|
|
if i == 1 or i == 2:
|
|
check pc in peers.with
|
|
check pc notin peers.without
|
|
else:
|
|
check pc notin peers.with
|
|
check pc in peers.without
|