Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 80e7d81

Browse files
author
Alan Shaw
authored
fix: passed config validation (#2270)
Fixes validation for `config.Addresses.API` and `config.Addresses.Gateway` to allow array of multiaddr and adds missing `config.Swarm.ConnMgr` validation. License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 298e541 commit 80e7d81

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/core/config.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const configSchema = s({
5555
Addresses: optional(s({
5656
Delegates: optional(s(['multiaddr'])),
5757
Swarm: optional(s(['multiaddr'])),
58-
API: 'multiaddr?',
59-
Gateway: 'multiaddr'
58+
API: optional(union([s('multiaddr'), s(['multiaddr'])])),
59+
Gateway: optional(union([s('multiaddr'), s(['multiaddr'])]))
6060
})),
6161
Discovery: optional(s({
6262
MDNS: optional(s({
@@ -67,7 +67,13 @@ const configSchema = s({
6767
Enabled: 'boolean?'
6868
}))
6969
})),
70-
Bootstrap: optional(s(['multiaddr-ipfs']))
70+
Bootstrap: optional(s(['multiaddr-ipfs'])),
71+
Swarm: optional(s({
72+
ConnMgr: optional(s({
73+
LowWater: 'number?',
74+
HighWater: 'number?'
75+
}))
76+
}))
7177
})),
7278
ipld: 'object?',
7379
libp2p: optional(union(['function', 'object'])) // libp2p validates this

test/core/config.spec.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,17 @@ describe('config', () => {
123123
{ config: { Addresses: { Swarm: undefined } } },
124124

125125
{ config: { Addresses: { API: '/ip4/127.0.0.1/tcp/5002' } } },
126+
{ config: { Addresses: { API: ['/ip4/127.0.0.1/tcp/5002', '/ip4/127.0.0.1/tcp/5003'] } } },
126127
{ config: { Addresses: { API: undefined } } },
127128

128129
{ config: { Addresses: { Gateway: '/ip4/127.0.0.1/tcp/9090' } } },
130+
{ config: { Addresses: { Gateway: ['/ip4/127.0.0.1/tcp/9090', '/ip4/127.0.0.1/tcp/9091'] } } },
129131
{ config: { Addresses: { Gateway: undefined } } },
130132

133+
{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
134+
{ config: { Addresses: { Delegates: [] } } },
135+
{ config: { Addresses: { Delegates: undefined } } },
136+
131137
{ config: { Addresses: undefined } },
132138

133139
{ config: { Discovery: { MDNS: { Enabled: true } } } },
@@ -144,9 +150,10 @@ describe('config', () => {
144150
{ config: { Bootstrap: ['/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'] } },
145151
{ config: { Bootstrap: [] } },
146152

147-
{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
148-
{ config: { Addresses: { Delegates: [] } } },
149-
{ config: { Addresses: { Delegates: undefined } } },
153+
{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: 500 } } } },
154+
{ config: { Swarm: { ConnMgr: { LowWater: undefined, HighWater: undefined } } } },
155+
{ config: { Swarm: { ConnMgr: undefined } } },
156+
{ config: { Swarm: undefined } },
150157

151158
{ config: undefined }
152159
]
@@ -173,6 +180,11 @@ describe('config', () => {
173180
{ config: { Bootstrap: ['/ip4/0.0.0.0/tcp/4002'] } },
174181
{ config: { Bootstrap: 138 } },
175182

183+
{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: {} } } } },
184+
{ config: { Swarm: { ConnMgr: { LowWater: {}, HighWater: 500 } } } },
185+
{ config: { Swarm: { ConnMgr: 138 } } },
186+
{ config: { Swarm: 138 } },
187+
176188
{ config: 138 }
177189
]
178190

0 commit comments

Comments
 (0)