Skip to content

Commit

Permalink
Fix tests partially
Browse files Browse the repository at this point in the history
  • Loading branch information
haadcode committed Oct 4, 2016
1 parent c5c962d commit cba3ab6
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 247 deletions.
7 changes: 1 addition & 6 deletions circle.yml
@@ -1,8 +1,3 @@
machine:
node:
version: 4.3.1
services:
- redis
dependencies:
pre:
- npm install -g npm@3.x.x
version: 6.1.0
6 changes: 4 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "orbit-db",
"version": "0.11.1",
"version": "0.11.2",
"description": "Distributed p2p database on IPFS",
"author": "Haad",
"license": "MIT",
Expand Down Expand Up @@ -30,7 +30,8 @@
"exports-loader": "^0.6.3",
"ipfs": "^0.15.0",
"ipfs-api": "https://github.com/haadcode/js-ipfs-api.git",
"ipfsd-ctl": "^0.14.0",
"go-ipfs-dep": "https://github.com/haadcode/go-ipfs-dep.git",
"ipfsd-ctl": "https://github.com/haadcode/js-ipfsd-ctl.git",
"json-loader": "^0.5.4",
"lodash": "^4.3.0",
"mocha": "^2.4.5",
Expand All @@ -39,6 +40,7 @@
"webpack": "^2.1.0-beta.7"
},
"scripts": {
"postinstall": "./scripts/post_install.sh",
"test": "mocha",
"build": "npm run build:dist && npm run build:minified && npm run build:examples",
"build:dist": "./node_modules/.bin/webpack --config webpack.config.js",
Expand Down
4 changes: 4 additions & 0 deletions scripts/post_install.sh
@@ -0,0 +1,4 @@
# !/bin/sh
rm -rf ./node_modules/ipfs/node_modules/ipfs-api
rm -rf ./node_modules/ipfsd-ctl/node_modules/go-ipfs-dep
rm -rf ./node_modules/ipfsd-ctl/node_modules/ipfs-api
59 changes: 1 addition & 58 deletions src/OrbitDB.js
Expand Up @@ -89,7 +89,7 @@ class OrbitDB {
/* Replication request from the message broker */

_onMessage(dbname, hash) {
// console.log(".MESSAGE", dbname, hash, this.stores)
console.log(".MESSAGE", dbname, hash)
const store = this.stores[dbname]
store.sync(hash)
.then((res) => Cache.set(dbname, hash))
Expand All @@ -116,63 +116,6 @@ class OrbitDB {
if(this._pubsub) this._pubsub.unsubscribe(dbname)
delete this.stores[dbname]
}

_connect(hash, username, password, allowOffline) {
if(allowOffline === undefined) allowOffline = false

const readNetworkInfo = (hash) => {
return new Promise((resolve, reject) => {
resolve(JSON.stringify({
name: 'Orbit DEV Network',
publishers: [hash]
}));
});
};

let host, port, name;
return readNetworkInfo(hash)
.then((object) => {
this.network = JSON.parse(object);
name = this.network.name;
host = this.network.publishers[0].split(":")[0];
port = this.network.publishers[0].split(":")[1];
})
.then(() => {
logger.debug(`Connecting to network ${hash} (${host}:${port})`);
return this._pubsub.connect(host, port, username, password)
})
.then(() => {
logger.debug(`Connected to network ${hash} (${host}:${port})`);
this.user = { username: username, id: username } // TODO: user id from ipfs hash
return;
})
.catch((e) => {
logger.warn(`Couldn't connect to ${hash} network: ${e.message}`);
if(!allowOffline) {
logger.debug(`'allowOffline' set to false, terminating`);
if(this._pubsub) this._pubsub.disconnect();
throw e;
}
this.user = { username: username, id: username } // TODO: user id from ipfs hash
return;
});
}
}

class OrbitClientFactory {
static connect(host, username, password, ipfs, options = { allowOffline: false }) {
// if(!options) options = { allowOffline: false };
if(!ipfs) {
logger.error("IPFS instance not provided");
throw new Error("IPFS instance not provided");
}

const client = new OrbitDB(ipfs, options);
client.user = { username: username, id: username } // TODO: user id from ipfs hash
return Promise.resolve(client)
// return client._connect(host, username, password, options.allowOffline)
// .then(() => client)
}
}

module.exports = OrbitDB;
28 changes: 12 additions & 16 deletions test/client.test.js
Expand Up @@ -15,9 +15,7 @@ const OrbitServer = require('orbit-server/src/server');
require('logplease').setLogLevel('ERROR');

// Orbit
const network = 'localhost:3333';
const username = 'testrunner';
const password = '';

let ipfs, ipfsDaemon;
const IpfsApis = [
Expand All @@ -43,27 +41,25 @@ const IpfsApis = [
name: 'js-ipfs-api',
start: () => {
return new Promise((resolve, reject) => {
// ipfsd.disposableApi((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
ipfsd.local((err, node) => {
ipfsd.disposableApi((err, ipfs) => {
if(err) reject(err);
ipfsDaemon = node;
ipfsDaemon.startDaemon((err, ipfs) => {
if(err) reject(err);
resolve(ipfs);
});
resolve(ipfs);
});
// ipfsd.local((err, node) => {
// if(err) reject(err);
// ipfsDaemon = node;
// ipfsDaemon.startDaemon((err, ipfs) => {
// if(err) reject(err);
// resolve(ipfs);
// });
// });
});
},
stop: () => Promise.resolve()
// stop: () => new Promise((resolve, reject) => ipfsDaemon.stopDaemon(resolve))
}
];

OrbitServer.start();

IpfsApis.forEach(function(ipfsApi) {

describe('Orbit Client with ' + ipfsApi.name, function() {
Expand All @@ -80,8 +76,8 @@ IpfsApis.forEach(function(ipfsApi) {
// const networkData = new Buffer(JSON.stringify({ Data: str }));
// const networkFile = await(ipfs.add(path.resolve(process.cwd(), './test/network.json')));
// assert.equal(networkFile[0].Hash, network);
client = await(OrbitDB.connect(network, username, password, ipfs, { allowOffline: true }));
client2 = await(OrbitDB.connect(network, username + "2", password, ipfs, { allowOffline: true }));
client = new OrbitDB(ipfs, username)
client2 = new OrbitDB(ipfs, username + '2')
} catch(e) {
console.log(e.stack);
assert.equal(e, null);
Expand Down

0 comments on commit cba3ab6

Please sign in to comment.