Пример #1
0
def test_transactions_validate_invalid_rewards():
    miner_wallet = Wallet()
    reward_transaction = Transactions.transaction_reward(miner_wallet)
    reward_transaction.output[miner_wallet.address] = 100
    reward_transaction.output['recp1'] = 100
    with pytest.raises(Exception, match="Invalid transaction reward"):
        Transactions.verify_transaction(reward_transaction)
Пример #2
0
def test_blockchain_valid_transaction_duplicate_rewardss():
    blockchain = Blockchain()
    transaction = Transactions(Wallet(), 'recipient', 100).to_json()
    reward_transaction = Transactions.transaction_reward(Wallet()).to_json()
    blockchain.add_block([transaction, reward_transaction, reward_transaction])
    with pytest.raises(Exception, match="has multiple rewards"):
        Blockchain.is_chain_transaction_valid(blockchain.chain)
Пример #3
0
def blockchain():
    blockchain = Blockchain()
    for i in range(3):
        miner_wallet = Wallet()
        transaction = Transactions(Wallet(), 'recipient', i)
        reward_transaction = Transactions.transaction_reward(miner_wallet)
        blockchain.add_block([transaction.to_json()])
        return blockchain
Пример #4
0
def mine_block():
    #get the transaction data and put it into the data field of add_block
    transaction_data = transaction_pool.transaction_data()
    #Append the transaction reward into the wallet of the miner
    transaction_reward = Transactions.transaction_reward(wallet).to_json()
    transaction_data.append(transaction_reward)
    blockchain.add_block(transaction_data)
    block = blockchain.chain[-1]
    #publish the block throughout the network to the subscribed channel
    pubsub.broadcast_block(block)
    #After everytime a block is mined, we need to clear the transaction pool.
    transaction_pool.clear_transaction(blockchain)
    return block.to_json(), 200
Пример #5
0
def test_transactions_validate_reward():
    miner_wallet = Wallet()
    reward_transaction = Transactions.transaction_reward(miner_wallet)
    Transactions.verify_transaction(reward_transaction)
Пример #6
0
def test_transactions_reward():
    miner_wallet = Wallet()
    reward_transaction = Transactions.transaction_reward(miner_wallet)
    assert reward_transaction.output[miner_wallet.address] == MINING_REWARD
    assert reward_transaction.input == MINING_REWARD_INPUT