From 988cf543b5439e46d1d0b7911e9689c4d28f50fc Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Fri, 13 Oct 2017 16:32:59 +0200
Subject: [PATCH] [mod] add more typage in some tests

---
 app/lib/dto/ConfDTO.ts                 | 19 +++++++-------
 test/integration/documents-currency.ts | 36 ++++++++++++++------------
 test/integration/server-shutdown.ts    |  4 ++-
 test/integration/tools/toolbox.ts      |  8 +++---
 4 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/app/lib/dto/ConfDTO.ts b/app/lib/dto/ConfDTO.ts
index 361eb49c9..7c0339f01 100644
--- a/app/lib/dto/ConfDTO.ts
+++ b/app/lib/dto/ConfDTO.ts
@@ -61,9 +61,9 @@ export interface NetworkConfDTO {
 
 export interface WS2PConfDTO {
   ws2p?: {
-    privateAccess: boolean
-    publicAccess: boolean
-    uuid: string
+    privateAccess?: boolean
+    publicAccess?: boolean
+    uuid?: string
     upnp?: boolean
     remotehost?: string|null
     remoteport?: number|null
@@ -135,9 +135,9 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
     public memory: boolean,
     public nobma: boolean,
     public ws2p?: {
-      privateAccess: boolean
-      publicAccess: boolean
-      uuid: string
+      privateAccess?: boolean
+      publicAccess?: boolean
+      uuid?: string
       upnp?: boolean
       remotehost?: string|null
       remoteport?: number|null
@@ -156,7 +156,8 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
   }
 
   static defaultConf() {
-    return {
+    return new ConfDTO("", "", [], [], 0, 3600 * 1000, constants.CONTRACT.DEFAULT.C, 1, 1, 0, 0, constants.CONTRACT.DEFAULT.C, constants.CONTRACT.DEFAULT.DT, constants.CONTRACT.DEFAULT.DT_REEVAL, 0, constants.CONTRACT.DEFAULT.UD0, 0, 0, constants.CONTRACT.DEFAULT.STEPMAX, constants.CONTRACT.DEFAULT.SIGPERIOD, 0, constants.CONTRACT.DEFAULT.SIGVALIDITY, constants.CONTRACT.DEFAULT.MSVALIDITY, constants.CONTRACT.DEFAULT.SIGQTY, constants.CONTRACT.DEFAULT.SIGSTOCK, constants.CONTRACT.DEFAULT.X_PERCENT, constants.CONTRACT.DEFAULT.PERCENTROT, constants.CONTRACT.DEFAULT.POWDELAY, constants.CONTRACT.DEFAULT.AVGGENTIME, constants.CONTRACT.DEFAULT.MEDIANTIMEBLOCKS, false, 3000, false, constants.BRANCHES.DEFAULT_WINDOW_SIZE, constants.CONTRACT.DEFAULT_IDTYWINDOW, constants.CONTRACT.DEFAULT.MSWINDOW, constants.CONTRACT.DEFAULT.SIGWINDOW, 0, { pub:'', sec:'' }, null, "", "", 0, "", "", "", 0, "", "", null, false, "", true, true)
+    /*return {
       "currency": null,
       "endpoints": [],
       "rmEndpoints": [],
@@ -182,10 +183,10 @@ export class ConfDTO implements CurrencyConfDTO, KeypairConfDTO, NetworkConfDTO,
       "isolate": false,
       "forksize": constants.BRANCHES.DEFAULT_WINDOW_SIZE,
       "switchOnHeadAdvance": CommonConstants.SWITCH_ON_BRANCH_AHEAD_BY_X_BLOCKS
-    };
+    };*/
   }
 
-  static complete(conf:any) {
+  static complete(conf:ConfDTO) {
     return _(ConfDTO.defaultConf()).extend(conf);
   }
 }
\ No newline at end of file
diff --git a/test/integration/documents-currency.ts b/test/integration/documents-currency.ts
index e18173af5..370b96ab9 100644
--- a/test/integration/documents-currency.ts
+++ b/test/integration/documents-currency.ts
@@ -1,30 +1,34 @@
-import {NewTestingServer} from "./tools/toolbox"
+import { NewTestingServer, TestingServer } from './tools/toolbox';
+import { unlock } from '../../app/lib/common-libs/txunlock';
+import { ConfDTO, CurrencyConfDTO } from '../../app/lib/dto/ConfDTO';
+import { Server } from '../../server';
 
 const co        = require('co');
 const should    = require('should');
 const user      = require('./tools/user');
 const commit    = require('./tools/commit');
 
-let s1:any, s2:any, cat1:any, tac1:any, toc2:any, tic2:any;
+let s1:TestingServer, s2:TestingServer, s1Conf:ConfDTO, s2Conf:ConfDTO, cat1:any, tac1:any, toc2:any, tic2:any;
 
 describe("Document pool currency", function() {
 
   before(() => co(function*() {
 
-    s1 = NewTestingServer({
-      currency: 'currency_one',
-      pair: {
-        pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
-        sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
-      }
-    });
-    s2 = NewTestingServer({
-      currency: 'currency_two',
-      pair: {
-        pub: 'DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo',
-        sec: '64EYRvdPpTfLGGmaX5nijLXRqWXaVz8r1Z1GtaahXwVSJGQRn7tqkxLb288zwSYzELMEG5ZhXSBYSxsTsz1m9y8F'
-      }
-    });
+    s1Conf = ConfDTO.defaultConf();
+    s1Conf.currency = 'currency_one'
+    s1Conf.pair = {
+      pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
+      sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
+    }
+    s1 = NewTestingServer(s1Conf)
+    
+    s2Conf = ConfDTO.defaultConf();
+    s2Conf.currency = 'currency_one'
+    s2Conf.pair = {
+      pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd',
+      sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'
+    }
+    s2 = NewTestingServer(s2Conf);
 
     cat1 = user('cat', { pub: 'HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd', sec: '51w4fEShBk1jCMauWu4mLpmDVfHksKmWcygpxriqCEZizbtERA6de4STKRkQBpxmMUwsKXRjSzuQ8ECwmqN1u2DP'}, { server: s1 });
     tac1 = user('tac', { pub: '2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc', sec: '2HuRLWgKgED1bVio1tdpeXrf7zuUszv1yPHDsDj7kcMC4rVSN9RC58ogjtKNfTbH1eFz7rn38U1PywNs3m6Q7UxE'}, { server: s1 });
diff --git a/test/integration/server-shutdown.ts b/test/integration/server-shutdown.ts
index 854e20eae..48af21914 100644
--- a/test/integration/server-shutdown.ts
+++ b/test/integration/server-shutdown.ts
@@ -1,3 +1,5 @@
+import { ConfDTO } from '../../app/lib/dto/ConfDTO';
+import { setTimeout } from 'timers';
 import {NewTestingServer} from "./tools/toolbox"
 
 const should = require('should')
@@ -6,7 +8,7 @@ const querablep = require('querablep')
 describe("Server shutdown", () => {
 
   it('should not interrupt a task in the documents FIFO', async () => {
-    const s1 = NewTestingServer({})
+    const s1 = NewTestingServer(ConfDTO.defaultConf())
 
     const fifo = s1._server.getDocumentsFIFO()
     const ops:any[] = []
diff --git a/test/integration/tools/toolbox.ts b/test/integration/tools/toolbox.ts
index fcf1e9670..7b68c60aa 100644
--- a/test/integration/tools/toolbox.ts
+++ b/test/integration/tools/toolbox.ts
@@ -218,11 +218,11 @@ export const fakeSyncServer = async (readBlocksMethod:any, readParticularBlockMe
  * Creates a new memory duniter server for Unit Test purposes.
  * @param conf
  */
-export const server = (conf:any) => NewTestingServer(conf)
-export const simpleTestingServer = (conf:any) => NewTestingServer(conf)
+export const server = (conf:ConfDTO) => NewTestingServer(conf)
+export const simpleTestingServer = (conf:ConfDTO) => NewTestingServer(conf)
 
-export const NewTestingServer = (conf:any) => {
-  const host = conf.host || HOST
+export const NewTestingServer = (conf:ConfDTO) => {
+  const host = conf.remotehost || HOST
   const port = conf.port || PORT++
   const commonConf = {
     nobma: false,
-- 
GitLab