Exemple #1
0
  def test_add_signature_or_message_invalid_start_index(self):
    """
    Attempting to add fragments to a bundle, but `start_index` is invalid.
    """
    # Add 3 transactions to the bundle.
    for i in ['A', 'B', 'C']:
      self.bundle.add_transaction(ProposedTransaction(
        address =
          Address(
            'TESTVALUE' + i + 'DONTUSEINPRODUCTION99999QARFLF'
            'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'
          ),
        message = TryteString.from_unicode('This should be overwritten'),
        value = 0,
      ))

    fragment1 = Fragment.from_unicode('This is the first fragment.')

    with self.assertRaises(ValueError):
      self.bundle.add_signature_or_message([fragment1], start_index=-1)

    with self.assertRaises(ValueError):
      self.bundle.add_signature_or_message([fragment1], start_index=3)

    with self.assertRaises(TypeError):
      self.bundle.add_signature_or_message([fragment1], 'not an int')
Exemple #2
0
  def test_add_signature_or_message_too_long_fragments(self):
    """
    Trying to add too many fragments to a bundle, when there aren't enough
    transactions to hold them.
    """
    # Add 3 transactions to the bundle.
    for i in ['A', 'B', 'C']:
      self.bundle.add_transaction(ProposedTransaction(
        address =
          Address(
            'TESTVALUE' + i + 'DONTUSEINPRODUCTION99999QARFLF'
            'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'
          ),
        message= TryteString.from_unicode('This should be overwritten'),
        value = 0,
      ))

    fragment1 = Fragment.from_unicode('This is the first fragment.')
    # 4 fragments, 3 txs in bundle
    fragments = [fragment1] * 4

    with self.assertRaises(ValueError):
      self.bundle.add_signature_or_message(fragments)

    # Length is okay, but overflow because of offset
    fragments = [fragment1] * 3

    with self.assertRaises(ValueError):
      self.bundle.add_signature_or_message(fragments,start_index=1)
Exemple #3
0
    def test_add_signature_or_message(self):
        """
    Add a fragment to a transaction.
    """
        # Add a transaction
        self.bundle.add_transaction(
            ProposedTransaction(
                address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999QARFLF'
                                b'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'),
                message=TryteString.from_unicode('This should be overwritten'),
                value=0,
            ))
        custom_msg = \
          'The early bird gets the worm, but the custom-msg gets into the bundle.'
        custom_fragment = Fragment.from_unicode(custom_msg)

        # Before finalization, the method adds to message field...
        self.bundle.add_signature_or_message([custom_fragment])
        self.assertEqual(self.bundle._transactions[0].message, custom_fragment)

        # ... because upon finalization, this is translated into
        # signature_message_fragment field.
        self.bundle.finalize()
        self.assertEqual(
            self.bundle._transactions[0].signature_message_fragment,
            custom_fragment)

        # Do we have the right text inside?
        self.assertEqual(self.bundle.get_messages()[0], custom_msg)
Exemple #4
0
    def test_add_signature_or_messagee_multiple(self):
        """
    Add multiple fragments.
    """
        # Add 3 transactions to the bundle, For convenience, we use
        # 3 different addresses, so they are not grouped together and
        # bundle.get_messages() returns a list of messages mapping to
        # the 3 transactions.
        for i in ['A', 'B', 'C']:
            self.bundle.add_transaction(
                ProposedTransaction(
                    address=Address(
                        'TESTVALUE' + i + 'DONTUSEINPRODUCTION99999QARFLF'
                        'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'),
                    message=TryteString.from_unicode(
                        'This should be overwritten'),
                    value=0,
                ))

        fragment1 = Fragment.from_unicode('This is the first fragment.')
        fragment2 = Fragment.from_unicode('This is the second fragment.')

        self.bundle.add_signature_or_message([fragment1, fragment2])

        bundle_fragments = []
        for tx in self.bundle:
            bundle_fragments.append(tx.message)

        self.assertListEqual(bundle_fragments, [
            fragment1, fragment2,
            TryteString.from_unicode('This should be overwritten')
        ])

        self.bundle.finalize()

        bundle_fragments_unicode = []
        for tx in self.bundle:
            bundle_fragments_unicode.append(
                tx.signature_message_fragment.decode())

        self.assertListEqual(bundle_fragments_unicode, [
            fragment1.decode(),
            fragment2.decode(), 'This should be overwritten'
        ])
Exemple #5
0
    def test_add_signature_or_message_multiple_offset(self):
        """
    Add multiple fragments with offset.
    """
        # Add 3 transactions to the bundle.
        for i in ['A', 'B', 'C']:
            self.bundle.add_transaction(
                ProposedTransaction(
                    address=Address(
                        'TESTVALUE' + i + 'DONTUSEINPRODUCTION99999QARFLF'
                        'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'),
                    message=TryteString.from_unicode(
                        'This should be overwritten'),
                    value=0,
                ))

        fragment1 = Fragment.from_unicode('This is the first fragment.')
        fragment2 = Fragment.from_unicode('This is the second fragment.')

        self.bundle.add_signature_or_message([fragment1, fragment2], 1)

        bundle_fragments = []
        for tx in self.bundle:
            bundle_fragments.append(tx.message)

        self.assertListEqual(bundle_fragments, [
            TryteString.from_unicode('This should be overwritten'), fragment1,
            fragment2
        ])

        self.bundle.finalize()

        bundle_fragments_unicode = []
        for tx in self.bundle:
            bundle_fragments_unicode.append(
                tx.signature_message_fragment.decode())

        self.assertListEqual(bundle_fragments_unicode, [
            'This should be overwritten',
            fragment1.decode(),
            fragment2.decode()
        ])
Exemple #6
0
    def test_add_signature_or_message_finalized_bundle(self):
        """
    Try to call the method on a finalized bundle.
    """
        self.bundle.add_transaction(
            ProposedTransaction(
                address=Address(b'TESTVALUE9DONTUSEINPRODUCTION99999QARFLF'
                                b'TDVATBVFTFCGEHLFJBMHPBOBOHFBSGAGWCM9PG9GX'),
                message=TryteString.from_unicode('This should be overwritten'),
                value=0,
            ))

        custom_msg = \
          'The early bird gets the worm, but the custom-msg gets into the bundle.'
        custom_fragment = Fragment.from_unicode(custom_msg)

        # Finalize the bundle, no further changes should be permitted.
        self.bundle.finalize()

        with self.assertRaises(RuntimeError):
            self.bundle.add_signature_or_message([custom_fragment])
Exemple #7
0
  def setUp(self):
    super(BundleTestCase, self).setUp()

    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'EAHDKDCDEAADTCBDEAGDWCXCJDTCFDTCSCEAKDXCHDWCEATCLDDDTCRCHDPCBDRC'
            b'MDSAEACCWCTCXCFDEAKDPCXCHDXCBDVCEAWCPCSCEABDCDHDEAQCTCTCBDEAXCBD'
            b'EAJDPCXCBDSAJ9GACCWCTCFDTCEAFDTCPC9D9DMDEAXCGDEACDBDTCIBGAEAQCFD'
            b'TCPCHDWCTCSCEAZBWCCDIDRCWCVCSAJ9GACCWCTCFDTCEAFDTCPC9D9DMDEAXCGD'
            b'EACDBDTCQAGAEARCCDBDUCXCFDADTCSCEANBTCTCDDEACCWCCDIDVCWCHDSAJ9GA'
            b'CCCDEAOBJDTCFDMDHDWCXCBDVCIBEACCCDEAHDWCTCEAVCFDTCPCHDEA9CIDTCGD'
            b'HDXCCDBDEACDUCEAVBXCUCTCQAEAHDWCTCEADCBDXCJDTCFDGDTCEAPCBDSCEAOB'
            b'JDTCFDMDHDWCXCBDVCIBGAJ9GAHCTCGDSAGAJ9LBCDHDWCEACDUCEAHDWCTCEAAD'
            b'TCBDEAWCPCSCEAQCTCTCBDEAHDFDPCXCBDTCSCEAUCCDFDEAHDWCXCGDEAADCDAD'
            b'TCBDHDEBEAHDWCTCXCFDEA9DXCJDTCGDEAWCPCSCEAQCTCTCBDEAPCJ9EAEADDFD'
            b'TCDDPCFDPCHDXCCDBDEAUCCDFDEAXCHDEBEAHDWCTCMDEAWCPCSCEAQCTCTCBDEA'
            b'GDTC9DTCRCHDTCSCEAPCHDEAQCXCFDHDWCEAPCGDEAHDWCCDGDTCEAKDWCCDEAKD'
            b'CDID9DSCJ9EAEAKDXCHDBDTCGDGDEAHDWCTCEAPCBDGDKDTCFDEBEAQCIDHDEATC'
            b'JDTCBDEAGDCDEAHDWCTCMDEAUCCDIDBDSCEAHDWCTCADGDTC9DJDTCGDEAVCPCGD'
            b'DDXCBDVCEAPCBDSCEAGDEDIDXCFDADXCBDVCJ9EAEA9DXCZCTCEATCLDRCXCHDTC'
            b'SCEARCWCXC9DSCFDTCBDSAJ9GAKBBDSCEAMDCDIDLAFDTCEAFDTCPCSCMDEAHDCD'
            b'EAVCXCJDTCEAXCHDEAHDCDEAIDGDIBGAEAIDFDVCTCSCEAVBCDCDBDEDIDPCKD9D'
            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,
      ),
    ])