Merge branch 'circle-ci' into 46-docstrings

This commit is contained in:
Sergi Delgado Segura
2019-12-16 11:42:30 +01:00
30 changed files with 111 additions and 24 deletions

71
.circleci/config.yml Normal file
View File

@@ -0,0 +1,71 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
- image: circleci/python:3.6.1
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
working_directory: ~/repo
steps:
- checkout
# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pisa/requirements.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r pisa/requirements.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "pisa/requirements.txt" }}
# run tests!
# this example uses Django's built-in test-runner
# other common Python testing frameworks include pytest and nose
# https://pytest.org
# https://nose.readthedocs.io
- run:
name: create config
command: cp pisa/sample_conf.py pisa/conf.py
- run:
name: run pisa unit tests
command: |
. venv/bin/activate
pytest test/pisa/unit/
- run:
name: run common unit tests
command: |
. venv/bin/activate
pytest test/common/unit
# - run:
# name: run cli unit tests
# command: |
# . venv/bin/activate
# pytest test/apps/cli/unit
# - store_artifacts:
# path: test-reports
# destination: test-reports

View File

@@ -1,4 +1,6 @@
zmq
flask
cryptography
requests
requests
plyvel
pytest

View File

@@ -1,14 +1,14 @@
# bitcoind
BTC_RPC_USER = None
BTC_RPC_PASSWD = None
BTC_RPC_HOST = None
BTC_RPC_PORT = None
BTC_NETWORK = None
BTC_RPC_USER = "user"
BTC_RPC_PASSWD = "passwd"
BTC_RPC_HOST = "localhost"
BTC_RPC_PORT = 18443
BTC_NETWORK = "regtest"
# ZMQ
FEED_PROTOCOL = None
FEED_ADDR = None
FEED_PORT = None
FEED_PROTOCOL = "tcp"
FEED_ADDR = "127.0.0.1"
FEED_PORT = 28332
# PISA
MAX_APPOINTMENTS = 100

0
test/apps/__init__.py Normal file
View File

View File

View File

View File

@@ -0,0 +1,7 @@
import random
def get_random_value_hex(nbytes):
pseudo_random_value = random.getrandbits(8 * nbytes)
prv_hex = "{:x}".format(pseudo_random_value)
return prv_hex.zfill(2 * nbytes)

View File

@@ -7,7 +7,7 @@ from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ec
import apps.cli.pisa_cli as pisa_cli
from test.unit.conftest import get_random_value_hex
from test.apps.cli.unit.conftest import get_random_value_hex
# TODO: should find a way of doing without this
from apps.cli.pisa_cli import build_appointment

0
test/common/__init__.py Normal file
View File

View File

View File

@@ -0,0 +1,7 @@
import random
def get_random_value_hex(nbytes):
pseudo_random_value = random.getrandbits(8 * nbytes)
prv_hex = "{:x}".format(pseudo_random_value)
return prv_hex.zfill(2 * nbytes)

View File

@@ -3,7 +3,7 @@ import binascii
from apps.cli.blob import Blob
from common.cryptographer import Cryptographer
from pisa.encrypted_blob import EncryptedBlob
from test.unit.conftest import get_random_value_hex
from test.common.unit.conftest import get_random_value_hex
data = "6097cdf52309b1b2124efeed36bd34f46dc1c25ad23ac86f28380f746254f777"
key = "b2e984a570f6f49bc38ace178e09147b0aa296cbb7c92eb01412f7e2d07b5659"

0
test/pisa/__init__.py Normal file
View File

View File

View File

@@ -11,7 +11,7 @@ from pisa.tools import bitcoin_cli
from pisa import HOST, PORT, c_logger
from pisa.conf import MAX_APPOINTMENTS
from test.unit.conftest import (
from test.pisa.unit.conftest import (
generate_block,
generate_blocks,
get_random_value_hex,

View File

@@ -5,7 +5,7 @@ from pisa import c_logger
from pisa.appointment import Appointment
from pisa.encrypted_blob import EncryptedBlob
from test.unit.conftest import get_random_value_hex
from test.pisa.unit.conftest import get_random_value_hex
from common.constants import LOCATOR_LEN_BYTES

View File

@@ -2,7 +2,7 @@ from binascii import unhexlify
from pisa import c_logger
from apps.cli.blob import Blob
from test.unit.conftest import get_random_value_hex
from test.pisa.unit.conftest import get_random_value_hex
c_logger.disabled = True

View File

@@ -2,7 +2,7 @@ import pytest
from pisa import c_logger
from pisa.block_processor import BlockProcessor
from test.unit.conftest import get_random_value_hex, generate_block, generate_blocks
from test.pisa.unit.conftest import get_random_value_hex, generate_block, generate_blocks
c_logger.disabled = True

View File

@@ -1,7 +1,7 @@
from uuid import uuid4
from pisa.builder import Builder
from test.unit.conftest import get_random_value_hex, generate_dummy_appointment, generate_dummy_tracker
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment, generate_dummy_tracker
def test_build_appointments():

View File

@@ -4,7 +4,7 @@ from pisa import c_logger
from pisa.carrier import Carrier
from test.simulator.utils import sha256d
from test.simulator.transaction import TX
from test.unit.conftest import generate_blocks, generate_block, get_random_value_hex
from test.pisa.unit.conftest import generate_blocks, get_random_value_hex
from pisa.rpc_errors import RPC_VERIFY_ALREADY_IN_CHAIN, RPC_DESERIALIZATION_ERROR
c_logger.disabled = True

View File

@@ -7,7 +7,7 @@ from pisa.cleaner import Cleaner
from pisa.appointment import Appointment
from pisa.db_manager import WATCHER_PREFIX
from test.unit.conftest import get_random_value_hex
from test.pisa.unit.conftest import get_random_value_hex
from common.constants import LOCATOR_LEN_BYTES, LOCATOR_LEN_HEX

View File

@@ -9,7 +9,7 @@ from pisa.db_manager import WATCHER_LAST_BLOCK_KEY, RESPONDER_LAST_BLOCK_KEY, LO
from common.constants import LOCATOR_LEN_BYTES
from test.unit.conftest import get_random_value_hex, generate_dummy_appointment
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment
@pytest.fixture(scope="module")

View File

@@ -1,6 +1,6 @@
from pisa import c_logger
from pisa.encrypted_blob import EncryptedBlob
from test.unit.conftest import get_random_value_hex
from test.pisa.unit.conftest import get_random_value_hex
c_logger.disabled = True

View File

@@ -11,7 +11,7 @@ from pisa.appointment import Appointment
from pisa.block_processor import BlockProcessor
from pisa.conf import MIN_TO_SELF_DELAY
from test.unit.conftest import get_random_value_hex, generate_dummy_appointment_data, generate_keypair
from test.pisa.unit.conftest import get_random_value_hex, generate_dummy_appointment_data, generate_keypair
from common.constants import LOCATOR_LEN_BYTES, LOCATOR_LEN_HEX
from common.cryptographer import Cryptographer

View File

@@ -18,7 +18,7 @@ from common.tools import check_sha256_hex_format
from test.simulator.utils import sha256d
from test.simulator.bitcoind_sim import TX
from test.unit.conftest import generate_block, generate_blocks, get_random_value_hex
from test.pisa.unit.conftest import generate_block, generate_blocks, get_random_value_hex
c_logger.disabled = True

View File

@@ -8,7 +8,7 @@ from pisa import c_logger
from pisa.watcher import Watcher
from pisa.responder import Responder
from pisa.tools import bitcoin_cli
from test.unit.conftest import (
from test.pisa.unit.conftest import (
generate_block,
generate_blocks,
generate_dummy_appointment,

View File

@@ -4,7 +4,7 @@ from time import sleep
from threading import Thread
from test.simulator.transaction import TX
from test.unit.conftest import get_random_value_hex
from test.pisa.unit import get_random_value_hex
from test.simulator.bitcoind_sim import run_simulator
from pisa.utils.auth_proxy import AuthServiceProxy, JSONRPCException
from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT