fixed integration tests, removed unused code and adjusted some docstrings

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
Lorenz Herzberger 2022-05-12 15:06:14 +02:00
parent b842ea78c4
commit 678cd6328b
No known key found for this signature in database
GPG Key ID: FA5EE906EB55316A
13 changed files with 40 additions and 63 deletions

View File

@ -76,9 +76,7 @@ condition_script_zencode, zenroom_data, zenroom_house_assets):
try: try:
assert(not zenSha.validate(message=message)) assert(not zenSha.validate(message=message))
except JSONDecodeError: except: # noqa
pass
except ValueError:
pass pass
message = zenSha.sign(message, condition_script_zencode, alice) message = zenSha.sign(message, condition_script_zencode, alice)

View File

@ -13,11 +13,9 @@ RUN mkdir -p /src
RUN pip install --upgrade meson ninja RUN pip install --upgrade meson ninja
RUN pip install --upgrade \ RUN pip install --upgrade \
pytest~=6.2.5 \ pytest~=6.2.5 \
# planetmint-driver~=0.9.0 \ git+https://github.com/planetmint/cryptoconditions.git@asset-migration \
git+https://github.com/planetmint/planetmint-driver-python.git@asset-migration \ git+https://github.com/planetmint/planetmint-driver-python.git@asset-migration \
pycco \ pycco \
websocket-client~=0.47.0 \ websocket-client~=0.47.0 \
#git+https://github.com/planetmint/cryptoconditions.git@gitzenroom \
#git+https://github.com/planetmint/planetmint-driver.git@gitzenroom \
blns blns

View File

@ -36,7 +36,7 @@ FULFILL_SCRIPT = \
When I verify the 'houses' has a signature in 'data.signature' by 'Alice' When I verify the 'houses' has a signature in 'data.signature' by 'Alice'
Then print the string 'ok'""" Then print the string 'ok'"""
HOUSE_ASSETS = { HOUSE_ASSETS = [{
"data": { "data": {
"houses": [ "houses": [
{ {
@ -49,7 +49,7 @@ HOUSE_ASSETS = {
} }
], ],
} }
} }]
ZENROOM_DATA = { ZENROOM_DATA = {
'also': 'more data' 'also': 'more data'

View File

@ -21,12 +21,12 @@ def test_basic():
alice = generate_keypair() alice = generate_keypair()
# create a digital asset for Alice # create a digital asset for Alice
game_boy_token = { game_boy_token = [{
'data': { 'data': {
'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
}, },
} }]
# prepare the transaction with the digital asset and issue 10 tokens to bob # prepare the transaction with the digital asset and issue 10 tokens to bob
prepared_creation_tx = pm_alpha.transactions.prepare( prepared_creation_tx = pm_alpha.transactions.prepare(
@ -36,7 +36,7 @@ def test_basic():
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', }, 'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },
signers=alice.public_key, signers=alice.public_key,
recipients=[([alice.public_key], 10)], recipients=[([alice.public_key], 10)],
asset=game_boy_token) assets=game_boy_token)
# fulfill and send the transaction # fulfill and send the transaction
fulfilled_creation_tx = pm_alpha.transactions.fulfill( fulfilled_creation_tx = pm_alpha.transactions.fulfill(
@ -52,18 +52,18 @@ def test_basic():
# Transfer # Transfer
# create the output and inout for the transaction # create the output and inout for the transaction
transfer_asset = {'id': creation_tx_id} transfer_assets = [{'id': creation_tx_id}]
output_index = 0 output_index = 0
output = fulfilled_creation_tx['outputs'][output_index] output = fulfilled_creation_tx['outputs'][output_index]
transfer_input = {'fulfillment': output['condition']['details'], transfer_input = {'fulfillment': output['condition']['details'],
'fulfills': {'output_index': output_index, 'fulfills': {'output_index': output_index,
'transaction_id': transfer_asset['id']}, 'transaction_id': transfer_assets[0]['id']},
'owners_before': output['public_keys']} 'owners_before': output['public_keys']}
# prepare the transaction and use 3 tokens # prepare the transaction and use 3 tokens
prepared_transfer_tx = pm_alpha.transactions.prepare( prepared_transfer_tx = pm_alpha.transactions.prepare(
operation='TRANSFER', operation='TRANSFER',
asset=transfer_asset, assets=transfer_assets,
inputs=transfer_input, inputs=transfer_input,
metadata={'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', metadata={'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', }, 'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },

View File

@ -50,7 +50,7 @@ def test_divisible_assets():
# the description, Bob and Alice agree that each token can be used to ride # the description, Bob and Alice agree that each token can be used to ride
# the bike for one hour. # the bike for one hour.
bike_token = { bike_token = [{
'data': { 'data': {
'token_for': { 'token_for': {
'bike': { 'bike': {
@ -59,7 +59,7 @@ def test_divisible_assets():
}, },
'description': 'Time share token. Each token equals one hour of riding.', 'description': 'Time share token. Each token equals one hour of riding.',
}, },
} }]
# She prepares a `CREATE` transaction and issues 10 tokens. # She prepares a `CREATE` transaction and issues 10 tokens.
# Here, Alice defines in a tuple that she wants to assign # Here, Alice defines in a tuple that she wants to assign
@ -68,7 +68,7 @@ def test_divisible_assets():
operation='CREATE', operation='CREATE',
signers=alice.public_key, signers=alice.public_key,
recipients=[([bob.public_key], 10)], recipients=[([bob.public_key], 10)],
asset=bike_token) assets=bike_token)
# She fulfills and sends the transaction. # She fulfills and sends the transaction.
fulfilled_token_tx = pm.transactions.fulfill( fulfilled_token_tx = pm.transactions.fulfill(
@ -94,7 +94,7 @@ def test_divisible_assets():
# To use the bike he has to send the tokens back to Alice. # To use the bike he has to send the tokens back to Alice.
# To learn about the details of transferring a transaction check out # To learn about the details of transferring a transaction check out
# [test_basic.py](./test_basic.html) # [test_basic.py](./test_basic.html)
transfer_asset = {'id': bike_token_id} transfer_assets = [{'id': bike_token_id}]
output_index = 0 output_index = 0
output = fulfilled_token_tx['outputs'][output_index] output = fulfilled_token_tx['outputs'][output_index]
@ -108,7 +108,7 @@ def test_divisible_assets():
# amount he wants to use to Alice. # amount he wants to use to Alice.
prepared_transfer_tx = pm.transactions.prepare( prepared_transfer_tx = pm.transactions.prepare(
operation='TRANSFER', operation='TRANSFER',
asset=transfer_asset, assets=transfer_assets,
inputs=transfer_input, inputs=transfer_input,
recipients=[([alice.public_key], 3), ([bob.public_key], 7)]) recipients=[([alice.public_key], 3), ([bob.public_key], 7)])
@ -138,7 +138,7 @@ def test_divisible_assets():
# Now he wants to ride for 8 hours, that's a lot Bob! # Now he wants to ride for 8 hours, that's a lot Bob!
# He prepares the transaction again. # He prepares the transaction again.
transfer_asset = {'id': bike_token_id} transfer_assets = [{'id': bike_token_id}]
# This time we need an `output_index` of 1, since we have two outputs # This time we need an `output_index` of 1, since we have two outputs
# in the `fulfilled_transfer_tx` we created before. The first output with # in the `fulfilled_transfer_tx` we created before. The first output with
# index 0 is for Alice and the second output is for Bob. # index 0 is for Alice and the second output is for Bob.
@ -157,7 +157,7 @@ def test_divisible_assets():
# to spend all his tokens # to spend all his tokens
prepared_transfer_tx = pm.transactions.prepare( prepared_transfer_tx = pm.transactions.prepare(
operation='TRANSFER', operation='TRANSFER',
asset=transfer_asset, assets=transfer_assets,
inputs=transfer_input, inputs=transfer_input,
recipients=[([alice.public_key], 8)]) recipients=[([alice.public_key], 8)])

View File

@ -26,7 +26,7 @@ def test_double_create():
pm.transactions.prepare( pm.transactions.prepare(
operation='CREATE', operation='CREATE',
signers=alice.public_key, signers=alice.public_key,
asset={'data': {'uuid': str(uuid4())}}), assets=[{'data': {'uuid': str(uuid4())}}]),
private_keys=alice.private_key) private_keys=alice.private_key)
def send_and_queue(tx): def send_and_queue(tx):

View File

@ -41,13 +41,13 @@ def test_multiple_owners():
# high rents anymore. Bob suggests to get a dish washer for the # high rents anymore. Bob suggests to get a dish washer for the
# kitchen. Alice agrees and here they go, creating the asset for their # kitchen. Alice agrees and here they go, creating the asset for their
# dish washer. # dish washer.
dw_asset = { dw_asset = [{
'data': { 'data': {
'dish washer': { 'dish washer': {
'serial_number': 1337 'serial_number': 1337
} }
} }
} }]
# They prepare a `CREATE` transaction. To have multiple owners, both # They prepare a `CREATE` transaction. To have multiple owners, both
# Bob and Alice need to be the recipients. # Bob and Alice need to be the recipients.
@ -55,7 +55,7 @@ def test_multiple_owners():
operation='CREATE', operation='CREATE',
signers=alice.public_key, signers=alice.public_key,
recipients=(alice.public_key, bob.public_key), recipients=(alice.public_key, bob.public_key),
asset=dw_asset) assets=dw_asset)
# Now they both sign the transaction by providing their private keys. # Now they both sign the transaction by providing their private keys.
# And send it afterwards. # And send it afterwards.
@ -91,7 +91,7 @@ def test_multiple_owners():
# Alice and Bob prepare the transaction to transfer the dish washer to # Alice and Bob prepare the transaction to transfer the dish washer to
# Carol. # Carol.
transfer_asset = {'id': dw_id} transfer_assets = [{'id': dw_id}]
output_index = 0 output_index = 0
output = fulfilled_dw_tx['outputs'][output_index] output = fulfilled_dw_tx['outputs'][output_index]
@ -104,7 +104,7 @@ def test_multiple_owners():
# Now they create the transaction... # Now they create the transaction...
prepared_transfer_tx = pm_alpha.transactions.prepare( prepared_transfer_tx = pm_alpha.transactions.prepare(
operation='TRANSFER', operation='TRANSFER',
asset=transfer_asset, assets=transfer_assets,
inputs=transfer_input, inputs=transfer_input,
recipients=carol.public_key) recipients=carol.public_key)

View File

@ -30,7 +30,7 @@ naughty_strings = blns.all()
# This is our base test case, but we'll reuse it to send naughty strings as both keys and values. # This is our base test case, but we'll reuse it to send naughty strings as both keys and values.
def send_naughty_tx(asset, metadata): def send_naughty_tx(assets, metadata):
# ## Set up a connection to Planetmint # ## Set up a connection to Planetmint
# Check [test_basic.py](./test_basic.html) to get some more details # Check [test_basic.py](./test_basic.html) to get some more details
# about the endpoint. # about the endpoint.
@ -44,7 +44,7 @@ def send_naughty_tx(asset, metadata):
prepared_transaction = pm.transactions.prepare( prepared_transaction = pm.transactions.prepare(
operation='CREATE', operation='CREATE',
signers=alice.public_key, signers=alice.public_key,
asset=asset, assets=assets,
metadata=metadata) metadata=metadata)
# She fulfills the transaction # She fulfills the transaction
@ -85,16 +85,16 @@ def send_naughty_tx(asset, metadata):
@pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings) @pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings)
def test_naughty_keys(naughty_string): def test_naughty_keys(naughty_string):
asset = {'data': {naughty_string: 'nice_value'}} assets = [{'data': {naughty_string: 'nice_value'}}]
metadata = {naughty_string: 'nice_value'} metadata = {naughty_string: 'nice_value'}
send_naughty_tx(asset, metadata) send_naughty_tx(assets, metadata)
@pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings) @pytest.mark.parametrize("naughty_string", naughty_strings, ids=naughty_strings)
def test_naughty_values(naughty_string): def test_naughty_values(naughty_string):
asset = {'data': {'nice_key': naughty_string}} assets = [{'data': {'nice_key': naughty_string}}]
metadata = {'nice_key': naughty_string} metadata = {'nice_key': naughty_string}
send_naughty_tx(asset, metadata) send_naughty_tx(assets, metadata)

View File

@ -92,7 +92,7 @@ def test_stream():
pm.transactions.prepare( pm.transactions.prepare(
operation='CREATE', operation='CREATE',
signers=alice.public_key, signers=alice.public_key,
asset={'data': {'uuid': str(uuid4())}}), assets=[{'data': {'uuid': str(uuid4())}}]),
private_keys=alice.private_key) private_keys=alice.private_key)
# We don't want to wait for each transaction to be in a block. By using # We don't want to wait for each transaction to be in a block. By using
# `async` mode, we make sure that the driver returns as soon as the # `async` mode, we make sure that the driver returns as soon as the

View File

@ -49,13 +49,13 @@ def test_threshold():
# high rents anymore. Bob suggests to get a dish washer for the # high rents anymore. Bob suggests to get a dish washer for the
# kitchen. Alice agrees and here they go, creating the asset for their # kitchen. Alice agrees and here they go, creating the asset for their
# dish washer. # dish washer.
dw_asset = { dw_asset = [{
'data': { 'data': {
'dish washer': { 'dish washer': {
'serial_number': 1337 'serial_number': 1337
} }
} }
} }]
# Create subfulfillments # Create subfulfillments
alice_ed25519 = Ed25519Sha256(public_key=base58.b58decode(alice.public_key)) alice_ed25519 = Ed25519Sha256(public_key=base58.b58decode(alice.public_key))
@ -92,7 +92,7 @@ def test_threshold():
# Assemble the handcrafted transaction # Assemble the handcrafted transaction
handcrafted_dw_tx = { handcrafted_dw_tx = {
'operation': 'CREATE', 'operation': 'CREATE',
'asset': dw_asset, 'assets': dw_asset,
'metadata': None, 'metadata': None,
'outputs': (output,), 'outputs': (output,),
'inputs': (input_,), 'inputs': (input_,),
@ -149,13 +149,13 @@ def test_weighted_threshold():
alice, bob, carol = generate_keypair(), generate_keypair(), generate_keypair() alice, bob, carol = generate_keypair(), generate_keypair(), generate_keypair()
asset = { assets = [{
'data': { 'data': {
'trashcan': { 'trashcan': {
'animals': ['racoon_1', 'racoon_2'] 'animals': ['racoon_1', 'racoon_2']
} }
} }
} }]
alice_ed25519 = Ed25519Sha256(public_key=base58.b58decode(alice.public_key)) alice_ed25519 = Ed25519Sha256(public_key=base58.b58decode(alice.public_key))
bob_ed25519 = Ed25519Sha256(public_key=base58.b58decode(bob.public_key)) bob_ed25519 = Ed25519Sha256(public_key=base58.b58decode(bob.public_key))
@ -193,7 +193,7 @@ def test_weighted_threshold():
# Assemble the handcrafted transaction # Assemble the handcrafted transaction
handcrafted_tx = { handcrafted_tx = {
'operation': 'CREATE', 'operation': 'CREATE',
'asset': asset, 'assets': assets,
'metadata': None, 'metadata': None,
'outputs': (output,), 'outputs': (output,),
'inputs': (input_,), 'inputs': (input_,),
@ -278,7 +278,7 @@ def test_weighted_threshold():
# Assemble the handcrafted transaction # Assemble the handcrafted transaction
handcrafted_transfer_tx = { handcrafted_transfer_tx = {
'operation': 'TRANSFER', 'operation': 'TRANSFER',
'asset': {'id': creation_tx_id}, 'assets': [{'id': creation_tx_id}],
'metadata': None, 'metadata': None,
'outputs': (transfer_output,), 'outputs': (transfer_output,),
'inputs': (transfer_input_,), 'inputs': (transfer_input_,),

View File

@ -57,7 +57,7 @@ def test_zenroom(gen_key_zencode, secret_key_to_private_key_zencode, fulfill_scr
token_creation_tx = { token_creation_tx = {
'operation': 'CREATE', 'operation': 'CREATE',
'asset': zenroom_house_assets, 'assets': zenroom_house_assets,
'metadata': None, 'metadata': None,
'outputs': (output,), 'outputs': (output,),
'inputs': (input_,), 'inputs': (input_,),
@ -75,9 +75,7 @@ def test_zenroom(gen_key_zencode, secret_key_to_private_key_zencode, fulfill_scr
try: try:
assert(not zenSha.validate(message=message)) assert(not zenSha.validate(message=message))
except JSONDecodeError: except: # noqa
pass
except ValueError:
pass pass
message = zenSha.sign(message, condition_script_zencode, alice) message = zenSha.sign(message, condition_script_zencode, alice)

View File

@ -105,23 +105,13 @@ class Transaction(object):
# dicts holding a `data` property. Asset payloads for 'TRANSFER' # dicts holding a `data` property. Asset payloads for 'TRANSFER'
# operations must be dicts holding an `id` property. # operations must be dicts holding an `id` property.
# NOTE: Changes: CREATE needs list of 1 asset that holds data in asset or None
if (operation == self.CREATE and if (operation == self.CREATE and
assets is not None and not (isinstance(assets, list) and 'data' in assets[0])): assets is not None and not (isinstance(assets, list) and 'data' in assets[0])):
raise TypeError(('`asset` must be None or a list of length 1 with a dict holding a `data` ' raise TypeError(('`asset` must be None or a list of length 1 with a dict holding a `data` '
" property instance for '{}' Transactions".format(operation))) " property instance for '{}' Transactions".format(operation)))
# if (operation == self.CREATE and
# asset is not None and not (isinstance(asset, dict) and 'data' in asset)):
# raise TypeError(('`asset` must be None or a dict holding a `data` '
# " property instance for '{}' Transactions".format(operation)))
# NOTE: Changes: TRANSFER needs a list of at least on asset that holds id in each asset
elif (operation == self.TRANSFER and elif (operation == self.TRANSFER and
assets is not None and not (isinstance(assets, list) and all('id' in asset for asset in assets))): assets is not None and not (isinstance(assets, list) and all('id' in asset for asset in assets))):
raise TypeError(('`asset` must be a list containing dicts holding an `id` property')) raise TypeError(('`asset` must be a list containing dicts holding an `id` property'))
# elif (operation == self.TRANSFER and
# not (isinstance(assets, dict) and 'id' in assets)):
# raise TypeError(('`asset` must be a dict holding an `id` property '
# 'for \'TRANSFER\' Transactions'))
if outputs and not isinstance(outputs, list): if outputs and not isinstance(outputs, list):
raise TypeError('`outputs` must be a list instance or None') raise TypeError('`outputs` must be a list instance or None')
@ -756,13 +746,6 @@ class Transaction(object):
if len(links) != len(set(links)): if len(links) != len(set(links)):
raise DoubleSpend('tx "{}" spends inputs twice'.format(self.id)) raise DoubleSpend('tx "{}" spends inputs twice'.format(self.id))
# validate asset id
# asset_id = self.get_asset_id(input_txs)
# if asset_id != self.asset['id']:
# raise AssetIdMismatch(('The asset id of the input does not'
# ' match the asset id of the'
# ' transaction'))
input_amount = sum([input_condition.amount for input_condition in input_conditions]) input_amount = sum([input_condition.amount for input_condition in input_conditions])
output_amount = sum([output_condition.amount for output_condition in self.outputs]) output_amount = sum([output_condition.amount for output_condition in self.outputs])

View File

@ -69,7 +69,7 @@ class Transfer(Transaction):
recipients (:obj:`list` of :obj:`tuple`): A list of recipients (:obj:`list` of :obj:`tuple`): A list of
([keys],amount) that represent the recipients of this ([keys],amount) that represent the recipients of this
Transaction. Transaction.
asset_id (str): The asset ID of the asset to be transferred in asset_ids (:obj:`list` of :obj:`str`): The asset IDs of the assets to be transferred in
this Transaction. this Transaction.
metadata (dict): Python dictionary to be stored along with the metadata (dict): Python dictionary to be stored along with the
Transaction. Transaction.