|
| 1 | +# coding=utf-8 |
| 2 | +from __future__ import absolute_import, division, print_function, \ |
| 3 | + unicode_literals |
| 4 | + |
| 5 | +from unittest import TestCase |
| 6 | + |
| 7 | +import mock |
| 8 | + |
| 9 | +from iota import Iota, MockAdapter, Transaction |
| 10 | +from iota.commands.extended import FindTransactionObjectsCommand |
| 11 | + |
| 12 | + |
| 13 | +class FindTransactionObjectsCommandTestCase(TestCase): |
| 14 | + # noinspection SpellCheckingInspection |
| 15 | + def setUp(self): |
| 16 | + super(FindTransactionObjectsCommandTestCase, self).setUp() |
| 17 | + |
| 18 | + self.adapter = MockAdapter() |
| 19 | + self.command = FindTransactionObjectsCommand(self.adapter) |
| 20 | + |
| 21 | + # Define values that we can reuse across tests. |
| 22 | + self.address = 'A' * 81 |
| 23 | + self.transaction_hash = \ |
| 24 | + b'BROTOVRCAEMFLRWGPVWDPDTBRAMLHVCHQDEHXLCWH' \ |
| 25 | + b'KKXLVDFCPIJEUZTPPFMPQQ9KOHAEUAMMVJN99999' |
| 26 | + self.trytes = \ |
| 27 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 28 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 29 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 30 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 31 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 32 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 33 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 34 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 35 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 36 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 37 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 38 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 39 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 40 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 41 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 42 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 43 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 44 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 45 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 46 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 47 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 48 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 49 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 50 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 51 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 52 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 53 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 54 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 55 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 56 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 57 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 58 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 59 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 60 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 61 | + b'99999999999999999999999999999999999999999999999999999999999999' \ |
| 62 | + b'99999999999999999AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' \ |
| 63 | + b'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA99999999999999999999999999' \ |
| 64 | + b'9QC9999999999999999999999999PQYJHAD99999999999999999999WHIUDFV' \ |
| 65 | + b'IFXNBJVEHYPLDADIDINGAWMHYIJNPYUDWXCAWL9GSKTUIZLJGGFIXEIYTJEDQZ' \ |
| 66 | + b'TIYRXHC9PBWBDSOTEJTQTYYSZLVTFLDQMZSGLHKLYVJOLMXIJJRTGS9RYBXLAT' \ |
| 67 | + b'ZJXBVBCPUGWRUKZJYLBGPKRKWIA9999FPYHMFFWMMKOHTSAPMMATZQLWXJSPMT' \ |
| 68 | + b'JSRQIPMDCQXFFMXMHCYDKVJCFSRECAVALCOFIYCJLNRZZZ9999999999999999' \ |
| 69 | + b'999999999999999KITCXNZOF999999999MMMMMMMMMEA9999F9999999999999' \ |
| 70 | + b'9999999' |
| 71 | + |
| 72 | + def test_wireup(self): |
| 73 | + """ |
| 74 | + Verify that the command is wired up correctly. |
| 75 | + """ |
| 76 | + self.assertIsInstance( |
| 77 | + Iota(self.adapter).findTransactionObjects, |
| 78 | + FindTransactionObjectsCommand, |
| 79 | + ) |
| 80 | + |
| 81 | + def test_transaction_found(self): |
| 82 | + """ |
| 83 | + A transaction is found with the inputs. A transaction object is |
| 84 | + returned |
| 85 | + """ |
| 86 | + with mock.patch( |
| 87 | + 'iota.commands.core.find_transactions.FindTransactionsCommand.' |
| 88 | + '_execute', |
| 89 | + mock.Mock(return_value={'hashes': [self.transaction_hash, ]}), |
| 90 | + ): |
| 91 | + with mock.patch( |
| 92 | + 'iota.commands.core.get_trytes.GetTrytesCommand._execute', |
| 93 | + mock.Mock(return_value={'trytes': [self.trytes, ]}), |
| 94 | + ): |
| 95 | + response = self.command(addresses=[self.address]) |
| 96 | + |
| 97 | + self.assertEqual(len(response['transactions']), 1) |
| 98 | + transaction = response['transactions'][0] |
| 99 | + self.assertIsInstance(transaction, Transaction) |
| 100 | + self.assertEqual(transaction.address, self.address) |
| 101 | + |
| 102 | + def test_no_transactions_fround(self): |
| 103 | + """ |
| 104 | + No transaction is found with the inputs. An empty list is returned |
| 105 | + """ |
| 106 | + with mock.patch( |
| 107 | + 'iota.commands.core.find_transactions.FindTransactionsCommand.' |
| 108 | + '_execute', |
| 109 | + mock.Mock(return_value={'hashes': []}), |
| 110 | + ): |
| 111 | + response = self.command(addresses=[self.address]) |
| 112 | + |
| 113 | + self.assertDictEqual( |
| 114 | + response, |
| 115 | + { |
| 116 | + 'transactions': [], |
| 117 | + }, |
| 118 | + ) |
0 commit comments