-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
347b8a4
commit 3600f3d
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { utils, errors } from '@/validation'; | ||
import * as nodesUtils from '@/nodes/utils'; | ||
|
||
describe('Validation utils', () => { | ||
describe('parseSeedNodes', () => { | ||
const nodeIdEncoded1 = 'vrsc24a1er424epq77dtoveo93meij0pc8ig4uvs9jbeld78n9nl0'; | ||
const nodeId1 = nodesUtils.decodeNodeId(nodeIdEncoded1)!; | ||
const nodeIdEncoded2 = 'vrcacp9vsb4ht25hds6s4lpp2abfaso0mptcfnh499n35vfcn2gkg'; | ||
const nodeId2 = nodesUtils.decodeNodeId(nodeIdEncoded2)!; | ||
const nodeIdEncoded3 = 'vi3et1hrpv2m2lrplcm7cu913kr45v51cak54vm68anlbvuf83ra0'; | ||
const nodeId3 = nodesUtils.decodeNodeId(nodeIdEncoded3)!; | ||
const hostname = 'testnet.polykey.io'; | ||
const hostIPv4 = '127.0.0.1'; | ||
const hostIPv6 = '[2001:db8:85a3:8d3:1319:8a2e:370:7348]'; | ||
const port1 = 1314; | ||
const port2 = 1315; | ||
const port3 = 1316; | ||
test('valid seed nodes (using hostname, IPv4, IPv6)', () => { | ||
const rawSeedNodes = | ||
`${nodeIdEncoded1}@${hostname}:${port1};` + | ||
`${nodeIdEncoded2}@${hostIPv4}:${port2};` + | ||
`${nodeIdEncoded3}@${hostIPv6}:${port3};`; | ||
const parsed = utils.parseSeedNodes(rawSeedNodes); | ||
const seeds = parsed[0]; | ||
console.log(seeds); | ||
expect(seeds[nodeId1]).toStrictEqual({ | ||
host: hostname, | ||
port: port1, | ||
}); | ||
expect(seeds[nodeId2]).toStrictEqual({ | ||
host: hostIPv4, | ||
port: port2, | ||
}); | ||
expect(seeds[nodeId3]).toStrictEqual({ | ||
host: hostIPv6.replace(/\[|\]/g, ''), | ||
port: port3, | ||
}); | ||
expect(parsed[1]).toBeFalsy(); | ||
}); | ||
test('invalid node ID', () => { | ||
const rawSeedNodes = `INVALIDNODEID@${hostname}:${port1}`; | ||
expect(() => utils.parseSeedNodes(rawSeedNodes)).toThrow(errors.ErrorParse); | ||
}); | ||
test('invalid hostname', () => { | ||
const rawSeedNodes = `${nodeIdEncoded1}@$invalidHost:${port1}`; | ||
expect(() => utils.parseSeedNodes(rawSeedNodes)).toThrow(errors.ErrorParse); | ||
}); | ||
test('invalid port', () => { | ||
const rawSeedNodes = `${nodeIdEncoded1}@${hostname}$:NOTAPORT`; | ||
// TODO: currently failing here | ||
expect(() => utils.parseSeedNodes(rawSeedNodes)).toThrow(errors.ErrorParse); | ||
}); | ||
test('invalid structure', () => { | ||
const rawSeedNodes = `` | ||
}); | ||
// TODO: remove - just testing this weird behaviour | ||
test.only('invalid', () => { | ||
expect(() => { | ||
new URL('bad URL'); | ||
}).toThrowError(TypeError) | ||
// try { | ||
// new URL('bad url'); | ||
// } catch (e) { | ||
// if (e instanceof TypeError) { | ||
// console.log('TypeError') | ||
// } | ||
// } | ||
}); | ||
}); | ||
}); |