bigchaindb/tests/assets/test_digital_assets.py
Muawia Khan 2b39566a4b Problem: Some configurations are defunct (#2338)
* Problem: BigchainDB config has stale/deprecated parameters

- Remove `keyring` and `keypair` from config
- Update tests
- Add `tendermint` config

* Fix flake8

* Update some naming conventions and redundant changes

* Remove redundant routine `fast_query`

* Remove deprecated parameters and descriptions

* remove some more unwanted code

* Problem: Two flake8 errors made Travis fail

Solution: Fix the two flake8 errors

* Address comments

- Remove reference of nodes_except_me and me_private and me
  as attributes of BigchainDB instances
- Update and re-add test(s)
- Do not introduce `tendermint` in configuration instead handle that
  in a separate PR along with docs

* Address comments

- Remove tests that are already covered with 2.0
- Remove tests that are no longer relevant
- Add TODO for more cleanup

* Remove tendermint config from configure command
2018-06-08 15:50:50 +02:00

72 lines
2.5 KiB
Python

import pytest
import random
pytestmark = pytest.mark.tendermint
def test_asset_transfer(b, signed_create_tx, user_pk, user_sk):
from bigchaindb.models import Transaction
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([signed_create_tx, tx_transfer])
assert tx_transfer_signed.validate(b) == tx_transfer_signed
assert tx_transfer_signed.asset['id'] == signed_create_tx.id
def test_validate_transfer_asset_id_mismatch(b, signed_create_tx, user_pk, user_sk):
from bigchaindb.common.exceptions import AssetIdMismatch
from bigchaindb.models import Transaction
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
tx_transfer.asset['id'] = 'a' * 64
tx_transfer_signed = tx_transfer.sign([user_sk])
b.store_bulk_transactions([signed_create_tx, tx_transfer_signed])
with pytest.raises(AssetIdMismatch):
tx_transfer_signed.validate(b)
def test_get_asset_id_create_transaction(alice, user_pk):
from bigchaindb.models import Transaction
tx_create = Transaction.create([alice.public_key], [([user_pk], 1)])
assert Transaction.get_asset_id(tx_create) == tx_create.id
def test_get_asset_id_transfer_transaction(b, signed_create_tx, user_pk):
from bigchaindb.models import Transaction
tx_transfer = Transaction.transfer(signed_create_tx.to_inputs(), [([user_pk], 1)],
signed_create_tx.id)
asset_id = Transaction.get_asset_id(tx_transfer)
assert asset_id == tx_transfer.asset['id']
def test_asset_id_mismatch(alice, user_pk):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import AssetIdMismatch
tx1 = Transaction.create([alice.public_key], [([user_pk], 1)],
metadata={'msg': random.random()})
tx1.sign([alice.private_key])
tx2 = Transaction.create([alice.public_key], [([user_pk], 1)],
metadata={'msg': random.random()})
tx2.sign([alice.private_key])
with pytest.raises(AssetIdMismatch):
Transaction.get_asset_id([tx1, tx2])
def test_create_valid_divisible_asset(b, user_pk, user_sk):
from bigchaindb.models import Transaction
tx = Transaction.create([user_pk], [([user_pk], 2)])
tx_signed = tx.sign([user_sk])
assert tx_signed.validate(b) == tx_signed