Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated blockchain.py server IP and minor fixes #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self):
self.chain = []
self.nodes = set()

# Create the genesis block
# Create the genesis block(1st Block)
self.new_block(previous_hash='1', proof=100)

def register_node(self, address):
Expand All @@ -37,7 +37,7 @@ def register_node(self, address):
def valid_chain(self, chain):
"""
Determine if a given blockchain is valid

:param chain: A blockchain
:return: True if valid, False if not
"""
Expand Down
3 changes: 3 additions & 0 deletions js/blockchain.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

const crypto = require("crypto");


Expand Down Expand Up @@ -80,6 +81,8 @@ class Blockchain {

/**
* Proof of Work mining algorithm
with RPoW and Mining Efficiency

*
* We hash the block with random string until the hash begins with
* a "difficulty" number of 0s.
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flask==0.12.2
requests==2.18.4
flask>=0.12.2
requests>=2.18.4
12 changes: 6 additions & 6 deletions tests/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ class TestRegisterNodes(BlockchainTestCase):
def test_valid_nodes(self):
blockchain = Blockchain()

blockchain.register_node('http://192.168.0.1:5000')
blockchain.register_node('http://192.168.0.1:4444')

self.assertIn('192.168.0.1:5000', blockchain.nodes)
self.assertIn('192.168.0.1:4444', blockchain.nodes)

def test_malformed_nodes(self):
blockchain = Blockchain()

blockchain.register_node('http//192.168.0.1:5000')
blockchain.register_node('http//192.168.0.1:4444')

self.assertNotIn('192.168.0.1:5000', blockchain.nodes)
self.assertNotIn('192.168.0.1:4444', blockchain.nodes)

def test_idempotency(self):
blockchain = Blockchain()

blockchain.register_node('http://192.168.0.1:5000')
blockchain.register_node('http://192.168.0.1:5000')
blockchain.register_node('http://192.168.0.1:4444')
blockchain.register_node('http://192.168.0.1:4444')

assert len(blockchain.nodes) == 1

Expand Down