Skip to content
Snippets Groups Projects
Commit 252a4597 authored by Éloïs's avatar Éloïs
Browse files

[enh] add method newEmptyFileInstance()

parent 1fc75139
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,14 @@ module.exports = { ...@@ -18,6 +18,14 @@ module.exports = {
return instance return instance
}, },
newEmptyFileInstance: (filePath, sigStock) => {
const instance = Object.create(WotB)
const id = binding.new_memory_instance(sigStock);
instance.init(id)
instance.setFilePath(filePath)
return instance
},
newMemoryInstance: (sigStock) => { newMemoryInstance: (sigStock) => {
const instance = Object.create(WotB) const instance = Object.create(WotB)
const id = binding.new_memory_instance(sigStock); const id = binding.new_memory_instance(sigStock);
......
...@@ -6,6 +6,7 @@ var fs = require('fs'); ...@@ -6,6 +6,7 @@ var fs = require('fs');
var path = require('path'); var path = require('path');
var should = require('should'); var should = require('should');
const EMPTY_FILE = path.join(__dirname, 'wotb.bin');
const FILE = path.join(__dirname, 'g1_genesis.bin'); const FILE = path.join(__dirname, 'g1_genesis.bin');
const X_PERCENT = 1.0; const X_PERCENT = 1.0;
const _100_PERCENT = 1.0; const _100_PERCENT = 1.0;
...@@ -479,6 +480,33 @@ function testSuite() { ...@@ -479,6 +480,33 @@ function testSuite() {
}); });
})); }));
describe('tests open written wot file', newInstance((wot) => {
before(() => {
wot.clear();
wot = addon.newFileInstance("test.bin", 3);
});
it('should have an instanceID zero', function() {
assert.equal(wot.instanceID, 0)
});
it('should have a wot size of 12', function() {
should.equal(wot.getWoTSize(), 12);
});
it('should add node, write and read new wot with 13 nodes', function() {
wot.addNode();
assert.equal(wot.write(), true)
wot.clear();
wot = addon.newFileInstance("test.bin", 3);
should.equal(wot.getWoTSize(), 13);
});
after(() => {
wot.clear();
});
}));
describe('tests g1 genesis wot', newInstance((wot) => { describe('tests g1 genesis wot', newInstance((wot) => {
before(() => { before(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment