From a0627ee34ac4beedd51e248d3b059c1bf2b3f874 Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Mon, 23 Mar 2020 19:30:55 +0100
Subject: [PATCH] [enh] #798 fix tests and add unit tests on lock_mode

---
 tests/technical/test_documents_service.py    |  1 +
 tests/technical/test_sources_service.py      |  2 +-
 tests/technical/test_transactions_service.py |  2 +-
 tests/unit/services/test_documents.py        | 71 ++++++++++++++++++++
 4 files changed, 74 insertions(+), 2 deletions(-)
 create mode 100644 tests/unit/services/test_documents.py

diff --git a/tests/technical/test_documents_service.py b/tests/technical/test_documents_service.py
index 4ecdda85..9ec0a14a 100644
--- a/tests/technical/test_documents_service.py
+++ b/tests/technical/test_documents_service.py
@@ -43,6 +43,7 @@ async def test_send_more_than_40_sources(
         amount_before_send,
         0,
         "Test comment",
+        0,
     )
     assert transactions[0].comment == "[CHAINED]"
     assert transactions[1].comment == "Test comment"
diff --git a/tests/technical/test_sources_service.py b/tests/technical/test_sources_service.py
index 2cc8c698..9cb1d21c 100644
--- a/tests/technical/test_sources_service.py
+++ b/tests/technical/test_sources_service.py
@@ -83,7 +83,7 @@ async def test_send_tx_then_cancel(
     )
     fake_server_with_blockchain.reject_next_post = True
     await application_with_one_connection.documents_service.send_money(
-        bob_connection, bob.salt, bob.password, alice.key.pubkey, 10, 0, "Test comment"
+        bob_connection, bob.salt, bob.password, alice.key.pubkey, 10, 0, None, 0
     )
     tx_after_send = application_with_one_connection.transactions_service.transfers(
         bob.key.pubkey
diff --git a/tests/technical/test_transactions_service.py b/tests/technical/test_transactions_service.py
index b6b073df..944f3477 100644
--- a/tests/technical/test_transactions_service.py
+++ b/tests/technical/test_transactions_service.py
@@ -18,7 +18,7 @@ async def test_send_tx_then_validate(
         pubkey=bob.key.pubkey
     )
     await application_with_one_connection.documents_service.send_money(
-        bob_connection, bob.salt, bob.password, alice.key.pubkey, 10, 0, "Test comment"
+        bob_connection, bob.salt, bob.password, alice.key.pubkey, 10, 0, None, 0
     )
     tx_after_send = application_with_one_connection.transactions_service.transfers(
         bob.key.pubkey
diff --git a/tests/unit/services/test_documents.py b/tests/unit/services/test_documents.py
new file mode 100644
index 00000000..00084fa9
--- /dev/null
+++ b/tests/unit/services/test_documents.py
@@ -0,0 +1,71 @@
+import pytest
+
+
+@pytest.mark.asyncio
+async def test_lock_mode_0(application_with_one_connection, fake_server, bob, alice):
+    """
+    Test the lock mode 0, Receiver signature
+
+    :param application_with_one_connection:
+    :param fake_server:
+    :param bob:
+    :param alice:
+    :return:
+    """
+    # check money amount in bob account
+    amount = application_with_one_connection.sources_service.amount(bob.key.pubkey)
+    assert amount == 1584
+
+    # create connection to have sources...
+    bob_connection = application_with_one_connection.db.connections_repo.get_one(
+        pubkey=bob.key.pubkey
+    )
+
+    # send transaction
+    (
+        _,
+        sakia_tx_list,
+    ) = await application_with_one_connection.documents_service.send_money(
+        bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 0
+    )
+
+    assert len(sakia_tx_list) == 1
+    assert (
+        "Outputs:\n100:0:SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo)\n"
+        in sakia_tx_list[0].raw
+    )
+
+
+@pytest.mark.asyncio
+async def test_lock_mode_1(application_with_one_connection, fake_server, bob, alice):
+    """
+    Test the lock mode 0, Receiver signature OR (Sender signature AND CSV(one week delay))
+
+    :param application_with_one_connection:
+    :param fake_server:
+    :param bob:
+    :param alice:
+    :return:
+    """
+    # check money amount in bob account
+    amount = application_with_one_connection.sources_service.amount(bob.key.pubkey)
+    assert amount == 1584
+
+    # create connection to have sources...
+    bob_connection = application_with_one_connection.db.connections_repo.get_one(
+        pubkey=bob.key.pubkey
+    )
+
+    # send transaction
+    (
+        _,
+        sakia_tx_list,
+    ) = await application_with_one_connection.documents_service.send_money(
+        bob_connection, bob.salt, bob.password, alice.key.pubkey, 100, 0, None, 1
+    )
+
+    assert len(sakia_tx_list) == 1
+    assert (
+        "Outputs:\n100:0:SIG(F3HWkYnUSbdpEueosKqzYd1m8ftwojwE2uXR7ScoAVKo) || (SIG(GfFUvqaVSgCt6nFDQCAuULWk6K16MUDckeyBJQFcaYj7) && CSV(604800))\n"
+        in sakia_tx_list[0].raw
+    )
-- 
GitLab