-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (56 loc) · 1.58 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
55
56
57
58
59
60
61
62
63
64
const IPFS =require('ipfs-core')
const tmp = require('tmp')
const getPort = require('get-port')
const OrbitDB = require('orbit-db')
const createTmpDir = () => {
return tmp.dirSync({ mode: 0o750, prefix: 'TestTmp_', unsafeCleanup: true })
}
const main = async () => {
const dir1 = createTmpDir()
const dir2 = createTmpDir()
const port1 = await getPort()
const port2 = await getPort()
const port3 = await getPort()
const port4 = await getPort()
const port5 = await getPort()
const port6 = await getPort()
const port7 = await getPort()
const port8 = await getPort()
const ipfs1 = await IPFS.create({
repo: dir1.name,
config: {
Addresses: {
Swarm: [`/ip4/0.0.0.0/tcp/${port1}`, `/ip4/127.0.0.1/tcp/${port2}/ws`],
API: `/ip4/127.0.0.1/tcp/${port3}`,
Gateway: `/ip4/127.0.0.1/tcp/${port4}`
}
}
})
const ipfs2 = await IPFS.create({
repo: dir2.name,
config: {
Addresses: {
Swarm: [`/ip4/0.0.0.0/tcp/${port5}`, `/ip4/127.0.0.1/tcp/${port6}/ws`],
API: `/ip4/127.0.0.1/tcp/${port7}`,
Gateway: `/ip4/127.0.0.1/tcp/${port8}`
}
}
})
const orbitdb1 = await OrbitDB.createInstance(ipfs1, { directory: dir1.name })
const orbitdb2 = await OrbitDB.createInstance(ipfs2, { directory: dir2.name })
const kev = await orbitdb1.keyvalue('kev', {
accessController: {
write: ['*']
}
})
const kev2 = await orbitdb2.keyvalue('kev', {
accessController: {
write: ['*']
}
})
await orbitdb1.stop()
await orbitdb2.stop()
await ipfs1.stop()
await ipfs2.stop()
}
main()