mirror of
https://github.com/planetmint/planetmint.git
synced 2025-06-06 14:16:38 +00:00
added integration tests incl docker-compose and travis-ci setup
This commit is contained in:
parent
263dfd49ed
commit
339b38b123
@ -13,6 +13,8 @@ elif [[ ${PLANETMINT_CI_ABCI} == 'enable' ]]; then
|
||||
docker-compose exec planetmint pytest -v -m abci
|
||||
elif [[ ${PLANETMINT_ACCEPTANCE_TEST} == 'enable' ]]; then
|
||||
./run-acceptance-test.sh
|
||||
elif [[ ${PLANETMINT_INTEGRATION_TEST} == 'enable' ]]; then
|
||||
./run-integration-test.sh
|
||||
else
|
||||
docker-compose exec planetmint pytest -v --cov=planetmint --cov-report xml:htmlcov/coverage.xml
|
||||
fi
|
||||
|
5
Makefile
5
Makefile
@ -1,4 +1,4 @@
|
||||
.PHONY: help run start stop logs test test-unit test-unit-watch test-acceptance cov doc doc-acceptance clean reset release dist check-deps clean-build clean-pyc clean-test
|
||||
.PHONY: help run start stop logs test test-unit test-unit-watch test-acceptance test-integration cov doc doc-acceptance clean reset release dist check-deps clean-build clean-pyc clean-test
|
||||
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
@ -82,6 +82,9 @@ test-unit-watch: check-deps ## Run all tests and wait. Every time you change cod
|
||||
test-acceptance: check-deps ## Run all acceptance tests
|
||||
@./run-acceptance-test.sh
|
||||
|
||||
test-integration: check-deps ## Run all integration tests
|
||||
@./run-integration-test.sh
|
||||
|
||||
cov: check-deps ## Check code coverage and open the result in the browser
|
||||
@$(DC) run --rm planetmint pytest -v --cov=planetmint --cov-report html
|
||||
$(BROWSER) htmlcov/index.html
|
||||
|
@ -83,6 +83,14 @@ services:
|
||||
environment:
|
||||
- PLANETMINT_ENDPOINT=planetmint
|
||||
|
||||
# Planetmint setup to do integration testing wtih Python
|
||||
python-integration:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: ./integration/python/Dockerfile
|
||||
volumes:
|
||||
- ./integration/python/src:/src
|
||||
|
||||
# Build docs only
|
||||
# docker-compose build bdocs
|
||||
# docker-compose up -d bdocs
|
||||
|
0
integration/README.md
Normal file
0
integration/README.md
Normal file
6
integration/python/Dockerfile
Normal file
6
integration/python/Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM python:3.9
|
||||
|
||||
RUN mkdir -p /src
|
||||
RUN pip install --upgrade \
|
||||
pytest~=6.2.5 \
|
||||
planetmint-driver~=0.9.0
|
92
integration/python/src/test_basic.py
Normal file
92
integration/python/src/test_basic.py
Normal file
@ -0,0 +1,92 @@
|
||||
# import Planetmint and create object
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
import time
|
||||
|
||||
def test_basic():
|
||||
# Setup up connection to Planetmint integration test nodes
|
||||
pm_itest1_url = 'https://itest1.planetmint.io'
|
||||
pm_itest2_url = 'https://itest2.planetmint.io'
|
||||
pm_itest1 = Planetmint(pm_itest1_url)
|
||||
pm_itest2 = Planetmint(pm_itest2_url)
|
||||
|
||||
# genarate a keypair
|
||||
alice, bob = generate_keypair(), generate_keypair()
|
||||
|
||||
# create a digital asset for Alice
|
||||
game_boy_token = {
|
||||
'data': {
|
||||
'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
},
|
||||
}
|
||||
|
||||
# prepare the transaction with the digital asset and issue 10 tokens to bob
|
||||
prepared_creation_tx = pm_itest1.transactions.prepare(
|
||||
operation='CREATE',
|
||||
metadata={
|
||||
'hash': '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(
|
||||
prepared_creation_tx,
|
||||
private_keys=alice.private_key)
|
||||
pm_itest1.transactions.send_commit(fulfilled_creation_tx)
|
||||
time.sleep(4)
|
||||
|
||||
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)
|
||||
|
||||
# Assert that transaction is stored on both planetmint nodes
|
||||
assert creation_tx_itest1 == creation_tx_itest2
|
||||
|
||||
# Transfer
|
||||
# create the output and inout for the transaction
|
||||
transfer_asset = {'id': creation_tx_id}
|
||||
output_index = 0
|
||||
output = fulfilled_creation_tx['outputs'][output_index]
|
||||
transfer_input = {'fulfillment': output['condition']['details'],
|
||||
'fulfills': {'output_index': output_index,
|
||||
'transaction_id': transfer_asset['id']},
|
||||
'owners_before': output['public_keys']}
|
||||
|
||||
# prepare the transaction and use 3 tokens
|
||||
prepared_transfer_tx = pm_itest1.transactions.prepare(
|
||||
operation='TRANSFER',
|
||||
asset=transfer_asset,
|
||||
inputs=transfer_input,
|
||||
metadata={'hash': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
'storageID': '0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', },
|
||||
recipients=[([alice.public_key], 10)])
|
||||
|
||||
# fulfill and send the transaction
|
||||
fulfilled_transfer_tx = pm_itest1.transactions.fulfill(
|
||||
prepared_transfer_tx,
|
||||
private_keys=alice.private_key)
|
||||
sent_transfer_tx = pm_itest1.transactions.send_commit(fulfilled_transfer_tx)
|
||||
|
||||
transfer_tx_id = fulfilled_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)
|
||||
|
||||
# Assert that transaction is stored on both planetmint nodes
|
||||
assert transfer_tx_itest1 == transfer_tx_itest2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
37
run-integration-test.sh
Executable file
37
run-integration-test.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
# 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
|
||||
|
||||
|
||||
# Set up a Planetmint node and return only when we are able to connect to both
|
||||
# the Planetmint container *and* the Tendermint container.
|
||||
setup () {
|
||||
docker-compose up -d planetmint
|
||||
|
||||
# Try to connect to the containers for maximum three times, and wait
|
||||
# one second between tries.
|
||||
for i in $(seq 3); do
|
||||
if $(docker-compose run --rm curl-client); then
|
||||
break
|
||||
else
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
run_test () {
|
||||
docker-compose run --rm python-integration pytest /src/test_basic.py
|
||||
}
|
||||
|
||||
teardown () {
|
||||
docker-compose down
|
||||
}
|
||||
|
||||
setup
|
||||
run_test
|
||||
exitcode=$?
|
||||
teardown
|
||||
|
||||
exit $exitcode
|
Loading…
x
Reference in New Issue
Block a user