Пример #1
0
    def test_testnet797966(self):

        path = '%s/fixtures/797966.txt' % os.getcwd()

        with open(path, 'rb') as f:
            blockraw = f.read().strip()

            hex = binascii.unhexlify(blockraw)

            block = Helper.AsSerializableWithType(hex, 'neo.Core.Block.Block')

            trimmed = block.Trim()

            trimmed_unhex = binascii.unhexlify(trimmed)

            blockfrom_trimmed = Block.FromTrimmedData(trimmed_unhex)

            self.assertEqual(blockfrom_trimmed.Version, block.Version)
            self.assertEqual(blockfrom_trimmed.Index, block.Index)
            self.assertEqual(blockfrom_trimmed.PrevHash, block.PrevHash)
            self.assertEqual(blockfrom_trimmed.MerkleRoot, block.MerkleRoot)
            self.assertEqual(blockfrom_trimmed.Timestamp, block.Timestamp)
            self.assertEqual(blockfrom_trimmed.Index, block.Index)
            self.assertEqual(blockfrom_trimmed.ConsensusData,
                             block.ConsensusData)
            self.assertEqual(blockfrom_trimmed.NextConsensus,
                             block.NextConsensus)
            self.assertEqual(len(block.Transactions),
                             len(blockfrom_trimmed.Transactions))
Пример #2
0
 def GetBlockByHash(self, hash):
     try:
         out = bytearray(self._db.get(DBPrefix.DATA_Block + hash))
         out = out[8:]
         outhex = binascii.unhexlify(out)
         return Block.FromTrimmedData(outhex)
     except Exception as e:
         logger.info("Could not get block %s " % e)
     return None