1+ import pytest
2+
13from crypto .configuration .network import set_network
24from crypto .constants import TRANSACTION_TRANSFER , TRANSACTION_TYPE_GROUP
35from crypto .identity .public_key import PublicKey
46from crypto .networks .devnet import Devnet
57from crypto .transactions .builder .transfer import Transfer
68
9+
710set_network (Devnet )
811
912
@@ -24,6 +27,53 @@ def test_transfer_transaction():
2427 assert transaction_dict ['type' ] is TRANSACTION_TRANSFER
2528 assert transaction_dict ['typeGroup' ] == 1
2629 assert transaction_dict ['typeGroup' ] == TRANSACTION_TYPE_GROUP .CORE .value
30+ assert transaction_dict ['fee' ] == 10000000
31+
32+ transaction .schnorr_verify () # if no exception is raised, it means the transaction is valid
33+
34+
35+ def test_transfer_transaction_update_amount ():
36+ """Test if a transfer transaction can update an amount
37+ """
38+ transaction = Transfer (
39+ recipientId = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
40+ amount = 200000000
41+ )
42+ transaction .set_amount (10 )
43+ transaction .set_type_group (TRANSACTION_TYPE_GROUP .CORE )
44+ transaction .set_nonce (1 )
45+ transaction .schnorr_sign ('this is a top secret passphrase' )
46+ transaction_dict = transaction .to_dict ()
47+
48+ assert transaction_dict ['nonce' ] == 1
49+ assert transaction_dict ['signature' ]
50+ assert transaction_dict ['type' ] is TRANSACTION_TRANSFER
51+ assert transaction_dict ['typeGroup' ] == 1
52+ assert transaction_dict ['typeGroup' ] == TRANSACTION_TYPE_GROUP .CORE .value
53+ assert transaction_dict ['amount' ] == 10
54+
55+ transaction .schnorr_verify () # if no exception is raised, it means the transaction is valid
56+
57+
58+ def test_transfer_transaction_custom_fee ():
59+ """Test if a transfer transaction gets built with a custom fee
60+ """
61+ transaction = Transfer (
62+ recipientId = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
63+ amount = 200000000 ,
64+ fee = 5
65+ )
66+ transaction .set_type_group (TRANSACTION_TYPE_GROUP .CORE )
67+ transaction .set_nonce (1 )
68+ transaction .schnorr_sign ('this is a top secret passphrase' )
69+ transaction_dict = transaction .to_dict ()
70+
71+ assert transaction_dict ['nonce' ] == 1
72+ assert transaction_dict ['signature' ]
73+ assert transaction_dict ['type' ] is TRANSACTION_TRANSFER
74+ assert transaction_dict ['typeGroup' ] == 1
75+ assert transaction_dict ['typeGroup' ] == TRANSACTION_TYPE_GROUP .CORE .value
76+ assert transaction_dict ['fee' ] == 5
2777
2878 transaction .schnorr_verify () # if no exception is raised, it means the transaction is valid
2979
@@ -49,9 +99,9 @@ def test_transfer_secondsig_transaction():
4999 assert transaction_dict ['typeGroup' ] == TRANSACTION_TYPE_GROUP .CORE .value
50100
51101 transaction .schnorr_verify () # if no exception is raised, it means the transaction is valid
52- transaction .schnorr_verify_second (PublicKey .from_passphrase ('second top secret passphrase' )) # if no exception is raised, it means the transaction is valid
53-
54-
102+ transaction .schnorr_verify_second (PublicKey .from_passphrase ('second top secret passphrase' )) # if no exception is raised, it means the transaction is valid
103+
104+
55105def test_parse_signatures (transaction_type_0 ):
56106 """Test if parse signature works when parsing serialized data
57107 """
@@ -62,3 +112,23 @@ def test_parse_signatures(transaction_type_0):
62112 assert transfer .transaction .signature is None
63113 transfer .transaction .parse_signatures (transaction_type_0 ['serialized' ], 166 )
64114 assert transfer .transaction .signature
115+
116+
117+ def test_transfer_transaction_amount_not_int ():
118+ with pytest .raises (ValueError ):
119+ """Test error handling in constructor for non-integer amount
120+ """
121+ Transfer (
122+ recipientId = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
123+ amount = 'bad amount'
124+ )
125+
126+
127+ def test_transfer_transaction_amount_zero ():
128+ with pytest .raises (ValueError ):
129+ """Test error handling in constructor for non-integer amount
130+ """
131+ Transfer (
132+ recipientId = 'AGeYmgbg2LgGxRW2vNNJvQ88PknEJsYizC' ,
133+ amount = 0
134+ )
0 commit comments