mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Problem: No test for '_input_valid' memoization
Solution: Add necessary test
This commit is contained in:
parent
0b9e4836c7
commit
7fa4e17f2c
@ -30,12 +30,6 @@ class ValidatorElection(Transaction):
|
||||
CREATE = VALIDATOR_ELECTION
|
||||
ALLOWED_OPERATIONS = (VALIDATOR_ELECTION,)
|
||||
|
||||
# def __init__(self, operation, asset, inputs, outputs,
|
||||
# metadata=None, version=None, hash_id=None, tx_):
|
||||
# # operation `CREATE` is being passed as argument as `VALIDATOR_ELECTION` is an extension
|
||||
# # of `CREATE` and any validation on `CREATE` in the parent class should apply to it
|
||||
# super().__init__(operation, asset, inputs, outputs, metadata, version, hash_id)
|
||||
|
||||
@classmethod
|
||||
def get_validators(cls, bigchain, height=None):
|
||||
"""Return a dictionary of validators with key as `public_key` and
|
||||
|
||||
@ -65,3 +65,29 @@ def test_memoize_from_dict(b):
|
||||
|
||||
assert from_dict.cache_info().hits == 2
|
||||
assert from_dict.cache_info().misses == 1
|
||||
|
||||
|
||||
def test_memoize_input_valid(b):
|
||||
alice = generate_key_pair()
|
||||
asset = {
|
||||
'data': {'id': 'test_id'},
|
||||
}
|
||||
|
||||
assert Transaction._input_valid.cache_info().hits == 0
|
||||
assert Transaction._input_valid.cache_info().misses == 0
|
||||
|
||||
tx = Transaction.create([alice.public_key],
|
||||
[([alice.public_key], 1)],
|
||||
asset=asset,)\
|
||||
.sign([alice.private_key])
|
||||
|
||||
tx.inputs_valid()
|
||||
|
||||
assert Transaction._input_valid.cache_info().hits == 0
|
||||
assert Transaction._input_valid.cache_info().misses == 1
|
||||
|
||||
tx.inputs_valid()
|
||||
tx.inputs_valid()
|
||||
|
||||
assert Transaction._input_valid.cache_info().hits == 2
|
||||
assert Transaction._input_valid.cache_info().misses == 1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user