@streamr/dht 102.0.0-beta.0 → 102.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/dist/package.json +15 -16
  2. package/dist/src/connection/ConnectionManager.js +18 -8
  3. package/dist/src/connection/ConnectionManager.js.map +1 -1
  4. package/dist/src/connection/Handshaker.d.ts +1 -1
  5. package/dist/src/connection/Handshaker.js +9 -5
  6. package/dist/src/connection/Handshaker.js.map +1 -1
  7. package/dist/src/connection/ManagedConnection.js +17 -7
  8. package/dist/src/connection/ManagedConnection.js.map +1 -1
  9. package/dist/src/connection/connectivityChecker.js +20 -10
  10. package/dist/src/connection/connectivityChecker.js.map +1 -1
  11. package/dist/src/connection/connectivityRequestHandler.js +3 -3
  12. package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
  13. package/dist/src/connection/simulator/Simulator.js +3 -2
  14. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  15. package/dist/src/connection/simulator/pings.d.ts +1 -1
  16. package/dist/src/connection/simulator/pings.js +3 -3
  17. package/dist/src/connection/simulator/pings.js.map +1 -1
  18. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -2
  19. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  20. package/dist/src/connection/webrtc/WebrtcConnector.js +19 -9
  21. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  22. package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
  23. package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
  24. package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -2
  25. package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -1
  26. package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
  27. package/dist/src/connection/websocket/WebsocketServerConnector.js +28 -18
  28. package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
  29. package/dist/src/dht/DhtNode.d.ts +1 -0
  30. package/dist/src/dht/DhtNode.js +3 -2
  31. package/dist/src/dht/DhtNode.js.map +1 -1
  32. package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
  33. package/dist/src/dht/PeerManager.d.ts +2 -1
  34. package/dist/src/dht/PeerManager.js +2 -1
  35. package/dist/src/dht/PeerManager.js.map +1 -1
  36. package/dist/src/dht/contact/SortedContactList.js +1 -1
  37. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  38. package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -1
  39. package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -1
  40. package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
  41. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +2 -2
  42. package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
  43. package/dist/src/dht/routing/RoutingSession.js +2 -2
  44. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  45. package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
  46. package/dist/src/dht/store/LocalDataStore.js +1 -1
  47. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  48. package/dist/src/dht/store/StoreManager.d.ts +1 -1
  49. package/dist/src/dht/store/StoreRpcLocal.d.ts +1 -1
  50. package/dist/src/helpers/AddressTools.js +2 -3
  51. package/dist/src/helpers/AddressTools.js.map +1 -1
  52. package/dist/src/helpers/debugHelpers.js +2 -2
  53. package/dist/src/helpers/debugHelpers.js.map +1 -1
  54. package/dist/src/helpers/protoClasses.d.ts +1 -1
  55. package/dist/src/helpers/protoClasses.js.map +1 -1
  56. package/dist/src/helpers/protoToString.js +1 -2
  57. package/dist/src/helpers/protoToString.js.map +1 -1
  58. package/dist/src/helpers/version.d.ts +1 -1
  59. package/dist/src/helpers/version.js +4 -4
  60. package/dist/src/helpers/version.js.map +1 -1
  61. package/eslint.config.mjs +12 -0
  62. package/jest.config.ts +12 -0
  63. package/package.json +15 -16
  64. package/protos/DhtRpc.proto +6 -4
  65. package/src/connection/ConnectionManager.ts +2 -2
  66. package/src/connection/Handshaker.ts +15 -11
  67. package/src/connection/connectivityChecker.ts +4 -4
  68. package/src/connection/connectivityRequestHandler.ts +3 -3
  69. package/src/connection/simulator/Simulator.ts +4 -3
  70. package/src/connection/simulator/pings.ts +1 -1
  71. package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -2
  72. package/src/connection/webrtc/WebrtcConnector.ts +3 -3
  73. package/src/connection/websocket/WebsocketServerConnector.ts +17 -13
  74. package/src/dht/DhtNode.ts +8 -3
  75. package/src/dht/DhtNodeRpcLocal.ts +1 -1
  76. package/src/dht/PeerManager.ts +4 -2
  77. package/src/dht/contact/SortedContactList.ts +1 -1
  78. package/src/dht/recursive-operation/RecursiveOperationManager.ts +1 -1
  79. package/src/dht/routing/DuplicateDetector.ts +1 -1
  80. package/src/dht/routing/RoutingSession.ts +2 -2
  81. package/src/dht/routing/RoutingTablesCache.ts +1 -1
  82. package/src/dht/store/LocalDataStore.ts +1 -1
  83. package/src/dht/store/StoreManager.ts +1 -1
  84. package/src/dht/store/StoreRpcLocal.ts +1 -1
  85. package/src/helpers/protoClasses.ts +1 -1
  86. package/src/helpers/version.ts +2 -2
  87. package/test/benchmark/Find.test.ts +3 -3
  88. package/test/benchmark/KademliaCorrectness.test.ts +2 -2
  89. package/test/benchmark/RingCorrectness.test.ts +3 -3
  90. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +2 -2
  91. package/test/end-to-end/WebsocketConnectionRequest.test.ts +2 -2
  92. package/test/end-to-end/memory-leak.test.ts +2 -2
  93. package/test/integration/ConnectionLocking.test.ts +32 -22
  94. package/test/integration/ConnectionManager.test.ts +3 -3
  95. package/test/integration/ConnectivityChecking.test.ts +1 -1
  96. package/test/integration/DhtNode.test.ts +2 -2
  97. package/test/integration/GeoIpConnectivityChecking.test.ts +6 -6
  98. package/test/integration/Layer1-scale.test.ts +1 -1
  99. package/test/integration/RouteMessage.test.ts +4 -4
  100. package/test/integration/SimultaneousConnections.test.ts +9 -9
  101. package/test/integration/StoreOnDhtWithThreeNodes.test.ts +1 -1
  102. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +3 -3
  103. package/test/integration/StoreRpcRemote.test.ts +1 -1
  104. package/test/integration/WebrtcConnectionManagement.test.ts +0 -28
  105. package/test/integration/WebrtcConnectorRpc.test.ts +5 -5
  106. package/test/integration/WebsocketConnectionManagement.test.ts +3 -3
  107. package/test/integration/rpc-connections-over-webrtc.test.ts +8 -43
  108. package/test/unit/AutoCertifierClientFacade.test.ts +6 -6
  109. package/test/unit/Handshaker.test.ts +1 -1
  110. package/test/unit/ListeningRpcCommunicator.test.ts +3 -3
  111. package/test/unit/PeerManager.test.ts +2 -2
  112. package/test/unit/RecursiveOperationSession.test.ts +2 -2
  113. package/test/unit/RoutingSession.test.ts +7 -0
  114. package/test/unit/SortedContactList.test.ts +3 -3
  115. package/test/unit/StoreManager.test.ts +2 -2
  116. package/test/unit/connectivityRequestHandler.test.ts +5 -5
  117. package/test/unit/customMatchers.test.ts +18 -0
  118. package/test/unit/getClosestNodes.test.ts +1 -1
  119. package/test/unit/version.test.ts +9 -9
  120. package/test/utils/customMatchers.ts +6 -6
  121. package/test/utils/topology.ts +0 -1
  122. package/test/utils/utils.ts +2 -2
  123. package/.eslintignore +0 -5
  124. package/.eslintrc +0 -3
  125. package/dist/generated/google/protobuf/any.d.ts +0 -180
  126. package/dist/generated/google/protobuf/any.js +0 -155
  127. package/dist/generated/google/protobuf/any.js.map +0 -1
  128. package/dist/generated/google/protobuf/empty.d.ts +0 -31
  129. package/dist/generated/google/protobuf/empty.js +0 -32
  130. package/dist/generated/google/protobuf/empty.js.map +0 -1
  131. package/dist/generated/google/protobuf/timestamp.d.ts +0 -155
  132. package/dist/generated/google/protobuf/timestamp.js +0 -136
  133. package/dist/generated/google/protobuf/timestamp.js.map +0 -1
  134. package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +0 -361
  135. package/dist/generated/packages/dht/protos/DhtRpc.client.js +0 -285
  136. package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +0 -1
  137. package/dist/generated/packages/dht/protos/DhtRpc.d.ts +0 -991
  138. package/dist/generated/packages/dht/protos/DhtRpc.js +0 -675
  139. package/dist/generated/packages/dht/protos/DhtRpc.js.map +0 -1
  140. package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +0 -162
  141. package/dist/generated/packages/dht/protos/DhtRpc.server.js +0 -3
  142. package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +0 -1
  143. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
  144. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +0 -66
  145. package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
  146. package/generated/google/protobuf/any.ts +0 -326
  147. package/generated/google/protobuf/empty.ts +0 -81
  148. package/generated/google/protobuf/timestamp.ts +0 -287
  149. package/generated/packages/dht/protos/DhtRpc.client.ts +0 -419
  150. package/generated/packages/dht/protos/DhtRpc.server.ts +0 -165
  151. package/generated/packages/dht/protos/DhtRpc.ts +0 -1266
  152. package/generated/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
  153. package/jest.config.js +0 -5
@@ -1,4 +1,4 @@
1
- import { MetricsContext, waitForCondition } from '@streamr/utils'
1
+ import { MetricsContext, until } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
3
  import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
4
4
  import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
@@ -79,8 +79,8 @@ describe('SimultaneousConnections', () => {
79
79
  simTransport1.send(msg1),
80
80
  simTransport2.send(msg2)
81
81
  ])
82
- await waitForCondition(() => simTransport2.hasConnection(toNodeId(peerDescriptor1)))
83
- await waitForCondition(() => simTransport1.hasConnection(toNodeId(peerDescriptor2)))
82
+ await until(() => simTransport2.hasConnection(toNodeId(peerDescriptor1)))
83
+ await until(() => simTransport1.hasConnection(toNodeId(peerDescriptor2)))
84
84
  })
85
85
 
86
86
  describe('Websocket 2 servers', () => {
@@ -160,8 +160,8 @@ describe('SimultaneousConnections', () => {
160
160
  connectionManager2.send(msg2)
161
161
  ])
162
162
 
163
- await waitForCondition(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
164
- await waitForCondition(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
163
+ await until(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
164
+ await until(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
165
165
  })
166
166
  })
167
167
 
@@ -240,8 +240,8 @@ describe('SimultaneousConnections', () => {
240
240
  connectionManager2.send(msg2)
241
241
  ])
242
242
 
243
- await waitForCondition(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
244
- await waitForCondition(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
243
+ await until(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
244
+ await until(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
245
245
  })
246
246
  })
247
247
 
@@ -308,8 +308,8 @@ describe('SimultaneousConnections', () => {
308
308
  connectionManager2.send(msg2)
309
309
  ])
310
310
 
311
- await waitForCondition(() => connectionManager1.hasConnection(toNodeId(wrtcPeerDescriptor2)))
312
- await waitForCondition(() => connectionManager2.hasConnection(toNodeId(wrtcPeerDescriptor1)))
311
+ await until(() => connectionManager1.hasConnection(toNodeId(wrtcPeerDescriptor2)))
312
+ await until(() => connectionManager2.hasConnection(toNodeId(wrtcPeerDescriptor1)))
313
313
  })
314
314
  })
315
315
 
@@ -34,7 +34,7 @@ describe('Storing data in DHT with two peers', () => {
34
34
  await entryPoint.stop()
35
35
  await node1.stop()
36
36
  await node2.stop()
37
- simulator?.stop()
37
+ simulator!.stop()
38
38
  })
39
39
 
40
40
  it('Node can store on three peer DHT', async () => {
@@ -1,7 +1,7 @@
1
1
  import { createMockConnectionDhtNode } from '../utils/utils'
2
2
  import { DhtNode } from '../../src/dht/DhtNode'
3
3
  import { Simulator } from '../../src/connection/simulator/Simulator'
4
- import { waitForCondition } from '@streamr/utils'
4
+ import { until } from '@streamr/utils'
5
5
  import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
6
6
  import { toDhtAddress } from '../../src/identifiers'
7
7
 
@@ -26,7 +26,7 @@ describe('Storing data in DHT with two peers', () => {
26
26
  afterEach(async () => {
27
27
  await entryPoint.stop()
28
28
  await otherNode.stop()
29
- simulator?.stop()
29
+ simulator!.stop()
30
30
  })
31
31
 
32
32
  it('Node can store on two peer DHT', async () => {
@@ -42,7 +42,7 @@ describe('Storing data in DHT with two peers', () => {
42
42
 
43
43
  it('Can store on one peer DHT', async () => {
44
44
  await otherNode.stop()
45
- await waitForCondition(() => entryPoint.getNeighborCount() === 0)
45
+ await until(() => entryPoint.getNeighborCount() === 0)
46
46
  const storedData = createMockDataEntry()
47
47
  await entryPoint.storeDataToDht(toDhtAddress(storedData.key), storedData.data!)
48
48
  const foundData = await entryPoint.fetchDataFromDht(toDhtAddress(storedData.key))
@@ -45,7 +45,7 @@ describe('StoreRpcRemote', () => {
45
45
 
46
46
  it('storeData rejects', async () => {
47
47
  serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.throwStoreDataError)
48
- await expect(rpcRemote.storeData(request)).rejects.toThrowError(
48
+ await expect(rpcRemote.storeData(request)).rejects.toThrow(
49
49
  'Could not store data to'
50
50
  + ` ${toNodeId(serverPeerDescriptor)} from ${toNodeId(clientPeerDescriptor)}`
51
51
  + ' Error: Mock'
@@ -162,34 +162,6 @@ describe('WebRTC Connection Management', () => {
162
162
 
163
163
  }, 20000)
164
164
 
165
- it('Disconnects webrtcconnection while being connected', async () => {
166
- const msg: Message = {
167
- serviceId,
168
- messageId: '1',
169
- body: {
170
- oneofKind: 'rpcMessage',
171
- rpcMessage: RpcMessage.create()
172
- },
173
- }
174
-
175
- const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
176
- manager1.on('disconnected', () => {
177
- resolve()
178
- })
179
- })
180
-
181
- msg.targetDescriptor = peerDescriptor2
182
- manager1.send(msg).catch((e) => {
183
- expect(e.code).toEqual('SEND_FAILED')
184
- })
185
-
186
- // @ts-expect-error private field
187
- manager1.closeConnection(peerDescriptor2)
188
-
189
- await disconnectedPromise1
190
-
191
- }, 20000)
192
-
193
165
  it('failed connections are cleaned up', async () => {
194
166
  const msg: Message = {
195
167
  serviceId,
@@ -9,7 +9,7 @@ import {
9
9
  import { Empty } from '../../generated/google/protobuf/empty'
10
10
  import { createMockPeerDescriptor } from '../utils/utils'
11
11
  import { IWebrtcConnectorRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
12
- import { waitForCondition } from '@streamr/utils'
12
+ import { until } from '@streamr/utils'
13
13
  import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
14
14
  import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
15
15
 
@@ -86,7 +86,7 @@ describe('WebRTC rpc messages', () => {
86
86
  { targetDescriptor, notification: true }
87
87
  )
88
88
 
89
- await waitForCondition(() => requestConnectionCounter === 1)
89
+ await until(() => requestConnectionCounter === 1)
90
90
  })
91
91
 
92
92
  it('send rtcOffer', async () => {
@@ -97,7 +97,7 @@ describe('WebRTC rpc messages', () => {
97
97
  { targetDescriptor, notification: true }
98
98
  )
99
99
 
100
- await waitForCondition(() => rtcOfferCounter === 1)
100
+ await until(() => rtcOfferCounter === 1)
101
101
  })
102
102
 
103
103
  it('send rtcAnswer', async () => {
@@ -108,7 +108,7 @@ describe('WebRTC rpc messages', () => {
108
108
  { targetDescriptor, notification: true }
109
109
  )
110
110
 
111
- await waitForCondition(() => rtcAnswerCounter === 1)
111
+ await until(() => rtcAnswerCounter === 1)
112
112
  })
113
113
 
114
114
  it('send iceCandidate', async () => {
@@ -120,6 +120,6 @@ describe('WebRTC rpc messages', () => {
120
120
  { targetDescriptor, notification: true }
121
121
  )
122
122
 
123
- await waitForCondition(() => iceCandidateCounter === 1)
123
+ await until(() => iceCandidateCounter === 1)
124
124
  })
125
125
  })
@@ -1,4 +1,4 @@
1
- import { MetricsContext, waitForCondition, waitForEvent3 } from '@streamr/utils'
1
+ import { MetricsContext, until, waitForEvent3 } from '@streamr/utils'
2
2
  import { ConnectionManager } from '../../src/connection/ConnectionManager'
3
3
  import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
4
4
  import { Simulator } from '../../src/connection/simulator/Simulator'
@@ -158,13 +158,13 @@ describe('Websocket Connection Management', () => {
158
158
  targetDescriptor: wsServerConnectorPeerDescriptor
159
159
  }
160
160
  await noWsServerManager.send(dummyMessage)
161
- await waitForCondition(
161
+ await until(
162
162
  () => {
163
163
  const nodeId = toNodeId(noWsServerConnectorPeerDescriptor)
164
164
  return wsServerManager.hasConnection(nodeId)
165
165
  }
166
166
  )
167
- await waitForCondition(
167
+ await until(
168
168
  () => noWsServerManager.hasConnection(toNodeId(wsServerConnectorPeerDescriptor))
169
169
  )
170
170
  })
@@ -51,7 +51,6 @@ describe('RPC connections over WebRTC', () => {
51
51
  await connectorTransport2.start()
52
52
  manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
53
53
  rpcCommunicator2 = new ListeningRpcCommunicator(SERVICE_ID, manager2)
54
- //client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator2.getRpcClientTransport()))
55
54
 
56
55
  await manager1.start()
57
56
  await manager2.start()
@@ -88,7 +87,7 @@ describe('RPC connections over WebRTC', () => {
88
87
  const response = await client1.ping(request, options)
89
88
 
90
89
  expect(response.requestId).toEqual(request.requestId)
91
- }, 60000)
90
+ })
92
91
 
93
92
  it('Throws an exception if RPC method is not defined', async () => {
94
93
 
@@ -102,57 +101,23 @@ describe('RPC connections over WebRTC', () => {
102
101
 
103
102
  await expect(client1.ping(request, options))
104
103
  .rejects.toThrow('Server does not implement method ping')
105
- }, 60000)
106
-
107
- /*
108
-
109
- TODO enable these tests (NET-1177)
104
+ })
110
105
 
111
- it.only('Throws a client-side exception if WebRTC connection fails', async () => {
106
+ it('Throws a client-side exception if WebRTC connection fails', async () => {
112
107
 
113
108
  const request: PingRequest = {
114
109
  requestId: v4()
115
110
  }
116
111
  const options: DhtRpcOptions = {
117
112
  sourceDescriptor: peerDescriptor1,
118
- targetDescriptor: peerDescriptor2
113
+ targetDescriptor: peerDescriptor2,
114
+ timeout: 10000
119
115
  }
120
- await connectorTransport1.stop()
121
116
  await manager2.stop()
122
117
 
123
- const result = await client1.ping(request, options)
124
-
125
- }, 60000)
126
-
127
- it('Disconnects WebrtcConnection while being connected', async () => {
128
-
129
- const rpcMessage: RpcMessage = {
130
- header: {},
131
- body: new Uint8Array(10),
132
- requestId: v4()
133
- }
134
-
135
- const msg: Message = {
136
- serviceId,
137
- messageId: '1',
138
- body: RpcMessage.toBinary(rpcMessage)
139
- }
118
+ await expect(client1.ping(request, options))
119
+ .rejects.toThrow('Peer disconnected')
140
120
 
141
- const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
142
- manager1.on('disconnected', () => {
143
- //expect(message.body.oneofKind).toBe('rpcMessage')
144
- resolve()
145
- })
146
- })
147
-
148
- msg.targetDescriptor = peerDescriptor2
149
- manager1.send(msg).catch((e) => {
150
- expect(e.code).toEqual('CONNECTION_FAILED')
151
- })
152
-
153
- manager1.disconnect(peerDescriptor2!, undefined, 100)
154
- await disconnectedPromise1
121
+ }, 10000)
155
122
 
156
- }, 20000)
157
- */
158
123
  })
@@ -42,17 +42,17 @@ describe('AutoCertifierClientFacade', () => {
42
42
 
43
43
  it('start', async () => {
44
44
  await client.start()
45
- expect(setHost).toBeCalled()
46
- expect(updateCertificate).toBeCalled()
45
+ expect(setHost).toHaveBeenCalled()
46
+ expect(updateCertificate).toHaveBeenCalled()
47
47
  })
48
48
 
49
49
  it('updated events are processed', async () => {
50
50
  await client.start()
51
- expect(setHost).toBeCalledTimes(1)
52
- expect(updateCertificate).toBeCalledTimes(1);
51
+ expect(setHost).toHaveBeenCalledTimes(1)
52
+ expect(updateCertificate).toHaveBeenCalledTimes(1);
53
53
  (mockClient as MockAutoCertifierClient).emitUpdateSubdomain()
54
- expect(setHost).toBeCalledTimes(2)
55
- expect(updateCertificate).toBeCalledTimes(2)
54
+ expect(setHost).toHaveBeenCalledTimes(2)
55
+ expect(updateCertificate).toHaveBeenCalledTimes(2)
56
56
  })
57
57
 
58
58
  })
@@ -104,7 +104,7 @@ describe('Handshaker', () => {
104
104
  })
105
105
 
106
106
  it('onHandshakeFailed unsupported version', () => {
107
- handshaker.emit('handshakeFailed', HandshakeError.UNSUPPORTED_VERSION)
107
+ handshaker.emit('handshakeFailed', HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
108
108
  expect(mockOnHandshakeCompleted).not.toHaveBeenCalled()
109
109
  expect(mockPendingConnectionClose).toHaveBeenCalledTimes(1)
110
110
  })
@@ -1,4 +1,4 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
3
3
  import { MockTransport } from '../utils/mock/MockTransport'
4
4
  import { createMockPeerDescriptor } from '../utils/utils'
@@ -44,9 +44,9 @@ describe('ListeningRpcCommunicator', () => {
44
44
  RpcMessage.create(),
45
45
  { targetDescriptor: peerDescriptor }, createDeferredPromises()
46
46
  )
47
- await waitForCondition(() => rpcCommunicator.getRequestIds(() => true).length > 0)
47
+ await until(() => rpcCommunicator.getRequestIds(() => true).length > 0)
48
48
  transport.emit('disconnected', peerDescriptor, false)
49
- await waitForCondition(() => rpcCommunicator.getRequestIds(() => true).length === 0)
49
+ await until(() => rpcCommunicator.getRequestIds(() => true).length === 0)
50
50
  }, 10000)
51
51
 
52
52
  })
@@ -1,4 +1,4 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { range, sample, sampleSize } from 'lodash'
3
3
  import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
4
4
  import { PeerManager } from '../../src/dht/PeerManager'
@@ -64,7 +64,7 @@ describe('PeerManager', () => {
64
64
  expect(manager.getNeighborCount()).toBe(0)
65
65
  manager.addContact(failureContact)
66
66
  const closesSuccessContact = getClosestNodes(toNodeId(localPeerDescriptor), successContacts)[0]
67
- await waitForCondition(() => {
67
+ await until(() => {
68
68
  const neighborNodeIds = manager.getNeighbors().map((n) => n.getNodeId())
69
69
  return neighborNodeIds.includes(toNodeId(closesSuccessContact))
70
70
  })
@@ -1,4 +1,4 @@
1
- import { waitForCondition } from '@streamr/utils'
1
+ import { until } from '@streamr/utils'
2
2
  import { range } from 'lodash'
3
3
  import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
4
4
  import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
@@ -59,7 +59,7 @@ describe('RecursiveOperationSession', () => {
59
59
 
60
60
  // TODO now waits for the 4s timeout, could setup test so that it completes by receiving
61
61
  // all data it wants
62
- await waitForCondition(() => onCompleted.mock.calls.length > 0)
62
+ await until(() => onCompleted.mock.calls.length > 0)
63
63
  const result = session.getResults()
64
64
  // TODO assert peer descriptors
65
65
  expect(result.closestNodes).toHaveLength(6)
@@ -76,4 +76,11 @@ describe('RoutingSession', () => {
76
76
  expect(session.updateAndGetRoutablePeers().length).toBe(0)
77
77
  })
78
78
 
79
+ it('recalculates Routing Table if it is empty', () => {
80
+ connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
81
+ expect(session.updateAndGetRoutablePeers().length).toBe(1)
82
+ routingTablesCache.onNodeDisconnected(toNodeId(mockPeerDescriptor2))
83
+ expect(session.updateAndGetRoutablePeers().length).toBe(1)
84
+ })
85
+
79
86
  })
@@ -38,7 +38,7 @@ describe('SortedContactList', () => {
38
38
  expect(list.getSize()).toEqual(3)
39
39
  expect(list.getClosestContacts()).toEqual([item1, item2, item3])
40
40
  expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
41
- expect(onContactRemoved).toBeCalledWith(item4)
41
+ expect(onContactRemoved).toHaveBeenCalledWith(item4)
42
42
  expect(list.getContact(item4.getNodeId())).toBeFalsy()
43
43
  })
44
44
 
@@ -106,9 +106,9 @@ describe('SortedContactList', () => {
106
106
  list.on('contactAdded', onContactAdded)
107
107
  list.addContact(item1)
108
108
  list.addContact(item2)
109
- expect(onContactAdded).toBeCalledTimes(2)
109
+ expect(onContactAdded).toHaveBeenCalledTimes(2)
110
110
  list.addContact(item3)
111
- expect(onContactAdded).toBeCalledTimes(2)
111
+ expect(onContactAdded).toHaveBeenCalledTimes(2)
112
112
  expect(list.getClosestContacts().length).toEqual(2)
113
113
  })
114
114
 
@@ -1,4 +1,4 @@
1
- import { wait, waitForCondition } from '@streamr/utils'
1
+ import { wait, until } from '@streamr/utils'
2
2
  import { range, without } from 'lodash'
3
3
  import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
4
4
  import { StoreManager } from '../../src/dht/store/StoreManager'
@@ -67,7 +67,7 @@ describe('StoreManager', () => {
67
67
  setAllEntriesAsStale
68
68
  )
69
69
  manager.onContactAdded(getNodeCloseToData(2))
70
- await waitForCondition(() => replicateData.mock.calls.length === 1)
70
+ await until(() => replicateData.mock.calls.length === 1)
71
71
  expect(replicateData).toHaveBeenCalledWith({
72
72
  entry: DATA_ENTRY
73
73
  }, true)
@@ -1,4 +1,4 @@
1
- import { ipv4ToNumber, waitForCondition } from '@streamr/utils'
1
+ import { ipv4ToNumber, until } from '@streamr/utils'
2
2
  import { EventEmitter } from 'eventemitter3'
3
3
  import { once } from 'events'
4
4
  import { Server as HttpServer, createServer as createHttpServer } from 'http'
@@ -48,7 +48,7 @@ describe('connectivityRequestHandler', () => {
48
48
  }
49
49
  connection.emit('data', Message.toBinary(request))
50
50
 
51
- await waitForCondition(() => connection.send.mock.calls.length > 0)
51
+ await until(() => connection.send.mock.calls.length > 0)
52
52
 
53
53
  const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
54
54
  expect(receivedMessage).toEqual({
@@ -62,7 +62,7 @@ describe('connectivityRequestHandler', () => {
62
62
  tls: false
63
63
  },
64
64
  ipAddress: ipv4ToNumber(HOST),
65
- version: LOCAL_PROTOCOL_VERSION
65
+ protocolVersion: LOCAL_PROTOCOL_VERSION
66
66
  },
67
67
  oneofKind: 'connectivityResponse'
68
68
  },
@@ -83,7 +83,7 @@ describe('connectivityRequestHandler', () => {
83
83
  }
84
84
  connection.emit('data', Message.toBinary(request))
85
85
 
86
- await waitForCondition(() => connection.send.mock.calls.length > 0)
86
+ await until(() => connection.send.mock.calls.length > 0)
87
87
 
88
88
  const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
89
89
  expect(receivedMessage).toEqual({
@@ -92,7 +92,7 @@ describe('connectivityRequestHandler', () => {
92
92
  host: HOST,
93
93
  natType: 'unknown',
94
94
  ipAddress: ipv4ToNumber(HOST),
95
- version: LOCAL_PROTOCOL_VERSION
95
+ protocolVersion: LOCAL_PROTOCOL_VERSION
96
96
  },
97
97
  oneofKind: 'connectivityResponse'
98
98
  },
@@ -13,4 +13,22 @@ describe('custom matchers', () => {
13
13
  it('no match', () => {
14
14
  expect(createMockPeerDescriptor()).not.toEqualPeerDescriptor(createMockPeerDescriptor())
15
15
  })
16
+
17
+ describe('error message', () => {
18
+
19
+ it('normal', () => {
20
+ const actual = createMockPeerDescriptor()
21
+ const expected = createMockPeerDescriptor()
22
+ expect(() => {
23
+ expect(actual).toEqualPeerDescriptor(expected)
24
+ }).toThrow('PeerDescriptor nodeId values don\'t match')
25
+ })
26
+
27
+ it('inverse', () => {
28
+ const peerDescriptor = createMockPeerDescriptor()
29
+ expect(() => {
30
+ expect(peerDescriptor).not.toEqualPeerDescriptor(peerDescriptor)
31
+ }).toThrow('PeerDescriptors are equal')
32
+ })
33
+ })
16
34
  })
@@ -10,7 +10,7 @@ describe('getClosestNodes', () => {
10
10
  it('happy path', () => {
11
11
  const peerDescriptors = range(10).map(() => createMockPeerDescriptor())
12
12
  const referenceId = randomDhtAddress()
13
- const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => toNodeId(n), 2)))
13
+ const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => toNodeId(n)), 2))
14
14
 
15
15
  const actual = getClosestNodes(
16
16
  referenceId,
@@ -1,18 +1,18 @@
1
- import { isMaybeSupportedVersion } from '../../src/helpers/version'
1
+ import { isMaybeSupportedProtocolVersion } from '../../src/helpers/version'
2
2
 
3
3
  describe('version', () => {
4
4
 
5
5
  it('supported', () => {
6
- expect(isMaybeSupportedVersion('1.0')).toBe(true)
7
- expect(isMaybeSupportedVersion('1.1')).toBe(true)
8
- expect(isMaybeSupportedVersion('2.0')).toBe(true)
9
- expect(isMaybeSupportedVersion('3.5')).toBe(true)
6
+ expect(isMaybeSupportedProtocolVersion('1.0')).toBe(true)
7
+ expect(isMaybeSupportedProtocolVersion('1.1')).toBe(true)
8
+ expect(isMaybeSupportedProtocolVersion('2.0')).toBe(true)
9
+ expect(isMaybeSupportedProtocolVersion('3.5')).toBe(true)
10
10
  })
11
11
 
12
12
  it('not supported', () => {
13
- expect(isMaybeSupportedVersion('')).toBe(false)
14
- expect(isMaybeSupportedVersion('100.0.0-testnet-three.3')).toBe(false)
15
- expect(isMaybeSupportedVersion('0.0')).toBe(false)
16
- expect(isMaybeSupportedVersion('0.1')).toBe(false)
13
+ expect(isMaybeSupportedProtocolVersion('')).toBe(false)
14
+ expect(isMaybeSupportedProtocolVersion('100.0.0-testnet-three.3')).toBe(false)
15
+ expect(isMaybeSupportedProtocolVersion('0.0')).toBe(false)
16
+ expect(isMaybeSupportedProtocolVersion('0.1')).toBe(false)
17
17
  })
18
18
  })
@@ -15,8 +15,8 @@ declare global {
15
15
  }
16
16
  }
17
17
 
18
- const formErrorMessage = (description: string, expected: string | number | undefined, actual: string | number | undefined): string => {
19
- return `${description}\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
18
+ const formErrorMessage = (field: keyof PeerDescriptor, expected: string | number | undefined, actual: string | number | undefined): string => {
19
+ return `PeerDescriptor ${field} values don't match:\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
20
20
  }
21
21
 
22
22
  const toEqualPeerDescriptor = (
@@ -32,7 +32,7 @@ const toEqualPeerDescriptor = (
32
32
  messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
33
33
  }
34
34
  expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
35
- expectEqualConnectivityMethod('tpc', expected.tcp, actual.tcp, messages)
35
+ expectEqualConnectivityMethod('tcp', expected.tcp, actual.tcp, messages)
36
36
  expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
37
37
  if (expected.region !== actual.region) {
38
38
  messages.push(formErrorMessage('region', expected?.region, actual?.region))
@@ -45,13 +45,13 @@ const toEqualPeerDescriptor = (
45
45
  } else {
46
46
  return {
47
47
  pass: true,
48
- message: () => `Expected not to throw ${printReceived('StreamrClientError')}`
48
+ message: () => 'PeerDescriptors are equal'
49
49
  }
50
50
  }
51
51
  }
52
52
 
53
53
  const expectEqualConnectivityMethod = (
54
- description: string,
54
+ field: keyof PeerDescriptor,
55
55
  method1: ConnectivityMethod | undefined,
56
56
  method2: ConnectivityMethod | undefined,
57
57
  messages: string[]
@@ -62,7 +62,7 @@ const expectEqualConnectivityMethod = (
62
62
  : undefined
63
63
  }
64
64
  if (!isEqual(method1, method2)) {
65
- messages.push(formErrorMessage(description, toOutput(method1), toOutput(method2)))
65
+ messages.push(formErrorMessage(field, toOutput(method1), toOutput(method2)))
66
66
  }
67
67
  }
68
68
 
@@ -59,7 +59,6 @@ export const createTestTopology = (nodeCount: number, minNeighorCount: number):
59
59
  }
60
60
  }
61
61
  }
62
- // eslint-disable-next-line no-constant-condition
63
62
  while (true) {
64
63
  const partitions = getTopologyPartitions(topology)
65
64
  if (partitions.length === 1) {
@@ -25,7 +25,7 @@ import { v4 } from 'uuid'
25
25
  import { getRandomRegion } from '../../src/connection/simulator/pings'
26
26
  import { Empty } from '../../generated/google/protobuf/empty'
27
27
  import { Any } from '../../generated/google/protobuf/any'
28
- import { wait, waitForCondition } from '@streamr/utils'
28
+ import { wait, until } from '@streamr/utils'
29
29
  import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
30
30
  import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
31
31
 
@@ -258,7 +258,7 @@ export const waitForStableTopology = async (nodes: DhtNode[], maxConnectionCount
258
258
  await Promise.all(connectionManagers.map(async (connectionManager) => {
259
259
  connectionManager.garbageCollectConnections(maxConnectionCount, MAX_IDLE_TIME)
260
260
  try {
261
- await waitForCondition(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
261
+ await until(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
262
262
  } catch {
263
263
  // the topology is very likely stable, but we can't be sure (maybe the node has more than maxConnectionCount
264
264
  // locked connections and therefore it is ok to that garbage collector was not able to remove any of those
package/.eslintignore DELETED
@@ -1,5 +0,0 @@
1
- node_modules/**
2
- coverage/**
3
- dist/**
4
- .idea/**
5
- generated/**
package/.eslintrc DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../.eslintrc.js"
3
- }