diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..759d90e --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,36 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Python application + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/app/codes/consensus/committee.py b/app/codes/consensus/committee.py index f6e12a5..63d1aad 100644 --- a/app/codes/consensus/committee.py +++ b/app/codes/consensus/committee.py @@ -7,7 +7,7 @@ def get_current_committee(): """Return the current committee members""" - new_block_idx = last_block_idx + 1 + # new_block_idx = last_block_idx + 1 peers = get_peers() committee = peers[:5] # TODO - Find the committe based on last block hash # use select_from function to select from peers diff --git a/app/codes/consensus/consensus.py b/app/codes/consensus/consensus.py index 18cf89a..4878469 100644 --- a/app/codes/consensus/consensus.py +++ b/app/codes/consensus/consensus.py @@ -7,14 +7,6 @@ from ...constants import MINIMUM_ACCEPTANCE_RATIO, MINIMUM_ACCEPTANCE_VOTES from ..auth.auth import get_wallet -try: - wallet_data = get_wallet() -except: - wallet_data = { - 'wallet': {'public': '', 'private': ''}, - } -public_key = wallet_data['public'] -private_key = wallet_data['private'] def generate_block_receipt(block): receipt_data = { @@ -22,6 +14,15 @@ def generate_block_receipt(block): 'block_hash': calculate_hash(block), 'vote': 1 } + + try: + wallet_data = get_wallet() + except: + wallet_data = { + 'wallet': {'public': '', 'private': ''}, + } + public_key = wallet_data['public'] + private_key = wallet_data['private'] return { "data": receipt_data, "public_key": public_key, diff --git a/app/codes/p2p/peers.py b/app/codes/p2p/peers.py index c5d69fd..f5cb01a 100644 --- a/app/codes/p2p/peers.py +++ b/app/codes/p2p/peers.py @@ -29,9 +29,6 @@ # return auth_data -auth_data = get_auth() - - def clear_peer_db(): con = sqlite3.connect(NEWRL_P2P_DB) cur = con.cursor() @@ -144,6 +141,7 @@ def init_bootstrap_nodes(): def register_me_with_them(address): + auth_data = get_auth() logger.info(f'Registering me with node {address}') response = requests.post('http://' + address + f':{NEWRL_PORT}/add-peer', json=auth_data, timeout=REQUEST_TIMEOUT) return response.json() diff --git a/app/sctest.py b/app/sctest.py index 6bf0c7f..1a1ec61 100644 --- a/app/sctest.py +++ b/app/sctest.py @@ -23,10 +23,10 @@ def test_usd1(): "legalparams":{} } callparamjson=json.dumps(callparams) - scoin1=nstablecoin.nusd1() - cur = "x" - scoin1.setup(cur, callparamjson) - scoin1.deploy(cur, "sender", callparams={"trans_code":"123sdwe2"}) + # scoin1=nstablecoin.nusd1() + # cur = "x" + # scoin1.setup(cur, callparamjson) + # scoin1.deploy(cur, "sender", callparams={"trans_code":"123sdwe2"}) # loan1=secloanv100.SecLoan1("0xa87cfed9b43a84d621b6ab4e2b928ac9c7e6c5df") diff --git a/app/tests/conftest.py b/app/tests/conftest.py index 2b2e1d0..16e3b57 100644 --- a/app/tests/conftest.py +++ b/app/tests/conftest.py @@ -2,15 +2,19 @@ import shutil import pytest +from ..codes.p2p.peers import init_peer_db def setup_test_files(): """Setup test files""" print('Setting up test files') if not os.path.exists('data_test/'): os.makedirs('data_test/') - if not os.path.exists('data_test/newrl.db'): + if os.path.exists('data_test/newrl.db'): os.remove('data_test/newrl.db') + if os.path.exists('data_test/newrl_p2p.db'): + os.remove('data_test/newrl_p2p.db') shutil.copyfile('data_test/template/newrl.db', 'data_test/newrl.db') + init_peer_db() @pytest.fixture(scope="session", autouse=True)