Exemplo n.º 1
0
def test_transaction_update():
    sender_wallet = Wallet()
    first_recipient = 'first_person'
    first_amount = 50
    transaction = Transaction(sender_wallet, first_recipient, first_amount)

    next_reciepient = 'other_person'
    next_amount = 80
    transaction.update(sender_wallet, next_reciepient, next_amount)

    assert transaction.output[next_reciepient] == next_amount
    assert transaction.output[
        sender_wallet.
        address] == sender_wallet.balance - first_amount - next_amount
    assert Wallet.verify(transaction.input['public_key'], transaction.output,
                         transaction.input['signature'])

    to_first_again_amount = 25
    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'])
Exemplo n.º 2
0
def test_transaction_update_exceeds_balance():
    sender_wallet = Wallet()
    transaction = Transaction(sender_wallet, 'reciepient', 50)

    with pytest.raises(Exception, match='Amount exceeds balance'):
        transaction.update(sender_wallet, 'new_reciepient', 1998)