mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fixed mongodb queries
Fixed some tests
This commit is contained in:
parent
ea4d01dec0
commit
1b3c909d51
@ -40,10 +40,20 @@ def get_stale_transactions(conn, reassign_delay):
|
|||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_transaction_from_block(conn, block_id, tx_id):
|
def get_transaction_from_block(conn, transaction_id, block_id):
|
||||||
# this is definitely wrong, but it's something like this
|
return conn.db['bigchain'].aggregate([
|
||||||
return conn.db['bigchain'].find_one({'id': block_id,
|
{'$match': {'id': block_id}},
|
||||||
'block.transactions.id': tx_id})
|
{'$project': {
|
||||||
|
'block.transactions': {
|
||||||
|
'$filter': {
|
||||||
|
'input': '$block.transactions',
|
||||||
|
'as': 'transaction',
|
||||||
|
'cond': {
|
||||||
|
'$eq': ['$$transaction.id', transaction_id]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}]).next()['block']['transactions'][0]
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
@ -92,14 +102,16 @@ def get_owned_ids(conn, owner):
|
|||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_votes_by_block_id(conn, block_id):
|
def get_votes_by_block_id(conn, block_id):
|
||||||
return conn.db['votes']\
|
return conn.db['votes']\
|
||||||
.find({'vote.voting_for_block': block_id})
|
.find({'vote.voting_for_block': block_id},
|
||||||
|
projection={'_id': False})
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
def get_votes_by_block_id_and_voter(conn, block_id, node_pubkey):
|
||||||
return conn.db['votes']\
|
return conn.db['votes']\
|
||||||
.find({'vote.voting_for_block': block_id,
|
.find({'vote.voting_for_block': block_id,
|
||||||
'node_pubkey': node_pubkey})
|
'node_pubkey': node_pubkey},
|
||||||
|
projection={'_id': False})
|
||||||
|
|
||||||
|
|
||||||
@register_query(MongoDBConnection)
|
@register_query(MongoDBConnection)
|
||||||
|
@ -153,14 +153,14 @@ class TestBigchainApi(object):
|
|||||||
def test_get_transaction_in_invalid_and_valid_block(self, monkeypatch, b):
|
def test_get_transaction_in_invalid_and_valid_block(self, monkeypatch, b):
|
||||||
from bigchaindb.models import Transaction
|
from bigchaindb.models import Transaction
|
||||||
|
|
||||||
monkeypatch.setattr('time.time', lambda: 1)
|
monkeypatch.setattr('time.time', lambda: 1000000000)
|
||||||
tx1 = Transaction.create([b.me], [([b.me], 1)],
|
tx1 = Transaction.create([b.me], [([b.me], 1)],
|
||||||
metadata={'msg': random.random()})
|
metadata={'msg': random.random()})
|
||||||
tx1 = tx1.sign([b.me_private])
|
tx1 = tx1.sign([b.me_private])
|
||||||
block1 = b.create_block([tx1])
|
block1 = b.create_block([tx1])
|
||||||
b.write_block(block1)
|
b.write_block(block1)
|
||||||
|
|
||||||
monkeypatch.setattr('time.time', lambda: 2222222222)
|
monkeypatch.setattr('time.time', lambda: 2000000000)
|
||||||
tx2 = Transaction.create([b.me], [([b.me], 1)],
|
tx2 = Transaction.create([b.me], [([b.me], 1)],
|
||||||
metadata={'msg': random.random()})
|
metadata={'msg': random.random()})
|
||||||
tx2 = tx2.sign([b.me_private])
|
tx2 = tx2.sign([b.me_private])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user