예제 #1
0
    def test_decode(self):
        encoded_stream = self._from_hex('0A00010203040506070809')

        # decode the address
        data = decode(encoded_stream)

        self.assertIsEncoded(data, '00010203040506070809')
예제 #2
0
    def assertIsExpectedTx(self, payload: Transaction,
                           transaction_bytes: bytes,
                           expected_hex_payload: str):
        # a payload needs at least one signee
        self.assertGreater(len(payload.signers), 0)

        # calculate the serial length of the signatures (so that we can extract the payload)
        signatures_serial_length = self.EXPECTED_SERIAL_SIGNATURE_LENGTH * len(
            payload.signers)

        # sanity check
        self.assertGreater(len(transaction_bytes), signatures_serial_length)

        expected_payload_end = len(
            transaction_bytes) - signatures_serial_length

        # extract and verify the payload
        payload_bytes = transaction_bytes[:expected_payload_end]
        self.assertEqual(expected_hex_payload, payload_bytes.hex())

        # loop through and verify all the signatures
        buffer = io.BytesIO(transaction_bytes[expected_payload_end:])
        for signee in payload.signers:
            # extract the signature from the stream
            signature = bytearray.decode(buffer)

            # validate the signature is correct for the payload
            self.assertTrue(signee.verify(payload_bytes, signature))