From 66259e0e076a692e13bb2c47e0465b37d70ca2b6 Mon Sep 17 00:00:00 2001
From: vtexier <vit@free.fr>
Date: Sat, 7 Dec 2019 09:33:41 +0100
Subject: [PATCH] [fix] #112 fix Unlock.from_inline error on a newly created
 Unlock

Removed newline at the end of the regexp
---
 duniterpy/documents/transaction.py  | 14 ++++++++------
 tests/documents/test_transaction.py |  5 +++++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/duniterpy/documents/transaction.py b/duniterpy/documents/transaction.py
index adc764c5..a4cfc8ee 100644
--- a/duniterpy/documents/transaction.py
+++ b/duniterpy/documents/transaction.py
@@ -254,7 +254,7 @@ class SIGParameter:
         return self.index == other.index
 
     def __hash__(self) -> int:
-        return hash((self.index))
+        return hash(self.index)
 
     @classmethod
     def from_parameter(
@@ -310,7 +310,7 @@ class XHXParameter:
         return self.integer == other.integer
 
     def __hash__(self) -> int:
-        return hash((self.integer))
+        return hash(self.integer)
 
     @classmethod
     def from_parameter(
@@ -380,7 +380,7 @@ class Unlock:
     A Transaction UNLOCK
     """
 
-    re_inline = re.compile("([0-9]+):((?:SIG\\([0-9]+\\)|XHX\\([0-9]+\\)|\\s)+)\n")
+    re_inline = re.compile("([0-9]+):((?:SIG\\([0-9]+\\)|XHX\\([0-9]+\\)|\\s)+)")
 
     def __init__(
         self, index: int, parameters: List[Union[SIGParameter, XHXParameter]]
@@ -425,8 +425,8 @@ class Unlock:
         index = int(data.group(1))
         parameters_str = data.group(2).split(" ")
         parameters = []
-        for p in parameters_str:
-            param = UnlockParameter.from_parameter(p)
+        for parameter in parameters_str:
+            param = UnlockParameter.from_parameter(parameter)
             if param:
                 parameters.append(param)
         return cls(index, parameters)
@@ -437,7 +437,9 @@ class Unlock:
 
         :return:
         """
-        return "{0}:{1}".format(self.index, " ".join([str(p) for p in self.parameters]))
+        return "{0}:{1}".format(
+            self.index, " ".join([str(parameter) for parameter in self.parameters])
+        )
 
 
 # required to type hint cls in classmethod
diff --git a/tests/documents/test_transaction.py b/tests/documents/test_transaction.py
index 108a3179..47d6432f 100644
--- a/tests/documents/test_transaction.py
+++ b/tests/documents/test_transaction.py
@@ -436,3 +436,8 @@ class TestTransaction(unittest.TestCase):
         self.assertTrue(transaction.time is None)
         self.assertTrue(transaction.currency == "gtest")
         self.assertTrue(transaction.inputs[0].amount == 30)
+
+    def test_unlock(self):
+        unlock1 = Unlock(0, [SIGParameter(0)])
+        unlock2 = Unlock.from_inline(unlock1.inline())
+        self.assertEqual(unlock1.inline(), unlock2.inline())
-- 
GitLab