def test_happy_path(self): """ Loading account data for an account. """ # noinspection PyUnusedLocal def mock_iter_used_addresses(adapter, seed, start, security_level): """ Mocks the ``iter_used_addresses`` function, so that we can simulate its functionality without actually connecting to the Tangle. References: - :py:func:`iota_async.commands.extended.utils.iter_used_addresses` """ yield self.addy1, [self.hash1] yield self.addy2, [self.hash2] mock_get_balances = mock.Mock(return_value={'balances': [42, 0]}) # Not particularly realistic, but good enough to prove that the # mocked function was invoked correctly. bundles = [Bundle(), Bundle()] mock_get_bundles_from_transaction_hashes = mock.Mock( return_value=bundles) with mock.patch( 'iota_async.commands.extended.get_account_data.iter_used_addresses', mock_iter_used_addresses, ): with mock.patch( 'iota_async.commands.extended.get_account_data.get_bundles_from_transaction_hashes', mock_get_bundles_from_transaction_hashes, ): with mock.patch( 'iota_async.commands.core.get_balances.GetBalancesCommand._execute', mock_get_balances, ): response = self.command(seed=Seed.random()) self.assertDictEqual( response, { 'addresses': [self.addy1, self.addy2], 'balance': 42, 'bundles': bundles, }, )
def test_happy_path(self): """ Successfully promoting a bundle. """ self.adapter.seed_response('checkConsistency', { 'state': True, }) result_bundle = Bundle.from_tryte_strings([ TransactionTrytes(self.trytes1), TransactionTrytes(self.trytes2), ]) mock_send_transfer = mock.Mock(return_value={ 'bundle': result_bundle, }) with mock.patch( 'iota_async.commands.extended.send_transfer.SendTransferCommand._execute', mock_send_transfer, ): response = self.command( transaction=self.hash1, depth=3, minWeightMagnitude=16, ) self.assertDictEqual(response, { 'bundle': result_bundle, })
async def _execute(self, request): transaction_hash = request['transaction'] # type: TransactionHash bundle = Bundle(await self._traverse_bundle(transaction_hash)) validator = BundleValidator(bundle) if not validator.is_valid(): raise with_context( exc=BadApiResponse( 'Bundle failed validation (``exc.context`` has more info).', ), context={ 'bundle': bundle, 'errors': validator.errors, }, ) return { # Always return a list, so that we have the necessary # structure to return multiple bundles in a future # iteration. 'bundles': [bundle], }
def setUp(self): super(BundleTestCase, self).setUp() # noinspection SpellCheckingInspection self.bundle = Bundle([ # This transaction does not have a message. Transaction( signature_message_fragment=Fragment(b''), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=0, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has something that can't be decoded as a UTF-8 # sequence. Transaction( signature_message_fragment=Fragment( b'OHCFVELH9GYEMHCF9GPHBGIEWHZFU'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999HAA9UA' b'MHCGKEUGYFUBIARAXBFASGLCHCBEVGTBDCSAEBTBM'), current_index=1, last_index=7, value=10, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has a message that fits into a single # fragment. Transaction( signature_message_fragment=Fragment.from_unicode( 'Hello, world!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999D99HEA' b'M9XADCPFJDFANCIHR9OBDHTAGGE9TGCI9EO9ZCRBN'), current_index=2, last_index=7, value=20, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has a message that spans multiple fragments. Transaction( signature_message_fragment=Fragment( b'J9GAQBCDCDS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CHDSAJ9GAHCTCGDFAEAXBCDKDFAGAJ9GAKB9D9DEAFD' b'XCVCWCHDQAGAEAGDPCXCSCEAHDWCTCEARCCDADDDIDHDTCFDEAPCBDSCEAGDTCHD' b'HD9DTCSCEAXCBDHDCDEAGDXC9DTCBDRCTCEAPCVCPCXCBDSAJ9EAEACCWCTCEAHD' b'KDCDEAADTCB'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=3, last_index=7, value=30, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), Transaction( signature_message_fragment=Fragment( b'DEAUCXCSCVCTCHDTCSCSAEACCWCTCEAHDTCBDGDXCCDBDEAKDPCGDEAIDBDQCTCP' b'CFDPCQC9DTCSAJ9GAHCCDIDLAFDTCEAFDTCPC9D9DMDEABDCDHDEAVCCDXCBDVCE' b'AHDCDEA9DXCZCTCEAXCHDQAGAEACDQCGDTCFDJDTCSCEANBTCTCDDEACCWCCDIDV' b'CWCHDSAJ9GACCTC9D9DEAIDGDFAGAJ9GAKB9D9DEAFDXCVCWCHDQAGAEAGDPCXCS' b'CEANBTCTCDDEACCWCCDIDVCWCHDSAEAGACCWCTCEAKBBDGDKDTCFDEAHDCDEAHDW' b'CTCEAQBFDTCPCHDEA9CIDTCGDHDXCCDBDSASASAGAJ9GAHCTCGDIBGAJ9GAYBUCE' b'AVBXCUCTCQAEAHDWCTCEADCBDXCJDTCFDGDTCEAPCBDSCEAOBJDTCFDMDHDWCXCB' b'DVCSASASAGAEAGDPCXCSCEANBTCTCDDEACCWCCDIDVCWCHDSAJ9GAHCTCGDIBIBG' b'AJ9GASBGDSASASAGAJ9GAHCTCGDIBFAGAJ9GAPBCDFDHDMDRAHDKDCDQAGAEAGDP' b'CXCSCEANBTCTCDDEACCWCCDIDVCWCHDQAEAKDXCHDWCEAXCBDUCXCBDXCHDTCEAA' b'DPCYCTCGDHDMDEAPCBDSCEARCPC9DADSAJ9EAEAEAEAEAEAEAEA'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=4, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Input, Part 1 of 2 Transaction( # Make the signature look like a message, so we can verify that # the Bundle skips it correctly. signature_message_fragment=Fragment.from_unicode( 'This is a signature, not a message!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999WGSBUA' b'HDVHYHOBHGP9VCGIZHNCAAQFJGE9YHEHEFTDAGXHY'), current_index=5, last_index=7, value=-100, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Input, Part 2 of 2 Transaction( # Make the signature look like a message, so we can verify that # the Bundle skips it correctly. signature_message_fragment=Fragment.from_unicode( 'This is a signature, not a message!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999WGSBUA' b'HDVHYHOBHGP9VCGIZHNCAAQFJGE9YHEHEFTDAGXHY'), current_index=6, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Change Transaction( # It's unusual for a change transaction to have a message, but # half the fun of unit tests is designing unusual scenarios! signature_message_fragment=Fragment.from_unicode( 'I can haz change?'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999FFYALH' b'N9ACYCP99GZBSDK9CECFI9RAIH9BRCCAHAIAWEFAN'), current_index=7, last_index=7, value=40, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), ])
class BundleTestCase(TestCase): def setUp(self): super(BundleTestCase, self).setUp() # noinspection SpellCheckingInspection self.bundle = Bundle([ # This transaction does not have a message. Transaction( signature_message_fragment=Fragment(b''), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=0, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has something that can't be decoded as a UTF-8 # sequence. Transaction( signature_message_fragment=Fragment( b'OHCFVELH9GYEMHCF9GPHBGIEWHZFU'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999HAA9UA' b'MHCGKEUGYFUBIARAXBFASGLCHCBEVGTBDCSAEBTBM'), current_index=1, last_index=7, value=10, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has a message that fits into a single # fragment. Transaction( signature_message_fragment=Fragment.from_unicode( 'Hello, world!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999D99HEA' b'M9XADCPFJDFANCIHR9OBDHTAGGE9TGCI9EO9ZCRBN'), current_index=2, last_index=7, value=20, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # This transaction has a message that spans multiple fragments. Transaction( signature_message_fragment=Fragment( b'J9GAQBCDCDSCEAADCDFDBDXCBDVCQAGAEAGDPCXCSCEANBTCTCDDEACCWCCDIDVC' b'WCHDEAPCHDEA9DPCGDHDSAJ9GAOBFDSASASAEAQBCDCDSCEAADCDFDBDXCBDVCQA' b'EAYBEANBTCTCDDEACCWCCDIDVCWCHDQAGAEAGDPCXCSCEAVBCDCDBDEDIDPCKD9D' b'EABDTCFDJDCDIDGD9DMDSAJ9EAEAGANBCDEAMDCDIDEAWCPCJDTCSASASAEATCFD' b'QAEAHDWCPCHDEAXCGDSASASAGAJ9GASASASAEAPCBDEAPCBDGDKDTCFDEAUCCDFD' b'EAMDCDIDIBGAEAXCBDHDTCFDFDIDDDHDTCSCEANBTCTCDDEACCWCCDIDVCWCHDEA' b'ADPCYCTCGDHDXCRCPC9D9DMDSAEAGAHCTCGDSAEASBEAWCPCJDTCSAGAJ9CCWCTC' b'EAHDKDCDEAADTCBDEAGDWCXCJDTCFDTCSCEAKDXCHDWCEATCLDDD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AHDCDEAIDGDIBGAEAIDFDVCTCSCEAVBCDCDBDEDIDPCKD9D' b'SAJ9GASBEAPCADSAGAJ9GAXBCDKDIBGAJ9GAXBCDKDQAGAEAGDPCXCSCEANBTCTC' b'DDEACCWCCDIDVCWCHDSAJ9CCWCTCMDEAQCCDHDWCEA9DXCRCZCTCSCEAHDWCTCXC' b'FDEASCFDMDEA9DXCDDGDSAJ9GACCWCCDIDVCWCEASBEASCCDBDLAHDEAHDWCXCBD' b'ZCQAGAEAPCSCSCTCSCEANBTCTCDDEACCWCCDIDVCWCHDQAEAGAHDWCPCHDEAMDCD' b'IDLAFDTCEAVCCDXCBDVCEAHDCDEA9DXCZCTCEAXCHDSAGAJ9GANBCDTCGDBDLAHD' b'EAADPCHDHDTCFDQAGAEAGDPCXCSCEAZBWCCDIDRCWCVCSAEAGAFCTCEAADIDGDHD' b'EAZCBDCDKDEAXCHDFAEAXBCDKDFAGAJ9GAXBCDKDIBGAEATCBDEDIDXCFDTCSCEA' b'NBTCTCDDEACCWCCDIDVCWCHDSAJ9GAHCTCGDFAEAXBCDKDFAGAJ9GAKB9D9DEAFD' b'XCVCWCHDQAGAEAGDPCXCSCEAHDWCTCEARCCDADDDIDHDTCFDEAPCBDSCEAGDTCHD' b'HD9DTCSCEAXCBDHDCDEAGDXC9DTCBDRCTCEAPCVCPCXCBDSAJ9EAEACCWCTCEAHD' b'KDCDEAADTCB'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=3, last_index=7, value=30, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), Transaction( signature_message_fragment=Fragment( b'DEAUCXCSCVCTCHDTCSCSAEACCWCTCEAHDTCBDGDXCCDBDEAKDPCGDEAIDBDQCTCP' b'CFDPCQC9DTCSAJ9GAHCCDIDLAFDTCEAFDTCPC9D9DMDEABDCDHDEAVCCDXCBDVCE' b'AHDCDEA9DXCZCTCEAXCHDQAGAEACDQCGDTCFDJDTCSCEANBTCTCDDEACCWCCDIDV' b'CWCHDSAJ9GACCTC9D9DEAIDGDFAGAJ9GAKB9D9DEAFDXCVCWCHDQAGAEAGDPCXCS' b'CEANBTCTCDDEACCWCCDIDVCWCHDSAEAGACCWCTCEAKBBDGDKDTCFDEAHDCDEAHDW' b'CTCEAQBFDTCPCHDEA9CIDTCGDHDXCCDBDSASASAGAJ9GAHCTCGDIBGAJ9GAYBUCE' b'AVBXCUCTCQAEAHDWCTCEADCBDXCJDTCFDGDTCEAPCBDSCEAOBJDTCFDMDHDWCXCB' b'DVCSASASAGAEAGDPCXCSCEANBTCTCDDEACCWCCDIDVCWCHDSAJ9GAHCTCGDIBIBG' b'AJ9GASBGDSASASAGAJ9GAHCTCGDIBFAGAJ9GAPBCDFDHDMDRAHDKDCDQAGAEAGDP' b'CXCSCEANBTCTCDDEACCWCCDIDVCWCHDQAEAKDXCHDWCEAXCBDUCXCBDXCHDTCEAA' b'DPCYCTCGDHDMDEAPCBDSCEARCPC9DADSAJ9EAEAEAEAEAEAEAEA'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999A9PG9A' b'XCQANAWGJBTFWEAEQCN9WBZB9BJAIIY9UDLIGFOAA'), current_index=4, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Input, Part 1 of 2 Transaction( # Make the signature look like a message, so we can verify that # the Bundle skips it correctly. signature_message_fragment=Fragment.from_unicode( 'This is a signature, not a message!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999WGSBUA' b'HDVHYHOBHGP9VCGIZHNCAAQFJGE9YHEHEFTDAGXHY'), current_index=5, last_index=7, value=-100, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Input, Part 2 of 2 Transaction( # Make the signature look like a message, so we can verify that # the Bundle skips it correctly. signature_message_fragment=Fragment.from_unicode( 'This is a signature, not a message!'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999WGSBUA' b'HDVHYHOBHGP9VCGIZHNCAAQFJGE9YHEHEFTDAGXHY'), current_index=6, last_index=7, value=0, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), # Change Transaction( # It's unusual for a change transaction to have a message, but # half the fun of unit tests is designing unusual scenarios! signature_message_fragment=Fragment.from_unicode( 'I can haz change?'), address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999FFYALH' b'N9ACYCP99GZBSDK9CECFI9RAIH9BRCCAHAIAWEFAN'), current_index=7, last_index=7, value=40, # These values are not relevant to the tests. branch_transaction_hash=TransactionHash(b''), bundle_hash=BundleHash(b''), hash_=TransactionHash(b''), nonce=Nonce(b''), timestamp=1485020456, trunk_transaction_hash=TransactionHash(b''), tag=Tag(b''), attachment_timestamp=1485020456, attachment_timestamp_upper_bound=1485020456, attachment_timestamp_lower_bound=1485020456, ), ]) def test_get_messages_errors_drop(self): """ Decoding messages from a bundle, with ``errors='drop'``. """ messages = self.bundle.get_messages('drop') self.assertEqual(len(messages), 3) self.assertEqual(messages[0], 'Hello, world!') # noinspection SpellCheckingInspection self.assertEqual( messages[1], ''' "Good morning," said Deep Thought at last. "Er... Good morning, O Deep Thought," said Loonquawl nervously. "Do you have... er, that is..." "... an answer for you?" interrupted Deep Thought majestically. "Yes. I have." The two men shivered with expectancy. Their waiting had not been in vain. "There really is one?" breathed Phouchg. "There really is one," confirmed Deep Thought. "To Everything? To the great Question of Life, the Universe and Everything?" "Yes." Both of the men had been trained for this moment; their lives had been a preparation for it; they had been selected at birth as those who would witness the answer; but even so they found themselves gasping and squirming like excited children. "And you're ready to give it to us?" urged Loonquawl. "I am." "Now?" "Now," said Deep Thought. They both licked their dry lips. "Though I don't think," added Deep Thought, "that you're going to like it." "Doesn't matter," said Phouchg. "We must know it! Now!" "Now?" enquired Deep Thought. "Yes! Now!" "All right," said the computer and settled into silence again. The two men fidgeted. The tension was unbearable. "You're really not going to like it," observed Deep Thought. "Tell us!" "All right," said Deep Thought. "The Answer to the Great Question..." "Yes?" "Of Life, the Universe and Everything..." said Deep Thought. "Yes??" "Is..." "Yes?!" "Forty-two," said Deep Thought, with infinite majesty and calm. ''', ) self.assertEqual(messages[2], 'I can haz change?') def test_get_messages_errors_strict(self): """ Decoding messages from a bundle, with ``errors='strict'``. """ with self.assertRaises(UnicodeDecodeError): self.bundle.get_messages('strict') def test_get_messages_errors_ignore(self): """ Decoding messages from a bundle, with ``errors='ignore'``. """ messages = self.bundle.get_messages('ignore') self.assertEqual(len(messages), 4) # The only message that is treated differently is the invalid one. self.assertEqual(messages[0], '祝你好运\x15') def test_get_messages_errors_replace(self): """ Decoding messages from a bundle, with ``errors='replace'``. """ messages = self.bundle.get_messages('replace') self.assertEqual(len(messages), 4) # The only message that is treated differently is the invalid one. self.assertEqual(messages[0], '祝你好运�\x15')
def test_unspent_inputs_with_change_address(self): """ The bundle has unspent inputs, so it uses the provided change address. """ self.adapter.seed_response( command = GetBalancesCommand.command, response = { 'balances': [101], 'duration': 86, }, ) pmt_result =\ self.command( transfers = [ ProposedTransaction( address = Address(self.trytes_1), value = 42, ), ], multisigInput = MultisigAddress( digests = [self.digest_1, self.digest_2], trytes = self.trytes_2, ), changeAddress = Address(self.trytes_3), ) bundle = Bundle.from_tryte_strings(pmt_result['trytes']) self.assertEqual(len(bundle), 6) # Spend Transaction txn_1 = bundle[0] self.assertEqual(txn_1.address, self.trytes_1) self.assertEqual(txn_1.value, 42) # Input 1, Part 1 of 4 txn_2 = bundle[1] self.assertEqual(txn_2.address, self.trytes_2) self.assertEqual(txn_2.value, -101) self.assertEqual(txn_2.signature_message_fragment, Fragment(b'')) # Input 1, Part 2 of 4 txn_3 = bundle[2] self.assertEqual(txn_3.address, self.trytes_2) self.assertEqual(txn_3.value, 0) self.assertEqual(txn_3.signature_message_fragment, Fragment(b'')) # Input 1, Part 3 of 4 txn_4 = bundle[3] self.assertEqual(txn_4.address, self.trytes_2) self.assertEqual(txn_4.value, 0) self.assertEqual(txn_4.signature_message_fragment, Fragment(b'')) # Input 1, Part 4 of 4 txn_5 = bundle[4] self.assertEqual(txn_5.address, self.trytes_2) self.assertEqual(txn_5.value, 0) self.assertEqual(txn_5.signature_message_fragment, Fragment(b'')) # Change txn_6 = bundle[5] self.assertEqual(txn_6.address, self.trytes_3) self.assertEqual(txn_6.value, 59)
def test_happy_path(self): """ Preparing a bundle with a multisig input. """ self.adapter.seed_response( command = GetBalancesCommand.command, response = { 'balances': [42], # Would it be cheeky to put "7½ million years" here? 'duration': 86, }, ) pmt_result =\ self.command( transfers = [ ProposedTransaction( address = Address(self.trytes_1), value = 42, ), ], multisigInput = MultisigAddress( digests = [self.digest_1, self.digest_2], trytes = self.trytes_2, ), ) # The command returns the raw trytes. This is useful in a # real-world scenario because trytes are easier to transfer between # each entity that needs to apply their signature. # # However, for purposes of this test, we will convert the trytes # back into a bundle so that we can inspect the end result more # easily. bundle = Bundle.from_tryte_strings(pmt_result['trytes']) # # This bundle looks almost identical to what you would expect from # :py:meth:`iota_async.api.Iota.prepare_transfer`, except: # - There are 4 inputs (to hold all of the signature fragments). # - The inputs are unsigned. # self.assertEqual(len(bundle), 5) # Spend Transaction txn_1 = bundle[0] self.assertEqual(txn_1.address, self.trytes_1) self.assertEqual(txn_1.value, 42) # Input 1, Part 1 of 4 txn_2 = bundle[1] self.assertEqual(txn_2.address, self.trytes_2) self.assertEqual(txn_2.value, -42) self.assertEqual(txn_2.signature_message_fragment, Fragment(b'')) # Input 1, Part 2 of 4 txn_3 = bundle[2] self.assertEqual(txn_3.address, self.trytes_2) self.assertEqual(txn_3.value, 0) self.assertEqual(txn_3.signature_message_fragment, Fragment(b'')) # Input 1, Part 3 of 4 txn_4 = bundle[3] self.assertEqual(txn_4.address, self.trytes_2) self.assertEqual(txn_4.value, 0) self.assertEqual(txn_4.signature_message_fragment, Fragment(b'')) # Input 1, Part 4 of 4 txn_5 = bundle[4] self.assertEqual(txn_5.address, self.trytes_2) self.assertEqual(txn_5.value, 0) self.assertEqual(txn_5.signature_message_fragment, Fragment(b''))
def test_happy_path(self): """ Successfully replaying a bundle. """ # noinspection SpellCheckingInspection bundle = Bundle([ # "Spend" transaction, Part 1 of 1 Transaction( hash_ = TransactionHash( b'LUQJUUDAZIHSTPBLCZYXWXYKXTFCOCQJ9EHXKLEB' b'IJBPSRFSBYRBYODDAZ9NPKPYSMPVNEFXYZQ999999' ), address = Address( b'FZXUHBBLASPIMBDIHYTDFCDFIRII9LRJPXFTQTPO' b'VLEIFE9NWTFPPQZHDCXYUOUCXHHNRPKCIROYYTWSA' ), branch_transaction_hash = TransactionHash( b'UKGIAYNLALFGJOVUZYJGNIOZSXBBZDXVQLUMHGQE' b'PZJWYDMGTPJIQXS9GOKXR9WIGWFRWRSKGCJ999999' ), bundle_hash = BundleHash( b'ZSATLX9HDENCIARERVLWYHXPQETFL9QKTNC9LUOL' b'CDXKKW9MYTLZJDXBNOHURUXSYWMGGD9UDGLHCSZO9' ), nonce = Nonce( b'LIJVXBVTYMEEPCKJRIQTGAKWJRA' ), trunk_transaction_hash = TransactionHash( b'KFCQSGDYENCECCPNNZDVDTBINCBRBERPTQIHFH9G' b'YLTCSGUFMVWWSAHVZFXDVEZO9UHAUIU9LNX999999' ), signature_message_fragment = Fragment(b''), current_index = 0, last_index = 3, tag = Tag(b''), timestamp = 1483033814, value = 1, attachment_timestamp = 0, attachment_timestamp_lower_bound = 0, attachment_timestamp_upper_bound = 0, ), # Input #1, Part 1 of 2 Transaction( hash_ = TransactionHash( b'KFCQSGDYENCECCPNNZDVDTBINCBRBERPTQIHFH9G' b'YLTCSGUFMVWWSAHVZFXDVEZO9UHAUIU9LNX999999' ), address = Address( b'GMHOSRRGXJLDPVWRWVSRWI9BCIVLUXWKTJYZATIA' b'RAZRUCRGTWXWP9SZPFOVAMLISUPQUKHNDMITUJKIB' ), branch_transaction_hash = TransactionHash( b'UKGIAYNLALFGJOVUZYJGNIOZSXBBZDXVQLUMHGQE' b'PZJWYDMGTPJIQXS9GOKXR9WIGWFRWRSKGCJ999999' ), bundle_hash = BundleHash( b'ZSATLX9HDENCIARERVLWYHXPQETFL9QKTNC9LUOL' b'CDXKKW9MYTLZJDXBNOHURUXSYWMGGD9UDGLHCSZO9' ), nonce = Nonce( b'VRYLDCKEWZJXPQVSWOJVYVBJSCW' ), trunk_transaction_hash = TransactionHash( b'QSTUKDIBYAZIQVEOMFGKQPHAIPBHUPSDQFFKKHRA' b'ABYMYMQDHMTEWCM9IMZHQMGXOTWNSJYHRNA999999' ), signature_message_fragment = Fragment( b'XS9OVIXHIGGR9IYQBHGMFAHPZBWLIBNAQPFMPVYUZDOLLFDJIPZEMIOGVANQJSCU' b'IPDNNUNAMWEL9OFXXK9NV9UTCRBYTARBJHPQYJYKNAQGMATG9EXQMHGXY9QOHPBA' b'FEVABDYMCXORXHBMPLEWJYGYFFBWVXAUXHGLTABBKOQMZLFAYWDAKEOMJPJX9TMT' b'GXIJXZTKRRI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), current_index = 1, last_index = 3, tag = Tag(b''), timestamp = 1483033814, value = -99, attachment_timestamp = 0, attachment_timestamp_lower_bound = 0, attachment_timestamp_upper_bound = 0, ), # Input #1, Part 2 of 2 Transaction( hash_ = TransactionHash( b'QSTUKDIBYAZIQVEOMFGKQPHAIPBHUPSDQFFKKHRA' b'ABYMYMQDHMTEWCM9IMZHQMGXOTWNSJYHRNA999999' ), address = Address( b'GMHOSRRGXJLDPVWRWVSRWI9BCIVLUXWKTJYZATIA' b'RAZRUCRGTWXWP9SZPFOVAMLISUPQUKHNDMITUJKIB' ), branch_transaction_hash = TransactionHash( b'UKGIAYNLALFGJOVUZYJGNIOZSXBBZDXVQLUMHGQE' b'PZJWYDMGTPJIQXS9GOKXR9WIGWFRWRSKGCJ999999' ), bundle_hash = BundleHash( b'ZSATLX9HDENCIARERVLWYHXPQETFL9QKTNC9LUOL' b'CDXKKW9MYTLZJDXBNOHURUXSYWMGGD9UDGLHCSZO9' ), nonce = Nonce( b'AAKVYZOEZSOXTX9LOLHZYLNAS9C' ), trunk_transaction_hash = TransactionHash( b'ZYQGVZABMFVLJXHXXJMVAXOXHRJTTQUVDIIQOOXN' b'NDPQGDFDRIDQMUWJGCQKKLGEUQRBFAJWZBC999999' ), signature_message_fragment = Fragment( b'YSNEGUCUHXEEFXPQEABV9ATGQMMXEVGMZWKKAFAVOVGUECOZZJFQDNRBCSXCOTBD' b'BRUJ9HF9CITXQI9ZQGZFKCXMFZTOYHUTCXDIBIMTBKVXMMTPNKRDRLQESLWFZSQQ' b'9BCGKVIZAHBWYTNXG9OWOXHAMQECMOVKN9SOEVJBBARPXUXYUQVFPYXWXQQMDIVP' b'VITRWTNNBY9CYBHXJTZUVIPJJG9WLTNMFVPXGYZCNOGSLGVMS9YXXNSV9AYPXZTA' b'QJYUNUFBCSZBZNKWCPMVMOGFIDENTOOOCPRDJTNGQRLA9YKMLYZQRO9QQJMCSYVF' b'YLISFIWQQYMWMHUOEZPATYCEZARLWLAMCZWYWJ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QTJAUUXTINWZSQUTPUKUMOZCGOBKKFBXCVR9AGTAQS' b'SVGTUBBHSIRHFRSIR9SKSZPXQFG9AOYAHZNQR9AHSEFCKWCJHUTLREDVGBQYVBZR' b'CZDXFG9PTSAWQOURYKNWYAZNASV9UMUYUMFCQSFDHZD99WUMCORLYTIZMRGNBAY9' b'UJYJMMRCLJP9XVLXTAZOHNVVYSCOSDHGUOPXIRBJDXJUCJYLQKUJOTNJCPRBDOKV' b'ZEMIGZRNJOQKFFAXQVGGY9YRJORZCOD9REIIIDDTRQ9TJWTFYRKOPLAFNUUPCHXA' b'WVPYUQXAFFCTYAESWAFUTQQYZRQVLVZW9OWAAJMPSAEPKWXVEZVTVPQEEBVXNZJP' b'ZU9JJSIAEPIT9HE99XNAUYOAKRIFQQJQTFIMWEOKLCH9JKCQTGZPEGWORFB9ARNS' b'DPYKRONBONYOGEVEFXGTMQTQBEMFQWEMIDSGAVEQHVHAPSMTCJ9FMEYBWAQWWJCE' b'ABUUMMVNDMSBORFLHVIIDOUQHHXQKXTVGRAYTLMECCSVZOZM9JKUWIGGFLMMDGBU' b'DBIHJFUINVOKSFTOGFCZEMIBSZNGPL9HXWGTNNAKYIMDITCRMSHFR9BDSFGHXQMR' b'ACZOVUOTSJSKMNHNYIFEOD9CVBWYVVMG9ZDNR9FOIXSZSTIO9GLOLPLMW9RPAJYB' b'WTCKV9JMSEVGD9ZPEGKXF9XYQMUMJPWTMFZJODFIEYNLI9PWODSPPW9MVJOWZQZU' b'CIKXCVVXDKWHXV99GOEZ9CMGUH9OWGLLISNZEPSAPEDHVRKKGFFNGBXFLDBQTTQL' b'WVLUITJQ9JM' ), current_index = 2, last_index = 3, tag = Tag(b''), timestamp = 1483033814, value = 0, attachment_timestamp = 0, attachment_timestamp_lower_bound = 0, attachment_timestamp_upper_bound = 0, ), # "Change" transaction, Part 1 of 1 Transaction( hash_ = TransactionHash( b'ZYQGVZABMFVLJXHXXJMVAXOXHRJTTQUVDIIQOOXN' b'NDPQGDFDRIDQMUWJGCQKKLGEUQRBFAJWZBC999999' ), address = Address( b'YOTMYW9YLZQCSLHB9WRSTZDYYYGUUWLVDRHFQFEX' b'UVOQARTQWZGLBU9DVSRDPCWYWQZHLFHY9NGLPZRAQ' ), branch_transaction_hash = TransactionHash( b'QCHKLZZBG9XQMNGCDVXZGDRXIJMFZP9XUGAWNNVP' b'GXBWB9NVEKEFMUWOEACULFUR9Q9XCWPBRNF999999' ), bundle_hash = BundleHash( b'ZSATLX9HDENCIARERVLWYHXPQETFL9QKTNC9LUOL' b'CDXKKW9MYTLZJDXBNOHURUXSYWMGGD9UDGLHCSZO9' ), nonce = Nonce( b'TPGXQFUGNEYYFFKPFWJSXKTWEUK' ), trunk_transaction_hash = TransactionHash( b'UKGIAYNLALFGJOVUZYJGNIOZSXBBZDXVQLUMHGQE' b'PZJWYDMGTPJIQXS9GOKXR9WIGWFRWRSKGCJ999999' ), signature_message_fragment = Fragment(b''), current_index = 3, last_index = 3, tag = Tag(b''), timestamp = 1483033814, value = 98, attachment_timestamp = 0, attachment_timestamp_lower_bound = 0, attachment_timestamp_upper_bound = 0, ), ]) mock_get_bundles =\ mock.Mock(return_value={ 'bundles': [bundle], }) send_trytes_response = { 'trytes': bundle.as_tryte_strings(), } def mock_send_trytes(_,request): """ Ensures that the correct trytes are sent to the ``sendTrytes`` command to replay the bundle. References: - https://github.com/iotaledger/iota.lib.py/issues/74 """ self.assertEqual(request['trytes'], send_trytes_response['trytes']) return send_trytes_response with mock.patch( 'iota_async.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): with mock.patch( 'iota_async.commands.extended.send_trytes.SendTrytesCommand._execute', mock_send_trytes, ): response = self.command( depth = 100, minWeightMagnitude = 18, transaction = bundle[0].hash, ) self.assertDictEqual(response, send_trytes_response)
def test_multiple_transactions(self): """ Getting a bundle that contains multiple transactions. """ bundle = Bundle.from_tryte_strings([ TransactionTrytes( b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999WUQXEGBVIECGIWO9IGSYKWWPYCIVUJJGSJPWGIAFJPYSF9NSQOHWAHS9P' b'9PWQHOBXNNQIF9IRHVQXKPZW999999999999999999999999999XZUIENOTTBKJMDP' b'RXWGQYG9PWGTHNLFMVD99A99999999A99999999PDQWLVVDPUU9VIBODGMRIAZPGQX' b'DOGSEXIHKIBWSLDAWUKZCZMK9Z9YZSPCKBDJSVDPRQLJSTKUMTNVSXBGUEHHGAIWWQ' b'BCJZHZAQOWZMAIDAFUZBVMUVPWQJLUGGQKNKLMGTWXXNZKUCBJLEDAMYVRGABAWBY9' b'999MYIYBTGIOQYYZFJBLIAWMPSZEFFTXUZPCDIXSLLQDQSFYGQSQOGSPKCZNLVSZ9L' b'MCUWVNGEN9EJEW9999XZUIENOTTBKJMDPRXWGQYG9PWGTXUO9AXMP9FLMDRMADLRPW' b'CZCJBROYCDRJMYU9HDYJM9NDBFUPIZVTR' ), # Well, it was bound to happen sooner or later... the ASCII # representation of this tryte sequence contains a very naughty # phrase. But I don't feel like doing another POW, so... enjoy. TransactionTrytes( b'NBTCPCFDEACCPCBDVC9DTCQAJ9RBTC9D9DCDQAEAKDCDFD9DSCFAJ9VBCDJDTCQAJ9' b'ZBMDYBCCKB99999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999SYRABNN9JD9PNDL' b'IKUNCECUELTOHNLFMVD99999999999A99999999PDQWLVVDPUU9VIBODGMRIAZPGQX' b'DOGSEXIHKIBWSLDAWUKZCZMK9Z9YZSPCKBDJSVDPRQLJSTKUMTNVSXFSEWUNJOEGNU' b'I9QOCRFMYSIFAZLJHKZBPQZZYFG9ORYCRDX9TOMJPFCRB9R9KPUUGFPVOWYXFIWEW9' b'999BGUEHHGAIWWQBCJZHZAQOWZMAIDAFUZBVMUVPWQJLUGGQKNKLMGTWXXNZKUCBJL' b'EDAMYVRGABAWBY9999SYRABNN9JD9PNDLIKUNCECUELTOQZPSBDILVHJQVCEOICFAD' b'YKZVGMOAXJRQNTCKMHGTAUMPGJJMX9LNF' ), ]) for txn in bundle: self.adapter.seed_response('getTrytes', { 'trytes': [txn.as_tryte_string()], }) self.adapter.seed_response('getTrytes', { 'trytes': [ 'SPAMSPAMSPAM999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999999999999999999' '999999999999999999999999999999999999999999999999999JECDITWO9999999' '999999999999ONLFMVD99999999999999999999VVCHSQSRVFKSBONDWB9EAQEMQOY' 'YRBIZHTBJLYNAVDHZPUZAZ9LYHXWKBEJ9IPR9FAMFLT9EEOHVYWUPRHHSRCILCLWFD' 'GBYBFFOKMCSAPVD9VGZZRRGBLGMZMXD9RMZQDBLMGN9BATWZGULRBCYQEIKIRBPHC9' '999KTLTRSYOWBD9HVNP9GCUABARNGMYXUZKXWRPGOPETZLKYYC9Z9EYXIWVARUBMBM' 'BPXGORN9WPBLY99999ZRBVQWULRFXDNDYZKRKIXPZQT9JJJH9FZU9PVWZJWLXBPODP' 'EHMKTTAGEPLPHUQCZNLDSHERONOMHJCOI' ], }) response = self.command( transaction = TransactionHash( b'TOYJPHKMLQNDVLDHDILARUJCCIUMQBLUSWPCTIVA' b'DRXICGYDGSVPXFTILFFGAPICYHGGJ9OHXINFX9999' ), ) self.maxDiff = None self.assertListEqual( response['bundles'][0].as_json_compatible(), bundle.as_json_compatible(), )
def test_get_inclusion_states(self): """ Fetching inclusion states with transactions. """ # noinspection PyUnusedLocal def create_generator(ag, start, step=1): for addy in [self.addy1][start::step]: yield addy # The first address received IOTA. self.adapter.seed_response( 'findTransactions', { 'duration': 42, 'hashes': [ 'TESTVALUEFIVE9DONTUSEINPRODUCTION99999VH' 'YHRHJETGYCAFZGABTEUBWCWAS9WF99UHBHRHLIOFJ', ], }, ) # For this test, we have to generate a real TryteString. transaction_trytes =\ TryteString( b'KMYUMNEUAYODAQSNGWTAERRRHNZBZCOLMVVOBTVWLOFYCJKYMGRAMH9RQ9MTZOSZMH' b'QNZFHFEJEDFQ99HSUNVOTULDJGXEDULS9ZHABVDZODJUMCNWVCPNSCUVKVYWCEXBHW' b'RBZBSWFPQLWZWMUPGQIGAEGOVE9DDXBVCIPKQYCFZFBELTSMVFSIXLPTACTKAFMCTK' b'CPYD9BWDJMLKWAOBDSJNQYAHS9GFIQKZCROLFZJVUEIVXVNBRRLEIWTYVHURUXHSCG' b'DKEIEGPOCXKCYWIBUG9ABYCALYJVFLBNGMS9ARHGTQXBZFLENXCJVKHPVKD9KSAEOL' b'FFVAJCNKLDVHOCDARWUNKARDYMVKFKRSMUTYOUXSBFFYTKRREBDJZTLVUROQFCBXQN' b'SXDDYTZTEBRSXOBMLXHJKSJAVOOVCXATOWNQDWHT9CCUAAJUJKDOQLMAEZACSNFKXZ' b'IGWDQEUEFRZYAOSDNVMSXWYLVDAUXZSHNHAIBEMNPFUGORYUETNJK9UCEMSUJYBBDK' b'BHIPKEINQCGOVYCPKUPJMUCUVZOJSIWYRFMFXYUVSMOUALAQBWIMXBUBXSAETGKJRP' b'AHVAXHQJDMEVSRFYEXUSIEBKMGYCUKFD9JPGUV9AIYUVCRUURKMYUHMVE9OJCYYWTQ' b'WUWFMTBZYFXASHHVCMSWXKBRQFHHQVEQMEULJRWZKLWFFSGGKEHUZZFNDNITSRAUH9' b'PQK9OGLYMVBSHXQLLZHOBBIM9KVUWDLHZRDKQQVLQXGWYXEEVQPDZUO9PVXMALOMRQ' b'VCTHGIZ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QI9NKOSHWJCNGPJBLEQPUIWJBIOAWKLBXUCERTSL9FVCLYN' b'ADPYTPKJOIEMAQGWBVGSRCZINXEJODUDCT9FHOUMQM9ZHRMBJYSOMPNMEAJGEHICJI' b'PVXRKCYX9RZVT9TDZIMXGZJAIYJRGIVMSOICSUINRBQILMJOUQYXCYNJ9WGGJFHYTU' b'LWOIPUXXFNTIFNOJRZFSQQNAWBQZOLHHLVGHEPWTKKQEVIPVWZUN9ZBICZ9DZZBVII' b'BF9EPHARZJUFJGBQXQFQIBUECAWRSEKYJNYKNSVBCOWTFBZ9NAHFSAMRBPEYGPRGKW' b'WTWACZOAPEOECUO9OTMGABJVAIICIPXGSXACVINSYEQFTRCQPCEJXZCY9XZWVWVJRZ' b'CYEYNFUUBKPWCHICGJZXKE9GSUDXZYUAPLHAKAHYHDXNPHENTERYMMBQOPSQIDENXK' b'LKCEYCPVTZQLEEJVYJZV9BWU999999999999999999999999999FFL999999999999' b'9999999999999RJQGVD99999999999A99999999USGBXHGJUEWAUAKNPPRHJXDDMQV' b'YDSYZJSDWFYLOQVFGBOSLE9KHFDLDYHUYTXVSFAFCOCLQUHJXTEIQRNBTLHEGJFGVF' b'DJCE9IKAOCSYHLCLWPVVNWNESKLYAJG9FGGZOFXCEYOTWLVIJUHGY9QCU9FMZJY999' b'9999HYBUYQKKRNAVDPVGYBTVDZ9SVQBLCCVLJTPEQWWOIG9CQZIFQKCROH9YHUCNJT' b'SYPBVZVBNESX999999D9TARGPQTNIYRZURQGVHCAWEDRBJIIEJIUZYENVE9LLJQMXH' b'GSUUYUCPSOWBCXVFDCHHAZUDC9LUODYWO' ) self.adapter.seed_response( 'getTrytes', { 'duration': 99, 'trytes': [binary_type(transaction_trytes)], }, ) transaction = Transaction.from_tryte_string(transaction_trytes) mock_get_bundles = mock.Mock(return_value={ 'bundles': [Bundle([transaction])], }) mock_get_latest_inclusion = mock.Mock(return_value={ 'states': { transaction.hash: True, }, }) with mock.patch( 'iota_async.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with mock.patch( 'iota_async.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): with mock.patch( 'iota_async.commands.extended.get_latest_inclusion.GetLatestInclusionCommand._execute', mock_get_latest_inclusion, ): response = self.command( seed=Seed.random(), inclusionStates=True, # To keep the test focused, only retrieve a single # transaction. start=0, stop=1, ) bundle = response['bundles'][0] # type: Bundle self.assertTrue(bundle[0].is_confirmed)
def test_stop(self): """ Scanning the Tangle for all transfers, with stop index. """ # noinspection PyUnusedLocal def create_generator(ag, start, step=1): # Inject an invalid value into the generator, to ensure it is # skipped. for addy in [self.addy1, None][start::step]: yield addy # The first address received IOTA. self.adapter.seed_response( 'findTransactions', { 'duration': 42, 'hashes': [ 'TESTVALUEFIVE9DONTUSEINPRODUCTION99999VH' 'YHRHJETGYCAFZGABTEUBWCWAS9WF99UHBHRHLIOFJ', ], }, ) self.adapter.seed_response( 'getTrytes', { 'duration': 99, 'trytes': [''], }, ) bundle = Bundle([ Transaction( address=self.addy1, timestamp=1483033814, # These values are not relevant to the test. hash_=None, signature_message_fragment=None, value=42, tag=Tag(b''), current_index=0, last_index=0, bundle_hash=None, trunk_transaction_hash=None, branch_transaction_hash=None, attachment_timestamp=1483033814, attachment_timestamp_lower_bound=12, attachment_timestamp_upper_bound=0, nonce=None, ) ]) mock_get_bundles = mock.Mock(return_value={ 'bundles': [bundle], }) with mock.patch( 'iota_async.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with mock.patch( 'iota_async.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): response = self.command(seed=Seed.random(), stop=1) self.assertDictEqual( response, { 'bundles': [bundle], }, )
def test_full_scan(self): """ Scanning the Tangle for all transfers. """ # To speed up the test, we will mock the address generator. # :py:class:`iota_async.crypto.addresses.AddressGenerator` already has # its own test case, so this does not impact the stability of the # codebase. # noinspection PyUnusedLocal def create_generator(ag, start, step=1): for addy in [self.addy1, self.addy2][start::step]: yield addy # The first address received IOTA. self.adapter.seed_response( 'findTransactions', { 'duration': 42, 'hashes': [ 'TESTVALUEFIVE9DONTUSEINPRODUCTION99999VH' 'YHRHJETGYCAFZGABTEUBWCWAS9WF99UHBHRHLIOFJ', ], }, ) # The second address is unused. self.adapter.seed_response( 'findTransactions', { 'duration': 1, 'hashes': [], }, ) self.adapter.seed_response( 'getTrytes', { 'duration': 99, # Thankfully, we do not have to seed a realistic response for # ``getTrytes``, as we will be mocking the ``getBundles`` # command that uses on it. 'trytes': [''], }, ) bundle = Bundle([ Transaction( address=self.addy1, timestamp=1483033814, # These values are not relevant to the test. hash_=None, signature_message_fragment=None, value=42, tag=Tag(b''), current_index=0, last_index=0, bundle_hash=None, trunk_transaction_hash=None, branch_transaction_hash=None, attachment_timestamp=1483033814, attachment_timestamp_lower_bound=12, attachment_timestamp_upper_bound=0, nonce=None, ) ]) mock_get_bundles =\ mock.Mock(return_value={ 'bundles': [bundle], }) with mock.patch( 'iota_async.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with mock.patch( 'iota_async.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): response = self.command(seed=Seed.random()) self.assertDictEqual( response, { 'bundles': [bundle], }, )