Lorenz Herzberger e401995637
updated asset migration (#276)
* started replacing asset with assets

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* switched asset_id for asset_ids

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* __init__ transfer now uses multiple assets

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* added VS Code debugging section to tests/README.md

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed typo

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* minor changes to get_transaction

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* Added ignore for .vscode

* convert cursor to list

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed get_assets

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* Resolved the error of validation for assets

* added additional check to get_transaction

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* adjusted backend queries for multiple assets

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* adjusted common tests for multiple assets

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed db test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed election test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed almost all tendermint tests

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some command test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed validation test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* added comment to get_transaction_filtered

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some core test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* Updated the unspent output function of Transaction according to new assets model

* fixed txlist tests

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* added comments to backend get_asset function, removed duplicate

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed further test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some more tests

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* added TODOs and changed test_client for aiohttp_client

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* Solved assert comparision issue and handled key error with fallback.

* Converted asset to assets in websocket

* Resolved store transaction tests

* added check to fix vote test cases, requires future change

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed test case

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed test case, added TODO on transaction.py for COMPOSE DECOMPOSE

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed last test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* added planetmint-driver branch reference to dockerfiles for testing

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* Updated asset to assets on the acceptance/integration test suite

* changed get transaction list api point to use comma separated txids

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed acceptance test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* change cryptoconditions to asset-migration branch

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* adjusted doc strings

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed integration tests, removed unused code and adjusted some docstrings

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* adjusted some test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed some more test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed tendermint test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed web test cases

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* bumped up planetmint-transactions version number

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* resolved linting issues

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* fixed abci test

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

* updated changelog and version umber

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>

Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
Co-authored-by: ArpitShukla007 <arpitnshukla@gmail.com>
2022-10-28 11:45:27 +02:00

116 lines
4.9 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
# # Basic Acceptance Test
# Here we check that the primitives of the system behave as expected.
# As you will see, this script tests basic stuff like:
#
# - create a transaction
# - check if the transaction is stored
# - check for the outputs of a given public key
# - transfer the transaction to another key
#
# We run a series of checks for each steps, that is retrieving the transaction from
# the remote system, and also checking the `outputs` of a given public key.
# ## Imports
# We need some utils from the `os` package, we will interact with
# env variables.
import os
# For this test case we import and use the Python Driver.
from planetmint_driver import Planetmint
from planetmint_driver.crypto import generate_keypair
from ipld import multihash, marshal
def test_basic():
# ## Set up a connection to Planetmint
# To use BighainDB we need a connection. Here we create one. By default we
# connect to localhost, but you can override this value using the env variable
# called `PLANETMINT_ENDPOINT`, a valid value must include the schema:
# `https://example.com:9984`
bdb = Planetmint(os.environ.get("PLANETMINT_ENDPOINT"))
# ## Create keypairs
# This test requires the interaction between two actors with their own keypair.
# The two keypairs will be called—drum roll—Alice and Bob.
alice, bob = generate_keypair(), generate_keypair()
# ## Alice registers her bike in Planetmint
# Alice has a nice bike, and here she creates the "digital twin"
# of her bike.
bike = [{"data": multihash(marshal({"bicycle": {"serial_number": 420420}}))}]
# She prepares a `CREATE` transaction...
prepared_creation_tx = bdb.transactions.prepare(operation="CREATE", signers=alice.public_key, assets=bike)
# ... and she fulfills it with her private key.
fulfilled_creation_tx = bdb.transactions.fulfill(prepared_creation_tx, private_keys=alice.private_key)
# We will use the `id` of this transaction several time, so we store it in
# a variable with a short and easy name
bike_id = fulfilled_creation_tx["id"]
# Now she is ready to send it to the Planetmint Network.
sent_transfer_tx = bdb.transactions.send_commit(fulfilled_creation_tx)
# And just to be 100% sure, she also checks if she can retrieve
# it from the Planetmint node.
assert bdb.transactions.retrieve(bike_id), "Cannot find transaction {}".format(bike_id)
# Alice is now the proud owner of one unspent asset.
assert len(bdb.outputs.get(alice.public_key, spent=False)) == 1
assert bdb.outputs.get(alice.public_key)[0]["transaction_id"] == bike_id
# ## Alice transfers her bike to Bob
# After registering her bike, Alice is ready to transfer it to Bob.
# She needs to create a new `TRANSFER` transaction.
# A `TRANSFER` transaction contains a pointer to the original asset. The original asset
# is identified by the `id` of the `CREATE` transaction that defined it.
transfer_assets = [{"id": bike_id}]
# Alice wants to spend the one and only output available, the one with index `0`.
output_index = 0
output = fulfilled_creation_tx["outputs"][output_index]
# Here, she defines the `input` of the `TRANSFER` transaction. The `input` contains
# several keys:
#
# - `fulfillment`, taken from the previous `CREATE` transaction.
# - `fulfills`, that specifies which condition she is fulfilling.
# - `owners_before`.
transfer_input = {
"fulfillment": output["condition"]["details"],
"fulfills": {"output_index": output_index, "transaction_id": fulfilled_creation_tx["id"]},
"owners_before": output["public_keys"],
}
# Now that all the elements are set, she creates the actual transaction...
prepared_transfer_tx = bdb.transactions.prepare(
operation="TRANSFER", assets=transfer_assets, inputs=transfer_input, recipients=bob.public_key
)
# ... and signs it with her private key.
fulfilled_transfer_tx = bdb.transactions.fulfill(prepared_transfer_tx, private_keys=alice.private_key)
# She finally sends the transaction to a Planetmint node.
sent_transfer_tx = bdb.transactions.send_commit(fulfilled_transfer_tx)
# And just to be 100% sure, she also checks if she can retrieve
# it from the Planetmint node.
assert bdb.transactions.retrieve(fulfilled_transfer_tx["id"]) == sent_transfer_tx
# Now Alice has zero unspent transactions.
assert len(bdb.outputs.get(alice.public_key, spent=False)) == 0
# While Bob has one.
assert len(bdb.outputs.get(bob.public_key, spent=False)) == 1
# Bob double checks what he got was the actual bike.
bob_tx_id = bdb.outputs.get(bob.public_key, spent=False)[0]["transaction_id"]
assert bdb.transactions.retrieve(bob_tx_id) == sent_transfer_tx