22from crypto .constants import TRANSACTION_HTLC_LOCK , TRANSACTION_TYPE_GROUP
33from crypto .networks .devnet import Devnet
44from crypto .transactions .builder .htlc_lock import HtlcLock
5+ import pytest
56
67set_network (Devnet )
78
89
10+ def test_htlc_lock_transation_amount_not_int ():
11+ with pytest .raises (ValueError ):
12+ """Test error handling in constructor for non-integer amount
13+ """
14+ HtlcLock (
15+ recipient_id = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
16+ amount = 'bad amount number' ,
17+ secret_hash = '0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454' ,
18+ expiration_type = 1 ,
19+ expiration_value = 1573455822
20+ )
21+
22+
23+ def test_htlc_lock_transation_amount_zero ():
24+ with pytest .raises (ValueError ):
25+ """Test error handling in constructor for non-integer amount
26+ """
27+ HtlcLock (
28+ recipient_id = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
29+ amount = 0 ,
30+ secret_hash = '0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454' ,
31+ expiration_type = 1 ,
32+ expiration_value = 1573455822
33+ )
34+
35+
36+ def test_htlc_lock_transation_amount_negative ():
37+ with pytest .raises (ValueError ):
38+ """Test error handling in constructor for non-integer amount
39+ """
40+ HtlcLock (
41+ recipient_id = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
42+ amount = - 5 ,
43+ secret_hash = '0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454' ,
44+ expiration_type = 1 ,
45+ expiration_value = 1573455822
46+ )
47+
48+
949def test_htlc_lock_transaction ():
1050 """Test if timelock transaction gets built
1151 """
1252 transaction = HtlcLock (
1353 recipient_id = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
54+ amount = 200000000 ,
1455 secret_hash = '0f128d401958b1b30ad0d10406f47f9489321017b4614e6cb993fc63913c5454' ,
1556 expiration_type = 1 ,
1657 expiration_value = 1573455822
@@ -22,6 +63,7 @@ def test_htlc_lock_transaction():
2263 transaction_dict = transaction .to_dict ()
2364
2465 assert transaction_dict ['recipientId' ] == 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC'
66+ assert transaction_dict ['amount' ] == 200000000
2567 assert transaction_dict ['nonce' ] == 1
2668 assert transaction_dict ['signature' ]
2769 assert transaction_dict ['type' ] is TRANSACTION_HTLC_LOCK
0 commit comments