mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-23 14:01:35 +00:00
fix: use placeholder dht/pubsub (#1193)
Instead of making the `.dht` and `.pubsub` properties optional, use dummy implementations that throw exceptions if they are not configured. This way we don't have to null guard everywhere they are accessed.
This commit is contained in:
@ -78,8 +78,8 @@ describe('DHT subsystem operates correctly', () => {
|
||||
expect(connection).to.exist()
|
||||
|
||||
return await Promise.all([
|
||||
pWaitFor(() => libp2p.dht?.lan.routingTable.size === 1),
|
||||
pWaitFor(() => remoteLibp2p.dht?.lan.routingTable.size === 1)
|
||||
pWaitFor(() => libp2p.dht.lan.routingTable.size === 1),
|
||||
pWaitFor(() => remoteLibp2p.dht.lan.routingTable.size === 1)
|
||||
])
|
||||
})
|
||||
|
||||
@ -89,8 +89,8 @@ describe('DHT subsystem operates correctly', () => {
|
||||
|
||||
await libp2p.dialProtocol(remAddr, subsystemMulticodecs)
|
||||
await Promise.all([
|
||||
pWaitFor(() => libp2p.dht?.lan.routingTable.size === 1),
|
||||
pWaitFor(() => remoteLibp2p.dht?.lan.routingTable.size === 1)
|
||||
pWaitFor(() => libp2p.dht.lan.routingTable.size === 1),
|
||||
pWaitFor(() => remoteLibp2p.dht.lan.routingTable.size === 1)
|
||||
])
|
||||
|
||||
await libp2p.components.getContentRouting().put(key, value)
|
||||
@ -141,7 +141,7 @@ describe('DHT subsystem operates correctly', () => {
|
||||
const connection = await libp2p.dial(remAddr)
|
||||
|
||||
expect(connection).to.exist()
|
||||
expect(libp2p.dht?.lan.routingTable).to.be.empty()
|
||||
expect(libp2p.dht.lan.routingTable).to.be.empty()
|
||||
|
||||
const dht = remoteLibp2p.dht
|
||||
|
||||
@ -151,9 +151,9 @@ describe('DHT subsystem operates correctly', () => {
|
||||
|
||||
// should be 0 directly after start - TODO this may be susceptible to timing bugs, we should have
|
||||
// the ability to report stats on the DHT routing table instead of reaching into it's heart like this
|
||||
expect(remoteLibp2p.dht?.lan.routingTable).to.be.empty()
|
||||
expect(remoteLibp2p.dht.lan.routingTable).to.be.empty()
|
||||
|
||||
return await pWaitFor(() => libp2p.dht?.lan.routingTable.size === 1)
|
||||
return await pWaitFor(() => libp2p.dht.lan.routingTable.size === 1)
|
||||
})
|
||||
|
||||
it('should put on a peer and get from the other', async () => {
|
||||
@ -168,7 +168,7 @@ describe('DHT subsystem operates correctly', () => {
|
||||
await dht.start()
|
||||
}
|
||||
|
||||
await pWaitFor(() => libp2p.dht?.lan.routingTable.size === 1)
|
||||
await pWaitFor(() => libp2p.dht.lan.routingTable.size === 1)
|
||||
await libp2p.components.getContentRouting().put(key, value)
|
||||
|
||||
const fetchedValue = await remoteLibp2p.components.getContentRouting().get(key)
|
||||
|
Reference in New Issue
Block a user