Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/codes/consensus/committee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions app/codes/consensus/consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
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 = {
'block_index': block['index'],
'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,
Expand Down
4 changes: 1 addition & 3 deletions app/codes/p2p/peers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
# return auth_data


auth_data = get_auth()


def clear_peer_db():
con = sqlite3.connect(NEWRL_P2P_DB)
cur = con.cursor()
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions app/sctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
6 changes: 5 additions & 1 deletion app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down