def test_from_raw(self): new_operation = Operation.from_raw(self.operation.raw()) self.assertIsInstance(new_operation, Operation) for attr in ('previous_operation_rev', 'uuid', 'address', 'signature'): self.assertEqual(getattr(new_operation, attr), getattr(self.operation, attr)) self.assertEqual(new_operation.owners_der, self.operation.owners_der) self.assertEqual(new_operation.public_key.der, self.operation.public_key.der)
def test_mangled_raw(self): raw = self.operation.raw() with self.assertRaisesRegex(RawFormatError, "raw input too short"): Operation.from_raw(raw[:-1]) with self.assertRaisesRegex(RawFormatError, "raw input too long"): Operation.from_raw(raw + b'\x00') with self.assertRaisesRegex(Operation.VerifyError, "wrong signature"): mangled_raw = bytearray(raw) mangled_raw[-1] = 0 Operation.from_raw(mangled_raw).verify() with self.assertRaisesRegex(Operation.VerifyError, "wrong object id"): Operation.from_raw(raw).verify_id(b'wrong hash') # wrong hash length with self.assertRaisesRegex(Operation.VerifyError, "wrong object id"): Operation.from_raw(raw).verify_id(sha256(b'wrong hash').digest()) # different hash
def process_operation(self, raw_operation): op = Operation.from_raw(raw_operation) future = asyncio.ensure_future(operation_queue.put(op)) future.add_done_callback(self.new_block)