mirror of
https://github.com/planetmint/planetmint.git
synced 2026-02-20 02:23:50 +00:00
Scalable integration test (#57)
* updated Dockerfile-all-in-one Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * adjusted all-in-one.bash and monit conf to work with dockerized setup Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * integration tests pass inconsistently Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added timeout for integration test pass Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * add startup control logic, adjusted tests to wait for transactions Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added pre-config for docker-compose approach, removed remnants of old integration tests Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * reverted changes to pkg, split pre-config, added clean-shared service Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed path in all-in-one.bash Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added ipdb copyright notice Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * chmod planetmint-monit-config Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * removed entrypoint from Dockerfile-all-in-one Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added integration stage to travis matrix Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * removed unused secret Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * changed pre-config and docker-compose.integration.yml to support scaling Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * using env var to control number of nodes Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * make test-integration now scalable Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added make docs-integration, added .gitignore to python integration tests, updated readme and removed clutter Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * fixed linter errors Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * disable planetmint for test purpose Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * test docker-compose down Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * disable every job except integration test Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * need more logs Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * name collision? Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * reverted changes to debug ci Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com> * added TODO for ci optimization Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
committed by
GitHub
parent
89a9caf597
commit
bf5b88fcb2
1
integration/python/.gitignore
vendored
Normal file
1
integration/python/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
docs
|
||||
@@ -3,5 +3,7 @@ FROM python:3.9
|
||||
RUN mkdir -p /src
|
||||
RUN pip install --upgrade \
|
||||
pytest~=6.2.5 \
|
||||
planetmint-driver~=0.9.0
|
||||
planetmint-driver~=0.9.0 \
|
||||
pycco
|
||||
|
||||
RUN apt-get update && apt-get install -y openssh-client openssh-server
|
||||
@@ -7,18 +7,21 @@
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
def test_basic():
|
||||
# Setup up connection to Planetmint integration test nodes
|
||||
pm_itest1_url = os.environ.get('PLANETMINT_ENDPOINT_1')
|
||||
pm_itest2_url = os.environ.get('PLANETMINT_ENDPOINT_1')
|
||||
pm_itest1 = Planetmint(pm_itest1_url)
|
||||
pm_itest2 = Planetmint(pm_itest2_url)
|
||||
hosts = []
|
||||
with open('/shared/hostnames') as f:
|
||||
hosts = f.readlines()
|
||||
|
||||
pm_hosts = list(map(lambda x: Planetmint(x), hosts))
|
||||
|
||||
pm_alpha = pm_hosts[0]
|
||||
pm_betas = pm_hosts[1:]
|
||||
|
||||
# genarate a keypair
|
||||
alice, bob = generate_keypair(), generate_keypair()
|
||||
alice = generate_keypair()
|
||||
|
||||
# create a digital asset for Alice
|
||||
game_boy_token = {
|
||||
@@ -29,30 +32,31 @@ def test_basic():
|
||||
}
|
||||
|
||||
# prepare the transaction with the digital asset and issue 10 tokens to bob
|
||||
prepared_creation_tx = pm_itest1.transactions.prepare(
|
||||
prepared_creation_tx = pm_alpha.transactions.prepare(
|
||||
operation='CREATE',
|
||||
metadata={
|
||||
'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',},
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },
|
||||
signers=alice.public_key,
|
||||
recipients=[([alice.public_key], 10)],
|
||||
asset=game_boy_token)
|
||||
|
||||
# fulfill and send the transaction
|
||||
fulfilled_creation_tx = pm_itest1.transactions.fulfill(
|
||||
fulfilled_creation_tx = pm_alpha.transactions.fulfill(
|
||||
prepared_creation_tx,
|
||||
private_keys=alice.private_key)
|
||||
pm_itest1.transactions.send_commit(fulfilled_creation_tx)
|
||||
time.sleep(4)
|
||||
pm_alpha.transactions.send_commit(fulfilled_creation_tx)
|
||||
time.sleep(1)
|
||||
|
||||
creation_tx_id = fulfilled_creation_tx['id']
|
||||
|
||||
# retrieve transactions from both planetmint nodes
|
||||
creation_tx_itest1 = pm_itest1.transactions.retrieve(creation_tx_id)
|
||||
creation_tx_itest2 = pm_itest2.transactions.retrieve(creation_tx_id)
|
||||
# retrieve transactions from all planetmint nodes
|
||||
creation_tx_alpha = pm_alpha.transactions.retrieve(creation_tx_id)
|
||||
creation_tx_betas = list(map(lambda beta: beta.transactions.retrieve(creation_tx_id), pm_betas))
|
||||
|
||||
# Assert that transaction is stored on both planetmint nodes
|
||||
assert creation_tx_itest1 == creation_tx_itest2
|
||||
# Assert that transaction is stored on all planetmint nodes
|
||||
for tx in creation_tx_betas:
|
||||
assert creation_tx_alpha == tx
|
||||
|
||||
# Transfer
|
||||
# create the output and inout for the transaction
|
||||
@@ -65,35 +69,28 @@ def test_basic():
|
||||
'owners_before': output['public_keys']}
|
||||
|
||||
# prepare the transaction and use 3 tokens
|
||||
prepared_transfer_tx = pm_itest1.transactions.prepare(
|
||||
prepared_transfer_tx = pm_alpha.transactions.prepare(
|
||||
operation='TRANSFER',
|
||||
asset=transfer_asset,
|
||||
inputs=transfer_input,
|
||||
metadata={'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },
|
||||
recipients=[([alice.public_key], 10)])
|
||||
|
||||
# fulfill and send the transaction
|
||||
fulfilled_transfer_tx = pm_itest1.transactions.fulfill(
|
||||
fulfilled_transfer_tx = pm_alpha.transactions.fulfill(
|
||||
prepared_transfer_tx,
|
||||
private_keys=alice.private_key)
|
||||
sent_transfer_tx = pm_itest1.transactions.send_commit(fulfilled_transfer_tx)
|
||||
sent_transfer_tx = pm_alpha.transactions.send_commit(fulfilled_transfer_tx)
|
||||
|
||||
transfer_tx_id = fulfilled_transfer_tx['id']
|
||||
time.sleep(1)
|
||||
|
||||
transfer_tx_id = sent_transfer_tx['id']
|
||||
|
||||
# retrieve transactions from both planetmint nodes
|
||||
transfer_tx_itest1 = pm_itest1.transactions.retrieve(transfer_tx_id)
|
||||
transfer_tx_itest2 = pm_itest2.transactions.retrieve(transfer_tx_id)
|
||||
transfer_tx_alpha = pm_alpha.transactions.retrieve(transfer_tx_id)
|
||||
transfer_tx_betas = list(map(lambda beta: beta.transactions.retrieve(transfer_tx_id), pm_betas))
|
||||
|
||||
# Assert that transaction is stored on both planetmint nodes
|
||||
assert transfer_tx_itest1 == transfer_tx_itest2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
for tx in transfer_tx_betas:
|
||||
assert transfer_tx_alpha == tx
|
||||
|
||||
@@ -18,21 +18,24 @@
|
||||
#
|
||||
# This integration test is a rip-off of our mutliple signature acceptance tests.
|
||||
|
||||
# ## Imports
|
||||
# We need some utils from the `os` package, we will interact with
|
||||
# env variables.
|
||||
import os
|
||||
# # Imports
|
||||
import time
|
||||
|
||||
# For this test case we need import and use the Python driver
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from planetmint_driver.exceptions import NotFoundError
|
||||
|
||||
|
||||
def test_multiple_owners():
|
||||
# ## Set up a connection to the Planetmint integration test nodes
|
||||
pm_itest1 = Planetmint(os.environ.get('PLANETMINT_ENDPOINT_1'))
|
||||
pm_itest2 = Planetmint(os.environ.get('PLANETMINT_ENDPOINT_2'))
|
||||
# Setup up connection to Planetmint integration test nodes
|
||||
hosts = []
|
||||
with open('/shared/hostnames') as f:
|
||||
hosts = f.readlines()
|
||||
|
||||
pm_hosts = list(map(lambda x: Planetmint(x), hosts))
|
||||
|
||||
pm_alpha = pm_hosts[0]
|
||||
pm_betas = pm_hosts[1:]
|
||||
|
||||
# Generate Keypairs for Alice and Bob!
|
||||
alice, bob = generate_keypair(), generate_keypair()
|
||||
@@ -52,7 +55,7 @@ def test_multiple_owners():
|
||||
|
||||
# They prepare a `CREATE` transaction. To have multiple owners, both
|
||||
# Bob and Alice need to be the recipients.
|
||||
prepared_dw_tx = pm_itest1.transactions.prepare(
|
||||
prepared_dw_tx = pm_alpha.transactions.prepare(
|
||||
operation='CREATE',
|
||||
signers=alice.public_key,
|
||||
recipients=(alice.public_key, bob.public_key),
|
||||
@@ -60,36 +63,31 @@ def test_multiple_owners():
|
||||
|
||||
# Now they both sign the transaction by providing their private keys.
|
||||
# And send it afterwards.
|
||||
fulfilled_dw_tx = pm_itest1.transactions.fulfill(
|
||||
fulfilled_dw_tx = pm_alpha.transactions.fulfill(
|
||||
prepared_dw_tx,
|
||||
private_keys=[alice.private_key, bob.private_key])
|
||||
|
||||
pm_itest1.transactions.send_commit(fulfilled_dw_tx)
|
||||
pm_alpha.transactions.send_commit(fulfilled_dw_tx)
|
||||
|
||||
# We store the `id` of the transaction to use it later on.
|
||||
dw_id = fulfilled_dw_tx['id']
|
||||
|
||||
time.sleep(1)
|
||||
# Let's retrieve the transaction from both nodes
|
||||
pm_itest1_tx = pm_itest1.transactions.retrieve(dw_id)
|
||||
pm_itest2_tx = {}
|
||||
# TODO: REPLACE WITH ASYNC OR POLL
|
||||
try:
|
||||
pm_itest2_tx = pm_itest2.transactions.retrieve(dw_id)
|
||||
except NotFoundError:
|
||||
print('TOO FAST')
|
||||
time.sleep(3)
|
||||
pm_itest2_tx = pm_itest2.transactions.retrieve(dw_id)
|
||||
pm_alpha_tx = pm_alpha.transactions.retrieve(dw_id)
|
||||
pm_betas_tx = list(map(lambda beta: beta.transactions.retrieve(dw_id), pm_betas))
|
||||
|
||||
# Both retrieved transactions should be the same
|
||||
assert pm_itest1_tx == pm_itest2_tx
|
||||
for tx in pm_betas_tx:
|
||||
assert pm_alpha_tx == tx
|
||||
|
||||
# Let's check if the transaction was successful.
|
||||
assert pm_itest1.transactions.retrieve(dw_id), \
|
||||
assert pm_alpha.transactions.retrieve(dw_id), \
|
||||
'Cannot find transaction {}'.format(dw_id)
|
||||
|
||||
# The transaction should have two public keys in the outputs.
|
||||
assert len(
|
||||
pm_itest1.transactions.retrieve(dw_id)['outputs'][0]['public_keys']) == 2
|
||||
pm_alpha.transactions.retrieve(dw_id)['outputs'][0]['public_keys']) == 2
|
||||
|
||||
# ## Alice and Bob transfer a transaction to Carol.
|
||||
# Alice and Bob save a lot of money living together. They often go out
|
||||
@@ -112,43 +110,37 @@ def test_multiple_owners():
|
||||
'owners_before': output['public_keys']}
|
||||
|
||||
# Now they create the transaction...
|
||||
prepared_transfer_tx = pm_itest1.transactions.prepare(
|
||||
prepared_transfer_tx = pm_alpha.transactions.prepare(
|
||||
operation='TRANSFER',
|
||||
asset=transfer_asset,
|
||||
inputs=transfer_input,
|
||||
recipients=carol.public_key)
|
||||
|
||||
# ... and sign it with their private keys, then send it.
|
||||
fulfilled_transfer_tx = pm_itest1.transactions.fulfill(
|
||||
fulfilled_transfer_tx = pm_alpha.transactions.fulfill(
|
||||
prepared_transfer_tx,
|
||||
private_keys=[alice.private_key, bob.private_key])
|
||||
|
||||
sent_transfer_tx = pm_itest1.transactions.send_commit(fulfilled_transfer_tx)
|
||||
sent_transfer_tx = pm_alpha.transactions.send_commit(fulfilled_transfer_tx)
|
||||
time.sleep(1)
|
||||
|
||||
# Retrieve the fulfilled transaction from both nodes
|
||||
pm_itest1_tx = pm_itest1.transactions.retrieve(fulfilled_transfer_tx['id'])
|
||||
pm_itest2_tx
|
||||
# TODO: REPLACE WITH ASYNC OR POLL
|
||||
try:
|
||||
pm_itest2_tx = pm_itest2.transactions.retrieve(fulfilled_transfer_tx['id'])
|
||||
except NotFoundError:
|
||||
print('TOO FAST')
|
||||
time.sleep(3)
|
||||
pm_itest2_tx = pm_itest2.transactions.retrieve(fulfilled_transfer_tx['id'])
|
||||
pm_alpha_tx = pm_alpha.transactions.retrieve(fulfilled_transfer_tx['id'])
|
||||
pm_betas_tx = list(map(lambda beta: beta.transactions.retrieve(fulfilled_transfer_tx['id']), pm_betas))
|
||||
|
||||
# Now compare if both nodes returned the same transaction
|
||||
assert pm_itest1_tx == pm_itest2_tx
|
||||
for tx in pm_betas_tx:
|
||||
assert pm_alpha_tx == tx
|
||||
|
||||
# They check if the transaction was successful.
|
||||
assert pm_itest1.transactions.retrieve(
|
||||
assert pm_alpha.transactions.retrieve(
|
||||
fulfilled_transfer_tx['id']) == sent_transfer_tx
|
||||
|
||||
# The owners before should include both Alice and Bob.
|
||||
assert len(
|
||||
pm_itest1.transactions.retrieve(fulfilled_transfer_tx['id'])['inputs'][0][
|
||||
pm_alpha.transactions.retrieve(fulfilled_transfer_tx['id'])['inputs'][0][
|
||||
'owners_before']) == 2
|
||||
|
||||
# While the new owner is Carol.
|
||||
assert pm_itest1.transactions.retrieve(fulfilled_transfer_tx['id'])[
|
||||
assert pm_alpha.transactions.retrieve(fulfilled_transfer_tx['id'])[
|
||||
'outputs'][0]['public_keys'][0] == carol.public_key
|
||||
|
||||
Reference in New Issue
Block a user