Esempio n. 1
0
    def test_from_raw(self):
        new_block = Block.from_raw_with_operations(self.block.raw_with_operations())

        self.assertIsInstance(new_block, Block)
        for attr in ('previous_block_rev', 'timestamp', 'operations_limit', 'difficulty',
                     'padding', 'signature'):
            self.assertEqual(getattr(new_block, attr), getattr(self.block, attr))

        self.assertEqual(new_block.operations_full_raw(), self.block.operations_full_raw())
        self.assertEqual(new_block.public_key.der, self.block.public_key.der)
        self.assertEqual(new_block.is_checksum_correct(), self.block.is_checksum_correct())
Esempio n. 2
0
    def test_mangled_raw(self):
        raw = self.block.raw_with_operations()

        with self.assertRaisesRegex(RawFormatError, "raw input too short"):
            Block.from_raw_with_operations(raw[:-1])
        with self.assertRaisesRegex(RawFormatError, "raw input too long"):
            Block.from_raw_with_operations(raw + b'\x00')

        with self.assertRaisesRegex(Block.VerifyError, "wrong signature"):
            mangled_raw = bytearray(raw)
            mangled_raw[-1] = 0
            Block.from_raw_with_operations(mangled_raw).verify_id(self.block.id)

        with self.assertRaisesRegex(Block.VerifyError, "wrong object id"):
            Block.from_raw_with_operations(raw).verify_id(b'wrong hash')

        with self.assertRaisesRegex(Block.VerifyError, "wrong object id"):
            Block.from_raw_with_operations(raw).verify_id(sha256(b'wrong hash'))

        with self.assertRaisesRegex(RawFormatError, "version number mismatch"):
            Block.from_raw((2).to_bytes(4, 'big') + self.block.raw()[4:])
Esempio n. 3
0
    def process_block(self, raw_block):
        block = Block.from_raw_with_operations(raw_block)

        with patch.object(BlockChain, '_get_new_blocks', return_value=[block]):
            pmpi.core.get_blockchain().update_blocks()