def test_count_backlog(signed_create_tx, signed_transfer_tx): from bigchaindb.backend import connect, query conn = connect() # create and insert some transations conn.db.backlog.insert_one(signed_create_tx.to_dict()) conn.db.backlog.insert_one(signed_transfer_tx.to_dict()) assert query.count_backlog(conn) == 2
def test_count_backlog(self, b, user_pk, alice): from bigchaindb.backend import query from bigchaindb.models import Transaction for i in range(4): tx = Transaction.create([alice.public_key], [([user_pk], 1)], metadata={'msg': i}) \ .sign([alice.private_key]) b.write_transaction(tx) assert query.count_backlog(b.connection) == 4
def test_full_pipeline(b, user_pk): import random from bigchaindb.backend import query from bigchaindb.models import Transaction outpipe = Pipe() # write two blocks txs = [] for i in range(100): tx = Transaction.create([b.me], [([user_pk], 1)], {'msg': random.random()}) tx = tx.sign([b.me_private]) txs.append(tx) valid_block = b.create_block(txs) b.write_block(valid_block) txs = [] for i in range(100): tx = Transaction.create([b.me], [([user_pk], 1)], {'msg': random.random()}) tx = tx.sign([b.me_private]) txs.append(tx) invalid_block = b.create_block(txs) b.write_block(invalid_block) pipeline = election.create_pipeline() pipeline.setup(indata=election.get_changefeed(), outdata=outpipe) pipeline.start() time.sleep(1) # vote one block valid, one invalid vote_valid = b.vote(valid_block.id, 'b' * 64, True) vote_invalid = b.vote(invalid_block.id, 'c' * 64, False) b.write_vote(vote_valid) b.write_vote(vote_invalid) outpipe.get() pipeline.terminate() # only transactions from the invalid block should be returned to # the backlog assert query.count_backlog(b.connection) == 100 # NOTE: I'm still, I'm still tx from the block. tx_from_block = set([tx.id for tx in invalid_block.transactions]) tx_from_backlog = set([ tx['id'] for tx in list(query.get_stale_transactions(b.connection, 0)) ]) assert tx_from_block == tx_from_backlog