This repository has been archived by the owner on Aug 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathorbit.test.js
71 lines (61 loc) · 1.79 KB
/
orbit.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
65
66
67
68
69
70
71
'use strict';
const _ = require('lodash');
const path = require('path');
const assert = require('assert');
const IPFS = require('exports?Ipfs!ipfs/dist/index.js');
const EventStore = require('orbit-db-eventstore');
const Post = require('ipfs-post');
const Main = require('../src/main');
// Mute logging
const Logger = require('logplease');
Logger.setLogLevel('ERROR');
describe('Orbit Skynet', function() {
this.timeout(60000);
let clients = [];
before(function (done) {
const amount = 3;
let bots = [];
for(var i = 0; i < amount; i ++) {
bots.push({ id: i, name: `Orbit-${i}` });
}
const promises = bots.map((bot) => {
return Main.start(bot.id)
.then((res) => {
Object.assign(bot, { orbit: res });
return bot;
})
.then(() => bot);
});
Promise.all(promises)
.then((res) => {
clients = res;
assert.equal(clients.length, amount);
console.log("Waiting 5 seconds for the peers to connect...")
setTimeout(done, 5000);
})
.catch((e) => {
console.log(e.stack);
assert.equal(e, null);
done();
});
});
after((done) => {
clients.forEach((e) => e.orbit.disconnect());
done();
});
describe('constructor', function() {
it.only('creates an instance', (done) => {
console.log();
Promise.all(clients.map((e) => {
return e.orbit.getSwarmPeers().then((peers) => {
console.log(`${e.name}'s peers:`);
peers.forEach((e) => console.log(e));
console.log();
assert.equal(peers.length, 2); // passes
assert.equal(peers[0], '1'); // TODO
assert.equal(peers[0], '2'); // TODO
});
})).then((res) => done())
});
});
});