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

fix: passed config validation #2270

Merged
merged 3 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ const configSchema = s({
Addresses: optional(s({
Delegates: optional(s(['multiaddr'])),
Swarm: optional(s(['multiaddr'])),
API: 'multiaddr?',
Gateway: 'multiaddr'
API: optional(union([s('multiaddr'), s(['multiaddr'])])),
Gateway: optional(union([s('multiaddr'), s(['multiaddr'])]))
})),
Discovery: optional(s({
MDNS: optional(s({
Expand All @@ -67,7 +67,13 @@ const configSchema = s({
Enabled: 'boolean?'
}))
})),
Bootstrap: optional(s(['multiaddr-ipfs']))
Bootstrap: optional(s(['multiaddr-ipfs'])),
Swarm: optional(s({
ConnMgr: optional(s({
LowWater: 'number?',
HighWater: 'number?'
}))
}))
})),
ipld: 'object?',
libp2p: optional(union(['function', 'object'])) // libp2p validates this
Expand Down
18 changes: 15 additions & 3 deletions test/core/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ describe('config', () => {
{ config: { Addresses: { Swarm: undefined } } },

{ config: { Addresses: { API: '/ip4/127.0.0.1/tcp/5002' } } },
{ config: { Addresses: { API: ['/ip4/127.0.0.1/tcp/5002', '/ip4/127.0.0.1/tcp/5003'] } } },
{ config: { Addresses: { API: undefined } } },

{ config: { Addresses: { Gateway: '/ip4/127.0.0.1/tcp/9090' } } },
{ config: { Addresses: { Gateway: ['/ip4/127.0.0.1/tcp/9090', '/ip4/127.0.0.1/tcp/9091'] } } },
{ config: { Addresses: { Gateway: undefined } } },

{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
{ config: { Addresses: { Delegates: [] } } },
{ config: { Addresses: { Delegates: undefined } } },

{ config: { Addresses: undefined } },

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

{ config: { Addresses: { Delegates: ['/dns4/node0.preload.ipfs.io/tcp/443/https'] } } },
{ config: { Addresses: { Delegates: [] } } },
{ config: { Addresses: { Delegates: undefined } } },
{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: 500 } } } },
{ config: { Swarm: { ConnMgr: { LowWater: undefined, HighWater: undefined } } } },
{ config: { Swarm: { ConnMgr: undefined } } },
{ config: { Swarm: undefined } },

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

{ config: { Swarm: { ConnMgr: { LowWater: 200, HighWater: {} } } } },
{ config: { Swarm: { ConnMgr: { LowWater: {}, HighWater: 500 } } } },
{ config: { Swarm: { ConnMgr: 138 } } },
{ config: { Swarm: 138 } },

{ config: 138 }
]

Expand Down