Esempio n. 1
0
    def test_get_latest_block_hash(self):
        reset_db()

        first_hash = BlockStorageDriver.get_latest_block_hash()

        # We reset the DB, so the latest hash we pull should be the genesis hash
        self.assertEqual(first_hash, GENESIS_HASH)
Esempio n. 2
0
    def test_validate_blockchain_invalid(self):
        reset_db()

        # Stuff a bunch of valid blocks in
        for _ in range(4):
            mn_sk = masternodes[0]['sk']
            timestamp = random.randint(0, pow(2, 32))
            raw_transactions = [
                build_test_transaction().serialize() for _ in range(19)
            ]

            tree = MerkleTree(raw_transactions)
            bc = build_test_contender(tree=tree)

            BlockStorageDriver.store_block(block_contender=bc,
                                           raw_transactions=raw_transactions,
                                           publisher_sk=mn_sk,
                                           timestamp=timestamp)

        # Stuff a sketch block in that doesn't link to the last
        sketch_block = self._build_block_data(
        )  # by default this has prev_block_hash = 'AAAAA...'
        sketch_block['hash'] = BlockStorageDriver.compute_block_hash(
            sketch_block)
        with DB() as db:
            db.tables.blocks.insert(
                [BlockStorageDriver._encode_block(sketch_block)]).run(db.ex)

        self.assertRaises(InvalidBlockLinkException,
                          BlockStorageDriver.validate_blockchain)
Esempio n. 3
0
    def test_validate_blockchain(self):
        reset_db()

        # Stuff a bunch of blocks in
        for _ in range(4):
            mn_sk = TESTNET_MASTERNODES[0]['sk']
            timestamp = random.randint(0, pow(2, 32))
            raw_transactions = [build_test_transaction().serialize() for _ in range(19)]

            tree = MerkleTree(raw_transactions)
            bc = build_test_contender(tree=tree)

            BlockStorageDriver.store_block(block_contender=bc, raw_transactions=raw_transactions, publisher_sk=mn_sk,
                                           timestamp=timestamp)

        # This should not blow up
        BlockStorageDriver.validate_blockchain()
Esempio n. 4
0
 def setUp(self):
     reset_db()