def test_append_block_1(self): """Should add the expected block.""" bc = Blockchain() block = bc.forge_block([]) bc.append_block(block) assert_that(bc.chain[1], is_(equal_to(block)))
def test_append_block_0(self): """Should add a block to the chain.""" bc = Blockchain() block = bc.forge_block([]) bc.append_block(block) assert_that(len(bc.chain), is_(2))
def get(self): blockchain = Blockchain() blockchain.forge_block([]) # print(b.__hash__()) self.response\ .write('Chan#1: {} ------> Chain#2: {} ------ |' .format(blockchain.chain[0].__str__(), blockchain.chain[1].__str__()))
def test___init___4(self, genesis): """Should call Block.genesis.""" Blockchain() genesis.assert_called_once()
def test___init___3(self): """The first element of the chain should not have a previous hash.""" new_bc = Blockchain() assert_that(new_bc.chain[0].previous_hash, is_(equal_to(None)))
def test___init___2(self): """Should set a Block instance as the first element of the chain.""" new_bc = Blockchain() assert_that(new_bc.chain[0], is_(instance_of(Block)))
def test___init___1(self): """Should have a chain of length == 1.""" new_bc = Blockchain() assert_that(len(new_bc.chain), is_(equal_to(1)))
def test___init___0(self): """Should have a chain property.""" new_bc = Blockchain() assert_that(new_bc.chain, is_(not_none()))
def setUp(self): self.blockchain_0 = Blockchain() self.blockchain_1 = Blockchain()
from flask import Flask, jsonify, request, redirect from coursechain.blockchain import Blockchain app = Flask(__name__) app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True blockchain = Blockchain() @app.route('/blocks') def blocks(): return jsonify([block.to_serializable() for block in blockchain.chain[:50]]) # limit results @app.route('/mine', methods=['POST']) def mine(): transactions = request.form['transactions'] blockchain.mine(transactions) return redirect('/blocks')