mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-06 14:16:37 +00:00
Remove seq and ver, use only IPFS hash for ordering. Remove dependency on POST for db operations.
This commit is contained in:
parent
3fb6261ee9
commit
55eac964d7
@ -25,8 +25,8 @@ DB
|
|||||||
|
|
||||||
### CRDTs
|
### CRDTs
|
||||||
- orbit-db is a CmRDT and implements an LWW-element-set
|
- orbit-db is a CmRDT and implements an LWW-element-set
|
||||||
- operation-based CRDT
|
- Operation-based CRDT
|
||||||
- (locally biased) vector clocks for partial ordering
|
- Uses Merkle Trees for partial ordering
|
||||||
|
|
||||||
### add/put IO:
|
### add/put IO:
|
||||||
==> Not expensive
|
==> Not expensive
|
||||||
|
@ -38,7 +38,7 @@ let run = (async(() => {
|
|||||||
console.log("---------------------------------------------------")
|
console.log("---------------------------------------------------")
|
||||||
console.log("Key | Value")
|
console.log("Key | Value")
|
||||||
console.log("---------------------------------------------------")
|
console.log("---------------------------------------------------")
|
||||||
console.log(items.map((e) => `${e.key} | ${e.value.content}`).join("\n"));
|
console.log(items.map((e) => `${e.key} | ${e.value}`).join("\n"));
|
||||||
console.log("---------------------------------------------------")
|
console.log("---------------------------------------------------")
|
||||||
console.log(`Query 2 #${count} took ${timer2.stop(true)} ms\n`);
|
console.log(`Query 2 #${count} took ${timer2.stop(true)} ms\n`);
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ class OrbitDB {
|
|||||||
// Get items from the db
|
// Get items from the db
|
||||||
query(channel, password, opts) {
|
query(channel, password, opts) {
|
||||||
// console.log("--> Query:", channel, opts);
|
// console.log("--> Query:", channel, opts);
|
||||||
|
|
||||||
if(!opts) opts = {};
|
if(!opts) opts = {};
|
||||||
|
|
||||||
const operations = Lazy(this._logs[channel].items);
|
const operations = Lazy(this._logs[channel].items);
|
||||||
@ -51,7 +50,7 @@ class OrbitDB {
|
|||||||
|
|
||||||
if(opts.key) {
|
if(opts.key) {
|
||||||
// Key-Value, search latest key first
|
// Key-Value, search latest key first
|
||||||
result = this._read(operations.reverse(), opts.key, 1, true).map((f) => f.value.content);
|
result = this._read(operations.reverse(), opts.key, 1, true).map((f) => f.value);
|
||||||
} else if(opts.gt || opts.gte) {
|
} else if(opts.gt || opts.gte) {
|
||||||
// Greater than case
|
// Greater than case
|
||||||
result = this._read(operations, opts.gt ? opts.gt : opts.gte, amount, opts.gte ? opts.gte : false)
|
result = this._read(operations, opts.gt ? opts.gt : opts.gte, amount, opts.gte ? opts.gte : false)
|
||||||
@ -68,25 +67,17 @@ class OrbitDB {
|
|||||||
|
|
||||||
// Adds an event to the log
|
// Adds an event to the log
|
||||||
add(channel, password, data) {
|
add(channel, password, data) {
|
||||||
let post;
|
return await(this._write(channel, password, DBOperation.Types.Add, null, data));
|
||||||
if(data.Post) {
|
|
||||||
post = data;
|
|
||||||
} else {
|
|
||||||
// Handle everything else as a string
|
|
||||||
post = await(Post.create(this._ipfs, Post.Types.Message, { content: data }));
|
|
||||||
}
|
|
||||||
return await(this._write(channel, password, DBOperation.Types.Add, post.Hash, post.Hash));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a key-value pair
|
// Sets a key-value pair
|
||||||
put(channel, password, key, data) {
|
put(channel, password, key, data) {
|
||||||
const post = await(Post.create(this._ipfs, Post.Types.Message, { content: data }));
|
return await(this._write(channel, password, DBOperation.Types.Put, key, data));
|
||||||
return await(this._write(channel, password, DBOperation.Types.Put, key, post.Hash));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes an event based on hash (of the operation) or 'key' of a key/val pair
|
// Deletes an event based on hash (of the operation) or 'key' of a key/val pair
|
||||||
del(channel, password, hash) {
|
del(channel, password, key) {
|
||||||
return await(this._write(channel, password, DBOperation.Types.Delete, hash, null));
|
return await(this._write(channel, password, DBOperation.Types.Delete, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteChannel(channel, password) {
|
deleteChannel(channel, password) {
|
||||||
@ -101,9 +92,11 @@ class OrbitDB {
|
|||||||
// Last-Write-Wins, ie. use only the first occurance of the key
|
// Last-Write-Wins, ie. use only the first occurance of the key
|
||||||
let handled = [];
|
let handled = [];
|
||||||
const _createLWWSet = (item) => {
|
const _createLWWSet = (item) => {
|
||||||
const wasHandled = Lazy(handled).indexOf(item.key) > -1;
|
if(Lazy(handled).indexOf(item.key) === -1) {
|
||||||
if(!wasHandled) handled.push(item.key);
|
handled.push(item.key);
|
||||||
if(DBOperation.Types.isInsert(item.op) && !wasHandled) return item;
|
if(DBOperation.Types.isInsert(item.op))
|
||||||
|
return item;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,8 +113,9 @@ class OrbitDB {
|
|||||||
// Write an op to the db
|
// Write an op to the db
|
||||||
_write(channel, password, operation, key, value) {
|
_write(channel, password, operation, key, value) {
|
||||||
const hash = await(DBOperation.create(this._ipfs, this._logs[channel], this.user, operation, key, value));
|
const hash = await(DBOperation.create(this._ipfs, this._logs[channel], this.user, operation, key, value));
|
||||||
this.events[channel].emit('write', channel, hash);
|
const listHash = await(this._logs[channel].ipfsHash);
|
||||||
return key;
|
this.events[channel].emit('write', channel, listHash);
|
||||||
|
return hash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@ const OpTypes = {
|
|||||||
Add: "ADD",
|
Add: "ADD",
|
||||||
Put: "PUT",
|
Put: "PUT",
|
||||||
Delete: "DELETE",
|
Delete: "DELETE",
|
||||||
isInsert: (op) => op === "ADD" || op === "PUT"
|
isInsert: (op) => op === "ADD" || op === "PUT",
|
||||||
|
isDelete: (op) => op === "DELETE"
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = OpTypes;
|
module.exports = OpTypes;
|
||||||
|
@ -12,8 +12,7 @@ class Operation {
|
|||||||
return new Promise(async((resolve, reject) => {
|
return new Promise(async((resolve, reject) => {
|
||||||
const hash = await(Operation._createOperation(ipfs, user, operation, key, value));
|
const hash = await(Operation._createOperation(ipfs, user, operation, key, value));
|
||||||
await(log.add(hash));
|
await(log.add(hash));
|
||||||
const listHash = await(log.ipfsHash);
|
resolve(hash);
|
||||||
resolve(listHash);
|
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
return await(createAsync());
|
return await(createAsync());
|
||||||
|
@ -7,8 +7,8 @@ const Node = require('./Node');
|
|||||||
class List {
|
class List {
|
||||||
constructor(id, seq, ver, items) {
|
constructor(id, seq, ver, items) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.seq = seq || 0;
|
// this.seq = seq || 0;
|
||||||
this.ver = ver || 0;
|
// this.ver = ver || 0;
|
||||||
this._items = items || [];
|
this._items = items || [];
|
||||||
this._currentBatch = [];
|
this._currentBatch = [];
|
||||||
}
|
}
|
||||||
@ -16,14 +16,14 @@ class List {
|
|||||||
/* Methods */
|
/* Methods */
|
||||||
add(data) {
|
add(data) {
|
||||||
const heads = List.findHeads(this.items);
|
const heads = List.findHeads(this.items);
|
||||||
const node = new Node(this.id, this.seq, this.ver, data, heads);
|
const node = new Node(this.id, -1, -1, data, heads);
|
||||||
this._currentBatch.push(node);
|
this._currentBatch.push(node);
|
||||||
this.ver ++;
|
// this.ver ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
join(other) {
|
join(other) {
|
||||||
this.seq = (other.seq && other.seq > this.seq ? other.seq : this.seq) + 1;
|
// this.seq = (other.seq && other.seq > this.seq ? other.seq : this.seq) + 1;
|
||||||
this.ver = 0;
|
// this.ver = 0;
|
||||||
// TODO: figure out how to do real equality check with Lazy.js
|
// TODO: figure out how to do real equality check with Lazy.js
|
||||||
// const current = Lazy(this._currentBatch).difference(this._items);
|
// const current = Lazy(this._currentBatch).difference(this._items);
|
||||||
// const others = Lazy(other.items).difference(current.toA);
|
// const others = Lazy(other.items).difference(current.toA);
|
||||||
@ -39,8 +39,8 @@ class List {
|
|||||||
clear() {
|
clear() {
|
||||||
this._items = [];
|
this._items = [];
|
||||||
this._currentBatch = [];
|
this._currentBatch = [];
|
||||||
this.seq = 0;
|
// this.seq = 0;
|
||||||
this.ver = 0;
|
// this.ver = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Private methods */
|
/* Private methods */
|
||||||
@ -48,8 +48,8 @@ class List {
|
|||||||
const current = Lazy(this._currentBatch).difference(this._items).toArray();
|
const current = Lazy(this._currentBatch).difference(this._items).toArray();
|
||||||
this._items = this._items.concat(current);
|
this._items = this._items.concat(current);
|
||||||
this._currentBatch = [];
|
this._currentBatch = [];
|
||||||
this.ver = 0;
|
// this.ver = 0;
|
||||||
this.seq ++;
|
// this.seq ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Properties */
|
/* Properties */
|
||||||
@ -58,14 +58,15 @@ class List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get compactId() {
|
get compactId() {
|
||||||
return "" + this.id + "." + this.seq + "." + this.ver;
|
// return "" + this.id + "." + this.seq + "." + this.ver;
|
||||||
|
return "" + this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
get asJson() {
|
get asJson() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
seq: this.seq,
|
// seq: this.seq,
|
||||||
ver: this.ver,
|
// ver: this.ver,
|
||||||
items: this._currentBatch.map((f) => f.asJson)
|
items: this._currentBatch.map((f) => f.asJson)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -73,10 +74,11 @@ class List {
|
|||||||
/* Static methods */
|
/* Static methods */
|
||||||
static fromJson(json) {
|
static fromJson(json) {
|
||||||
let list = new List(json.id);
|
let list = new List(json.id);
|
||||||
list.seq = json.seq;
|
// list.seq = json.seq;
|
||||||
list.ver = json.ver;
|
// list.ver = json.ver;
|
||||||
list._items = Lazy(json.items)
|
list._items = Lazy(json.items)
|
||||||
.map((f) => new Node(f.id, f.seq, f.ver, f.data, f.next))
|
// .map((f) => new Node(f.id, f.seq, f.ver, f.data, f.next))
|
||||||
|
.map((f) => new Node(f.id, -1, -1, f.data, f.next))
|
||||||
.unique()
|
.unique()
|
||||||
.toArray();
|
.toArray();
|
||||||
return list;
|
return list;
|
||||||
|
@ -6,11 +6,13 @@ class Node {
|
|||||||
this.seq = seq;
|
this.seq = seq;
|
||||||
this.ver = ver;
|
this.ver = ver;
|
||||||
this.data = data || null;
|
this.data = data || null;
|
||||||
this.next = next ? next.map((f) => f.compactId ? f.compactId : f) : [];
|
// this.next = next ? next.map((f) => f.compactId ? f.compactId : f) : [];
|
||||||
|
this.next = next ? next.map((f) => f.id ? f.id : f) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
hasChild(a) {
|
hasChild(a) {
|
||||||
const id = a.compactId;
|
// const id = a.compactId;
|
||||||
|
const id = a.id;
|
||||||
for(let i = 0; i < this.next.length; i++) {
|
for(let i = 0; i < this.next.length; i++) {
|
||||||
if(this.next[i] === id)
|
if(this.next[i] === id)
|
||||||
return true;
|
return true;
|
||||||
@ -19,19 +21,23 @@ class Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get compactId() {
|
get compactId() {
|
||||||
return "" + this.id + "." + this.seq + "." + this.ver;
|
return "" + this.id;
|
||||||
|
// return "" + this.id + "." + this.seq + "." + this.ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
get heads() {
|
get heads() {
|
||||||
return Object.keys(this.next).map((e) => this.next[e]);
|
// return Object.keys(this.next).map((e) => this.next[e]);
|
||||||
|
return this.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
get asJson() {
|
get asJson() {
|
||||||
return { id: this.id, seq: this.seq, ver: this.ver, data: this.data, next: this.next };
|
// return { id: this.id, seq: this.seq, ver: this.ver, data: this.data, next: this.next };
|
||||||
|
return { id: this.id, data: this.data, next: this.next };
|
||||||
}
|
}
|
||||||
|
|
||||||
static equals(a, b) {
|
static equals(a, b) {
|
||||||
return a.id === b.id && a.seq === b.seq && a.ver === b.ver;
|
// return a.id === b.id && a.seq === b.seq && a.ver === b.ver;
|
||||||
|
return a.id === b.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,39 +1,47 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const Lazy = require('lazy.js');
|
const Lazy = require('lazy.js');
|
||||||
const async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
const await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
const ipfsAPI = require('orbit-common/lib/ipfs-api-promised');
|
const OrbitNode = require('./OrbitNode');
|
||||||
const List = require('./List');
|
|
||||||
const OrbitNode = require('./OrbitNode');
|
|
||||||
|
|
||||||
const MaxBatchSize = 10; // How many items per sequence. Saves a snapshot to ipfs in batches of this many items.
|
const MaxBatchSize = 10; // How many items per sequence. Saves a snapshot to ipfs in batches of this many items.
|
||||||
const MaxHistory = 256; // How many items to fetch in the chain per join
|
const MaxHistory = 256; // How many items to fetch in the chain per join
|
||||||
|
|
||||||
// class IPFSLWWSet extends LWWSet {
|
// class IPFSLWWSet extends LWWSet {
|
||||||
class OrbitList extends List {
|
class OrbitList {
|
||||||
constructor(ipfs, id, seq, ver, items) {
|
constructor(ipfs, id, seq, ver, items) {
|
||||||
super(id, seq, ver, items);
|
this.id = id;
|
||||||
this._ipfs = ipfs;
|
this._ipfs = ipfs;
|
||||||
|
this._items = items || [];
|
||||||
|
this._currentBatch = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
add(data) {
|
add(data) {
|
||||||
if(this.ver >= MaxBatchSize)
|
if(this._currentBatch.length >= MaxBatchSize)
|
||||||
this._commit();
|
this._commit();
|
||||||
|
|
||||||
const heads = List.findHeads(this.items);
|
const heads = OrbitList.findHeads(this.items);
|
||||||
const node = new OrbitNode(this._ipfs, this.id, this.seq, this.ver, data, heads);
|
const node = new OrbitNode(this._ipfs, this.id, data, heads);
|
||||||
this._currentBatch.push(node);
|
this._currentBatch.push(node);
|
||||||
this.ver ++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
join(other) {
|
join(other) {
|
||||||
super.join(other);
|
const current = _.differenceWith(this._currentBatch, this._items, OrbitNode.equals);
|
||||||
|
const others = _.differenceWith(other.items, this._items, OrbitNode.equals);
|
||||||
|
const final = _.unionWith(current, others, OrbitNode.equals);
|
||||||
|
this._items = Lazy(this._items).concat(final).toArray();
|
||||||
|
this._currentBatch = [];
|
||||||
const history = _.flatten(await(this._fetchHistory(other.items)));
|
const history = _.flatten(await(this._fetchHistory(other.items)));
|
||||||
history.forEach((f) => this._insert(f)) // Insert to the list
|
history.forEach((f) => this._insert(f)) // Insert to the list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
this._items = [];
|
||||||
|
this._currentBatch = [];
|
||||||
|
}
|
||||||
|
|
||||||
/* Private methods */
|
/* Private methods */
|
||||||
_fetchHistory(items) {
|
_fetchHistory(items) {
|
||||||
var _fetchAsync = async(() => {
|
var _fetchAsync = async(() => {
|
||||||
@ -41,7 +49,7 @@ class OrbitList extends List {
|
|||||||
let allHashes = this._items.map((a) => a.hash);
|
let allHashes = this._items.map((a) => a.hash);
|
||||||
const handle = Lazy(items)
|
const handle = Lazy(items)
|
||||||
.reverse() // Start from the latest item
|
.reverse() // Start from the latest item
|
||||||
.map((f) => f.heads).flatten() // Go through all heads
|
.map((f) => f.next).flatten() // Go through all heads
|
||||||
.filter((f) => !(f instanceof OrbitNode === true)) // OrbitNode vs. {}, filter out instances (we already have them in mem)
|
.filter((f) => !(f instanceof OrbitNode === true)) // OrbitNode vs. {}, filter out instances (we already have them in mem)
|
||||||
.async() // Do the next map asynchronously
|
.async() // Do the next map asynchronously
|
||||||
.map(async((f) => _.flatten(await(this._fetchRecursive(f, allHashes, MaxHistory, 0))))) // IO - fetch items recursively
|
.map(async((f) => _.flatten(await(this._fetchRecursive(f, allHashes, MaxHistory, 0))))) // IO - fetch items recursively
|
||||||
@ -67,24 +75,25 @@ class OrbitList extends List {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isReferenced(all, hash)) {
|
if(isReferenced(all, hash)) {
|
||||||
const item = await(OrbitNode.fromIpfsHash(this._ipfs, hash)); // IO - get from IPFS
|
resolve(result);
|
||||||
result.push(item);
|
return;
|
||||||
all.push(hash);
|
|
||||||
depth ++;
|
|
||||||
|
|
||||||
const handle = Lazy(item.heads)
|
|
||||||
.async()
|
|
||||||
.map(async((f) => _.flatten(await(this._fetchRecursive(f, all, amount, depth)))))
|
|
||||||
.toArray()
|
|
||||||
|
|
||||||
handle.onComplete((res) => {
|
|
||||||
result = result.concat(res);
|
|
||||||
resolve(result);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const item = await(OrbitNode.fromIpfsHash(this._ipfs, hash)); // IO - get from IPFS
|
||||||
|
result.push(item);
|
||||||
|
all.push(hash);
|
||||||
|
depth ++;
|
||||||
|
|
||||||
|
const handle = Lazy(item.next)
|
||||||
|
.async()
|
||||||
|
.map(async((f) => _.flatten(await(this._fetchRecursive(f, all, amount, depth)))))
|
||||||
|
.toArray()
|
||||||
|
|
||||||
|
handle.onComplete((res) => {
|
||||||
|
result = result.concat(res);
|
||||||
|
resolve(result);
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
return await(_fetchAsync());
|
return await(_fetchAsync());
|
||||||
@ -92,18 +101,28 @@ class OrbitList extends List {
|
|||||||
|
|
||||||
// Insert to the list right after the latest parent
|
// Insert to the list right after the latest parent
|
||||||
_insert(item) {
|
_insert(item) {
|
||||||
let indices = Lazy(item.heads).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
|
let indices = Lazy(item.next).map((next) => Lazy(this._items).map((f) => f.hash).indexOf(next)) // Find the item's parent's indices
|
||||||
const index = indices.length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
|
const index = indices.length > 0 ? Math.max(indices.max() + 1, 0) : 0; // find the largest index (latest parent)
|
||||||
this._items.splice(index, 0, item);
|
this._items.splice(index, 0, item);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_commit() {
|
||||||
|
const current = Lazy(this._currentBatch).difference(this._items).toArray();
|
||||||
|
this._items = this._items.concat(current);
|
||||||
|
this._currentBatch = [];
|
||||||
|
}
|
||||||
|
|
||||||
/* Properties */
|
/* Properties */
|
||||||
|
get items() {
|
||||||
|
return this._items.concat(this._currentBatch);
|
||||||
|
}
|
||||||
|
|
||||||
get ipfsHash() {
|
get ipfsHash() {
|
||||||
const toIpfs = async(() => {
|
const toIpfs = async(() => {
|
||||||
return new Promise(async((resolve, reject) => {
|
return new Promise(async((resolve, reject) => {
|
||||||
var data = await(this.asJson)
|
var data = await(this.asJson)
|
||||||
const list = await(ipfsAPI.putObject(this._ipfs, JSON.stringify(data)));
|
const list = await(this._ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(data) }))));
|
||||||
resolve(list.Hash);
|
resolve(list.Hash);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
@ -112,23 +131,30 @@ class OrbitList extends List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get asJson() {
|
get asJson() {
|
||||||
let items = {};
|
|
||||||
this._currentBatch.forEach((f) => {
|
|
||||||
if(!items[f.compactId.toString()])
|
|
||||||
Object.defineProperty(items, f.compactId.toString(), { value: await(f.ipfsHash), enumerable: true });
|
|
||||||
});
|
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: this.id,
|
||||||
seq: this.seq,
|
items: this._currentBatch.map((f) => await(f.ipfsHash))
|
||||||
ver: this.ver,
|
|
||||||
items: items
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static findHeads(list) {
|
||||||
|
return Lazy(list)
|
||||||
|
.reverse()
|
||||||
|
.indexBy((f) => f.id)
|
||||||
|
.pairs()
|
||||||
|
.map((f) => f[1])
|
||||||
|
.filter((f) => !OrbitList.isReferencedInChain(list, f))
|
||||||
|
.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
static isReferencedInChain(all, item) {
|
||||||
|
return Lazy(all).reverse().find((e) => e.hasChild(item)) !== undefined;
|
||||||
|
}
|
||||||
|
|
||||||
static fromIpfsHash(ipfs, hash) {
|
static fromIpfsHash(ipfs, hash) {
|
||||||
const fromIpfs = async(() => {
|
const fromIpfs = async(() => {
|
||||||
return new Promise(async((resolve, reject) => {
|
return new Promise(async((resolve, reject) => {
|
||||||
const l = await(ipfsAPI.getObject(ipfs, hash));
|
const l = await(ipfs.object.get(hash));
|
||||||
const list = OrbitList.fromJson(ipfs, JSON.parse(l.Data));
|
const list = OrbitList.fromJson(ipfs, JSON.parse(l.Data));
|
||||||
resolve(list);
|
resolve(list);
|
||||||
}));
|
}));
|
||||||
@ -137,8 +163,8 @@ class OrbitList extends List {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static fromJson(ipfs, json) {
|
static fromJson(ipfs, json) {
|
||||||
const items = Object.keys(json.items).map((f) => await(OrbitNode.fromIpfsHash(ipfs, json.items[f])));
|
const items = json.items.map((f) => await(OrbitNode.fromIpfsHash(ipfs, f)));
|
||||||
return new OrbitList(ipfs, json.id, json.seq, json.ver, items);
|
return new OrbitList(ipfs, json.id, -1, -1, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
static get batchSize() {
|
static get batchSize() {
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
const await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
const ipfsAPI = require('orbit-common/lib/ipfs-api-promised');
|
|
||||||
const Node = require('./Node');
|
|
||||||
|
|
||||||
class OrbitNode extends Node {
|
class OrbitNode {
|
||||||
constructor(ipfs, id, seq, ver, data, next, hash) {
|
constructor(ipfs, id, data, next, hash) {
|
||||||
super(id, seq, ver, data);
|
|
||||||
this.hash = null;
|
|
||||||
this._ipfs = ipfs;
|
this._ipfs = ipfs;
|
||||||
|
this.id = id;
|
||||||
|
this.data = data || null;
|
||||||
this.next = next || [];
|
this.next = next || [];
|
||||||
this.hash = hash ? hash : this.ipfsHash;
|
this.hash = hash ? hash : this.ipfsHash;
|
||||||
}
|
}
|
||||||
@ -17,44 +15,37 @@ class OrbitNode extends Node {
|
|||||||
fetchPayload() {
|
fetchPayload() {
|
||||||
return new Promise(async((resolve, reject) => {
|
return new Promise(async((resolve, reject) => {
|
||||||
if(!this.Payload) {
|
if(!this.Payload) {
|
||||||
const payload = await(ipfsAPI.getObject(this._ipfs, this.data));
|
const payload = await(this._ipfs.object.get(this.data));
|
||||||
this.Payload = JSON.parse(payload.Data);
|
this.Payload = JSON.parse(payload.Data);
|
||||||
if(this.Payload.value) {
|
|
||||||
const value = await(ipfsAPI.getObject(this._ipfs, this.Payload.value));
|
|
||||||
this.Payload.value = JSON.parse(value.Data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let res = this.Payload;
|
let res = this.Payload;
|
||||||
Object.assign(res, { hash: this.data });
|
Object.assign(res, { hash: this.data });
|
||||||
|
if(this.Payload.key === null)
|
||||||
|
Object.assign(res, { key: this.data });
|
||||||
resolve(res);
|
resolve(res);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
hasChild(a) {
|
hasChild(a) {
|
||||||
const id = a.compactId;
|
const id = a;
|
||||||
for(let i = 0; i < this.next.length; i++) {
|
for(let i = 0; i < this.next.length; i++) {
|
||||||
if(this.next[i].compactId === id)
|
if(this.next[i] === id)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_commit() {
|
get ipfsHash() {
|
||||||
if(!this.hash) {
|
if(!this.hash) {
|
||||||
const r = await(ipfsAPI.putObject(this._ipfs, JSON.stringify(this.asJson)));
|
const r = await(this._ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(this.asJson) }))));
|
||||||
this.hash = r.Hash;
|
this.hash = r.Hash;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get ipfsHash() {
|
|
||||||
await(this._commit());
|
|
||||||
return this.hash;
|
return this.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
get asJson() {
|
get asJson() {
|
||||||
let res = { id: this.id, seq: this.seq, ver: this.ver, data: this.data }
|
let res = { id: this.id, data: this.data }
|
||||||
let items = {};
|
let items = this.next.map((f) => f.ipfsHash);
|
||||||
this.next.forEach((f) => Object.defineProperty(items, f.compactId.toString(), { value: f.ipfsHash, enumerable: true }));
|
|
||||||
Object.assign(res, { next: items });
|
Object.assign(res, { next: items });
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -62,14 +53,18 @@ class OrbitNode extends Node {
|
|||||||
static fromIpfsHash(ipfs, hash) {
|
static fromIpfsHash(ipfs, hash) {
|
||||||
const createNode = async(() => {
|
const createNode = async(() => {
|
||||||
return new Promise(async((resolve, reject) => {
|
return new Promise(async((resolve, reject) => {
|
||||||
const o = await(ipfsAPI.getObject(ipfs, hash));
|
const o = await(ipfs.object.get(hash));
|
||||||
const f = JSON.parse(o.Data)
|
const f = JSON.parse(o.Data)
|
||||||
const node = new OrbitNode(ipfs, f.id, f.seq, f.ver, f.data, f.next, hash)
|
const node = new OrbitNode(ipfs, f.id, f.data, f.next, hash)
|
||||||
resolve(node);
|
resolve(node);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
return await(createNode());
|
return await(createNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static equals(a, b) {
|
||||||
|
return a.hash === b.hash;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = OrbitNode;
|
module.exports = OrbitNode;
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
const async = require('asyncawait/async');
|
const async = require('asyncawait/async');
|
||||||
const await = require('asyncawait/await');
|
const await = require('asyncawait/await');
|
||||||
const ipfsAPI = require('orbit-common/lib/ipfs-api-promised');
|
|
||||||
const Encryption = require('orbit-common/lib/Encryption');
|
|
||||||
|
|
||||||
const Post = require('./BasePost');
|
const Post = require('./BasePost');
|
||||||
const TextPost = require('./TextPost');
|
const TextPost = require('./TextPost');
|
||||||
@ -40,7 +38,7 @@ class Posts {
|
|||||||
const size = data.size ? data.size : Buffer.byteLength(data, 'utf8');
|
const size = data.size ? data.size : Buffer.byteLength(data, 'utf8');
|
||||||
post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from);
|
post.meta = new MetaInfo(post.type, size, new Date().getTime(), data.from);
|
||||||
if(post.type) delete post.type;
|
if(post.type) delete post.type;
|
||||||
const res = await (ipfsAPI.putObject(ipfs, JSON.stringify(post)));
|
const res = await(ipfs.object.put(new Buffer(JSON.stringify({ Data: JSON.stringify(post) })), "json"));
|
||||||
resolve({ Post: post, Hash: res.Hash });
|
resolve({ Post: post, Hash: res.Hash });
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,67 +1,67 @@
|
|||||||
'use strict';
|
// 'use strict';
|
||||||
|
|
||||||
const assert = require('assert');
|
// const assert = require('assert');
|
||||||
const List = require('../src/list/List');
|
// const List = require('../src/list/List');
|
||||||
const Node = require('../src/list/Node');
|
// const Node = require('../src/list/Node');
|
||||||
|
|
||||||
describe('Node', () => {
|
// describe('Node', () => {
|
||||||
describe('Constructor', () => {
|
// describe('Constructor', () => {
|
||||||
it('initializes member variables', (done) => {
|
// it('initializes member variables', (done) => {
|
||||||
const node = new Node('A', 0, 0, 'hello', []);
|
// const node = new Node('A', 0, 0, 'hello', []);
|
||||||
assert.equal(node.id, 'A');
|
// assert.equal(node.id, 'A');
|
||||||
assert.equal(node.seq, 0);
|
// assert.equal(node.seq, 0);
|
||||||
assert.equal(node.ver, 0);
|
// assert.equal(node.ver, 0);
|
||||||
assert.equal(node.data, 'hello');
|
// assert.equal(node.data, 'hello');
|
||||||
assert.equal(node.next instanceof Array, true);
|
// assert.equal(node.next instanceof Array, true);
|
||||||
done();
|
// done();
|
||||||
});
|
// });
|
||||||
|
|
||||||
it('initializes member variables without specified data and next', (done) => {
|
// it('initializes member variables without specified data and next', (done) => {
|
||||||
const node = new Node('A', 0, 0);
|
// const node = new Node('A', 0, 0);
|
||||||
assert.equal(node.id, 'A');
|
// assert.equal(node.id, 'A');
|
||||||
assert.equal(node.seq, 0);
|
// assert.equal(node.seq, 0);
|
||||||
assert.equal(node.ver, 0);
|
// assert.equal(node.ver, 0);
|
||||||
assert.equal(node.data, null);
|
// assert.equal(node.data, null);
|
||||||
assert.equal(node.next instanceof Array, true);
|
// assert.equal(node.next instanceof Array, true);
|
||||||
done();
|
// done();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
describe('compactId', () => {
|
// describe('compactId', () => {
|
||||||
it('presents the node as a string with id, sequence and version', (done) => {
|
// it('presents the node as a string with id, sequence and version', (done) => {
|
||||||
const node1 = new Node('A', 0, 0);
|
// const node1 = new Node('A', 0, 0);
|
||||||
const node2 = new Node('B', 123, 456);
|
// const node2 = new Node('B', 123, 456);
|
||||||
assert.equal(node1.compactId, 'A.0.0');
|
// assert.equal(node1.compactId, 'A.0.0');
|
||||||
assert.equal(node2.compactId, 'B.123.456');
|
// assert.equal(node2.compactId, 'B.123.456');
|
||||||
done();
|
// done();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
describe('equals', () => {
|
// describe('equals', () => {
|
||||||
it('check if nodes are equal', (done) => {
|
// it('check if nodes are equal', (done) => {
|
||||||
const node1 = new Node('A', 0, 0);
|
// const node1 = new Node('A', 0, 0);
|
||||||
const node2 = new Node('A', 0, 0);
|
// const node2 = new Node('A', 0, 0);
|
||||||
const node3 = new Node('A', 1, 1);
|
// const node3 = new Node('A', 1, 1);
|
||||||
const node4 = new Node('B', 123, 456);
|
// const node4 = new Node('B', 123, 456);
|
||||||
assert.equal(Node.equals(node1, node1), true);
|
// assert.equal(Node.equals(node1, node1), true);
|
||||||
assert.equal(Node.equals(node1, node2), true);
|
// assert.equal(Node.equals(node1, node2), true);
|
||||||
assert.equal(Node.equals(node1, node3), false);
|
// assert.equal(Node.equals(node1, node3), false);
|
||||||
assert.equal(Node.equals(node1, node4), false);
|
// assert.equal(Node.equals(node1, node4), false);
|
||||||
assert.equal(Node.equals(node3, node4), false);
|
// assert.equal(Node.equals(node3, node4), false);
|
||||||
done();
|
// done();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
describe('hasChild', () => {
|
// describe('hasChild', () => {
|
||||||
it('finds the child reference', (done) => {
|
// it('finds the child reference', (done) => {
|
||||||
const a = new Node('A', 0, 0);
|
// const a = new Node('A', 0, 0);
|
||||||
const b = new Node('B', 0, 0, "hello", [a]);
|
// const b = new Node('B', 0, 0, "hello", [a]);
|
||||||
const c = new Node('C', 0, 0, "hello", [a, b]);
|
// const c = new Node('C', 0, 0, "hello", [a, b]);
|
||||||
assert.equal(b.hasChild(a), true)
|
// assert.equal(b.hasChild(a), true)
|
||||||
assert.equal(c.hasChild(a), true)
|
// assert.equal(c.hasChild(a), true)
|
||||||
assert.equal(c.hasChild(b), true)
|
// assert.equal(c.hasChild(b), true)
|
||||||
done();
|
// done();
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
|
|
||||||
});
|
// });
|
||||||
|
1026
test/list-tests.js
1026
test/list-tests.js
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,11 @@ describe('Orbit Client', function() {
|
|||||||
let items2 = [];
|
let items2 = [];
|
||||||
const itemCount = 5;
|
const itemCount = 5;
|
||||||
|
|
||||||
|
beforeEach(async((done) => {
|
||||||
|
db.delete();
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
after(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
done();
|
done();
|
||||||
@ -51,7 +56,7 @@ describe('Orbit Client', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('adds a new item to a channel with one item', async((done) => {
|
it('adds a new item to a channel with one item', async((done) => {
|
||||||
const head = db.iterator().collect()[0];
|
const head = db.iterator().collect();
|
||||||
const second = db.add('hello');
|
const second = db.add('hello');
|
||||||
assert.notEqual(second, null);
|
assert.notEqual(second, null);
|
||||||
assert.notEqual(second, head);
|
assert.notEqual(second, head);
|
||||||
@ -82,7 +87,7 @@ describe('Orbit Client', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Delete events', function() {
|
describe('Delete events', function() {
|
||||||
before(async((done) => {
|
beforeEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
let items = db.iterator().collect();
|
let items = db.iterator().collect();
|
||||||
assert.equal(items.length, 0);
|
assert.equal(items.length, 0);
|
||||||
@ -95,7 +100,7 @@ describe('Orbit Client', function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('deletes an item when only one item in the database', async((done) => {
|
it('deletes an item when only one item in the database', async((done) => {
|
||||||
const head = db.add('hello-');
|
const head = db.add('hello1');
|
||||||
let item = db.iterator().collect();
|
let item = db.iterator().collect();
|
||||||
const delop = db.del(head);
|
const delop = db.del(head);
|
||||||
const items = db.iterator().collect();
|
const items = db.iterator().collect();
|
||||||
@ -111,9 +116,8 @@ describe('Orbit Client', function() {
|
|||||||
db.del(head);
|
db.del(head);
|
||||||
const items = db.iterator().collect();
|
const items = db.iterator().collect();
|
||||||
assert.equal(items.length, 1);
|
assert.equal(items.length, 1);
|
||||||
assert.equal(items[0].op, 'ADD');
|
// assert.equal(items[0].op, 'ADD');
|
||||||
assert.equal(items[0].value.content, 'hello1');
|
assert.equal(items[0].value, 'hello1');
|
||||||
assert.notEqual(items[0].value.meta, null);
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -124,10 +128,10 @@ describe('Orbit Client', function() {
|
|||||||
db.add('hello3');
|
db.add('hello3');
|
||||||
const items = db.iterator().collect();
|
const items = db.iterator().collect();
|
||||||
assert.equal(items.length, 1);
|
assert.equal(items.length, 1);
|
||||||
|
assert.equal(items[0].key.startsWith('Qm'), true);
|
||||||
assert.equal(items[0].hash.startsWith('Qm'), true);
|
assert.equal(items[0].hash.startsWith('Qm'), true);
|
||||||
assert.equal(items[0].op, 'ADD');
|
// assert.equal(items[0].op, 'ADD');
|
||||||
assert.equal(items[0].value.content, 'hello3');
|
assert.equal(items[0].value, 'hello3');
|
||||||
assert.notEqual(items[0].value.meta, null);
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
@ -137,16 +141,17 @@ describe('Orbit Client', function() {
|
|||||||
let items2 = [];
|
let items2 = [];
|
||||||
const itemCount = 5;
|
const itemCount = 5;
|
||||||
|
|
||||||
before(async((done) => {
|
beforeEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
|
items2 = [];
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 0; i < itemCount; i ++) {
|
||||||
const hash = db.add('hello' + i);
|
const hash = db.add('hello' + i);
|
||||||
items.push(hash);
|
items2.push(hash);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
afterEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -166,28 +171,20 @@ describe('Orbit Client', function() {
|
|||||||
const next = iter.next().value;
|
const next = iter.next().value;
|
||||||
|
|
||||||
assert.notEqual(next, null);
|
assert.notEqual(next, null);
|
||||||
assert.notEqual(next.hash, null);
|
assert.notEqual(next.key, null);
|
||||||
assert.equal(next.hash.startsWith('Qm'), true);
|
// assert.equal(next.op, 'ADD');
|
||||||
assert.notEqual(next, null);
|
|
||||||
assert.equal(next.op, 'ADD');
|
|
||||||
assert.equal(next.key.startsWith('Qm'), true);
|
assert.equal(next.key.startsWith('Qm'), true);
|
||||||
assert.equal(next.value.content, 'hello4');
|
assert.equal(next.hash.startsWith('Qm'), true);
|
||||||
assert.notEqual(next.value.meta, null);
|
assert.equal(next.value, 'hello4');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('implements Iterator interface', async((done) => {
|
it('implements Iterator interface', async((done) => {
|
||||||
db.delete();
|
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
|
||||||
const hash = db.add('hello' + i);
|
|
||||||
items2.push(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
const iter = db.iterator({ limit: -1 });
|
const iter = db.iterator({ limit: -1 });
|
||||||
let messages = [];
|
let messages = [];
|
||||||
|
|
||||||
for(let i of iter)
|
for(let i of iter)
|
||||||
messages.push(i.hash);
|
messages.push(i.key);
|
||||||
|
|
||||||
assert.equal(messages.length, items2.length);
|
assert.equal(messages.length, items2.length);
|
||||||
done();
|
done();
|
||||||
@ -199,7 +196,7 @@ describe('Orbit Client', function() {
|
|||||||
const second = iter.next().value;
|
const second = iter.next().value;
|
||||||
assert.equal(first.key, items2[items2.length - 1]);
|
assert.equal(first.key, items2[items2.length - 1]);
|
||||||
assert.equal(second, null);
|
assert.equal(second, null);
|
||||||
assert.equal(first.value.content, 'hello4');
|
assert.equal(first.value, 'hello4');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
@ -207,8 +204,8 @@ describe('Orbit Client', function() {
|
|||||||
describe('Collect', function() {
|
describe('Collect', function() {
|
||||||
let items2;
|
let items2;
|
||||||
before(async((done) => {
|
before(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
items2 = [];
|
items2 = [];
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 0; i < itemCount; i ++) {
|
||||||
const hash = db.add('hello' + i);
|
const hash = db.add('hello' + i);
|
||||||
items2.push(hash);
|
items2.push(hash);
|
||||||
@ -216,17 +213,17 @@ describe('Orbit Client', function() {
|
|||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
// after(async((done) => {
|
||||||
db.delete();
|
// db.delete();
|
||||||
items2 = [];
|
// items2 = [];
|
||||||
done();
|
// done();
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it('returns all items', async((done) => {
|
it('returns all items', async((done) => {
|
||||||
const messages = db.iterator({ limit: -1 }).collect();
|
const messages = db.iterator({ limit: -1 }).collect();
|
||||||
assert.equal(messages.length, items.length);
|
assert.equal(messages.length, items2.length);
|
||||||
assert.equal(messages[0].value.content, 'hello0');
|
assert.equal(messages[0].value, 'hello0');
|
||||||
assert.equal(messages[messages.length - 1].value.content, 'hello4');
|
assert.equal(messages[messages.length - 1].value, 'hello4');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -245,27 +242,27 @@ describe('Orbit Client', function() {
|
|||||||
|
|
||||||
describe('Options: limit', function() {
|
describe('Options: limit', function() {
|
||||||
let items2;
|
let items2;
|
||||||
before(async((done) => {
|
beforeEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
items2 = [];
|
items2 = [];
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 1; i <= itemCount; i ++) {
|
||||||
const hash = db.add('hello' + i);
|
const hash = db.add('hello' + i);
|
||||||
items2.push(hash);
|
items2.push(hash);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
// after(async((done) => {
|
||||||
db.delete();
|
// db.delete();
|
||||||
items2 = [];
|
// items2 = [];
|
||||||
done();
|
// done();
|
||||||
}));
|
// }));
|
||||||
|
|
||||||
it('returns 1 item when limit is 0', async((done) => {
|
it('returns 1 item when limit is 0', async((done) => {
|
||||||
const iter = db.iterator({ limit: 1 });
|
const iter = db.iterator({ limit: 1 });
|
||||||
const first = iter.next().value;
|
const first = iter.next().value;
|
||||||
const second = iter.next().value;
|
const second = iter.next().value;
|
||||||
assert.equal(first.key, items2[items.length - 1]);
|
assert.equal(first.key, _.last(items2));
|
||||||
assert.equal(second, null);
|
assert.equal(second, null);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -274,7 +271,7 @@ describe('Orbit Client', function() {
|
|||||||
const iter = db.iterator({ limit: 1 });
|
const iter = db.iterator({ limit: 1 });
|
||||||
const first = iter.next().value;
|
const first = iter.next().value;
|
||||||
const second = iter.next().value;
|
const second = iter.next().value;
|
||||||
assert.equal(first.key, items2[items.length - 1]);
|
assert.equal(first.key, _.last(items2));
|
||||||
assert.equal(second, null);
|
assert.equal(second, null);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -285,9 +282,9 @@ describe('Orbit Client', function() {
|
|||||||
const second = iter.next().value;
|
const second = iter.next().value;
|
||||||
const third = iter.next().value;
|
const third = iter.next().value;
|
||||||
const fourth = iter.next().value;
|
const fourth = iter.next().value;
|
||||||
assert.equal(first.key, items2[items.length - 3]);
|
assert.equal(first.key, items2[items2.length - 3]);
|
||||||
assert.equal(second.key, items2[items.length - 2]);
|
assert.equal(second.key, items2[items2.length - 2]);
|
||||||
assert.equal(third.key, items2[items.length - 1]);
|
assert.equal(third.key, items2[items2.length - 1]);
|
||||||
assert.equal(fourth, null);
|
assert.equal(fourth, null);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -326,22 +323,16 @@ describe('Orbit Client', function() {
|
|||||||
|
|
||||||
describe('Options: reverse', function() {
|
describe('Options: reverse', function() {
|
||||||
let items2;
|
let items2;
|
||||||
before(async((done) => {
|
beforeEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
items2 = [];
|
items2 = [];
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 1; i <= itemCount; i ++) {
|
||||||
const hash = db.add('hello' + i);
|
const hash = db.add('hello' + i);
|
||||||
items2.push(hash);
|
items2.push(hash);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
|
||||||
db.delete();
|
|
||||||
items2 = [];
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('returns all items reversed', async((done) => {
|
it('returns all items reversed', async((done) => {
|
||||||
const messages = db.iterator({ limit: -1, reverse: true })
|
const messages = db.iterator({ limit: -1, reverse: true })
|
||||||
.collect()
|
.collect()
|
||||||
@ -355,22 +346,16 @@ describe('Orbit Client', function() {
|
|||||||
|
|
||||||
describe('Options: ranges', function() {
|
describe('Options: ranges', function() {
|
||||||
let items2;
|
let items2;
|
||||||
before(async((done) => {
|
beforeEach(async((done) => {
|
||||||
db.delete();
|
db.delete();
|
||||||
items2 = [];
|
items2 = [];
|
||||||
for(let i = 0; i < itemCount; i ++) {
|
for(let i = 1; i <= itemCount; i ++) {
|
||||||
const hash = db.add('hello' + i);
|
const hash = db.add('hello' + i);
|
||||||
items2.push(hash);
|
items2.push(hash);
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
after(async((done) => {
|
|
||||||
db.delete();
|
|
||||||
items2 = [];
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('gt & gte', function() {
|
describe('gt & gte', function() {
|
||||||
it('returns 1 item when gte is the head', async((done) => {
|
it('returns 1 item when gte is the head', async((done) => {
|
||||||
const messages = db.iterator({ gte: _.last(items2), limit: -1 })
|
const messages = db.iterator({ gte: _.last(items2), limit: -1 })
|
||||||
@ -378,7 +363,7 @@ describe('Orbit Client', function() {
|
|||||||
.map((e) => e.key);
|
.map((e) => e.key);
|
||||||
|
|
||||||
assert.equal(messages.length, 1);
|
assert.equal(messages.length, 1);
|
||||||
assert.equal(messages[0], items2[items.length -1]);
|
assert.equal(messages[0], _.last(items2));
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -407,7 +392,7 @@ describe('Orbit Client', function() {
|
|||||||
|
|
||||||
assert.equal(messages.length, items2.length);
|
assert.equal(messages.length, items2.length);
|
||||||
assert.equal(messages[0], items2[0]);
|
assert.equal(messages[0], items2[0]);
|
||||||
assert.equal(messages[messages.length - 1], items2[items2.length - 1]);
|
assert.equal(messages[messages.length - 1], _.last(items2));
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -418,7 +403,7 @@ describe('Orbit Client', function() {
|
|||||||
|
|
||||||
assert.equal(messages.length, itemCount - 1);
|
assert.equal(messages.length, itemCount - 1);
|
||||||
assert.equal(messages[0], items2[1]);
|
assert.equal(messages[0], items2[1]);
|
||||||
assert.equal(messages[3], items2[items.length - 1]);
|
assert.equal(messages[3], _.last(items2));
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -538,7 +523,7 @@ describe('Orbit Client', function() {
|
|||||||
assert.equal(all.length, 1);
|
assert.equal(all.length, 1);
|
||||||
assert.equal(all[0].hash.startsWith('Qm'), true);
|
assert.equal(all[0].hash.startsWith('Qm'), true);
|
||||||
assert.equal(all[0].key, 'key1');
|
assert.equal(all[0].key, 'key1');
|
||||||
assert.equal(all[0].op, 'PUT');
|
// assert.equal(all[0].op, 'PUT');
|
||||||
assert.notEqual(all[0].meta, null);
|
assert.notEqual(all[0].meta, null);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
@ -20,7 +20,7 @@ const startIpfs = async (() => {
|
|||||||
let ipfs;
|
let ipfs;
|
||||||
|
|
||||||
describe('OrbitList', async(function() {
|
describe('OrbitList', async(function() {
|
||||||
this.timeout(15000);
|
this.timeout(5000);
|
||||||
|
|
||||||
before(async((done) => {
|
before(async((done) => {
|
||||||
try {
|
try {
|
||||||
@ -35,8 +35,8 @@ describe('OrbitList', async(function() {
|
|||||||
it('initializes member variables', async((done) => {
|
it('initializes member variables', async((done) => {
|
||||||
const list = new List(ipfs, 'A');
|
const list = new List(ipfs, 'A');
|
||||||
assert.equal(list.id, 'A');
|
assert.equal(list.id, 'A');
|
||||||
assert.equal(list.seq, 0);
|
// assert.equal(list.seq, 0);
|
||||||
assert.equal(list.ver, 0);
|
// assert.equal(list.ver, 0);
|
||||||
assert.equal(list._items instanceof Array, true);
|
assert.equal(list._items instanceof Array, true);
|
||||||
assert.equal(list._currentBatch instanceof Array, true);
|
assert.equal(list._currentBatch instanceof Array, true);
|
||||||
assert.equal(list._items.length, 0);
|
assert.equal(list._items.length, 0);
|
||||||
@ -47,48 +47,6 @@ describe('OrbitList', async(function() {
|
|||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('add', async(() => {
|
|
||||||
it('saves the data to ipfs', async((done) => {
|
|
||||||
const list = new List(ipfs, 'A');
|
|
||||||
const text = 'testing 1 2 3 4';
|
|
||||||
list.add(text)
|
|
||||||
const hash = list.ipfsHash;
|
|
||||||
|
|
||||||
const l = await(ipfsAPI.getObject(ipfs, hash));
|
|
||||||
const list2 = List.fromJson(ipfs, JSON.parse(l.Data));
|
|
||||||
assert.equal(list2.items[0].data, text);
|
|
||||||
assert.equal(list2.items[0].id, 'A');
|
|
||||||
assert.equal(list2.items[0].seq, 0);
|
|
||||||
assert.equal(list2.items[0].ver, 0);
|
|
||||||
assert.equal(list2.items[0].hash, 'QmWqjmn62GQjR7RTsUKXMtxDYVoY7GQVCfUECGmLET3BQ2');
|
|
||||||
assert.equal(Object.keys(list2.items[0].next).length, 0);
|
|
||||||
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('updates the data to ipfs', async((done) => {
|
|
||||||
const list = new List(ipfs, 'A');
|
|
||||||
const text1 = 'testing 1 2 3';
|
|
||||||
const text2 = 'testing 456';
|
|
||||||
let hash;
|
|
||||||
|
|
||||||
list.add(text1)
|
|
||||||
|
|
||||||
hash = list.ipfsHash;
|
|
||||||
assert.equal(hash, 'Qmf1Fjq7y2s7LbH3ktZfd99knCzYwP8cAE9zFQWj7LSv9x');
|
|
||||||
|
|
||||||
list.add(text2)
|
|
||||||
hash = list.ipfsHash;
|
|
||||||
assert.equal(hash, 'Qmecju6aNyQF8LHUNbUrujMmXPfUit7tDkqnmLKLF22aRk');
|
|
||||||
|
|
||||||
const list2 = List.fromIpfsHash(ipfs, hash);
|
|
||||||
assert.equal(list2.items[0].data, text1);
|
|
||||||
assert.equal(list2.items[1].data, text2);
|
|
||||||
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('ipfsHash', async(() => {
|
describe('ipfsHash', async(() => {
|
||||||
it('returns the list as ipfs hash', async((done) => {
|
it('returns the list as ipfs hash', async((done) => {
|
||||||
const list = new List(ipfs, 'A');
|
const list = new List(ipfs, 'A');
|
||||||
@ -116,33 +74,30 @@ describe('OrbitList', async(function() {
|
|||||||
const res = List.fromIpfsHash(ipfs, hash);
|
const res = List.fromIpfsHash(ipfs, hash);
|
||||||
|
|
||||||
assert.equal(res.id, 'A');
|
assert.equal(res.id, 'A');
|
||||||
assert.equal(res.seq, 0);
|
// assert.equal(res.seq, 0);
|
||||||
assert.equal(res.ver, 3);
|
// assert.equal(res.ver, 3);
|
||||||
assert.equal(res.items.length, 3);
|
assert.equal(res.items.length, 3);
|
||||||
assert.equal(res.items[0].compactId, 'A.0.0');
|
// assert.equal(res.items[0].compactId, 'A.0.0');
|
||||||
assert.equal(res.items[0].hash, 'QmQQyTLqcB7ySH5zVCbks1UWQEgrv3m5ygSRL88BHghg95');
|
assert.equal(res.items[0].hash, 'QmQgLATYR4Af3oCVaQ8LHumvkwtjHfZ3Tumz8RfKMxHZfo');
|
||||||
assert.equal(res.items[1].compactId, 'A.0.1');
|
// assert.equal(res.items[1].compactId, 'A.0.1');
|
||||||
assert.equal(res.items[1].hash, 'Qmbwx1b2CYxMmpQmJFKRsqDdGjD5CwfB2QRGP63jypyYFC');
|
assert.equal(res.items[1].hash, 'QmTLP2MccfhZGjXHZgLL1euh2d2PkEhLf7G1pGR2Hdg4h6');
|
||||||
assert.equal(res.items[2].compactId, 'A.0.2');
|
// assert.equal(res.items[2].compactId, 'A.0.2');
|
||||||
assert.equal(res.items[2].hash, 'QmfLnHHPbMwwAzUNs8inVGzM8tXxb2eLeeQb8Zgc7p3nfY');
|
assert.equal(res.items[2].hash, 'QmUX8qTWAqumSxzviV4YvWyWT727pqgZX6XdViWZdoL8fC');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('serialize', async(() => {
|
describe('serialize', async(() => {
|
||||||
|
|
||||||
let list;
|
let list;
|
||||||
const expected = {
|
const expected = {
|
||||||
id: "A",
|
id: "A",
|
||||||
seq: 0,
|
items: [
|
||||||
ver: 3,
|
"QmQgLATYR4Af3oCVaQ8LHumvkwtjHfZ3Tumz8RfKMxHZfo",
|
||||||
items: {
|
"QmTLP2MccfhZGjXHZgLL1euh2d2PkEhLf7G1pGR2Hdg4h6",
|
||||||
"A.0.0": "QmQQyTLqcB7ySH5zVCbks1UWQEgrv3m5ygSRL88BHghg95",
|
"QmUX8qTWAqumSxzviV4YvWyWT727pqgZX6XdViWZdoL8fC"
|
||||||
"A.0.1": "Qmbwx1b2CYxMmpQmJFKRsqDdGjD5CwfB2QRGP63jypyYFC",
|
]
|
||||||
"A.0.2": "QmfLnHHPbMwwAzUNs8inVGzM8tXxb2eLeeQb8Zgc7p3nfY"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
before(async((done) => {
|
before(async((done) => {
|
||||||
@ -164,20 +119,18 @@ describe('OrbitList', async(function() {
|
|||||||
it('creates a list from parsed json', async((done) => {
|
it('creates a list from parsed json', async((done) => {
|
||||||
const str = JSON.stringify(list.asJson, null, 2)
|
const str = JSON.stringify(list.asJson, null, 2)
|
||||||
const res = List.fromJson(ipfs, JSON.parse(str));
|
const res = List.fromJson(ipfs, JSON.parse(str));
|
||||||
|
|
||||||
assert.equal(res.id, 'A');
|
assert.equal(res.id, 'A');
|
||||||
assert.equal(res.seq, 0);
|
// assert.equal(res.seq, 0);
|
||||||
assert.equal(res.ver, 3);
|
// assert.equal(res.ver, 3);
|
||||||
assert.equal(res.items.length, 3);
|
assert.equal(res.items.length, 3);
|
||||||
assert.equal(res.items[0].hash, 'QmQQyTLqcB7ySH5zVCbks1UWQEgrv3m5ygSRL88BHghg95');
|
assert.equal(res.items[0].hash, 'QmQgLATYR4Af3oCVaQ8LHumvkwtjHfZ3Tumz8RfKMxHZfo');
|
||||||
assert.equal(res.items[1].hash, 'Qmbwx1b2CYxMmpQmJFKRsqDdGjD5CwfB2QRGP63jypyYFC');
|
assert.equal(res.items[1].hash, 'QmTLP2MccfhZGjXHZgLL1euh2d2PkEhLf7G1pGR2Hdg4h6');
|
||||||
assert.equal(res.items[2].hash, 'QmfLnHHPbMwwAzUNs8inVGzM8tXxb2eLeeQb8Zgc7p3nfY');
|
assert.equal(res.items[2].hash, 'QmUX8qTWAqumSxzviV4YvWyWT727pqgZX6XdViWZdoL8fC');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
describe('items', () => {
|
describe('items', () => {
|
||||||
it('returns items', async((done) => {
|
it('returns items', async((done) => {
|
||||||
const list = new List(ipfs, 'A');
|
const list = new List(ipfs, 'A');
|
||||||
@ -200,15 +153,15 @@ describe('OrbitList', async(function() {
|
|||||||
list.add("hello1")
|
list.add("hello1")
|
||||||
const item = list.items[0];
|
const item = list.items[0];
|
||||||
assert.equal(list.id, 'A');
|
assert.equal(list.id, 'A');
|
||||||
assert.equal(list.seq, 0);
|
// assert.equal(list.seq, 0);
|
||||||
assert.equal(list.ver, 1);
|
// assert.equal(list.ver, 1);
|
||||||
assert.equal(list.items.length, 1);
|
assert.equal(list.items.length, 1);
|
||||||
assert.equal(list._currentBatch.length, 1);
|
assert.equal(list._currentBatch.length, 1);
|
||||||
assert.equal(list._items.length, 0);
|
assert.equal(list._items.length, 0);
|
||||||
assert.equal(item, list._currentBatch[0]);
|
assert.equal(item, list._currentBatch[0]);
|
||||||
assert.equal(item.id, 'A');
|
assert.equal(item.id, 'A');
|
||||||
assert.equal(item.seq, 0);
|
// assert.equal(item.seq, 0);
|
||||||
assert.equal(item.ver, 0);
|
// assert.equal(item.ver, 0);
|
||||||
assert.equal(item.data, 'hello1');
|
assert.equal(item.data, 'hello1');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -240,16 +193,16 @@ describe('OrbitList', async(function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(list.id, 'A');
|
assert.equal(list.id, 'A');
|
||||||
assert.equal(list.seq, 0);
|
// assert.equal(list.seq, 0);
|
||||||
assert.equal(list.ver, List.batchSize);
|
// assert.equal(list.ver, List.batchSize);
|
||||||
assert.equal(list.items.length, List.batchSize);
|
assert.equal(list.items.length, List.batchSize);
|
||||||
assert.equal(list._currentBatch.length, List.batchSize);
|
assert.equal(list._currentBatch.length, List.batchSize);
|
||||||
assert.equal(list._items.length, 0);
|
assert.equal(list._items.length, 0);
|
||||||
|
|
||||||
const item = list.items[list.items.length - 1];
|
const item = list.items[list.items.length - 1];
|
||||||
assert.equal(item.id, 'A');
|
assert.equal(item.id, 'A');
|
||||||
assert.equal(item.seq, 0);
|
// assert.equal(item.seq, 0);
|
||||||
assert.equal(item.ver, List.batchSize - 1);
|
assert.equal(list.items.length, List.batchSize);
|
||||||
assert.equal(item.data, 'hello' + List.batchSize);
|
assert.equal(item.data, 'hello' + List.batchSize);
|
||||||
assert.notEqual(item.next.length, 0);
|
assert.notEqual(item.next.length, 0);
|
||||||
|
|
||||||
@ -258,39 +211,6 @@ describe('OrbitList', async(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('join', () => {
|
describe('join', () => {
|
||||||
it('increases the sequence and resets the version if other list has the same or higher sequence', async((done) => {
|
|
||||||
const list1 = new List(ipfs, 'A');
|
|
||||||
const list2 = new List(ipfs, 'B');
|
|
||||||
|
|
||||||
list2.seq = 7;
|
|
||||||
list1.add("helloA1")
|
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
|
||||||
assert.equal(list1.seq, 0);
|
|
||||||
assert.equal(list1.ver, 1);
|
|
||||||
|
|
||||||
list2.add("helloB1")
|
|
||||||
list1.join(list2);
|
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
|
||||||
assert.equal(list1.seq, 8);
|
|
||||||
assert.equal(list1.ver, 0);
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('increases the sequence by one if other list has lower sequence', async((done) => {
|
|
||||||
const list1 = new List(ipfs, 'A');
|
|
||||||
const list2 = new List(ipfs, 'B');
|
|
||||||
list1.seq = 4;
|
|
||||||
list2.seq = 1;
|
|
||||||
list2.add("helloB1")
|
|
||||||
list1.join(list2);
|
|
||||||
assert.equal(list1.id, 'A');
|
|
||||||
assert.equal(list1.seq, 5);
|
|
||||||
assert.equal(list1.ver, 0);
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('joins unique items', async((done) => {
|
it('joins unique items', async((done) => {
|
||||||
const list1 = new List(ipfs, 'A');
|
const list1 = new List(ipfs, 'A');
|
||||||
const list2 = new List(ipfs, 'B');
|
const list2 = new List(ipfs, 'B');
|
||||||
@ -312,8 +232,7 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
assert.equal(list1.items.length, 7);
|
assert.equal(list1.items.length, 7);
|
||||||
assert.equal(lastItem.next.length, 1);
|
assert.equal(lastItem.next.length, 1);
|
||||||
assert.equal(lastItem.next[0].compactId, 'A.3.0');
|
assert.equal(lastItem.next[0].hash, 'QmPT7qgkysupMuMf2k8yESBL8A55Cva9Y8pqTuA1AMWB4m');
|
||||||
assert.equal(lastItem.next[0].hash, 'QmbHkdCAcDnqBmjWEttEJ96cjhXUHx7b4fR3QyE3YYpczL');
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -326,11 +245,9 @@ describe('OrbitList', async(function() {
|
|||||||
assert.equal(list1._currentBatch.length, 3);
|
assert.equal(list1._currentBatch.length, 3);
|
||||||
assert.equal(list1._currentBatch[0].next.length, 0);
|
assert.equal(list1._currentBatch[0].next.length, 0);
|
||||||
assert.equal(list1._currentBatch[1].next.length, 1);
|
assert.equal(list1._currentBatch[1].next.length, 1);
|
||||||
assert.equal(list1._currentBatch[1].next[0].compactId, 'A.0.0');
|
assert.equal(list1._currentBatch[1].next[0].hash, 'QmQQhCyFHWAwNm7k5CbDF5iKuHfT2VJU5qUkncQDNAfTbL');
|
||||||
assert.equal(list1._currentBatch[1].next[0].hash, 'QmYTUeiK82guFDyB9tJgHZuBpNkUqNyFBuajYrCsaxPXvW');
|
|
||||||
assert.equal(list1._currentBatch[2].next.length, 1);
|
assert.equal(list1._currentBatch[2].next.length, 1);
|
||||||
assert.equal(list1._currentBatch[2].next[0].compactId, 'A.0.1');
|
assert.equal(list1._currentBatch[2].next[0].hash, 'QmbKmxJv6mhGvvUQwU3A5BBWvpBMVvGkpFr5AMrrqib6EH');
|
||||||
assert.equal(list1._currentBatch[2].next[0].hash, 'QmUycQmNU8apkbPqsWPK3VxMHJeHt86UQrzfSFDNRGbvsd');
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -345,10 +262,10 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
assert.equal(list1._currentBatch.length, 1);
|
assert.equal(list1._currentBatch.length, 1);
|
||||||
assert.equal(list1._currentBatch[0].next.length, 2);
|
assert.equal(list1._currentBatch[0].next.length, 2);
|
||||||
assert.equal(list1._currentBatch[0].next[1].compactId, 'A.0.0');
|
// assert.equal(list1._currentBatch[0].next[1].compactId, 'A.0.0');
|
||||||
assert.equal(list1._currentBatch[0].next[1].hash, 'QmYTUeiK82guFDyB9tJgHZuBpNkUqNyFBuajYrCsaxPXvW');
|
assert.equal(list1._currentBatch[0].next[1].hash, 'QmQQhCyFHWAwNm7k5CbDF5iKuHfT2VJU5qUkncQDNAfTbL');
|
||||||
assert.equal(list1._currentBatch[0].next[0].compactId, 'B.0.1');
|
// assert.equal(list1._currentBatch[0].next[0].compactId, 'B.0.1');
|
||||||
assert.equal(list1._currentBatch[0].next[0].hash, 'QmVmkwMoz4vnvHQwvFwqaoWCrjonsPpyJ6i436Zajht5ao');
|
assert.equal(list1._currentBatch[0].next[0].hash, 'QmUnaa1dT2FEYmK1nDD5fJ53Pd2iEDtGL3oLM5M7VLBqHJ');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -365,13 +282,13 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
assert.equal(list1._currentBatch.length, 2);
|
assert.equal(list1._currentBatch.length, 2);
|
||||||
assert.equal(list1._currentBatch[1].next.length, 1);
|
assert.equal(list1._currentBatch[1].next.length, 1);
|
||||||
assert.equal(list1._currentBatch[1].next[0].compactId, 'A.1.0');
|
// assert.equal(list1._currentBatch[1].next[0].compactId, 'A.1.0');
|
||||||
assert.equal(list1._currentBatch[1].next[0].hash, 'QmcMUW2F6wqoNtsiV2gXXTvEzXGM9xexN1mgyCLH4LXJ51');
|
assert.equal(list1._currentBatch[1].next[0].hash, 'QmaGPFKz6qJLuLhUFN2J48FVZttVF2y2gmgU3666H21BWQ');
|
||||||
assert.equal(list1._currentBatch[0].next.length, 2);
|
assert.equal(list1._currentBatch[0].next.length, 2);
|
||||||
assert.equal(list1._currentBatch[0].next[0].compactId, 'B.0.1');
|
// assert.equal(list1._currentBatch[0].next[0].compactId, 'B.0.1');
|
||||||
assert.equal(list1._currentBatch[0].next[0].hash, 'QmVmkwMoz4vnvHQwvFwqaoWCrjonsPpyJ6i436Zajht5ao');
|
assert.equal(list1._currentBatch[0].next[0].hash, 'QmUnaa1dT2FEYmK1nDD5fJ53Pd2iEDtGL3oLM5M7VLBqHJ');
|
||||||
assert.equal(list1._currentBatch[0].next[1].compactId, 'A.0.0');
|
// assert.equal(list1._currentBatch[0].next[1].compactId, 'A.0.0');
|
||||||
assert.equal(list1._currentBatch[0].next[1].hash, 'QmYTUeiK82guFDyB9tJgHZuBpNkUqNyFBuajYrCsaxPXvW');
|
assert.equal(list1._currentBatch[0].next[1].hash, 'QmQQhCyFHWAwNm7k5CbDF5iKuHfT2VJU5qUkncQDNAfTbL');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -395,8 +312,8 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
assert.equal(list1.items.length, 7);
|
assert.equal(list1.items.length, 7);
|
||||||
assert.equal(lastItem.next.length, 1);
|
assert.equal(lastItem.next.length, 1);
|
||||||
assert.equal(lastItem.next[0].compactId, 'A.2.0');
|
// assert.equal(lastItem.next[0].compactId, 'A.2.0');
|
||||||
assert.equal(lastItem.next[0].hash, 'QmbKQRZC9HTNSDVypeAudJbDdBuT3DAYRvyREvm6CupKrQ');
|
assert.equal(lastItem.next[0].hash, 'QmPT7qgkysupMuMf2k8yESBL8A55Cva9Y8pqTuA1AMWB4m');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -431,10 +348,10 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
assert.equal(list1.items.length, 11);
|
assert.equal(list1.items.length, 11);
|
||||||
assert.equal(lastItem.next.length, 2);
|
assert.equal(lastItem.next.length, 2);
|
||||||
assert.equal(lastItem.next[1].compactId, 'A.4.0');
|
// assert.equal(lastItem.next[1].compactId, 'A.4.0');
|
||||||
assert.equal(lastItem.next[1].hash, 'QmWPqc6XCK1TCVSz9rayHWQjeMFQEKWhk6VD1ZAU8Vhio7');
|
assert.equal(lastItem.next[1].hash, 'QmdyS6VUP5wAENpdT1sp6o1JJwMaKajPg1W441MD71r4pE');
|
||||||
assert.equal(lastItem.next[0].compactId, 'D.0.2');
|
// assert.equal(lastItem.next[0].compactId, 'D.0.2');
|
||||||
assert.equal(lastItem.next[0].hash, 'QmVT3DvmggXq3AdVK7JBfF4Jit3xpbgqP8dFK7TePtit4B');
|
assert.equal(lastItem.next[0].hash, 'QmfWbsDTKd3zhRoJZ2oGeBYmgsnerK3SmFYXZtydgADec7');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -449,13 +366,13 @@ describe('OrbitList', async(function() {
|
|||||||
const lastItem = list1.items[list1.items.length - 1];
|
const lastItem = list1.items[list1.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
assert.equal(list1.id, 'A');
|
||||||
assert.equal(list1.seq, 1);
|
// assert.equal(list1.seq, 1);
|
||||||
assert.equal(list1.ver, 0);
|
// assert.equal(list1.ver, 0);
|
||||||
assert.equal(list1._currentBatch.length, 0);
|
assert.equal(list1._currentBatch.length, 0);
|
||||||
assert.equal(list1._items.length, 3);
|
assert.equal(list1._items.length, 3);
|
||||||
assert.equal(lastItem.id, 'B');
|
assert.equal(lastItem.id, 'B');
|
||||||
assert.equal(lastItem.seq, 0);
|
// assert.equal(lastItem.seq, 0);
|
||||||
assert.equal(lastItem.ver, 1);
|
// assert.equal(lastItem.ver, 1);
|
||||||
assert.equal(lastItem.data, 'helloB2');
|
assert.equal(lastItem.data, 'helloB2');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -473,25 +390,25 @@ describe('OrbitList', async(function() {
|
|||||||
const lastItem1 = list1.items[list1.items.length - 1];
|
const lastItem1 = list1.items[list1.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
assert.equal(list1.id, 'A');
|
||||||
assert.equal(list1.seq, 1);
|
// assert.equal(list1.seq, 1);
|
||||||
assert.equal(list1.ver, 0);
|
// assert.equal(list1.ver, 0);
|
||||||
assert.equal(list1._currentBatch.length, 0);
|
assert.equal(list1._currentBatch.length, 0);
|
||||||
assert.equal(list1._items.length, 4);
|
assert.equal(list1._items.length, 4);
|
||||||
assert.equal(lastItem1.id, 'B');
|
assert.equal(lastItem1.id, 'B');
|
||||||
assert.equal(lastItem1.seq, 0);
|
// assert.equal(lastItem1.seq, 0);
|
||||||
assert.equal(lastItem1.ver, 1);
|
// assert.equal(lastItem1.ver, 1);
|
||||||
assert.equal(lastItem1.data, 'helloB2');
|
assert.equal(lastItem1.data, 'helloB2');
|
||||||
|
|
||||||
const lastItem2 = list2.items[list2.items.length - 1];
|
const lastItem2 = list2.items[list2.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list2.id, 'B');
|
assert.equal(list2.id, 'B');
|
||||||
assert.equal(list2.seq, 2);
|
// assert.equal(list2.seq, 2);
|
||||||
assert.equal(list2.ver, 0);
|
// assert.equal(list2.ver, 0);
|
||||||
assert.equal(list2._currentBatch.length, 0);
|
assert.equal(list2._currentBatch.length, 0);
|
||||||
assert.equal(list2._items.length, 4);
|
assert.equal(list2._items.length, 4);
|
||||||
assert.equal(lastItem2.id, 'A');
|
assert.equal(lastItem2.id, 'A');
|
||||||
assert.equal(lastItem2.seq, 0);
|
// assert.equal(lastItem2.seq, 0);
|
||||||
assert.equal(lastItem2.ver, 1);
|
// assert.equal(lastItem2.ver, 1);
|
||||||
assert.equal(lastItem2.data, 'helloA2');
|
assert.equal(lastItem2.data, 'helloA2');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -512,17 +429,17 @@ describe('OrbitList', async(function() {
|
|||||||
const lastItem = list2.items[list2.items.length - 1];
|
const lastItem = list2.items[list2.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list2.id, 'B');
|
assert.equal(list2.id, 'B');
|
||||||
assert.equal(list2.seq, 2);
|
// assert.equal(list2.seq, 2);
|
||||||
assert.equal(list2.ver, 0);
|
// assert.equal(list2.ver, 0);
|
||||||
assert.equal(list2._currentBatch.length, 0);
|
assert.equal(list2._currentBatch.length, 0);
|
||||||
assert.equal(list2._items.length, 4);
|
assert.equal(list2._items.length, 4);
|
||||||
assert.equal(secondItem.id, 'A');
|
assert.equal(secondItem.id, 'A');
|
||||||
assert.equal(secondItem.seq, 0);
|
// assert.equal(secondItem.seq, 0);
|
||||||
assert.equal(secondItem.ver, 0);
|
// assert.equal(secondItem.ver, 0);
|
||||||
assert.equal(secondItem.data, 'helloA1');
|
assert.equal(secondItem.data, 'helloA1');
|
||||||
assert.equal(lastItem.id, 'A');
|
assert.equal(lastItem.id, 'A');
|
||||||
assert.equal(lastItem.seq, 0);
|
// assert.equal(lastItem.seq, 0);
|
||||||
assert.equal(lastItem.ver, 1);
|
// assert.equal(lastItem.ver, 1);
|
||||||
assert.equal(lastItem.data, 'helloA2');
|
assert.equal(lastItem.data, 'helloA2');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -549,17 +466,17 @@ describe('OrbitList', async(function() {
|
|||||||
const lastItem = list1.items[list1.items.length - 1];
|
const lastItem = list1.items[list1.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
assert.equal(list1.id, 'A');
|
||||||
assert.equal(list1.seq, 3);
|
// assert.equal(list1.seq, 3);
|
||||||
assert.equal(list1.ver, 0);
|
// assert.equal(list1.ver, 0);
|
||||||
assert.equal(list1._currentBatch.length, 0);
|
assert.equal(list1._currentBatch.length, 0);
|
||||||
assert.equal(list1._items.length, 8);
|
assert.equal(list1._items.length, 8);
|
||||||
assert.equal(secondItem.id, 'A');
|
assert.equal(secondItem.id, 'A');
|
||||||
assert.equal(secondItem.seq, 0);
|
// assert.equal(secondItem.seq, 0);
|
||||||
assert.equal(secondItem.ver, 1);
|
// assert.equal(secondItem.ver, 1);
|
||||||
assert.equal(secondItem.data, 'helloA2');
|
assert.equal(secondItem.data, 'helloA2');
|
||||||
assert.equal(lastItem.id, 'D');
|
assert.equal(lastItem.id, 'D');
|
||||||
assert.equal(lastItem.seq, 0);
|
// assert.equal(lastItem.seq, 0);
|
||||||
assert.equal(lastItem.ver, 1);
|
// assert.equal(lastItem.ver, 1);
|
||||||
assert.equal(lastItem.data, 'helloD2');
|
assert.equal(lastItem.data, 'helloD2');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -600,21 +517,21 @@ describe('OrbitList', async(function() {
|
|||||||
const lastItem2 = list4.items[list4.items.length - 1];
|
const lastItem2 = list4.items[list4.items.length - 1];
|
||||||
|
|
||||||
assert.equal(list4.id, 'D');
|
assert.equal(list4.id, 'D');
|
||||||
assert.equal(list4.seq, 7);
|
// assert.equal(list4.seq, 7);
|
||||||
assert.equal(list4.ver, 2);
|
// assert.equal(list4.ver, 2);
|
||||||
assert.equal(list4._currentBatch.length, 2);
|
assert.equal(list4._currentBatch.length, 2);
|
||||||
assert.equal(list4._items.length, 8);
|
assert.equal(list4._items.length, 8);
|
||||||
assert.equal(secondItem.id, 'D');
|
assert.equal(secondItem.id, 'D');
|
||||||
assert.equal(secondItem.seq, 0);
|
// assert.equal(secondItem.seq, 0);
|
||||||
assert.equal(secondItem.ver, 1);
|
// assert.equal(secondItem.ver, 1);
|
||||||
assert.equal(secondItem.data, 'helloD2');
|
assert.equal(secondItem.data, 'helloD2');
|
||||||
assert.equal(lastItem1.id, 'C');
|
assert.equal(lastItem1.id, 'C');
|
||||||
assert.equal(lastItem1.seq, 3);
|
// assert.equal(lastItem1.seq, 3);
|
||||||
assert.equal(lastItem1.ver, 1);
|
// assert.equal(lastItem1.ver, 1);
|
||||||
assert.equal(lastItem1.data, 'helloC2');
|
assert.equal(lastItem1.data, 'helloC2');
|
||||||
assert.equal(lastItem2.id, 'D');
|
assert.equal(lastItem2.id, 'D');
|
||||||
assert.equal(lastItem2.seq, 7);
|
// assert.equal(lastItem2.seq, 7);
|
||||||
assert.equal(lastItem2.ver, 1);
|
// assert.equal(lastItem2.ver, 1);
|
||||||
assert.equal(lastItem2.data, 'helloD4');
|
assert.equal(lastItem2.data, 'helloD4');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -631,15 +548,13 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
const hash1 = list1.ipfsHash;
|
const hash1 = list1.ipfsHash;
|
||||||
const hash2 = list2.ipfsHash;
|
const hash2 = list2.ipfsHash;
|
||||||
assert.equal(hash1, 'QmWTHVjf95GSFMErzGwNRzjnEwb7Z5SUo1Qb283oRzLvAT');
|
|
||||||
assert.equal(hash2, 'QmVME1BiyuNZZRXZu1npPypav1jMy3XbqHjFt4xdTzUzCd');
|
|
||||||
|
|
||||||
const final = new List(ipfs, 'B');
|
const final = new List(ipfs, 'B');
|
||||||
const other1 = List.fromIpfsHash(ipfs, hash1);
|
const other1 = List.fromIpfsHash(ipfs, hash1);
|
||||||
const other2 = List.fromIpfsHash(ipfs, hash2);
|
const other2 = List.fromIpfsHash(ipfs, hash2);
|
||||||
final.join(other1);
|
final.join(other1);
|
||||||
|
|
||||||
assert.equal(_.includes(final.items.map((a) => a.compactId), undefined), false);
|
assert.equal(_.includes(final.items.map((a) => a.hash), undefined), false);
|
||||||
assert.equal(final.items.length, count);
|
assert.equal(final.items.length, count);
|
||||||
assert.equal(final.items[0].data, "first 1");
|
assert.equal(final.items[0].data, "first 1");
|
||||||
assert.equal(final.items[final.items.length - 1].data, "first " + count);
|
assert.equal(final.items[final.items.length - 1].data, "first " + count);
|
||||||
@ -654,15 +569,13 @@ describe('OrbitList', async(function() {
|
|||||||
it('orders fetched items correctly', async((done) => {
|
it('orders fetched items correctly', async((done) => {
|
||||||
const list1 = new List(ipfs, 'A');
|
const list1 = new List(ipfs, 'A');
|
||||||
const list2 = new List(ipfs, 'AAA');
|
const list2 = new List(ipfs, 'AAA');
|
||||||
|
const final = new List(ipfs, 'B');
|
||||||
|
|
||||||
const count = List.batchSize * 3;
|
const count = List.batchSize * 3;
|
||||||
for(let i = 1; i < (count * 2) + 1; i ++)
|
for(let i = 1; i < (count * 2) + 1; i ++)
|
||||||
list1.add("first " + i);
|
list1.add("first " + i);
|
||||||
|
|
||||||
const hash1 = list1.ipfsHash;
|
const hash1 = list1.ipfsHash;
|
||||||
assert.equal(hash1, 'QmaJ2a1AxPBhKcis1HLRnc1UNixSmwd9XBNJzxdnqQSyYa');
|
|
||||||
|
|
||||||
const final = new List(ipfs, 'B');
|
|
||||||
const other1 = List.fromIpfsHash(ipfs, hash1);
|
const other1 = List.fromIpfsHash(ipfs, hash1);
|
||||||
final.join(other1);
|
final.join(other1);
|
||||||
|
|
||||||
@ -675,8 +588,6 @@ describe('OrbitList', async(function() {
|
|||||||
list2.add("second " + i);
|
list2.add("second " + i);
|
||||||
|
|
||||||
const hash2 = list2.ipfsHash;
|
const hash2 = list2.ipfsHash;
|
||||||
assert.equal(hash2, 'QmVQ55crzwWY21D7LwMLrxT7aKvCoSVtpo23WRdajSHtBN');
|
|
||||||
|
|
||||||
const other2 = List.fromIpfsHash(ipfs, hash2);
|
const other2 = List.fromIpfsHash(ipfs, hash2);
|
||||||
final.join(other2);
|
final.join(other2);
|
||||||
|
|
||||||
@ -687,7 +598,6 @@ describe('OrbitList', async(function() {
|
|||||||
assert.equal(final.items[final.items.length - 1].data, "second " + count);
|
assert.equal(final.items[final.items.length - 1].data, "second " + count);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('findHeads', () => {
|
describe('findHeads', () => {
|
||||||
@ -712,7 +622,7 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
const heads = List2.findHeads(list1.items)
|
const heads = List2.findHeads(list1.items)
|
||||||
assert.equal(heads.length, 1);
|
assert.equal(heads.length, 1);
|
||||||
assert.equal(heads[0].compactId, 'A.2.1');
|
assert.equal(heads[0].hash, 'QmfUmywxAP8ZXNkxN1CJJ3UsbmEracdeDCzaZzid9zwoe9');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -735,18 +645,12 @@ describe('OrbitList', async(function() {
|
|||||||
|
|
||||||
const heads = List2.findHeads(list1.items)
|
const heads = List2.findHeads(list1.items)
|
||||||
assert.equal(heads.length, 2);
|
assert.equal(heads.length, 2);
|
||||||
assert.equal(heads[0].compactId, 'B.1.0');
|
assert.equal(heads[0].hash, 'QmT8oHPp2x5t5sKy2jw3ZXKihm1danLbmHMbQ6nnzWRdj6');
|
||||||
assert.equal(heads[1].compactId, 'A.1.1');
|
assert.equal(heads[1].hash, 'QmPT7qgkysupMuMf2k8yESBL8A55Cva9Y8pqTuA1AMWB4m');
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('_isReferencedInChain', () => {
|
|
||||||
it('TODO', (done) => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('is a CRDT', () => {
|
describe('is a CRDT', () => {
|
||||||
it('join is associative', async((done) => {
|
it('join is associative', async((done) => {
|
||||||
let list1 = new List(ipfs, 'A');
|
let list1 = new List(ipfs, 'A');
|
||||||
@ -763,7 +667,7 @@ describe('OrbitList', async(function() {
|
|||||||
list2.join(list3);
|
list2.join(list3);
|
||||||
list1.join(list2);
|
list1.join(list2);
|
||||||
|
|
||||||
const res1 = list1.items.map((e) => e.compactId).join(", ");
|
const res1 = list1.items.map((e) => e.hash).join(",");
|
||||||
|
|
||||||
list1 = new List(ipfs, 'A');
|
list1 = new List(ipfs, 'A');
|
||||||
list2 = new List(ipfs, 'B');
|
list2 = new List(ipfs, 'B');
|
||||||
@ -779,9 +683,12 @@ describe('OrbitList', async(function() {
|
|||||||
list1.join(list2);
|
list1.join(list2);
|
||||||
list1.join(list3);
|
list1.join(list3);
|
||||||
|
|
||||||
const res2 = list1.items.map((e) => e.compactId).join(", ");
|
const res2 = list1.items.map((e) => e.hash).join(",");
|
||||||
|
|
||||||
// associativity: a + (b + c) == (a + b) + c
|
// associativity: a + (b + c) == (a + b) + c
|
||||||
|
const len = (46 + 1) * 6- 1; // 46 == ipfs hash, +1 == .join(","), * 4 == number of items, -1 == last item doesn't get a ',' from .join
|
||||||
|
assert.equal(res1.length, len)
|
||||||
|
assert.equal(res2.length, len)
|
||||||
assert.equal(res1, res2);
|
assert.equal(res1, res2);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -798,7 +705,7 @@ describe('OrbitList', async(function() {
|
|||||||
// b + a
|
// b + a
|
||||||
list2.join(list1);
|
list2.join(list1);
|
||||||
|
|
||||||
const res1 = list2.items.map((e) => e.compactId).join(", ");
|
const res1 = list2.items.map((e) => e.hash).join(",");
|
||||||
|
|
||||||
list1 = new List(ipfs, 'A');
|
list1 = new List(ipfs, 'A');
|
||||||
list2 = new List(ipfs, 'B');
|
list2 = new List(ipfs, 'B');
|
||||||
@ -811,9 +718,12 @@ describe('OrbitList', async(function() {
|
|||||||
// a + b
|
// a + b
|
||||||
list1.join(list2);
|
list1.join(list2);
|
||||||
|
|
||||||
const res2 = list1.items.map((e) => e.compactId).join(", ");
|
const res2 = list1.items.map((e) => e.hash).join(",");
|
||||||
|
|
||||||
// commutativity: a + (b + c) == (a + b) + c
|
// commutativity: a + (b + c) == (a + b) + c
|
||||||
|
const len = (46 + 1) * 4 - 1; // 46 == ipfs hash, +1 == .join(","), * 4 == number of items, -1 == last item doesn't get a ',' from .join
|
||||||
|
assert.equal(res1.length, len)
|
||||||
|
assert.equal(res2.length, len)
|
||||||
assert.equal(res1, res2);
|
assert.equal(res1, res2);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
@ -834,15 +744,51 @@ describe('OrbitList', async(function() {
|
|||||||
list1.join(list2);
|
list1.join(list2);
|
||||||
|
|
||||||
assert.equal(list1.id, 'A');
|
assert.equal(list1.id, 'A');
|
||||||
assert.equal(list1.seq, 1);
|
// assert.equal(list1.seq, 1);
|
||||||
assert.equal(list1.ver, 0);
|
// assert.equal(list1.ver, 0);
|
||||||
assert.equal(list1.items.length, 3);
|
assert.equal(list1.items.length, 3);
|
||||||
assert.equal(list1.items[0].ver, 0);
|
// assert.equal(list1.items[0].ver, 0);
|
||||||
assert.equal(list1.items[1].ver, 1);
|
// assert.equal(list1.items[1].ver, 1);
|
||||||
assert.equal(list1.items[2].ver, 2);
|
// assert.equal(list1.items[2].ver, 2);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('clear', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_fetchHistory', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_fetchRecursive', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_insert', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('_commit', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isReferencedInChain', () => {
|
||||||
|
it('TODO', (done) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
@ -18,7 +18,7 @@ const startIpfs = async (() => {
|
|||||||
let ipfs;
|
let ipfs;
|
||||||
|
|
||||||
describe('OrbitNode', function() {
|
describe('OrbitNode', function() {
|
||||||
this.timeout(10000);
|
this.timeout(5000);
|
||||||
|
|
||||||
before(async((done) => {
|
before(async((done) => {
|
||||||
ipfs = await(startIpfs());
|
ipfs = await(startIpfs());
|
||||||
@ -27,37 +27,72 @@ describe('OrbitNode', function() {
|
|||||||
|
|
||||||
describe('Constructor', () => {
|
describe('Constructor', () => {
|
||||||
it('initializes member variables', async((done) => {
|
it('initializes member variables', async((done) => {
|
||||||
const node = new Node(ipfs, 'A', 0, 0);
|
const node = new Node(ipfs, 'A');
|
||||||
assert.equal(node.id, 'A');
|
assert.equal(node.id, 'A');
|
||||||
assert.equal(node.seq, 0);
|
|
||||||
assert.equal(node.ver, 0);
|
|
||||||
assert.equal(node.data, null);
|
assert.equal(node.data, null);
|
||||||
assert.equal(node.next.length, 0);
|
assert.equal(node.next.length, 0);
|
||||||
assert.equal(node.hash, 'QmNcbwc5V42kkQbnBvtWsmREbUy8PB5cG3J5DTyPWqYkho');
|
assert.equal(node.hash, 'QmbibmqvDT4LHo6oEFRMgRhKUBw6Fn7SLCp57GKu5eY1uY');
|
||||||
assert.equal(node._ipfs, ipfs);
|
assert.equal(node._ipfs, ipfs);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('initializes member variables with data', async((done) => {
|
it('initializes member variables with data', async((done) => {
|
||||||
const node = new Node(ipfs, 'A', 0, 0, 'QmTnaGEpw4totXN7rhv2jPMXKfL8s65PhhCKL5pwtJfRxn');
|
const node = new Node(ipfs, 'A', 'QmbibmqvDT4LHo6oEFRMgRhKUBw6Fn7SLCp57GKu5eY1uY');
|
||||||
assert.equal(node.id, 'A');
|
assert.equal(node.id, 'A');
|
||||||
assert.equal(node.seq, 0);
|
assert.equal(node.data, 'QmbibmqvDT4LHo6oEFRMgRhKUBw6Fn7SLCp57GKu5eY1uY');
|
||||||
assert.equal(node.ver, 0);
|
|
||||||
assert.equal(node.data, 'QmTnaGEpw4totXN7rhv2jPMXKfL8s65PhhCKL5pwtJfRxn');
|
|
||||||
assert.equal(node.next.length, 0);
|
assert.equal(node.next.length, 0);
|
||||||
assert.equal(node.hash, 'QmULakc8SCkz5wz3s1TDkQgZWP1yBrhdXMpHJGJY3sV33r');
|
assert.equal(node.hash, 'Qme1c5GGCtkBLZV4dVsZtJj2ZREraupAfyJXrYrzfEVKN5');
|
||||||
assert.equal(node._ipfs, ipfs);
|
assert.equal(node._ipfs, ipfs);
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('compactId', () => {
|
describe('fetchPayload', () => {
|
||||||
it('presents the node as a string with id, sequence, version and hash', async((done) => {
|
it('TODO', async((done) => {
|
||||||
const node1 = new Node(ipfs, 'A', 0, 0, "QmTnaGEpw4totXN7rhv2jPMXKfL8s65PhhCKL5pwtJfRxn");
|
|
||||||
const node2 = new Node(ipfs, 'B', 123, 456, "QmdcCucbM2rnHHaVhAmjMxWDY5cCDwtTtjhYuS5nBHThQq");
|
|
||||||
assert.equal(node1.compactId, 'A.0.0');
|
|
||||||
assert.equal(node2.compactId, 'B.123.456');
|
|
||||||
done();
|
done();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('hasChild', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fetchPayload', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('heads', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ipfsHash', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('asJson', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fromIpfsHash', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('equals', () => {
|
||||||
|
it('TODO', async((done) => {
|
||||||
|
done();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user