Repository: ArkEcosystem/python-crypto

Issue:
feat: add amount to HTLC Lock constructor
A HTLC lock transaction requires an amount, but the current constructor does not allow for passing an amount.

Discussion:

Patch:
diff --git a/crypto/transactions/builder/htlc_lock.py b/crypto/transactions/builder/htlc_lock.py
index baa361d..0ee2c7a 100644
--- a/crypto/transactions/builder/htlc_lock.py
+++ b/crypto/transactions/builder/htlc_lock.py
@@ -6,11 +6,12 @@ class HtlcLock(BaseTransactionBuilder):
 
     transaction_type = TRANSACTION_HTLC_LOCK
 
-    def __init__(self, recipient_id, secret_hash, expiration_type, expiration_value, vendorField=None, fee=None):
+    def __init__(self, recipient_id, amount, secret_hash, expiration_type, expiration_value, vendorField=None, fee=None):
         """Create a timelock transaction
 
         Args:
             recipient_id (str): recipient identifier
+            amount (int): amount of coins you want to transfer
             secret_hash (str): a hash of the secret. The SAME hash must be used in the corresponding “claim” transaction
             expiration_type (int): type of the expiration. Either block height or network epoch timestamp based
             expiration_value (int): Expiration of transaction in seconds or height depending on expiration_type
@@ -20,6 +21,11 @@ class HtlcLock(BaseTransactionBuilder):
         super().__init__()
 
         self.transaction.recipientId = recipient_id
+        
+        if type(amount) == int and amount > 0:
+            self.transaction.amount = amount
+        else:
+            raise ValueError('Amount is not valid')
 
         self.transaction.typeGroup = self.get_type_group()
 


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 030dfd9..dc62fc3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -14,7 +14,7 @@ jobs:
     strategy:
       max-parallel: 4
       matrix:
-        python-version: [3.5, 3.6, 3.7]
+        python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
 
     steps:
       - uses: actions/checkout@v1
diff --git a/tests/transactions/builder/test_htlc_lock.py b/tests/transactions/builder/test_htlc_lock.py
index 92a39d5..45a088f 100644
--- a/tests/transactions/builder/test_htlc_lock.py
+++ b/tests/transactions/builder/test_htlc_lock.py
@@ -2,15 +2,56 @@ from crypto.configuration.network import set_network
 from crypto.constants import TRANSACTION_HTLC_LOCK, TRANSACTION_TYPE_GROUP
 from crypto.networks.devnet import Devnet
 from crypto.transactions.builder.htlc_lock import HtlcLock
+import pytest
 
 set_network(Devnet)
 
 
+def test_htlc_lock_transation_amount_not_int():
+    with pytest.raises(ValueError):
+        """Test error handling in constructor for non-integer amount
+        """
+        HtlcLock(
+          recipient_id='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC',
+          amount='bad amount number',
+          secret_hash='0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454',
+          expiration_type=1,
+          expiration_value=1573455822
+        )
+
+
+def test_htlc_lock_transation_amount_zero():
+    with pytest.raises(ValueError):
+        """Test error handling in constructor for non-integer amount
+        """
+        HtlcLock(
+          recipient_id='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC',
+          amount=0,
+          secret_hash='0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454',
+          expiration_type=1,
+          expiration_value=1573455822
+        )
+
+
+def test_htlc_lock_transation_amount_negative():
+    with pytest.raises(ValueError):
+        """Test error handling in constructor for non-integer amount
+        """
+        HtlcLock(
+          recipient_id='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC',
+          amount=-5,
+          secret_hash='0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454',
+          expiration_type=1,
+          expiration_value=1573455822
+        )
+
+
 def test_htlc_lock_transaction():
     """Test if timelock transaction gets built
     """
     transaction = HtlcLock(
       recipient_id='AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC',
+      amount=200000000,
       secret_hash='0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454',
       expiration_type=1,
       expiration_value=1573455822
@@ -22,6 +63,7 @@ def test_htlc_lock_transaction():
     transaction_dict = transaction.to_dict()
 
     assert transaction_dict['recipientId'] == 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC'
+    assert transaction_dict['amount'] == 200000000
     assert transaction_dict['nonce'] == 1
     assert transaction_dict['signature']
     assert transaction_dict['type'] is TRANSACTION_HTLC_LOCK