mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-07 06:36:38 +00:00

* Integrate zenroom acceptance test * fixed zenroom reference * added additional dependences to the docker fils so that zenroom can be executed. added zenroom from git repo, because pypi servs an older buggy version * using the custom planetmintdriver branch to avoid pypi zendesk downloads * Added zenroom test * Added zenroom test Signed-off-by: Sangat Das <sangatdas5@gmail.com> * Change reference to planetmint-driver to planetmint-driver-python Signed-off-by: Sangat Das <sangatdas5@gmail.com> * Basic structuring * Added new classes in transactions/common * Added Create and Transfer as separate transactions * Resolved errors related to transactions.common * Fixing imports * Resolved issues of election transaction * Resolve flake8 issues Signed-off-by: Sangat Das <sangatdas5@gmail.com> * Resolve remaining flake8 issues Signed-off-by: Sangat Das <sangatdas5@gmail.com> * Resolve remaining flake8 issues Signed-off-by: Sangat Das <sangatdas5@gmail.com> Co-authored-by: Jürgen Eckel <juergen@riddleandcode.com> Co-authored-by: ArpitShukla007 <arpitnshukla@gmail.com>
94 lines
2.5 KiB
Python
94 lines
2.5 KiB
Python
# Copyright © 2020 Interplanetary Database Association e.V.,
|
|
# Planetmint and IPDB software contributors.
|
|
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
|
# Code is Apache-2.0 and docs are CC-BY-4.0
|
|
|
|
import pytest
|
|
from copy import deepcopy
|
|
|
|
from planetmint.models import Transaction
|
|
from planetmint.transactions.common.crypto import generate_key_pair
|
|
from planetmint.transactions.common.memoize import to_dict, from_dict
|
|
|
|
|
|
pytestmark = pytest.mark.bdb
|
|
|
|
|
|
def test_memoize_to_dict(b):
|
|
alice = generate_key_pair()
|
|
asset = {
|
|
'data': {'id': 'test_id'},
|
|
}
|
|
|
|
assert to_dict.cache_info().hits == 0
|
|
assert to_dict.cache_info().misses == 0
|
|
|
|
tx = Transaction.create([alice.public_key],
|
|
[([alice.public_key], 1)],
|
|
asset=asset,)\
|
|
.sign([alice.private_key])
|
|
|
|
tx.to_dict()
|
|
|
|
assert to_dict.cache_info().hits == 0
|
|
assert to_dict.cache_info().misses == 1
|
|
|
|
tx.to_dict()
|
|
tx.to_dict()
|
|
|
|
assert to_dict.cache_info().hits == 2
|
|
assert to_dict.cache_info().misses == 1
|
|
|
|
|
|
def test_memoize_from_dict(b):
|
|
alice = generate_key_pair()
|
|
asset = {
|
|
'data': {'id': 'test_id'},
|
|
}
|
|
|
|
assert from_dict.cache_info().hits == 0
|
|
assert from_dict.cache_info().misses == 0
|
|
|
|
tx = Transaction.create([alice.public_key],
|
|
[([alice.public_key], 1)],
|
|
asset=asset,)\
|
|
.sign([alice.private_key])
|
|
tx_dict = deepcopy(tx.to_dict())
|
|
|
|
Transaction.from_dict(tx_dict)
|
|
|
|
assert from_dict.cache_info().hits == 0
|
|
assert from_dict.cache_info().misses == 1
|
|
|
|
Transaction.from_dict(tx_dict)
|
|
Transaction.from_dict(tx_dict)
|
|
|
|
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
|