Example #1
0
    def test_write_block(self, b, user_public_key):
        # create transactions
        transactions = []
        blocks = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            transactions.append(tx)

        # create block
        block = b.create_block(transactions)
        blocks.put(block)
        blocks.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_block = blocks

        # make sure that we only have the genesis block in bigchain
        r.table('bigchain').delete().run(b.conn)
        b.create_genesis_block()

        # write blocks
        block.write_blocks()
        # lets give it some time for the block to be written
        time.sleep(1)

        # check if the number of blocks in bigchain increased
        assert r.table('bigchain').count() == 2
    def test_start(self, b):
        # start with 100 transactions in the backlog and 100 in the changefeed

        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)

        # create 100 more transactions to emulate the changefeed
        new_transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)
            new_transactions.put(tx)
        new_transactions.put('stop')

        # create a block instance
        block = Block(new_transactions)

        # start the block processes
        block.start()

        assert new_transactions.qsize() == 0
        assert r.table('backlog').count() == 0
        assert r.table('bigchain').count() == 2
    def test_delete_transactions(self, b):
        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)
            transactions.put(tx['id'])
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_delete = transactions

        # make sure that there are transactions on the backlog
        r.table('backlog').count().run(b.conn) == 100

        # run the delete process
        block.delete_transactions()
        # give the db time
        time.sleep(1)

        # check if all transactions were deleted from the backlog
        assert r.table('backlog').count() == 0
    def test_write_block(self, b):
        # create transactions
        transactions = []
        blocks = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            transactions.append(tx)

        # create block
        block = b.create_block(transactions)
        blocks.put(block)
        blocks.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_block = blocks

        # make sure that we only have the genesis block in bigchain
        r.table('bigchain').delete().run(b.conn)
        b.create_genesis_block()

        # write blocks
        block.write_blocks()
        # lets give it some time for the block to be written
        time.sleep(1)

        # check if the number of blocks in bigchain increased
        assert r.table('bigchain').count() == 2
Example #5
0
    def test_start(self, b, user_public_key):
        # start with 100 transactions in the backlog and 100 in the changefeed

        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)

        # create 100 more transactions to emulate the changefeed
        new_transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)
            new_transactions.put(tx)
        new_transactions.put('stop')

        # create a block instance
        block = Block(new_transactions)

        # start the block processes
        block.start()

        assert new_transactions.qsize() == 0
        assert r.table('backlog').count() == 0
        assert r.table('bigchain').count() == 2
Example #6
0
    def test_delete_transactions(self, b, user_public_key):
        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)
            transactions.put(tx['id'])
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_delete = transactions

        # make sure that there are transactions on the backlog
        r.table('backlog').count().run(b.conn) == 100

        # run the delete process
        block.delete_transactions()
        # give the db time
        time.sleep(1)

        # check if all transactions were deleted from the backlog
        assert r.table('backlog').count() == 0
    def start(self):
        logger.info('Initializing BigchainDB...')

        # instantiate block and voter
        block = Block(self.q_new_transaction)

        # start the web api
        app_server = server.create_server(bigchaindb.config['server'])
        p_webapi = mp.Process(name='webapi', target=app_server.run)
        p_webapi.start()

        # initialize the processes
        p_map_bigchain = mp.Process(name='bigchain_mapper',
                                    target=self.map_bigchain)
        p_map_backlog = mp.Process(name='backlog_mapper',
                                   target=self.map_backlog)
        p_block = mp.Process(name='block', target=block.start)
        p_voter = Voter(self.q_new_block)

        # start the processes
        logger.info('starting bigchain mapper')
        p_map_bigchain.start()
        logger.info('starting backlog mapper')
        p_map_backlog.start()
        logger.info('starting block')
        p_block.start()

        logger.info('starting voter')
        p_voter.start()

        # start message
        block.initialized.wait()
        p_voter.initialized.wait()
        logger.info(BANNER.format(bigchaindb.config['server']['bind']))
Example #8
0
    def test_create_block(self, b, user_public_key):
        # create transactions
        transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_validated = transactions
        # create blocks
        block.create_blocks()

        # check if the number of valid transactions
        assert block.q_block.qsize() - 1 == 1
    def test_create_block(self, b):
        # create transactions
        transactions = mp.Queue()
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_validated = transactions
        # create blocks
        block.create_blocks()

        # check if the number of valid transactions
        assert block.q_block.qsize() - 1 == 1
Example #10
0
    def test_bootstrap(self, b, user_public_key):
        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)

        # create a block instance
        block = Block(None)

        # run bootstrap
        initial_results = block.bootstrap()

        # we should have gotten a queue with 100 results
        assert initial_results.qsize() - 1 == 100
    def test_bootstrap(self, b):
        # make sure that there are no transactions in the backlog
        r.table('backlog').delete().run(b.conn)

        # create and write transactions to the backlog
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            b.write_transaction(tx)

        # create a block instance
        block = Block(None)

        # run bootstrap
        initial_results = block.bootstrap()

        # we should have gotten a queue with 100 results
        assert initial_results.qsize() - 1 == 100
    def test_by_assignee(self, b):
        # create transactions and randomly assigne them
        transactions = mp.Queue()
        count_assigned_to_me = 0
        for i in range(100):
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            assignee = random.choice([b.me, 'aaa', 'bbb', 'ccc'])
            if assignee == b.me:
                count_assigned_to_me += 1

            tx['assignee'] = assignee
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_new_transaction = transactions
        # filter the transactions
        block.filter_by_assignee()

        # check if the number of transactions assigned to the node is the same as the number in
        # the queue minus 'stop'
        assert block.q_tx_to_validate.qsize() - 1 == count_assigned_to_me
Example #13
0
    def test_by_assignee(self, b, user_public_key):
        # create transactions and randomly assigne them
        transactions = mp.Queue()
        count_assigned_to_me = 0
        for i in range(100):
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            assignee = random.choice([b.me, 'aaa', 'bbb', 'ccc'])
            if assignee == b.me:
                count_assigned_to_me += 1

            tx['assignee'] = assignee
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_new_transaction = transactions
        # filter the transactions
        block.filter_by_assignee()

        # check if the number of transactions assigned to the node is the same as the number in
        # the queue minus 'stop'
        assert block.q_tx_to_validate.qsize() - 1 == count_assigned_to_me
    def test_validate_transactions(self, b):
        # create transactions and randomly invalidate some of them by changing the hash
        transactions = mp.Queue()
        count_valid = 0
        for i in range(100):
            valid = random.choice([True, False])
            tx = b.create_transaction(b.me, USER_PUBLIC_KEY, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            if not valid:
                tx['id'] = 'a' * 64
            else:
                count_valid += 1
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_to_validate = transactions
        # validate transactions
        block.validate_transactions()

        # check if the number of valid transactions
        assert block.q_tx_validated.qsize() - 1 == count_valid
        assert block.q_tx_delete.qsize() - 1 == 100
Example #15
0
    def test_validate_transactions(self, b, user_public_key):
        # create transactions and randomly invalidate some of them by changing the hash
        transactions = mp.Queue()
        count_valid = 0
        for i in range(100):
            valid = random.choice([True, False])
            tx = b.create_transaction(b.me, user_public_key, None, 'CREATE')
            tx = b.sign_transaction(tx, b.me_private)
            if not valid:
                tx['id'] = 'a' * 64
            else:
                count_valid += 1
            transactions.put(tx)
        transactions.put('stop')

        # create a block instance
        block = Block(transactions)
        block.q_tx_to_validate = transactions
        # validate transactions
        block.validate_transactions()

        # check if the number of valid transactions
        assert block.q_tx_validated.qsize() - 1 == count_valid
        assert block.q_tx_delete.qsize() - 1 == 100
Example #16
0
    def start(self):
        # instantiate block and voter
        block = Block(self.q_new_transaction)

        # initialize the processes
        p_map_bigchain = mp.Process(name='bigchain_mapper', target=self.map_bigchain)
        p_map_backlog = mp.Process(name='backlog_mapper', target=self.map_backlog)
        p_block = mp.Process(name='block', target=block.start)
        p_voter = Voter(self.q_new_block)

        # start the processes
        logger.info('starting bigchain mapper')
        p_map_bigchain.start()
        logger.info('starting backlog mapper')
        p_map_backlog.start()
        logger.info('starting block')
        p_block.start()

        logger.info('starting voter')
        p_voter.start()
Example #17
0
    def test_empty_queues(self, b):
        # create empty queue
        new_transactions = mp.Queue()

        # create block instance
        block = Block(new_transactions)

        # create block_process
        p_block = mp.Process(target=block.start)

        # start block process
        p_block.start()

        # wait for 6 seconds to give it time for an empty queue exception to occur
        time.sleep(6)

        # send the poison pill
        new_transactions.put('stop')

        # join the process
        p_block.join()