From 9f0caf31756822dedec1dc0c90f069464325ebda Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Mon, 30 Sep 2019 20:43:13 +0200
Subject: [PATCH] [tests] create bc-db-tests-tools & blocks-tests-tools

---
 Cargo.lock                                    | 33 ++++++-
 Cargo.toml                                    |  2 +
 lib/modules-lib/bc-db-reader/Cargo.toml       |  1 +
 .../bc-db-reader/src/blocks/fork_tree.rs      |  7 +-
 .../blockchain/bc-db-writer/Cargo.toml        |  1 +
 .../blockchain/bc-db-writer/src/blocks.rs     |  1 +
 .../bc-db-writer/src/blocks/fork_tree.rs      |  4 +-
 lib/modules/blockchain/blockchain/Cargo.toml  |  1 +
 .../blockchain/src/fork/fork_algo.rs          | 59 +++++-------
 lib/tests-tools/bc-db-tests-tools/Cargo.toml  | 27 ++++++
 lib/tests-tools/bc-db-tests-tools/src/lib.rs  | 42 ++++++++
 .../bc-db-tests-tools/src/mocks.rs            | 67 +++++++++++++
 lib/tests-tools/blocks-tests-tools/Cargo.toml | 24 +++++
 lib/tests-tools/blocks-tests-tools/src/lib.rs | 29 ++++++
 .../blocks-tests-tools/src/mocks.rs           | 96 +++++++++++++++++++
 .../user-docs-tests-tools/Cargo.toml          |  1 -
 .../user-docs-tests-tools/src/mocks/mod.rs    | 80 ----------------
 17 files changed, 354 insertions(+), 121 deletions(-)
 create mode 100644 lib/tests-tools/bc-db-tests-tools/Cargo.toml
 create mode 100644 lib/tests-tools/bc-db-tests-tools/src/lib.rs
 create mode 100644 lib/tests-tools/bc-db-tests-tools/src/mocks.rs
 create mode 100644 lib/tests-tools/blocks-tests-tools/Cargo.toml
 create mode 100644 lib/tests-tools/blocks-tests-tools/src/lib.rs
 create mode 100644 lib/tests-tools/blocks-tests-tools/src/mocks.rs

diff --git a/Cargo.lock b/Cargo.lock
index 3ea57d5a..aac36f52 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -90,6 +90,22 @@ dependencies = [
  "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "bc-db-tests-tools"
+version = "0.1.0"
+dependencies = [
+ "dubp-block-doc 0.1.0",
+ "dubp-blocks-tests-tools 0.1.0",
+ "dubp-common-doc 0.1.0",
+ "dubp-currency-params 0.2.0",
+ "dubp-user-docs 0.14.0",
+ "dup-crypto 0.7.0",
+ "dup-crypto-tests-tools 0.1.0",
+ "durs-bc-db-reader 0.3.0-dev",
+ "durs-bc-db-writer 0.3.0-dev",
+ "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "bincode"
 version = "1.0.1"
@@ -371,6 +387,19 @@ dependencies = [
  "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "dubp-blocks-tests-tools"
+version = "0.1.0"
+dependencies = [
+ "dubp-block-doc 0.1.0",
+ "dubp-common-doc 0.1.0",
+ "dubp-currency-params 0.2.0",
+ "dubp-user-docs 0.14.0",
+ "dubp-user-docs-tests-tools 0.1.0",
+ "dup-crypto 0.7.0",
+ "dup-crypto-tests-tools 0.1.0",
+]
+
 [[package]]
 name = "dubp-common-doc"
 version = "0.1.0"
@@ -440,7 +469,6 @@ dependencies = [
 name = "dubp-user-docs-tests-tools"
 version = "0.1.0"
 dependencies = [
- "dubp-block-doc 0.1.0",
  "dubp-common-doc 0.1.0",
  "dubp-currency-params 0.2.0",
  "dubp-user-docs 0.14.0",
@@ -494,6 +522,7 @@ name = "durs-bc-db-reader"
 version = "0.3.0-dev"
 dependencies = [
  "dubp-block-doc 0.1.0",
+ "dubp-blocks-tests-tools 0.1.0",
  "dubp-common-doc 0.1.0",
  "dubp-currency-params 0.2.0",
  "dubp-indexes 0.1.0",
@@ -520,6 +549,7 @@ name = "durs-bc-db-writer"
 version = "0.3.0-dev"
 dependencies = [
  "dubp-block-doc 0.1.0",
+ "dubp-blocks-tests-tools 0.1.0",
  "dubp-common-doc 0.1.0",
  "dubp-currency-params 0.2.0",
  "dubp-indexes 0.1.0",
@@ -548,6 +578,7 @@ version = "0.3.0-dev"
 dependencies = [
  "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "dubp-block-doc 0.1.0",
+ "dubp-blocks-tests-tools 0.1.0",
  "dubp-common-doc 0.1.0",
  "dubp-currency-params 0.2.0",
  "dubp-user-docs 0.14.0",
diff --git a/Cargo.toml b/Cargo.toml
index 6298c974..078c9139 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,8 @@ members = [
     "lib/modules/ws2p-v1-legacy",
     "lib/modules/ws2p/ws2p",
     "lib/modules/ws2p/ws2p-protocol",
+    "lib/tests-tools/bc-db-tests-tools",
+    "lib/tests-tools/blocks-tests-tools",
     "lib/tests-tools/crypto-tests-tools",
     "lib/tests-tools/user-docs-tests-tools",
     "lib/tests-tools/common-tests-tools",
diff --git a/lib/modules-lib/bc-db-reader/Cargo.toml b/lib/modules-lib/bc-db-reader/Cargo.toml
index 20bbab46..e23d3c15 100644
--- a/lib/modules-lib/bc-db-reader/Cargo.toml
+++ b/lib/modules-lib/bc-db-reader/Cargo.toml
@@ -30,6 +30,7 @@ unwrap = "1.2.1"
 [dev-dependencies]
 dup-crypto-tests-tools = { path = "../../tests-tools/crypto-tests-tools" }
 dubp-user-docs-tests-tools = { path = "../../tests-tools/user-docs-tests-tools" }
+dubp-blocks-tests-tools = { path = "../../tests-tools/blocks-tests-tools" }
 durs-common-tests-tools = { path = "../../tests-tools/common-tests-tools" }
 tempfile = "3.1.0"
 
diff --git a/lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs b/lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs
index 391f228c..87b1cb14 100644
--- a/lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs
+++ b/lib/modules-lib/bc-db-reader/src/blocks/fork_tree.rs
@@ -584,8 +584,7 @@ mod tests {
     fn insert_fork_blocks() {
         // Fill tree with 10 nodes
         let mut tree = ForkTree::default();
-        let blockstamps: Vec<Blockstamp> =
-            dubp_user_docs_tests_tools::mocks::generate_blockstamps(10);
+        let blockstamps: Vec<Blockstamp> = dubp_blocks_tests_tools::mocks::generate_blockstamps(10);
         tree.insert_new_node(blockstamps[0], None, true);
         for i in 1..10 {
             tree.insert_new_node(blockstamps[i], Some(TreeNodeId(i - 1)), true);
@@ -672,7 +671,7 @@ mod tests {
     fn insert_more_fork_window_size_nodes() {
         let mut tree = ForkTree::default();
         let blockstamps: Vec<Blockstamp> =
-            dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
+            dubp_blocks_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
 
         // Fill tree with MAX_DEPTH nodes
         tree.insert_new_node(blockstamps[0], None, true);
@@ -709,7 +708,7 @@ mod tests {
     fn test_change_main_branch() {
         let mut tree = ForkTree::default();
         let blockstamps: Vec<Blockstamp> =
-            dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
+            dubp_blocks_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
 
         // Fill tree with MAX_DEPTH nodes
         tree.insert_new_node(blockstamps[0], None, true);
diff --git a/lib/modules/blockchain/bc-db-writer/Cargo.toml b/lib/modules/blockchain/bc-db-writer/Cargo.toml
index 4de7c2e9..7b7ded53 100644
--- a/lib/modules/blockchain/bc-db-writer/Cargo.toml
+++ b/lib/modules/blockchain/bc-db-writer/Cargo.toml
@@ -30,6 +30,7 @@ unwrap = "1.2.1"
 
 [dev-dependencies]
 dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" }
+dubp-blocks-tests-tools = { path = "../../../tests-tools/blocks-tests-tools" }
 dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" }
 durs-common-tests-tools = { path = "../../../tests-tools/common-tests-tools" }
 tempfile = "3.1.0"
diff --git a/lib/modules/blockchain/bc-db-writer/src/blocks.rs b/lib/modules/blockchain/bc-db-writer/src/blocks.rs
index 38246e68..0cb83ff0 100644
--- a/lib/modules/blockchain/bc-db-writer/src/blocks.rs
+++ b/lib/modules/blockchain/bc-db-writer/src/blocks.rs
@@ -29,6 +29,7 @@ use durs_bc_db_reader::DbValue;
 use unwrap::unwrap;
 
 /// Insert new head Block in databases
+/// Update MAIN_BLOCK and CURRENT_META_DATAS
 pub fn insert_new_head_block(
     db: &Db,
     w: &mut DbWriter,
diff --git a/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs b/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs
index bb058054..019eefa3 100644
--- a/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs
+++ b/lib/modules/blockchain/bc-db-writer/src/blocks/fork_tree.rs
@@ -103,7 +103,7 @@ mod test {
     fn test_insert_new_head_block() -> Result<(), DbError> {
         // Create mock datas
         let blockstamps =
-            dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
+            dubp_blocks_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2);
         let mut fork_tree = ForkTree::default();
 
         // Insert genesis block
@@ -154,7 +154,7 @@ mod test {
     fn test_insert_new_fork_block() -> Result<(), DbError> {
         // Create mock datas
         let blockstamps =
-            dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 3);
+            dubp_blocks_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 3);
         let mut fork_tree = ForkTree::default();
 
         // Insert 4 main blocks
diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml
index 8d494dbb..0e4667d0 100644
--- a/lib/modules/blockchain/blockchain/Cargo.toml
+++ b/lib/modules/blockchain/blockchain/Cargo.toml
@@ -41,4 +41,5 @@ unwrap = "1.2.1"
 [dev-dependencies]
 dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" }
 dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" }
+dubp-blocks-tests-tools = { path = "../../../tests-tools/blocks-tests-tools" }
 tempfile = "3.1.0"
diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs
index 645fef8c..d01bc5cf 100644
--- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs
+++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs
@@ -118,10 +118,7 @@ mod tests {
 
         // Generate `FORK_WINDOW_SIZE + 2` mock blocks
         let main_branch: Vec<BlockDocument> =
-            dubp_user_docs_tests_tools::mocks::gen_empty_timed_blocks_v10(
-                fork_window_size + 2,
-                0u64,
-            );
+            dubp_blocks_tests_tools::mocks::gen_empty_timed_blocks_v10(fork_window_size + 2, 0u64);
 
         // Insert mock blocks in forks_dbs
         db.write(|mut w| {
@@ -160,20 +157,18 @@ mod tests {
         let fork_point = &main_branch[main_branch.len() - 2];
         let fork_blocks: Vec<BlockDocument> = (0..3)
             .map(|i| {
-                BlockDocument::V10(
-                    dubp_user_docs_tests_tools::mocks::gen_empty_timed_block_v10(
-                        Blockstamp {
-                            id: BlockNumber(fork_point.number().0 + i + 1),
-                            hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')),
-                        },
-                        ADVANCE_TIME - 1,
-                        if i == 0 {
-                            fork_point.hash().expect("safe unwrap").0
-                        } else {
-                            dup_crypto_tests_tools::mocks::hash('A')
-                        },
-                    ),
-                )
+                BlockDocument::V10(dubp_blocks_tests_tools::mocks::gen_empty_timed_block_v10(
+                    Blockstamp {
+                        id: BlockNumber(fork_point.number().0 + i + 1),
+                        hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')),
+                    },
+                    ADVANCE_TIME - 1,
+                    if i == 0 {
+                        fork_point.hash().expect("safe unwrap").0
+                    } else {
+                        dup_crypto_tests_tools::mocks::hash('A')
+                    },
+                ))
             })
             .collect();
 
@@ -208,7 +203,7 @@ mod tests {
                     &mut fork_tree,
                     DbBlock {
                         block: BlockDocument::V10(
-                            dubp_user_docs_tests_tools::mocks::gen_empty_timed_block_v10(
+                            dubp_blocks_tests_tools::mocks::gen_empty_timed_block_v10(
                                 determining_blockstamp,
                                 *ADVANCE_TIME,
                                 dup_crypto_tests_tools::mocks::hash('A'),
@@ -243,20 +238,18 @@ mod tests {
         // The old main branch catches up and overlaps with the fork
         let new_main_blocks: Vec<BlockDocument> = (0..7)
             .map(|i| {
-                BlockDocument::V10(
-                    dubp_user_docs_tests_tools::mocks::gen_empty_timed_block_v10(
-                        Blockstamp {
-                            id: BlockNumber(fork_point.number().0 + i + 1),
-                            hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')),
-                        },
-                        ADVANCE_TIME * 2,
-                        if i == 0 {
-                            fork_point.hash().expect("safe unwrap").0
-                        } else {
-                            dup_crypto_tests_tools::mocks::hash('B')
-                        },
-                    ),
-                )
+                BlockDocument::V10(dubp_blocks_tests_tools::mocks::gen_empty_timed_block_v10(
+                    Blockstamp {
+                        id: BlockNumber(fork_point.number().0 + i + 1),
+                        hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')),
+                    },
+                    ADVANCE_TIME * 2,
+                    if i == 0 {
+                        fork_point.hash().expect("safe unwrap").0
+                    } else {
+                        dup_crypto_tests_tools::mocks::hash('B')
+                    },
+                ))
             })
             .collect();
         insert_fork_blocks(&db, &mut fork_tree, &new_main_blocks)?;
diff --git a/lib/tests-tools/bc-db-tests-tools/Cargo.toml b/lib/tests-tools/bc-db-tests-tools/Cargo.toml
new file mode 100644
index 00000000..97ad6bd5
--- /dev/null
+++ b/lib/tests-tools/bc-db-tests-tools/Cargo.toml
@@ -0,0 +1,27 @@
+[package]
+name = "bc-db-tests-tools"
+version = "0.1.0"
+authors = ["elois <elois@duniter.org>"]
+description = "Blockchain DB tests tools for Dunitrust."
+repository = "https://git.duniter.org/nodes/rust/duniter-rs"
+readme = "README.md"
+keywords = ["dunitrust", "test", "tools"]
+license = "AGPL-3.0"
+edition = "2018"
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" }
+dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" }
+dubp-currency-params = { path = "../../dubp/currency-params" }
+dubp-user-docs = { path = "../../dubp/user-docs" }
+dup-crypto = { path = "../../crypto" }
+durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" }
+durs-bc-db-writer = { path = "../../modules/blockchain/bc-db-writer" }
+dup-crypto-tests-tools = { path = "../crypto-tests-tools" }
+dubp-blocks-tests-tools = { path = "../blocks-tests-tools" }
+tempfile = "3.1.0"
+
+[dev-dependencies]
\ No newline at end of file
diff --git a/lib/tests-tools/bc-db-tests-tools/src/lib.rs b/lib/tests-tools/bc-db-tests-tools/src/lib.rs
new file mode 100644
index 00000000..d4814444
--- /dev/null
+++ b/lib/tests-tools/bc-db-tests-tools/src/lib.rs
@@ -0,0 +1,42 @@
+//  Copyright (C) 2019  Éloïs SANCHEZ
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+//! Crypto tests tools for projects use dup-crypto.
+
+#![deny(
+    missing_docs,
+    missing_debug_implementations,
+    missing_copy_implementations,
+    trivial_casts,
+    trivial_numeric_casts,
+    unsafe_code,
+    unstable_features,
+    unused_import_braces
+)]
+
+pub mod mocks;
+
+use durs_bc_db_writer::{Db, DbError};
+use tempfile::tempdir;
+
+#[inline]
+/// Open database in an arbitrary temporary directory given by OS
+/// and automatically cleaned when `Db` is dropped
+pub fn open_tmp_db() -> Result<Db, DbError> {
+    Db::open_db(
+        tempdir().map_err(DbError::FileSystemError)?.path(),
+        &durs_bc_db_reader::bc_db_schema(),
+    )
+}
diff --git a/lib/tests-tools/bc-db-tests-tools/src/mocks.rs b/lib/tests-tools/bc-db-tests-tools/src/mocks.rs
new file mode 100644
index 00000000..1f28ca62
--- /dev/null
+++ b/lib/tests-tools/bc-db-tests-tools/src/mocks.rs
@@ -0,0 +1,67 @@
+//  Copyright (C) 2019  Éloïs SANCHEZ
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+//! Mocks for Dunitrust Blockchain DB
+
+use dubp_block_doc::BlockDocument;
+use durs_bc_db_reader::blocks::fork_tree::ForkTree;
+use durs_bc_db_reader::blocks::DbBlock;
+use durs_bc_db_writer::blocks::{insert_new_fork_block, insert_new_head_block};
+use durs_bc_db_writer::{Db, DbError};
+
+/// Warning : This function does not update the indexes and considers
+/// that your block is valid (so chainable on the main chain).
+/// To be used only for tests that do not use indexes.
+/// To insert a fork block, use `insert_fork_block` instead.
+pub fn insert_main_block(
+    db_tmp: &Db,
+    block: BlockDocument,
+    fork_tree: Option<&mut ForkTree>,
+) -> Result<(), DbError> {
+    db_tmp.write(|mut w| {
+        insert_new_head_block(
+            &db_tmp,
+            &mut w,
+            fork_tree,
+            DbBlock {
+                block,
+                expire_certs: None,
+            },
+        )?;
+        Ok(w)
+    })
+}
+
+/// Insert fork block
+pub fn insert_fork_block(
+    db_tmp: &Db,
+    fork_tree: &mut ForkTree,
+    block: BlockDocument,
+) -> Result<bool, DbError> {
+    let mut orphan = false;
+    db_tmp.write(|mut w| {
+        orphan = !insert_new_fork_block(
+            db_tmp,
+            &mut w,
+            fork_tree,
+            DbBlock {
+                block,
+                expire_certs: None,
+            },
+        )?;
+        Ok(w)
+    })?;
+    Ok(orphan)
+}
diff --git a/lib/tests-tools/blocks-tests-tools/Cargo.toml b/lib/tests-tools/blocks-tests-tools/Cargo.toml
new file mode 100644
index 00000000..67547dd7
--- /dev/null
+++ b/lib/tests-tools/blocks-tests-tools/Cargo.toml
@@ -0,0 +1,24 @@
+[package]
+name = "dubp-blocks-tests-tools"
+version = "0.1.0"
+authors = ["elois <elois@duniter.org>"]
+description = "Tests tools for projects use dubp-block-doc."
+repository = "https://git.duniter.org/nodes/rust/duniter-rs"
+readme = "README.md"
+keywords = ["rust", "test", "tools"]
+license = "AGPL-3.0"
+edition = "2018"
+
+[lib]
+path = "src/lib.rs"
+
+[dependencies]
+dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" }
+dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" }
+dubp-currency-params = { path = "../../dubp/currency-params" }
+dubp-user-docs = { path = "../../dubp/user-docs" }
+dup-crypto = { path = "../../crypto" }
+dup-crypto-tests-tools = { path = "../crypto-tests-tools" }
+dubp-user-docs-tests-tools = { path = "../user-docs-tests-tools" }
+
+[dev-dependencies]
diff --git a/lib/tests-tools/blocks-tests-tools/src/lib.rs b/lib/tests-tools/blocks-tests-tools/src/lib.rs
new file mode 100644
index 00000000..d2daaa74
--- /dev/null
+++ b/lib/tests-tools/blocks-tests-tools/src/lib.rs
@@ -0,0 +1,29 @@
+//  Copyright (C) 2019  Éloïs SANCHEZ
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+//! Tests tools for projects use dubp-block-doc.
+
+#![deny(
+    missing_docs,
+    missing_debug_implementations,
+    missing_copy_implementations,
+    trivial_casts,
+    trivial_numeric_casts,
+    unsafe_code,
+    unstable_features,
+    unused_import_braces
+)]
+
+pub mod mocks;
diff --git a/lib/tests-tools/blocks-tests-tools/src/mocks.rs b/lib/tests-tools/blocks-tests-tools/src/mocks.rs
new file mode 100644
index 00000000..12a82525
--- /dev/null
+++ b/lib/tests-tools/blocks-tests-tools/src/mocks.rs
@@ -0,0 +1,96 @@
+//  Copyright (C) 2019  Éloïs SANCHEZ
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+//! Mocks for projects use dubp-block-doc
+
+use dubp_block_doc::{BlockDocument, BlockDocumentV10};
+use dubp_common_doc::blockstamp::Blockstamp;
+use dubp_common_doc::{BlockHash, BlockNumber};
+use dubp_currency_params::CurrencyName;
+use dup_crypto::hashs::Hash;
+
+/// Generate n mock blockstamps
+pub fn generate_blockstamps(n: usize) -> Vec<Blockstamp> {
+    (0..n)
+        .map(|i| Blockstamp {
+            id: BlockNumber(i as u32),
+            hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(
+                (i % 255) as u8,
+            )),
+        })
+        .collect()
+}
+
+/// Generate n empty timed block document
+pub fn gen_empty_timed_blocks_v10(n: usize, time_step: u64) -> Vec<BlockDocument> {
+    (0..n)
+        .map(|i| {
+            BlockDocument::V10(gen_empty_timed_block_v10(
+                Blockstamp {
+                    id: BlockNumber(i as u32),
+                    hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(
+                        (i % 255) as u8,
+                    )),
+                },
+                time_step * n as u64,
+                if i == 0 {
+                    Hash::default()
+                } else {
+                    dup_crypto_tests_tools::mocks::hash_from_byte(((i - 1) % 255) as u8)
+                },
+            ))
+        })
+        .collect()
+}
+
+/// Generate empty timed block document
+/// (usefull for tests that only need blockstamp and median_time fields)
+pub fn gen_empty_timed_block_v10(
+    blockstamp: Blockstamp,
+    time: u64,
+    previous_hash: Hash,
+) -> BlockDocumentV10 {
+    BlockDocumentV10 {
+        version: 10,
+        nonce: 0,
+        number: blockstamp.id,
+        pow_min: 0,
+        time: 0,
+        median_time: time,
+        members_count: 0,
+        monetary_mass: 0,
+        unit_base: 0,
+        issuers_count: 0,
+        issuers_frame: 0,
+        issuers_frame_var: 0,
+        currency: CurrencyName("test_currency".to_owned()),
+        issuers: vec![],
+        signatures: vec![],
+        hash: Some(blockstamp.hash),
+        parameters: None,
+        previous_hash: Some(previous_hash),
+        previous_issuer: None,
+        dividend: None,
+        identities: vec![],
+        joiners: vec![],
+        actives: vec![],
+        leavers: vec![],
+        revoked: vec![],
+        excluded: vec![],
+        certifications: vec![],
+        transactions: vec![],
+        inner_hash: None,
+    }
+}
diff --git a/lib/tests-tools/user-docs-tests-tools/Cargo.toml b/lib/tests-tools/user-docs-tests-tools/Cargo.toml
index 5906780f..a558a3ed 100644
--- a/lib/tests-tools/user-docs-tests-tools/Cargo.toml
+++ b/lib/tests-tools/user-docs-tests-tools/Cargo.toml
@@ -13,7 +13,6 @@ edition = "2018"
 path = "src/lib.rs"
 
 [dependencies]
-dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" }
 dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" }
 dubp-currency-params = { path = "../../dubp/currency-params" }
 dubp-user-docs = { path = "../../dubp/user-docs" }
diff --git a/lib/tests-tools/user-docs-tests-tools/src/mocks/mod.rs b/lib/tests-tools/user-docs-tests-tools/src/mocks/mod.rs
index 160cb738..0a0822e9 100644
--- a/lib/tests-tools/user-docs-tests-tools/src/mocks/mod.rs
+++ b/lib/tests-tools/user-docs-tests-tools/src/mocks/mod.rs
@@ -17,83 +17,3 @@
 
 pub mod identity;
 pub mod tx;
-
-use dubp_block_doc::{BlockDocument, BlockDocumentV10};
-use dubp_common_doc::blockstamp::Blockstamp;
-use dubp_common_doc::{BlockHash, BlockNumber};
-use dubp_currency_params::CurrencyName;
-use dup_crypto::hashs::Hash;
-
-/// Generate n mock blockstamps
-pub fn generate_blockstamps(n: usize) -> Vec<Blockstamp> {
-    (0..n)
-        .map(|i| Blockstamp {
-            id: BlockNumber(i as u32),
-            hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(
-                (i % 255) as u8,
-            )),
-        })
-        .collect()
-}
-
-/// Generate n empty timed block document
-pub fn gen_empty_timed_blocks_v10(n: usize, time_step: u64) -> Vec<BlockDocument> {
-    (0..n)
-        .map(|i| {
-            BlockDocument::V10(gen_empty_timed_block_v10(
-                Blockstamp {
-                    id: BlockNumber(i as u32),
-                    hash: BlockHash(dup_crypto_tests_tools::mocks::hash_from_byte(
-                        (i % 255) as u8,
-                    )),
-                },
-                time_step * n as u64,
-                if i == 0 {
-                    Hash::default()
-                } else {
-                    dup_crypto_tests_tools::mocks::hash_from_byte(((i - 1) % 255) as u8)
-                },
-            ))
-        })
-        .collect()
-}
-
-/// Generate empty timed block document
-/// (usefull for tests that only need blockstamp and median_time fields)
-pub fn gen_empty_timed_block_v10(
-    blockstamp: Blockstamp,
-    time: u64,
-    previous_hash: Hash,
-) -> BlockDocumentV10 {
-    BlockDocumentV10 {
-        version: 10,
-        nonce: 0,
-        number: blockstamp.id,
-        pow_min: 0,
-        time: 0,
-        median_time: time,
-        members_count: 0,
-        monetary_mass: 0,
-        unit_base: 0,
-        issuers_count: 0,
-        issuers_frame: 0,
-        issuers_frame_var: 0,
-        currency: CurrencyName("test_currency".to_owned()),
-        issuers: vec![],
-        signatures: vec![],
-        hash: Some(blockstamp.hash),
-        parameters: None,
-        previous_hash: Some(previous_hash),
-        previous_issuer: None,
-        dividend: None,
-        identities: vec![],
-        joiners: vec![],
-        actives: vec![],
-        leavers: vec![],
-        revoked: vec![],
-        excluded: vec![],
-        certifications: vec![],
-        transactions: vec![],
-        inner_hash: None,
-    }
-}
-- 
GitLab