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() transaction = Transaction(sender_wallet, 'recipient', 50) with pytest.raises(Exception, match='Amount exceeds balance'): transaction.update(sender_wallet, 'new_recipient', 9001)