forked from holepunchto/autopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
54 lines (40 loc) · 1.2 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const test = require('brittle')
const Autopass = require('./')
const Corestore = require('corestore')
const testnet = require('hyperdht/testnet')
const tmp = require('test-tmp')
test('basic', async function (t) {
const a = await create(t, { replicate: false })
await a.add('hello', 'world')
t.ok(a.base.encryptionKey)
t.is(await a.get('hello'), 'world')
await a.close()
})
test('invites', async function (t) {
t.plan(2)
const tn = await testnet(10, t)
const a = await create(t, { bootstrap: tn.bootstrap })
t.teardown(() => a.close())
a.on('update', function () {
if (a.base.system.members === 2) t.pass('a has two members')
})
const inv = await a.createInvite()
const p = await pair(t, inv, { bootstrap: tn.bootstrap })
const b = await p.finished()
await b.ready()
t.teardown(() => b.close())
b.on('update', function () {
if (b.base.system.members === 2) t.pass('b has two members')
})
})
async function create (t, opts) {
const dir = await tmp(t)
const a = new Autopass(new Corestore(dir), opts)
await a.ready()
return a
}
async function pair (t, inv, opts) {
const dir = await tmp(t)
const a = Autopass.pair(new Corestore(dir), inv, opts)
return a
}