def test_blockchain_proof_of_work(): """test proof of work works correctly""" block = Block(0, "01-01-2020", "genesis", "", "") blockchain = BlockChain() output = blockchain.proof_of_work(block=block) expected = "00eddca60c19374852bebd291a7ec6baaf3bbeb4bcb4737edca7974150567c3f" assert output == expected
def test_blockchain_is_valid_proof(): """test the valid proof function works correctly""" block = Block(0, "01-01-2020", "genesis", "", "") blockchain = BlockChain() blockchain.proof_of_work(block=block) input_hash = "00eddca60c19374852bebd291a7ec6baaf3bbeb4bcb4737edca7974150567c3f" output = blockchain.is_valid_proof(block, input_hash) assert output is True
def test_blockchain_work_mine_result(): """test the blockchain work flow""" blockchain = BlockChain() # Start a chain blockchain.add_new_transaction("claim") for i in range(1, 7): blockchain.add_new_transaction(i) blockchain.mine() assert blockchain.chain[1].news["mean"] == 3.5 assert blockchain.chain[1].news["value"] == "claim"
def test_blockchain_create_genesis_block(): """test that blockchain creates the genesis block correctly""" blockchain = BlockChain() output = blockchain.chain[0].index assert output == 0
from pydantic import BaseModel try: from src.blockchain import Block, BlockChain except ImportError: from blockchain import Block, BlockChain print("Instantiating node") node = FastAPI() print("Generating globally unique address for this node") NODE_IDENTIFIER = str(uuid4()).replace("-", "") print(f"This is node ID {NODE_IDENTIFIER}") print("Instantiating Blockchain for this node") blockchain = BlockChain() print("Blockchain up and running!") class ActiveNode(BaseModel): nodes: List[str] @node.get("/") def root(): """ Greet info """ return {"message": "Welcome to the simplified blockchain news platform"}