Commit 0a4d87ff authored by nanocryk's avatar nanocryk
Browse files

tests (failing)

parent 79740cfc
let addon = require('./build');
let AtomicFileWebOfTrust = addon.AtomicFileWebOfTrust;
let MemoryWebOfTrust = addon.MemoryWebOfTrust;
exports.newFileInstance = function(path) {
return new AtomicFileWebOfTrust(path);
}
exports.newMemoryInstance = function(max_cert) {
var max_cert = max_cert || 3;
return new MemoryWebOfTrust(max_cert);
}
\ No newline at end of file
let native: any = require('../native');
let NativeWebOfTrust = native.WebOfTrust;
interface WebOfTrust {
export interface WebOfTrust {
filePath: String;
toFile(path: String): Boolean;
addNode(): Number;
removeNode(): Number;
......@@ -20,11 +22,13 @@ interface WebOfTrust {
getMaxCert(): Number;
}
class MemoryWebOfTrust implements WebOfTrust {
export class MemoryWebOfTrust implements WebOfTrust {
private wot: any;
filePath: String;
constructor (max_cert: Number) {
this.wot = new NativeWebOfTrust(max_cert);
this.filePath = "";
}
toFile(path: String): Boolean {
......@@ -92,13 +96,13 @@ class MemoryWebOfTrust implements WebOfTrust {
}
}
class AtomicFileWebOfTrust implements WebOfTrust {
export class AtomicFileWebOfTrust implements WebOfTrust {
private wot: any;
private path: String;
filePath: String;
constructor (path: String) {
this.wot = new NativeWebOfTrust(path);
this.path = path;
this.filePath = path;
}
toFile(path: String): Boolean {
......@@ -107,13 +111,13 @@ class AtomicFileWebOfTrust implements WebOfTrust {
addNode(): Number {
let result = this.wot.addNode()
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
return result
}
removeNode(): Number {
let result = this.wot.removeNode()
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
return result
}
......@@ -143,19 +147,19 @@ class AtomicFileWebOfTrust implements WebOfTrust {
setEnabled(node: Number, state: Boolean): Boolean {
let result = this.wot.setEnabled(node, state)
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
return result
}
addLink(from: Number, to: Number): Number {
let result = this.wot.addLink(from, to)
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
return result
}
removeLink(from: Number, to: Number): Number {
let result = this.wot.removeLink(from, to)
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
return result
}
......@@ -169,32 +173,10 @@ class AtomicFileWebOfTrust implements WebOfTrust {
setMaxCert(max_cert: Number): void {
this.wot.setMaxCert(max_cert)
if (!this.toFile(this.path)) throw new Error("Error while writing file")
if (!this.toFile(this.filePath)) throw new Error("Error while writing file")
}
getMaxCert(): Number {
return this.wot.getMaxCert()
}
}
{
let wot = new MemoryWebOfTrust(3);
console.log(wot.getMaxCert())
wot.setMaxCert(4);
console.log(wot.getMaxCert())
console.log(wot.addNode());
console.log(wot.getWoTSize())
}
console.log("-----")
{
let wot = new AtomicFileWebOfTrust("hey.wot");
console.log(wot.getMaxCert())
console.log(wot.addNode());
console.log(wot.getWoTSize());
//console.log(wot.toFile("hey.wot"));
}
}
\ No newline at end of file
......@@ -171,7 +171,7 @@ declare_types! {
wot.is_enabled(NodeId(node))
}) {
Some(state) => Ok(JsBoolean::new(scope, state).upcast()),
None => Err(Throw),
None => Ok(JsBoolean::new(scope, false).upcast()),
}
}
......
......@@ -10,15 +10,22 @@
"author": "nanocryk <nanocryk@gmail.com>",
"license": "GPL-3.0",
"dependencies": {
"neon-cli": "^0.1.20"
"neon-cli": "^0.1.20",
"aws-sdk": "2.2.43",
"mocha": "2.2.5",
"should": "8.1.1"
},
"scripts": {
"install": "neon build",
"prepublish": "tsc",
"tsc": "tsc"
"tsc": "tsc",
"test": "node \"node_modules/mocha/bin/mocha\" tests/"
},
"devDependencies": {
"@types/node": "^8.0.50",
"typescript": "^2.6.1"
}
},
"bundledDependencies": [
"node-pre-gyp"
]
}
"use strict";
const addon = require('./../index');
const assert = require('assert');
const should = require('should');
let baseInstance
describe('Testing getPaths()', function() {
this.timeout(10000) // 10 seconds max for a test
before(() => {
baseInstance = addon.newMemoryInstance()
baseInstance.addNode()
baseInstance.addNode()
baseInstance.addNode()
baseInstance.addNode()
baseInstance.addLink(0, 1)
baseInstance.addLink(1, 2)
baseInstance.addLink(2, 3)
baseInstance.addLink(0, 3)
/**
* Wot:
*
* 0 --> 1 --> 2 --> 3
* `----------------^
*/
})
it('wotb.getPaths() should return arrays with the size of the paths', () => {
// Path 0 --> 1
assert.equal(baseInstance.getPaths(0, 1, 1).length, 1);
assert.equal(baseInstance.getPaths(0, 1, 1)[0].length, 2); // 0, 1
// Path 0 --> 2
assert.equal(baseInstance.getPaths(0, 2, 1).length, 0);
assert.equal(baseInstance.getPaths(0, 2, 2).length, 1);
assert.equal(baseInstance.getPaths(0, 2, 2)[0].length, 3); // 0, 1, 2
// Path 0 --> 3
assert.equal(baseInstance.getPaths(0, 3, 1).length, 1);
assert.equal(baseInstance.getPaths(0, 3, 1)[0].length, 2);
assert.equal(baseInstance.getPaths(0, 3, 2).length, 1);
assert.equal(baseInstance.getPaths(0, 3, 2)[0].length, 2);
})
})
This diff is collapsed.
......@@ -62,6 +62,14 @@ async@^1.4.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
aws-sdk@2.2.43:
version "2.2.43"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.2.43.tgz#69058034aae175337740961cced777664a6ebd4d"
dependencies:
sax "1.1.5"
xml2js "0.4.15"
xmlbuilder "2.6.2"
balanced-match@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
......@@ -157,10 +165,24 @@ command-line-usage@^4.0.0:
table-layout "^0.4.1"
typical "^2.6.1"
commander@0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-0.6.1.tgz#fa68a14f6a945d54dbbe50d8cdb3320e9e3b1a06"
commander@2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.3.0.tgz#fd430e889832ec353b9acd1de217c11cb3eef873"
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
debug@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.0.0.tgz#89bd9df6732b51256bc6705342bba02ed12131ef"
dependencies:
ms "0.6.2"
decamelize@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
......@@ -169,6 +191,14 @@ deep-extend@~0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.5.0.tgz#6ef4a09b05f98b0e358d6d93d4ca3caec6672803"
diff@1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"
escape-string-regexp@1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.2.tgz#4dbc2fe674e71949caf3fb2695ce7f2dc1d9a8d1"
escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
......@@ -204,6 +234,14 @@ git-config@0.0.7:
dependencies:
iniparser "~1.0.5"
glob@3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-3.2.3.tgz#e313eeb249c7affaa5c475286b0e115b59839467"
dependencies:
graceful-fs "~2.0.0"
inherits "2"
minimatch "~0.2.11"
glob@^7.0.5:
version "7.1.2"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
......@@ -215,6 +253,14 @@ glob@^7.0.5:
once "^1.3.0"
path-is-absolute "^1.0.0"
graceful-fs@~2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-2.0.3.tgz#7cd2cdb228a4a3f36e95efa6cc142de7d1a136d0"
growl@1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.8.1.tgz#4b2dec8d907e93db336624dcec0183502f8c9428"
handlebars@^4.0.3:
version "4.0.11"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc"
......@@ -289,6 +335,13 @@ is-promise@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-promise/-/is-promise-2.1.0.tgz#79a2a9ece7f096e80f36d2b2f3bc16c1ff4bf3fa"
jade@0.26.3:
version "0.26.3"
resolved "https://registry.yarnpkg.com/jade/-/jade-0.26.3.tgz#8f10d7977d8d79f2f6ff862a81b0513ccb25686c"
dependencies:
commander "0.6.1"
mkdirp "0.3.0"
jschardet@^1.4.2:
version "1.6.0"
resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-1.6.0.tgz#c7d1a71edcff2839db2f9ec30fc5d5ebd3c1a678"
......@@ -311,10 +364,18 @@ lodash@^4.3.0:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
lodash@~3.5.0:
version "3.5.0"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.5.0.tgz#19bb3f4d51278f0b8c818ed145c74ecf9fe40e6d"
longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"
mimic-fn@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18"
......@@ -325,6 +386,13 @@ minimatch@^3.0.4:
dependencies:
brace-expansion "^1.1.7"
minimatch@~0.2.11:
version "0.2.14"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.2.14.tgz#c74e780574f63c6f9a090e90efbe6ef53a6a756a"
dependencies:
lru-cache "2"
sigmund "~1.0.0"
minimist@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d"
......@@ -333,12 +401,40 @@ minimist@~0.0.1:
version "0.0.10"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
mkdirp@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e"
mkdirp@0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.0.tgz#1d73076a6df986cd9344e15e71fcc05a4c9abf12"
dependencies:
minimist "0.0.8"
mkdirp@^0.5.1, mkdirp@~0.5.0:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
dependencies:
minimist "0.0.8"
mocha@2.2.5:
version "2.2.5"
resolved "https://registry.yarnpkg.com/mocha/-/mocha-2.2.5.tgz#d3b72a4fe49ec9439353f1ac893dbc430d993140"
dependencies:
commander "2.3.0"
debug "2.0.0"
diff "1.4.0"
escape-string-regexp "1.0.2"
glob "3.2.3"
growl "1.8.1"
jade "0.26.3"
mkdirp "0.5.0"
supports-color "~1.2.0"
ms@0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.6.2.tgz#d89c2124c6fdc1353d65a8b77bf1aac4b193708c"
mute-stream@0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
......@@ -445,10 +541,46 @@ rx-lite@*, rx-lite@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
sax@1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.1.5.tgz#1da50a8d00cdecd59405659f5ff85349fe773743"
sax@>=0.6.0:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
semver@^5.1.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
should-equal@0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/should-equal/-/should-equal-0.6.0.tgz#5b470303a88f5b960a7d10917224b4554dab470c"
dependencies:
should-type "0.2.0"
should-format@0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/should-format/-/should-format-0.3.2.tgz#a59831e01a2ddee149911bc7148be5c80319e1ff"
dependencies:
should-type "0.2.0"
should-type@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/should-type/-/should-type-0.2.0.tgz#6707ef95529d989dcc098fe0753ab1f9136bb7f6"
should@8.1.1:
version "8.1.1"
resolved "https://registry.yarnpkg.com/should/-/should-8.1.1.tgz#64796ddc28bdf7b38c434518d292feff51f13c65"
dependencies:
should-equal "0.6.0"
should-format "0.3.2"
should-type "0.2.0"
sigmund@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
......@@ -506,6 +638,10 @@ supports-color@^4.0.0:
dependencies:
has-flag "^2.0.0"
supports-color@~1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-1.2.1.tgz#12ee21507086cd98c1058d9ec0f4ac476b7af3b2"
table-layout@^0.4.1:
version "0.4.2"
resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-0.4.2.tgz#10e9043c142a1e2d155da7257e478f0ef4981786"
......@@ -600,6 +736,23 @@ wrappy@1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
xml2js@0.4.15:
version "0.4.15"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.15.tgz#95cd03ff2dd144ec28bc6273bf2b2890c581ad0c"
dependencies:
sax ">=0.6.0"
xmlbuilder ">=2.4.6"
xmlbuilder@2.6.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-2.6.2.tgz#f916f6d10d45dc171b1be2e6e673fb6e0cc35d0a"
dependencies:
lodash "~3.5.0"
xmlbuilder@>=2.4.6:
version "9.0.4"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.4.tgz#519cb4ca686d005a8420d3496f3f0caeecca580f"
yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment