-
Notifications
You must be signed in to change notification settings - Fork 482
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
Support symbolic amount/bid=everything which spends all funds from selected account/wallets. #3605
Draft
moodyjon
wants to merge
16
commits into
lbryio:master
Choose a base branch
from
moodyjon:send-max-pr1628
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9cf28f0
Add an "everything" option to Transaction.create() and unit test.
moodyjon 7bafce0
Support everything argument in Transaction.pay(), claim_create(), cla…
moodyjon 262c30e
Support amount/bid "everything" in various JSON RPC methods as an alt…
moodyjon 508acb3
Lint fix for transaction.py
moodyjon 1fb3d83
Revising API away from decimal/str generalization. Use separate bool …
moodyjon 6f12ea3
More revisions supporting bool args (bid_everything and amount_everyt…
moodyjon 42708fc
Add some usages of bid_everything/amount_everything to test_claim_com…
moodyjon 0fce4f8
Correct jsonrpc_account_fund handling of amount/everything.
moodyjon c1fe4ca
Correct some docstrings and regenerate api.json with scripts/generate…
moodyjon f7dfc66
Update type annotations to reflect new args and behavior of get_dewie…
moodyjon 4a1b1da
Update expected error string on missing bid.
moodyjon 07e8ab3
Simplify InsufficientFundsError testcase.
moodyjon cfefe99
Convert --amount, --amount_everything to generic amount (int or str) …
moodyjon 8b2c284
Use the definite txo.amount (not EVERYTHING) when calling save_claims().
moodyjon 665c12b
Use the definite txo.amount (not EVERYTHING) when calling save_suppor…
moodyjon 6cfcb6e
In the general case, limit utxo selection to txo_type=other which exc…
moodyjon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1125,23 +1125,31 @@ async def test_channel_bids(self): | |
tx = await self.channel_update(claim_id) | ||
self.assertEqual(tx['outputs'][0]['amount'], '5.0') | ||
|
||
# bid changed on update | ||
# spend exactly amount available, no change | ||
tx = await self.channel_update(claim_id, bid_everything=True) | ||
await self.assertBalance(self.account, '0.0') | ||
self.assertEqual(len(tx['outputs']), 1) # no change | ||
self.assertEqual(tx['outputs'][0]['amount'], '9.991457') | ||
self.assertItemCount(await self.daemon.jsonrpc_channel_list(), 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this to the end of the test, this way you don't have to change the values of the other asserts. |
||
|
||
# bid reduced on update | ||
tx = await self.channel_update(claim_id, bid='4.0') | ||
self.assertEqual(tx['outputs'][0]['amount'], '4.0') | ||
|
||
await self.assertBalance(self.account, '5.991503') | ||
await self.assertBalance(self.account, '5.991299') | ||
|
||
# not enough funds | ||
with self.assertRaisesRegex( | ||
InsufficientFundsError, "Not enough funds to cover this transaction."): | ||
await self.channel_create('@foo2', '9.0') | ||
self.assertItemCount(await self.daemon.jsonrpc_channel_list(), 1) | ||
await self.assertBalance(self.account, '5.991503') | ||
await self.assertBalance(self.account, '5.991299') | ||
|
||
# spend exactly amount available, no change | ||
tx = await self.channel_create('@foo3', '5.981322') | ||
tx = await self.channel_create('@foo3', bid=None, bid_everything=True) | ||
await self.assertBalance(self.account, '0.0') | ||
self.assertEqual(len(tx['outputs']), 1) # no change | ||
self.assertEqual(tx['outputs'][0]['amount'], '5.98122') | ||
self.assertItemCount(await self.daemon.jsonrpc_channel_list(), 2) | ||
|
||
async def test_setting_channel_fields(self): | ||
|
@@ -1337,23 +1345,31 @@ async def test_stream_bids(self): | |
tx = await self.stream_update(claim_id) | ||
self.assertEqual(tx['outputs'][0]['amount'], '2.0') | ||
|
||
# bid changed on update | ||
# spend exactly amount available, no change | ||
tx = await self.stream_update(claim_id, bid_everything=True) | ||
await self.assertBalance(self.account, '0.0') | ||
self.assertEqual(len(tx['outputs']), 1) # no change | ||
self.assertEqual(tx['outputs'][0]['amount'], '9.993347') | ||
self.assertItemCount(await self.daemon.jsonrpc_claim_list(), 1) | ||
|
||
# bid reduced on update | ||
tx = await self.stream_update(claim_id, bid='3.0') | ||
self.assertEqual(tx['outputs'][0]['amount'], '3.0') | ||
|
||
await self.assertBalance(self.account, '6.993319') | ||
await self.assertBalance(self.account, '6.993134') | ||
|
||
# not enough funds | ||
with self.assertRaisesRegex( | ||
InsufficientFundsError, "Not enough funds to cover this transaction."): | ||
await self.stream_create('foo2', '9.0') | ||
self.assertItemCount(await self.daemon.jsonrpc_claim_list(), 1) | ||
await self.assertBalance(self.account, '6.993319') | ||
await self.assertBalance(self.account, '6.993134') | ||
|
||
# spend exactly amount available, no change | ||
tx = await self.stream_create('foo3', '6.98523') | ||
tx = await self.stream_create('foo3', bid=None, bid_everything=True) | ||
await self.assertBalance(self.account, '0.0') | ||
self.assertEqual(len(tx['outputs']), 1) # no change | ||
self.assertEqual(tx['outputs'][0]['amount'], '6.985055') | ||
self.assertItemCount(await self.daemon.jsonrpc_claim_list(), 2) | ||
|
||
async def test_stream_update_and_abandon_across_accounts(self): | ||
|
@@ -2113,7 +2129,7 @@ async def test_abandoning_stream_at_loss(self): | |
async def test_publish(self): | ||
|
||
# errors on missing arguments to create a stream | ||
with self.assertRaisesRegex(Exception, "'bid' is a required argument for new publishes."): | ||
with self.assertRaisesRegex(Exception, "None or null is not valid value for argument 'bid'."): | ||
await self.daemon.jsonrpc_publish('foo') | ||
|
||
# successfully create stream | ||
|
@@ -2271,9 +2287,32 @@ async def test_regular_supports_and_tip_supports(self): | |
self.assertEqual(txs2[0]['value'], '0.0') | ||
self.assertEqual(txs2[0]['fee'], '-0.0001415') | ||
|
||
# send all remaining funds to support the claim using account2 | ||
support = await self.out( | ||
self.daemon.jsonrpc_support_create( | ||
claim_id, amount=None, tip=False, account_id=account2.id, wallet_id='wallet2', | ||
funding_account_ids=[account2.id], amount_everything=True, blocking=True) | ||
) | ||
await self.confirm_tx(support['txid']) | ||
|
||
# account2 balance went down to 0.0 | ||
await self.assertBalance(self.account, '3.979769') | ||
await self.assertBalance(account2, '0.0') | ||
|
||
# verify that the outgoing support is marked correctly as is_tip=False in account2 | ||
txs2 = await self.transaction_list(wallet_id='wallet2') | ||
self.assertEqual(len(txs2[0]['support_info']), 1) | ||
self.assertEqual(txs2[0]['support_info'][0]['balance_delta'], '-1.9996035') | ||
self.assertEqual(txs2[0]['support_info'][0]['claim_id'], claim_id) | ||
self.assertFalse(txs2[0]['support_info'][0]['is_tip']) | ||
self.assertFalse(txs2[0]['support_info'][0]['is_spent']) | ||
self.assertEqual(txs2[0]['value'], '0.0') | ||
self.assertEqual(txs2[0]['fee'], '-0.0001135') | ||
|
||
# abandoning the tip increases balance and shows tip as spent | ||
await self.support_abandon(claim_id) | ||
await self.assertBalance(self.account, '4.979662') | ||
await self.assertBalance(account2, '0.0') | ||
txs = await self.transaction_list(account_id=self.account.id) | ||
self.assertEqual(len(txs[0]['abandon_info']), 1) | ||
self.assertEqual(len(txs[1]['support_info']), 1) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
All caps variable already means this is a constant, doesn't need a comment above it saying the same.