22import unittest
33
44from lbry .testcase import CommandTestCase
5-
5+ from lbry . wallet import Transaction
66
77class TransactionCommandsTestCase (CommandTestCase ):
88
@@ -29,17 +29,42 @@ async def test_transaction_show(self):
2929 # someone's tx
3030 change_address = await self .blockchain .get_raw_change_address ()
3131 sendtxid = await self .blockchain .send_to_address (change_address , 10 )
32- await asyncio .sleep (0.2 )
33- tx = await self .daemon .jsonrpc_transaction_show (sendtxid )
34- self .assertEqual (tx .id , sendtxid )
35- self .assertEqual (tx .height , - 1 )
32+ # After a few tries, Hub should have the transaction (in mempool).
33+ for i in range (5 ):
34+ tx = await self .daemon .jsonrpc_transaction_show (sendtxid )
35+ # Retry if Hub is not aware of the transaction.
36+ if isinstance (tx , dict ):
37+ # Fields: 'success', 'code', 'message'
38+ self .assertFalse (tx ['success' ], tx )
39+ self .assertEqual (tx ['code' ], 404 , tx )
40+ self .assertEqual (tx ['message' ], "transaction not found" , tx )
41+ await asyncio .sleep (0.1 )
42+ continue
43+ break
44+ # verify transaction show (in mempool)
45+ self .assertTrue (isinstance (tx , Transaction ), str (tx ))
46+ # Fields: 'txid', 'raw', 'height', 'position', 'is_verified', and more.
47+ self .assertEqual (tx .id , sendtxid , vars (tx ))
48+ self .assertEqual (tx .height , - 1 , vars (tx ))
49+ self .assertEqual (tx .is_verified , False , vars (tx ))
50+
51+ # transaction is confirmed and leaves mempool
3652 await self .generate (1 )
53+
54+ # verify transaction show
3755 tx = await self .daemon .jsonrpc_transaction_show (sendtxid )
38- self .assertEqual (tx .height , self .ledger .headers .height )
56+ self .assertTrue (isinstance (tx , Transaction ), str (tx ))
57+ self .assertEqual (tx .id , sendtxid , vars (tx ))
58+ self .assertEqual (tx .height , self .ledger .headers .height , vars (tx ))
59+ self .assertEqual (tx .is_verified , True , vars (tx ))
3960
4061 # inexistent
4162 result = await self .daemon .jsonrpc_transaction_show ('0' * 64 )
42- self .assertFalse (result ['success' ])
63+ self .assertTrue (isinstance (result , dict ), result )
64+ # Fields: 'success', 'code', 'message'
65+ self .assertFalse (result ['success' ], result )
66+ self .assertEqual (result ['code' ], 404 , result )
67+ self .assertEqual (result ['message' ], "transaction not found" , result )
4368
4469 async def test_utxo_release (self ):
4570 await self .send_to_address_and_wait (
0 commit comments