mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
rewrited get_validator_set
This commit is contained in:
parent
6cc8a6cbb4
commit
e500cd8492
@ -349,6 +349,7 @@ def delete_transactions(connection, txn_ids: list):
|
||||
for _outpID in _outputs:
|
||||
outputs_space.delete(_outpID[5], index="unique_search")
|
||||
|
||||
|
||||
# # @register_query(LocalMongoDBConnection)
|
||||
# def store_unspent_outputs(conn, *unspent_outputs: list):
|
||||
# if unspent_outputs:
|
||||
@ -463,9 +464,11 @@ def get_validator_set(connection, height: int = None):
|
||||
_validators = space.select()
|
||||
_validators = _validators.data
|
||||
if height is not None:
|
||||
_validators = [validator for validator in _validators if validator[1] <= height]
|
||||
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators if
|
||||
validator[1] <= height]
|
||||
return next(iter(sorted(_validators, key=itemgetter(1))), None)
|
||||
|
||||
else:
|
||||
_validators = [{"height": validator[1], "validators": validator[2]} for validator in _validators]
|
||||
return next(iter(sorted(_validators, key=itemgetter(1))), None)
|
||||
|
||||
|
||||
|
||||
@ -451,31 +451,33 @@ def test_get_pre_commit_state(db_context):
|
||||
space.delete(pre[0])
|
||||
# TODO First IN, First OUT
|
||||
state = dict(height=3, transactions=[])
|
||||
# db_context.conn.db.pre_commit.insert_one(state)
|
||||
# db_context.conn.db.pre_commit.insert_one
|
||||
query.store_pre_commit_state(state=state, connection=conn)
|
||||
resp = query.get_pre_commit_state(connection=conn)
|
||||
assert resp == state
|
||||
|
||||
|
||||
def test_validator_update():
|
||||
from planetmint.backend import connect, query
|
||||
from planetmint.backend import connect
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
conn = connect()
|
||||
conn = connect().get_connection()
|
||||
|
||||
def gen_validator_update(height):
|
||||
return {'data': 'somedata', 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
||||
return {'validators': [], 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
||||
# return {'data': 'somedata', 'height': height, 'election_id': f'election_id_at_height_{height}'}
|
||||
|
||||
for i in range(1, 100, 10):
|
||||
value = gen_validator_update(i)
|
||||
query.store_validator_set(conn, value)
|
||||
query.store_validator_set(connection=conn, validators_update=value)
|
||||
|
||||
v1 = query.get_validator_set(conn, 8)
|
||||
v1 = query.get_validator_set(connection=conn, height=8)
|
||||
assert v1['height'] == 1
|
||||
|
||||
v41 = query.get_validator_set(conn, 50)
|
||||
v41 = query.get_validator_set(connection=conn, height=50)
|
||||
assert v41['height'] == 41
|
||||
|
||||
v91 = query.get_validator_set(conn)
|
||||
v91 = query.get_validator_set(connection=conn)
|
||||
assert v91['height'] == 91
|
||||
|
||||
|
||||
@ -518,7 +520,10 @@ def test_validator_update():
|
||||
),
|
||||
])
|
||||
def test_store_abci_chain(description, stores, expected):
|
||||
conn = connect()
|
||||
from planetmint.backend import connect
|
||||
from planetmint.backend.tarantool import query
|
||||
|
||||
conn = connect().get_connection()
|
||||
|
||||
for store in stores:
|
||||
query.store_abci_chain(conn, **store)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user