def test_pass_tags_only(self): """ The request only includes tags. """ request = { 'tags': [ Tag(self.trytes1), Tag(self.trytes3), ], } filter_ = self._filter(request) self.assertFilterPasses(filter_) self.assertDictEqual( filter_.cleaned_data, { 'tags': [ text_type(Tag(self.trytes1)), text_type(Tag(self.trytes3)), ], # Null criteria are not included in the request. # https://github.com/iotaledger/iota.lib.py/issues/96 # 'addresses': [], # 'approvees': [], # 'bundles': [], }, )
def test_pass_all_parameters(self): """ The request contains valid values for all parameters. """ # Raw trytes are extracted to match the IRI's JSON protocol. request = { 'bundles': [ text_type(BundleHash(self.trytes1)), text_type(BundleHash(self.trytes2)), ], 'addresses': [ text_type(Address(self.trytes1)), text_type(Address(self.trytes2)), ], 'tags': [ text_type(Tag(self.trytes1)), text_type(Tag(self.trytes3)), ], 'approvees': [ text_type(TransactionHash(self.trytes1)), text_type(TransactionHash(self.trytes3)), ], } filter_ = self._filter(request) self.assertFilterPasses(filter_) self.assertDictEqual(filter_.cleaned_data, request)
def test_init_error_too_long(self): """ Attempting to create a tag longer than 27 trytes. """ with self.assertRaises(ValueError): # 28 chars = no va. Tag(b'COLOREDCOINS9999999999999999')
def test_init_automatic_pad(self): """ Tags are automatically padded to 27 trytes. """ tag = Tag(b'COLOREDCOINS') self.assertEqual(binary_type(tag), b'COLOREDCOINS999999999999999')
def test_pass_compatible_types(self): """ The request contains values that can be converted to the expected types. """ filter_ = self._filter({ 'bundles': [ self.trytes1.encode('ascii'), BundleHash(self.trytes2), ], 'addresses': [ self.trytes1.encode('ascii'), Address(self.trytes2), ], 'tags': [ self.trytes1.encode('ascii'), Tag(self.trytes3), ], 'approvees': [ self.trytes1.encode('ascii'), TransactionHash(self.trytes3), ], }) self.assertFilterPasses(filter_) self.assertDictEqual( filter_.cleaned_data, { # Raw trytes are extracted to match the IRI's JSON protocol. 'bundles': [ text_type(BundleHash(self.trytes1)), text_type(BundleHash(self.trytes2)), ], 'addresses': [ text_type(Address(self.trytes1)), text_type(Address(self.trytes2)), ], 'tags': [ text_type(Tag(self.trytes1)), text_type(Tag(self.trytes3)), ], 'approvees': [ text_type(TransactionHash(self.trytes1)), text_type(TransactionHash(self.trytes3)), ], }, )
def test_finalize_insecure_bundle(self): """ When finalizing, the bundle detects an insecure bundle hash. References: - https://github.com/iotaledger/iota.lib.py/issues/84 """ # noinspection SpellCheckingInspection bundle =\ ProposedBundle([ ProposedTransaction( address =\ Address( '9XV9RJGFJJZWITDPKSQXRTHCKJAIZZY9BYLBEQUX' 'UNCLITRQDR9CCD99AANMXYEKD9GLJGVB9HIAGRIBQ', ), tag = Tag('PPDIDNQDJZGUQKOWJ9JZRCKOVGP'), timestamp = 1509136296, value = 0, ), ]) bundle.finalize() # The resulting bundle hash is insecure (contains a [1, 1, 1]), so # the legacy tag is manipulated until a secure hash is generated. # noinspection SpellCheckingInspection self.assertEqual(bundle[0].legacy_tag, Tag('ZTDIDNQDJZGUQKOWJ9JZRCKOVGP')) # The proper tag is left alone, however. # noinspection SpellCheckingInspection self.assertEqual(bundle[0].tag, Tag('PPDIDNQDJZGUQKOWJ9JZRCKOVGP')) # The bundle hash takes the modified legacy tag into account. # noinspection SpellCheckingInspection self.assertEqual( bundle.hash, BundleHash( 'NYSJSEGCWESDAFLIFCNJFWGZ9PCYDOT9VCSALKBD' '9UUNKBJAJCB9KVMTHZDPRDDXC9UFJQBJBQFUPJKFC', ))
def test_fail_tags_wrong_type(self): """ ``tags`` is not an array. """ self.assertFilterErrors( { 'tags': Tag(self.trytes1), }, { 'tags': [f.Type.CODE_WRONG_TYPE], }, )
def test_create_tag_from_string(self): """ Check if string value of tag is converted into a Tag object """ transaction = ProposedTransaction( address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999QARFLF' b'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'), tag="AAAZZZZ999", value=42, ) self.assertEqual(type(transaction.tag), type(Tag(b'')))
def test_fail_unexpected_parameters(self): """ The request contains unexpected parameters. """ self.assertFilterErrors( { 'addresses': [Address(self.trytes1)], 'approvees': [TransactionHash(self.trytes1)], 'bundles': [BundleHash(self.trytes1)], 'tags': [Tag(self.trytes1)], # Hey, you're not allowed in he-argh! 'foo': 'bar', }, { 'foo': [f.FilterMapper.CODE_EXTRA_KEY], }, )
def test_add_inputs_with_change(self): """ Adding inputs to a bundle results in unspent inputs. """ tag = Tag(b'CHANGE9TXN') # noinspection SpellCheckingInspection self.bundle.add_transaction( ProposedTransaction( address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999VELDTF' b'QHDFTHIHFE9II9WFFDFHEATEI99GEDC9BAUH9EBGZ'), value=29, )) # noinspection SpellCheckingInspection self.bundle.add_transaction( ProposedTransaction( address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999OGVEEF' b'BCYAM9ZEAADBGBHH9BPBOHFEGCFAM9DESCCHODZ9Y'), tag=tag, value=13, )) self.bundle.add_inputs([self.input_3_bal_eq_100]) # noinspection SpellCheckingInspection change_address =\ Address( b'TESTVALUE9DONTUSEINPRODUCTION99999KAFGVC' b'IBLHS9JBZCEFDELEGFDCZGIEGCPFEIQEYGA9UFPAE' ) self.bundle.send_unspent_inputs_to(change_address) self.bundle.finalize() # 2 spends + 1 input (with security level 1) + 1 change self.assertEqual(len(self.bundle), 4) change_txn = self.bundle[-1] self.assertEqual(change_txn.address, change_address) self.assertEqual(change_txn.value, 58) self.assertEqual(change_txn.tag, tag)
def test_init_from_tryte_string_error_wrong_subclass(self): """ Initializing a TryteString from a conflicting subclass instance. This restriction does not apply when initializing a TryteString instance; only subclasses. """ tag = Tag(b'RBTC9D9DCDQAEASBYBCCKBFA') with self.assertRaises(TypeError): # When initializing a subclassed TryteString, you have to use the # same type (or a generic TryteString). Address(tag) # If you are 110% confident that you know what you are doing, you # can force the conversion by casting as a generic TryteString # first. addy = Address(TryteString(tag)) self.assertEqual( binary_type(addy), b'RBTC9D9DCDQAEASBYBCCKBFA9999999999999999' b'99999999999999999999999999999999999999999', )
def test_add_transaction_long_message(self): """ Adding a transaction to a bundle, with a message so long that it has to be split into multiple transactions. """ # noinspection SpellCheckingInspection address = Address(b'TESTVALUE9DONTUSEINPRODUCTION99999N9GIUF' b'HCFIUGLBSCKELC9IYENFPHCEWHIDCHCGGEH9OFZBN') tag = Tag.from_unicode('H2G2') self.bundle.add_transaction( ProposedTransaction( address=address, tag=tag, message=TryteString.from_unicode(''' "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. '''), # Now you know.... # Eh, who am I kidding? You probably knew before I did (: value=42, )) # Because the message is too long to fit into a single fragment, # the transaction is split into two parts. self.assertEqual(len(self.bundle), 2) txn1 = self.bundle[0] self.assertEqual(txn1.address, address) self.assertEqual(txn1.tag, tag) self.assertEqual(txn1.value, 42) txn2 = self.bundle[1] self.assertEqual(txn2.address, address) self.assertEqual(txn2.tag, tag) # Supplementary transactions are assigned zero IOTA value. self.assertEqual(txn2.value, 0)
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_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'GXIJXZTKRRIPAMYY9UNSP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_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'YLISFIWQQYMWMHUOEZPATYCEZARLWLAMCZWYWJZVD9WWKYJUR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ZSQUTPUKUMOZCGOBKKFBXCVR9AGTAQS' 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_single_transaction(self): """ Getting a bundle that contains a single transaction. """ transaction =\ Transaction( current_index = 0, last_index = 0, tag = Tag(b''), timestamp = 1484960990, value = 0, attachment_timestamp = 1484960990, attachment_timestamp_lower_bound = 12, attachment_timestamp_upper_bound = 0, # These values are not relevant for 0-value transactions. nonce = Nonce(b''), signature_message_fragment = Fragment(b''), # This value is computed automatically, so it has to be real. hash_ = TransactionHash( b'XPJIYZWPF9LBCYZPNBFARDRCSUGJGF9TWZT9K9PX' b'VYDFPZOZBGXUCKLTJEUCFBEKQQ9VCSQVQDMMJQAY9', ), address = Address( b'TESTVALUE9DONTUSEINPRODUCTION99999OCSGVF' b'IBQA99KGTCPCZ9NHR9VGLGADDDIEGGPCGBDEDDTBC', ), bundle_hash = BundleHash( b'TESTVALUE9DONTUSEINPRODUCTION99999DIOAZD' b'M9AIUHXGVGBC9EMGI9SBVBAIXCBFJ9EELCPDRAD9U', ), branch_transaction_hash = TransactionHash( b'TESTVALUE9DONTUSEINPRODUCTION99999BBCEDI' b'ZHUDWBYDJEXHHAKDOCKEKDFIMB9AMCLFW9NBDEOFV', ), trunk_transaction_hash = TransactionHash( b'TESTVALUE9DONTUSEINPRODUCTION999999ARAYA' b'MHCB9DCFEIWEWDLBCDN9LCCBQBKGDDAECFIAAGDAS', ), ) self.adapter.seed_response('getTrytes', { 'trytes': [transaction.as_tryte_string()], }) response = self.command(transaction=transaction.hash) bundle = response['bundles'][0] # type: Bundle self.assertEqual(len(bundle), 1) self.maxDiff = None self.assertDictEqual( bundle[0].as_json_compatible(), transaction.as_json_compatible(), )
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'QAEAHDWCPCHDEAXCGDSASASAGAJ9GAS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_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_as_tryte_string(self): """ Converting a Transaction into a TryteString. """ transaction = Transaction( hash_=TransactionHash( b'SYABNCYPLULQQBTDCUWJPVVMYNWHKEHGAZPKRBGE' b'QKEHUIKJCHWGAUKLSYMDOUUBMXPKCPTNFWUFU9JKW'), signature_message_fragment=Fragment( b'GYPRVHBEZOOFXSHQBLCYW9ICTCISLHDBNMMVYD9JJHQMPQCTIQAQTJNNNJ9IDXLRCC' b'OYOXYPCLR9PBEY9ORZIEPPDNTI9CQWYZUOTAVBXPSBOFEQAPFLWXSWUIUSJMSJIIIZ' b'WIKIRH9GCOEVZFKNXEVCUCIIWZQCQEUVRZOCMEL9AMGXJNMLJCIA9UWGRPPHCEOPTS' b'VPKPPPCMQXYBHMSODTWUOABPKWFFFQJHCBVYXLHEWPD9YUDFTGNCYAKQKVEZYRBQRB' b'XIAUX9SVEDUKGMTWQIYXRGSWYRK9SRONVGTW9YGHSZRIXWGPCCUCDRMAXBPDFVHSRY' b'WHGB9DQSQFQKSNICGPIPTRZINYRXQAFSWSEWIFRMSBMGTNYPRWFSOIIWWT9IDSELM9' b'JUOOWFNCCSHUSMGNROBFJX9JQ9XT9PKEGQYQAWAFPRVRRVQPUQBHLSNTEFCDKBWRCD' b'X9EYOBB9KPMTLNNQLADBDLZPRVBCKVCYQEOLARJYAGTBFR9QLPKZBOYWZQOVKCVYRG' b'YI9ZEFIQRKYXLJBZJDBJDJVQZCGYQMROVHNDBLGNLQODPUXFNTADDVYNZJUVPGB9LV' b'PJIYLAPBOEHPMRWUIAJXVQOEM9ROEYUOTNLXVVQEYRQWDTQGDLEYFIYNDPRAIXOZEB' b'CS9P99AZTQQLKEILEVXMSHBIDHLXKUOMMNFKPYHONKEYDCHMUNTTNRYVMMEYHPGASP' b'ZXASKRUPWQSHDMU9VPS99ZZ9SJJYFUJFFMFORBYDILBXCAVJDPDFHTTTIYOVGLRDYR' b'TKHXJORJVYRPTDH9ZCPZ9ZADXZFRSFPIQKWLBRNTWJHXTOAUOL9FVGTUMMPYGYICJD' b'XMOESEVDJWLMCVTJLPIEKBE9JTHDQWV9MRMEWFLPWGJFLUXI9BXPSVWCMUWLZSEWHB' b'DZKXOLYNOZAPOYLQVZAQMOHGTTQEUAOVKVRRGAHNGPUEKHFVPVCOYSJAWHZU9DRROH' b'BETBAFTATVAUGOEGCAYUXACLSSHHVYDHMDGJP9AUCLWLNTFEVGQGHQXSKEMVOVSKQE' b'EWHWZUDTYOBGCURRZSJZLFVQQAAYQO9TRLFFN9HTDQXBSPPJYXMNGLLBHOMNVXNOWE' b'IDMJVCLLDFHBDONQJCJVLBLCSMDOUQCKKCQJMGTSTHBXPXAMLMSXRIPUBMBAWBFNLH' b'LUJTRJLDERLZFUBUSMF999XNHLEEXEENQJNOFFPNPQ9PQICHSATPLZVMVIWLRTKYPI' b'XNFGYWOJSQDAXGFHKZPFLPXQEHCYEAGTIWIJEZTAVLNUMAFWGGLXMBNUQTOFCNLJTC' b'DMWVVZGVBSEBCPFSM99FLOIDTCLUGPSEDLOKZUAEVBLWNMODGZBWOVQT9DPFOTSKRA' b'BQAVOQ9RXWBMAKFYNDCZOJGTCIDMQSQQSODKDXTPFLNOKSIZEOY9HFUTLQRXQMEPGO' b'XQGLLPNSXAUCYPGZMNWMQWSWCKAQYKXJTWINSGPPZG9HLDLEAWUWEVCTVRCBDFOXKU' b'ROXH9HXXAXVPEJFRSLOGRVGYZASTEBAQNXJJROCYRTDPYFUIQJVDHAKEG9YACV9HCP' b'JUEUKOYFNWDXCCJBIFQKYOXGRDHVTHEQUMHO999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999'), address=Address(b'99999999999999999999999999999999999999999' b'9999999999999999999999999999999999999999'), value=0, timestamp=1480690413, current_index=1, last_index=1, bundle_hash=BundleHash( b'NFDPEEZCWVYLKZGSLCQNOFUSENIXRHWWTZFBXMPS' b'QHEDFWZULBZFEOMNLRNIDQKDNNIELAOXOVMYEI9PG'), trunk_transaction_hash=TransactionHash( b'TKORV9IKTJZQUBQAWTKBKZ9NEZHBFIMCLV9TTNJN' b'QZUIJDFPTTCTKBJRHAITVSKUCUEMD9M9SQJ999999'), branch_transaction_hash=TransactionHash( b'TKORV9IKTJZQUBQAWTKBKZ9NEZHBFIMCLV9TTNJN' b'QZUIJDFPTTCTKBJRHAITVSKUCUEMD9M9SQJ999999'), tag=Tag(b'999999999999999999999999999'), attachment_timestamp=1480690413, attachment_timestamp_lower_bound=1480690413, attachment_timestamp_upper_bound=1480690413, nonce=Nonce(b'999999999999999999999999999'), ) self.assertEqual( transaction.as_tryte_string(), TransactionTrytes( b'GYPRVHBEZOOFXSHQBLCYW9ICTCISLHDBNMMVYD9JJHQMPQCTIQAQTJNNNJ9IDXLRCC' b'OYOXYPCLR9PBEY9ORZIEPPDNTI9CQWYZUOTAVBXPSBOFEQAPFLWXSWUIUSJMSJIIIZ' b'WIKIRH9GCOEVZFKNXEVCUCIIWZQCQEUVRZOCMEL9AMGXJNMLJCIA9UWGRPPHCEOPTS' b'VPKPPPCMQXYBHMSODTWUOABPKWFFFQJHCBVYXLHEWPD9YUDFTGNCYAKQKVEZYRBQRB' b'XIAUX9SVEDUKGMTWQIYXRGSWYRK9SRONVGTW9YGHSZRIXWGPCCUCDRMAXBPDFVHSRY' b'WHGB9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FLOIDTCLUGPSEDLOKZUAEVBLWNMODGZBWOVQT9DPFOTSKRA' b'BQAVOQ9RXWBMAKFYNDCZOJGTCIDMQSQQSODKDXTPFLNOKSIZEOY9HFUTLQRXQMEPGO' b'XQGLLPNSXAUCYPGZMNWMQWSWCKAQYKXJTWINSGPPZG9HLDLEAWUWEVCTVRCBDFOXKU' b'ROXH9HXXAXVPEJFRSLOGRVGYZASTEBAQNXJJROCYRTDPYFUIQJVDHAKEG9YACV9HCP' b'JUEUKOYFNWDXCCJBIFQKYOXGRDHVTHEQUMHO999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999RKWEEVD99A99999999A99999999NFDPEEZCWVYLKZGSLCQNOFUSENI' b'XRHWWTZFBXMPSQHEDFWZULBZFEOMNLRNIDQKDNNIELAOXOVMYEI9PGTKORV9IKTJZQ' b'UBQAWTKBKZ9NEZHBFIMCLV9TTNJNQZUIJDFPTTCTKBJRHAITVSKUCUEMD9M9SQJ999' b'999TKORV9IKTJZQUBQAWTKBKZ9NEZHBFIMCLV9TTNJNQZUIJDFPTTCTKBJRHAITVSK' b'UCUEMD9M9SQJ999999999999999999999999999999999RKWEEVD99RKWEEVD99RKW' b'EEVD99999999999999999999999999999'), )
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], }, )