def test_happy_path(self): """ Loading account data for an account. """ # noinspection PyUnusedLocal def mock_iter_used_addresses(adapter, seed, start): """ Mocks the ``iter_used_addresses`` function, so that we can simulate its functionality without actually connecting to the Tangle. References: - :py:func:`cornode.commands.extended.utils.iter_used_addresses` """ yield self.addy1, [self.hash1] yield self.addy2, [self.hash2] mock_get_balances = 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(return_value=bundles) with patch( 'cornode.commands.extended.get_account_data.iter_used_addresses', mock_iter_used_addresses, ): with patch( 'cornode.commands.extended.get_account_data.get_bundles_from_transaction_hashes', mock_get_bundles_from_transaction_hashes, ): with patch( 'cornode.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 _execute(self, request): transaction_hash = request['transaction'] # type: TransactionHash bundle = Bundle(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 _execute(self, request): change_address = request['changeAddress'] # type: Optional[Address] depth = request['depth'] # type: int inputs = request['inputs'] # type: Optional[List[Address]] min_weight_magnitude = request['minWeightMagnitude'] # type: int seed = request['seed'] # type: Seed transfers = request['transfers'] # type: List[ProposedTransaction] pt_response = PrepareTransferCommand(self.adapter)( changeAddress=change_address, inputs=inputs, seed=seed, transfers=transfers, ) st_response = SendTrytesCommand(self.adapter)( depth=depth, minWeightMagnitude=min_weight_magnitude, trytes=pt_response['trytes'], ) return { 'bundle': Bundle.from_tryte_strings(st_response['trytes']), }
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'9PWQHOBXNNQIF9IRHVQXKPZW999999999999999999999999999999999999999999' b'999999999999HNLFMVD99A99999999A99999999PDQWLVVDPUU9VIBODGMRIAZPGQX' 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'999999999999999999999999999999999999999999999999999999999999999999' b'999999999999HNLFMVD99999999999A99999999PDQWLVVDPUU9VIBODGMRIAZPGQX' 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_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=Hash(b'LIJVXBVTYMEEPCKJRIQTGAKWJRAMYNPJEGHEWAUL' b'XPBBUQPCJTJPRZTISQPJRJGMSBGQLER9OXYQXFGQO'), 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, ), # 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'ZSATLX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NXAPCYFXQ9ORMSFICDOZTS' b'GQOMDI9FKEKRIMZTWSIWMYAUSBIN9TPFSMQZCYGVPVWKSFZXPE9BP9ALNWQOVJGM' b'SCSJSTNUTMUAJUIQTITPPOHG9NKIFRNXSCMDAEW9LSUCTCXITSTZSBYMPOMSMTXP' b'CEBEOAUJK9STIZRXUORRQBCYJPCNHFKEVY9YBJL9QGLVUCSZKOLHD9BDNKIVJX9T' b'PPXQVGAXUSQQYGFDWQRZPKZKKWB9ZBFXTUGUGOAQLDTJPQXPUPHNATSGILEQCSQX' b'X9IAGIVKUW9MVNGKTSCYDMPSVWXCGLXEHWKRPVARKJFWGRYFCATYNZDTRZDGNZAI' b'OULYHRIPACAZLN9YHOFDSZYIRZJEGDUZBHFFWWQRNOLLWKZZENKOWQQYHGLMBMPF' b'HE9VHDDTBZYHMKQGZNCSLACYRCGYSFFTZQJUSZGJTZKKLWAEBGCRLXQRADCSFQYZ' b'G9CM9VLMQZA'), current_index=1, last_index=3, tag=Tag(b''), timestamp=1483033814, value=-99, ), # 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=Hash(b'AAKVYZOEZSOXTX9LOLHZYLNAS9CXBLSWVZQAMRGW' b'YW9GHHMVIOHWBMTXHDBXRTF9DEFFQFQESNV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TVGRAYTLMECCSVZOZM9JKUWIGGFLMMDGBU' b'DBIHJFUINVOKSFTOGFCZEMIBSZNGPL9HXWGTNNAKYIMDITCRMSHFR9BDSFGHXQMR' b'ACZOVUOTSJSKMNHNYIFEOD9CVBWYVVMG9ZDNR9FOIXSZSTIO9GLOLPLMW9RPAJYB' b'WTCKV9JMSEVGD9ZPEGKXF9XYQMUMJPWTMFZJODFIEYNLI9PWODSPPW9MVJOWZQZU' b'CIKXCVVXDKWHXV99GOEZ9CMGUH9OWGLLISNZEPSAPEDHVRKKGFFNGBXFLDBQTTQL' b'WVLUITJQ9JM'), current_index=2, last_index=3, tag=Tag(b''), timestamp=1483033814, value=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=Hash(b'TPGXQFUGNEYYFFKPFWJSXKTWEUKUFTRJCQKKXLXL' b'PSOHBZTGIBFPGLSVRIVYAC9NZMOMZLARFZYCNNRCM'), 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, ), ]) mock_get_bundles = Mock(return_value={ 'bundles': [bundle], }) send_trytes_response = { 'trytes': bundle.as_tryte_strings(head_to_tail=True), } mock_send_trytes = Mock(return_value=send_trytes_response) with patch( 'cornode.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): with patch( 'cornode.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_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 cornode. 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'BHIPKEINQCGOVY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PQTNIYRZURQGVHCAWEDRBJIIEJIUZYENVE9LLJQMXH' 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(return_value={ 'bundles': [Bundle([transaction])], }) mock_get_latest_inclusion = Mock(return_value={ 'states': { transaction.hash: True, }, }) with patch( 'cornode.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with patch( 'cornode.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): with patch( 'cornode.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 cornode. 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, nonce = None, ) ]) mock_get_bundles = Mock(return_value={ 'bundles': [bundle], }) with patch( 'cornode.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with patch( 'cornode.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:`cornode.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 cornode. 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, nonce = None, ) ]) mock_get_bundles = Mock(return_value={ 'bundles': [bundle], }) with patch( 'cornode.crypto.addresses.AddressGenerator.create_iterator', create_generator, ): with patch( 'cornode.commands.extended.get_bundles.GetBundlesCommand._execute', mock_get_bundles, ): response = self.command(seed=Seed.random()) self.assertDictEqual( response, { 'bundles': [bundle], }, )