bigchaindb/tests/common/conftest.py
libscott 8343bab89f Schema definition (#798)
Commit messages for posterity:

* wip transaction schema definition
* test for SchemaObject
* test SchemaObject definions meta property
* schema documentation updates
* test for basic validation
* commit before change to .json file definiton + rst generation
* move to straight .json schema, test for additionalProperties on each object
* add asset to transaction definiton
* remove outdated tx validation
* make all tests pass
* create own exception for validation error and start validating transactions
* more tx validation fixes
* move to yaml file for schema
* automatic schema documentation generator
* remove redundant section
* use YAML safe loading
* change current_owners to owners_before in tx schema
* re-run tests and make correct yaml schema
* fix some broken tests
* update Release_Process.md
* move tx validation into it's own method
* add jsonschema dependency
* perform schema validation after ID validation on Transaction
* Release_Process.md, markdown auto numbering
* remove old transaction.json
* resolve remaining TODOs in schema docuementation
* add `id` and `$schema` to transaction.yaml
* add transaction.yaml to setup.py so it gets copied
* address some concernes in PR for transaction.yaml
* address more PR concerns in transaction.yaml
* refactor validtion exceptions and move transaction schema validation into it's own function in bigchaindb.common.schema.__init__
* add note to generated schema.rst indicating when and how it's generated
* move tx schema validation back above ID validation in Transaction.validate_structure, test that structurally invalid transaction gets caught and 400 returned in TX POST handler
* remove timestamp from transaction schema index
* Add README.md to bigchaindb.common.schema for introduction to JSON Schema and reasons for YAML
* Use constant for schema definitions' base prefix
* Move import of ValidationError exception into only the tests that require it
* Move validate transaction test helper to tests/common/util.py
* move ordered transaction schema load to generate_schema_documentation.py where it's needed
* use double backticks to render terms in schema docs
* change more backticks and change transaction version description in transaction schema
* make details a mandatory property of condition
* Many more documentation fixes
* rename schema.rst to schema/transaction.rst
* Fix documentation for Metadata
* Add more links to documentation
* Various other documentation fixes
* Rename section titles in rendered documentation
* use  to manage file handle
* fix extrenuous comma in test_tx_serialization_with_incorrect_hash args
* 'a' * 64
* remove schema validation until we can analyze properly impact on downstream consumers
* fix flake8 error
* use `with` always
2016-11-22 11:17:06 +01:00

170 lines
4.0 KiB
Python

import pytest
USER_PRIVATE_KEY = '8eJ8q9ZQpReWyQT5aFCiwtZ5wDZC4eDnCen88p3tQ6ie'
USER_PUBLIC_KEY = 'JEAkEJqLbbgDRAtMm8YAjGp759Aq2qTn9eaEHUj2XePE'
USER2_PRIVATE_KEY = 'F86PQPiqMTwM2Qi2Sda3U4Vdh3AgadMdX3KNVsu5wNJr'
USER2_PUBLIC_KEY = 'GDxwMFbwdATkQELZbMfW8bd9hbNYMZLyVXA3nur2aNbE'
USER3_PRIVATE_KEY = '4rNQFzWQbVwuTiDVxwuFMvLG5zd8AhrQKCtVovBvcYsB'
USER3_PUBLIC_KEY = 'Gbrg7JtxdjedQRmr81ZZbh1BozS7fBW88ZyxNDy7WLNC'
CC_FULFILLMENT_URI = 'cf:0:'
CC_CONDITION_URI = 'cc:0:3:47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU:0'
DATA = {
'msg': 'Hello BigchainDB!'
}
DATA_ID = '872fa6e6f46246cd44afdb2ee9cfae0e72885fb0910e2bcf9a5a2a4eadb417b8'
UUID4 = 'dc568f27-a113-46b4-9bd4-43015859e3e3'
@pytest.fixture
def user_priv():
return USER_PRIVATE_KEY
@pytest.fixture
def user_pub():
return USER_PUBLIC_KEY
@pytest.fixture
def user2_priv():
return USER2_PRIVATE_KEY
@pytest.fixture
def user2_pub():
return USER2_PUBLIC_KEY
@pytest.fixture
def user3_priv():
return USER3_PRIVATE_KEY
@pytest.fixture
def user3_pub():
return USER3_PUBLIC_KEY
@pytest.fixture
def ffill_uri():
return CC_FULFILLMENT_URI
@pytest.fixture
def cond_uri():
return CC_CONDITION_URI
@pytest.fixture
def user_Ed25519(user_pub):
from cryptoconditions import Ed25519Fulfillment
return Ed25519Fulfillment(public_key=user_pub)
@pytest.fixture
def user_user2_threshold(user_pub, user2_pub):
from cryptoconditions import (ThresholdSha256Fulfillment,
Ed25519Fulfillment)
user_pub_keys = [user_pub, user2_pub]
threshold = ThresholdSha256Fulfillment(threshold=len(user_pub_keys))
for user_pub in user_pub_keys:
threshold.add_subfulfillment(Ed25519Fulfillment(public_key=user_pub))
return threshold
@pytest.fixture
def user2_Ed25519(user2_pub):
from cryptoconditions import Ed25519Fulfillment
return Ed25519Fulfillment(public_key=user2_pub)
@pytest.fixture
def user_ffill(user_Ed25519, user_pub):
from bigchaindb.common.transaction import Fulfillment
return Fulfillment(user_Ed25519, [user_pub])
@pytest.fixture
def user2_ffill(user2_Ed25519, user2_pub):
from bigchaindb.common.transaction import Fulfillment
return Fulfillment(user2_Ed25519, [user2_pub])
@pytest.fixture
def user_user2_threshold_cond(user_user2_threshold, user_pub, user2_pub):
from bigchaindb.common.transaction import Condition
return Condition(user_user2_threshold, [user_pub, user2_pub])
@pytest.fixture
def user_user2_threshold_ffill(user_user2_threshold, user_pub, user2_pub):
from bigchaindb.common.transaction import Fulfillment
return Fulfillment(user_user2_threshold, [user_pub, user2_pub])
@pytest.fixture
def user_cond(user_Ed25519, user_pub):
from bigchaindb.common.transaction import Condition
return Condition(user_Ed25519, [user_pub])
@pytest.fixture
def user2_cond(user2_Ed25519, user2_pub):
from bigchaindb.common.transaction import Condition
return Condition(user2_Ed25519, [user2_pub])
@pytest.fixture
def data():
return DATA
@pytest.fixture
def data_id():
return DATA_ID
@pytest.fixture
def uuid4():
return UUID4
@pytest.fixture
def metadata(data, data_id):
from bigchaindb.common.transaction import Metadata
return Metadata(data, data_id)
@pytest.fixture
def utx(user_ffill, user_cond):
from bigchaindb.common.transaction import Transaction, Asset
return Transaction(Transaction.CREATE, Asset(), [user_ffill], [user_cond])
@pytest.fixture
def tx(utx, user_priv):
return utx.sign([user_priv])
@pytest.fixture
def transfer_utx(user_cond, user2_cond, utx):
from bigchaindb.common.transaction import (Fulfillment, TransactionLink,
Transaction, Asset)
user_cond = user_cond.to_dict()
ffill = Fulfillment(utx.conditions[0].fulfillment,
user_cond['owners_after'],
TransactionLink(utx.id, 0))
return Transaction('TRANSFER', Asset(), [ffill], [user2_cond])
@pytest.fixture
def transfer_tx(transfer_utx, user_priv):
return transfer_utx.sign([user_priv])