From 252a4597c2ad107d561cd6effef2f93ef79d5ef2 Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Tue, 24 Apr 2018 16:27:47 +0200
Subject: [PATCH] [enh] add method newEmptyFileInstance()

---
 lib/index.js  |  8 ++++++++
 tests/test.js | 28 ++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/lib/index.js b/lib/index.js
index ee1d086..3ca5b13 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -18,6 +18,14 @@ module.exports = {
         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) => {
         const instance = Object.create(WotB)
         const id = binding.new_memory_instance(sigStock);
diff --git a/tests/test.js b/tests/test.js
index d23bc15..d905fbd 100644
--- a/tests/test.js
+++ b/tests/test.js
@@ -6,6 +6,7 @@ var fs = require('fs');
 var path = require('path');
 var should = require('should');
 
+const EMPTY_FILE = path.join(__dirname, 'wotb.bin');
 const FILE = path.join(__dirname, 'g1_genesis.bin');
 const X_PERCENT = 1.0;
 const _100_PERCENT = 1.0;
@@ -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) => {
 
             before(() => {
-- 
GitLab