def test_transaction_update():
    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
    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'])
Example #2
0
def test_transaction_update_exceeds_balance():
    sender_wallet = Wallet()
    transaction = Transaction(sender_wallet, 'recipient', 50)

    with pytest.raises(Exception, match="Amount exceeds the balance."):
        transaction.update(sender_wallet, 'new_recipient',
                           STARTING_BALANCE + 50)
def test_transaction_update():
    sender_wallet = Wallet()
    first_recipient = 'first recipient'
    first_amount = 50
    transaction = Transaction(sender_wallet, first_recipient, first_amount)
    second_recipient = 'second recipient'
    second_amount = 50
    transaction.update(sender_wallet, second_recipient, second_amount)

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

    transaction.update(sender_wallet, first_recipient, first_amount)

    assert transaction.output[first_recipient] == first_amount + first_amount
    assert transaction.output[sender_wallet.address] == \
        sender_wallet.balance - first_amount - second_amount - first_amount
    assert Wallet.verify(
        transaction.input['public_key'],
        transaction.output,
        transaction.input['signature']
    )
Example #4
0
def test_transaction_update():
    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.get(next_recipient) == next_amount
    assert transaction.output.get(
        sender_wallet.address
    ) == sender_wallet.balance - first_amount - next_amount
    assert Wallet.verify(transaction.input.get('public_key'),
                         transaction.output,
                         transaction.input.get('signature'))

    first_again_amount = 25
    transaction.update(sender_wallet, first_recipient, first_again_amount)
    assert transaction.output.get(
        first_recipient) == first_amount + first_again_amount
    assert transaction.output.get(
        sender_wallet.address
    ) == sender_wallet.balance - first_amount - next_amount - first_again_amount
    assert Wallet.verify(transaction.input.get('public_key'),
                         transaction.output,
                         transaction.input.get('signature'))
Example #5
0
def test_transaction_update():
    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)

    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"],
    )
def test_transaction_update_exceeds_balance():
    sender_wallet = Wallet()
    recipient = 'recipient'
    amount = 50
    transaction = Transaction(sender_wallet, recipient, amount)

    with pytest.raises(Exception, match="The amount exceeds sender's balance"):
        transaction.update(sender_wallet, 'new_recipient', 9000)
Example #7
0
def test_transaction_update():
    # Block Wallet that will be subtracting amounts from.
    sender_wallet = Wallet()

    # Set the first recipient, the first amount that will be subtracted from
    # the Block's wallet, and the transaction item that will be used in the
    # process.
    recipient1 = 'first_recipient'
    amount1 = 50
    trans = Transaction(sender_wallet, recipient1, amount1)

    # Set the second recipient, the second amount that will be subtracted from
    # the Block's wallet, and the transaction item that will be used in the
    # process.
    recipient2 = 'next_recipient'
    amount2 = 75
    trans.update(sender_wallet, recipient2, amount2)

    # Assert that the transaction output for the recipient2 is amount2.
    assert(trans.output[recipient2] == amount2)
    # Assert that the sender wallet in the output is updated.
    updated_balance = sender_wallet.balance - amount1 - amount2
    assert(trans.output[sender_wallet.address] == updated_balance)
    # Run transaction through the Wallet.verify() to verify the signature and
    # assert that it is verified.
    assert(Wallet.verify(trans.input['public_key'], trans.output,
           trans.input['signature']))

    # Make an update to the first recipient using the wallet and new third
    # amount.
    amount3 = 25
    trans.update(sender_wallet, recipient1, amount3)

    # Assert that the total amount recieved by recipient1 during the
    # transactions are the sum total of amount1 + amount3.
    total_amount_added = amount1 + amount3
    assert(trans.output[recipient1] == total_amount_added)

    # Assert amount1, amount2, and amount3 was subtracted from wallet.
    total_update_change = (sender_wallet.balance - amount1 - amount2 - amount3)
    assert(trans.output[sender_wallet.address] == total_update_change)

    # Run transaction through the Wallet.verify() to verify the signature and
    # assert that it is verified.
    assert(Wallet.verify(trans.input['public_key'], trans.output,
           trans.input['signature']))
Example #8
0
def test_transaction_update():
    sender_wallet = Wallet()
    recipient = 'recipient'
    new_recipient = 'new_recipient'
    amount = 50
    new_amount = 150
    transaction = Transaction(sender_wallet, recipient, amount)
    transaction.update(sender_wallet, new_recipient, new_amount)
    assert transaction.output[new_recipient] == new_amount
    assert transaction.output[
        sender_wallet.address] == sender_wallet.balance - new_amount - amount
    assert Wallet.verify(transaction.input['public_key'], transaction.output,
                         transaction.input['signature'])

    to_first_again_amount = 25
    transaction.update(sender_wallet, recipient, to_first_again_amount)
    assert transaction.output[recipient] == amount + to_first_again_amount
    assert transaction.output[
        sender_wallet.
        address] == sender_wallet.balance - new_amount - amount - to_first_again_amount
    assert Wallet.verify(transaction.input['public_key'], transaction.output,
                         transaction.input['signature'])
Example #9
0
def test_update_transaction_same_recipient():
    """
    Test update transaction with the same recipient
    """
    sender_wallet = Wallet()
    recipient = 'recipient'
    amount = 50

    transaction = Transaction().new_transaction(sender_wallet, recipient,
                                                amount)

    new_amount = 30
    new_recipient = 'recipient'

    transaction = transaction.update(sender_wallet, new_recipient, new_amount)

    assert transaction.outputs['recipient_address'] == new_recipient
    assert transaction.outputs['recipient_amount'] == new_amount
    assert transaction.outputs[
        'sender_amount'] == sender_wallet.balance - amount - new_amount
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', 9001)