def test_clear_blockchain_transaction():
    transaction_pool = TransactionPool()
    transaction_1 = Transaction(Wallet(), 'recipient', 1)
    transaction_2 = Transaction(Wallet(), 'recipient', 2)

    transaction_pool.set_transaction(transaction_1)
    transaction_pool.set_transaction(transaction_2)

    blockchain = Blockchain()
    blockchain.add_block([transaction_1.to_json(), transaction_2.to_json()])

    assert transaction_1.id in transaction_pool.transaction_map
    assert transaction_2.id in transaction_pool.transaction_map

    transaction_pool.clear_blockchain_transactions(blockchain)

    assert not transaction_1.id in transaction_pool.transaction_map
    assert not transaction_2.id in transaction_pool.transaction_map
def test_set_transaction():
    transaction_pool = TransactionPool()
    transaction = Transaction(Wallet(), 'recipient', 1)
    transaction_pool.set_transaction(transaction)

    assert transaction_pool.transaction_map[transaction.id] == transaction
示例#3
0
import os
import random

from flask import Blueprint, jsonify, request

from backend.models.blockchain import Blockchain
from backend.models.wallet import Wallet
from backend.models.transaction import Transaction
from backend.models.transaction_pool import TransactionPool
from backend.pubsub import PubSub

blockchain = Blockchain()
wallet = Wallet(blockchain)
transaction_pool = TransactionPool()
pubsub = PubSub(blockchain, transaction_pool)

BLOCKCHAIN = Blueprint('BLOCKCHAIN', __name__)


@BLOCKCHAIN.route('/', methods=['GET'])
def default_blockchain_route():
    return jsonify(blockchain.to_json())


@BLOCKCHAIN.route('/range', methods=['GET'])
# http://localhost:5000/blockchain/range?start=3&&end=6
def route_blockchain_range():
    start = int(request.args.get('start'))
    end = int(request.args.get('end'))

    return jsonify(blockchain.to_json()[::-1][start:end])
示例#4
0
import os
import random

from flask import Blueprint, jsonify
from backend.models.transaction_pool import TransactionPool
from backend.models.transaction import Transaction
from backend.models.wallet import Wallet

transaction_pool = TransactionPool()

TRANSACTION = Blueprint('TRANSACTION', __name__)


@TRANSACTION.route('/', methods=['GET'])
def route_transactions():
    return jsonify(transaction_pool.transaction_data())


if os.environ.get('SEED_DATA') == 'True':
    for i in range(5):
        transaction_pool.set_transaction(
            Transaction(Wallet(),
                        Wallet().address, random.randint(5, 100)))