Exemple #1
0
    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)))
Exemple #2
0
    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))
Exemple #3
0
 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__()))
Exemple #4
0
    def test___init___4(self, genesis):
        """Should call Block.genesis."""
        Blockchain()

        genesis.assert_called_once()
Exemple #5
0
    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)))
Exemple #6
0
    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)))
Exemple #7
0
    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)))
Exemple #8
0
    def test___init___0(self):
        """Should have a chain property."""
        new_bc = Blockchain()

        assert_that(new_bc.chain, is_(not_none()))
Exemple #9
0
 def setUp(self):
     self.blockchain_0 = Blockchain()
     self.blockchain_1 = Blockchain()
Exemple #10
0
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')