-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Append-only wallet transactions #21
Conversation
d72481f
to
e1db6d0
Compare
Codecov Report
@@ Coverage Diff @@
## develop #21 +/- ##
===========================================
+ Coverage 87.71% 87.79% +0.07%
===========================================
Files 73 73
Lines 2410 2417 +7
Branches 126 125 -1
===========================================
+ Hits 2114 2122 +8
+ Misses 278 276 -2
- Partials 18 19 +1
Continue to review full report at Codecov.
|
For example, rejected transactions does not contribute to | ||
the wallet balance. | ||
For example, rejected transactions do not contribute to the wallet | ||
balance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a spelling mistake here, shouldn't it say: ...example, pending transactions do ...
?
As that is what we check at line 84
src/wallet/api.py
Outdated
"""Withdraw given amount from the wallet. | ||
|
||
Throw InsufficientFunds if there is not enough money in the wallet. | ||
""" | ||
assert amount.amount >= 0, "Cannot withdraw a negative amount of money" | ||
assert amount.amount > 0, "The amount must be non-negative." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer positive
instead of non-negative
. Otherwise it could seem like 0
is OK, which it is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incoming soon!
src/wallet/api.py
Outdated
"""Deposit given amount into the wallet.""" | ||
assert amount.amount >= 0, "Cannot deposit a negative amount of money" | ||
assert amount.amount > 0, "The amount must be non-negative." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previously mentioned
trx_status=enums.TrxStatus.FINALIZED, | ||
amount=amount, | ||
trx_type=TrxType.PENDING if pending else TrxType.FINALIZED, | ||
amount=-amount, | ||
reference=reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if pending=False
and reference=None
? Is it necessary to cover this case?
@@ -13,14 +25,13 @@ def transfer_currency(apps, schema_editor): | |||
for wallet in Wallet.objects.all(): | |||
incoming = WalletTrx.objects.filter( | |||
wallet=wallet.id, | |||
trx_status=enums.TrxStatus.FINALIZED, | |||
trx_type=enums.TrxType.INCOMING | |||
trx_status=TrxStatus.FINALIZED, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't TrxStatus.PENDING
interesting here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incoming transactions that are PENDING do not contribute to the wallet balance.
src/wallet/signals/handlers.py
Outdated
elif not created: | ||
# A transaction has been updated, so we simply recalculate | ||
# the wallet balance. | ||
wallet_obj.balance = wallet_obj.transactions.balance() | ||
wallet_obj.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we always need to call save()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, definitely not! Good catch.
e1db6d0
to
4c03ea3
Compare
Wallet transactions should never be altered once created. Should solve #19.