def test_transaction_update_successful():
    sender_wallet = Wallet()
    first_recipient = 'first_recipient'
    first_amount = 50

    transaction = Transaction(sender_wallet, first_recipient, first_amount)

    next_recipient = 'next_recipient'
    next_amount = 75
    transaction.update(sender_wallet, next_recipient, next_amount)

    assert transaction.output[next_recipient] == next_amount
    assert transaction.output[
        sender_wallet.
        address] == sender_wallet.balance - first_amount - next_amount

    # Verifies making an update on a transaction correctly reduces the output inside the transaction class.
    assert Wallet.verify(transaction.input['public_key'], transaction.output,
                         transaction.input['signature'])

    # Update going to a recipient that already existed showing that they made two transactions.
    to_first_again_amount = 50
    transaction.update(sender_wallet, first_recipient, to_first_again_amount)

    assert transaction.output[
        first_recipient] == first_amount + to_first_again_amount
    assert transaction.output[
        sender_wallet.
        address] == sender_wallet.balance - first_amount - next_amount - to_first_again_amount

    assert Wallet.verify(transaction.input['public_key'], transaction.output,
                         transaction.input['signature'])
def test_transaction_update_exceeds_balance():
    sender_wallet = Wallet()
    transaction = Transaction(sender_wallet, 'recipient', 50)

    with pytest.raises(Exception, match="Amount exceeds balance"):
        transaction.update(sender_wallet, 'new_recipient', 9000)