From 8840097fe2fb9818ead065efb64978e6bc6c1fad Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 9 Dec 2019 18:44:50 -0500 Subject: [PATCH] test that creator can spend purchases received --- lbry/lbry/wallet/account.py | 4 +-- .../integration/test_purchase_command.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lbry/lbry/wallet/account.py b/lbry/lbry/wallet/account.py index de61a7b6b..5ff6e40b6 100644 --- a/lbry/lbry/wallet/account.py +++ b/lbry/lbry/wallet/account.py @@ -5,7 +5,7 @@ from hashlib import sha256 from string import hexdigits import ecdsa -from lbry.wallet.constants import CLAIM_TYPES +from lbry.wallet.constants import CLAIM_TYPES, TXO_TYPES from torba.client.baseaccount import BaseAccount, HierarchicalDeterministic @@ -83,7 +83,7 @@ class Account(BaseAccount): def get_balance(self, confirmations=0, include_claims=False, **constraints): if not include_claims: - constraints.update({'txo_type': 0}) + constraints.update({'txo_type__in': (0, TXO_TYPES['purchase'])}) return super().get_balance(confirmations, **constraints) async def get_detailed_balance(self, confirmations=0, reserved_subtotals=False): diff --git a/lbry/tests/integration/test_purchase_command.py b/lbry/tests/integration/test_purchase_command.py index eda70fc7b..1e33d10dd 100644 --- a/lbry/tests/integration/test_purchase_command.py +++ b/lbry/tests/integration/test_purchase_command.py @@ -152,3 +152,29 @@ class PurchaseCommandTests(CommandTestCase): files = await self.file_list() self.assertEqual(files[0]['claim_id'], files[0]['purchase_receipt']['claim_id']) self.assertEqual(files[1]['claim_id'], files[1]['purchase_receipt']['claim_id']) + + async def test_seller_can_spend_received_purchase_funds(self): + self.merchant_address = await self.account.receiving.get_or_create_usable_address() + daemon2 = await self.add_daemon() + address2 = await daemon2.wallet_manager.default_account.receiving.get_or_create_usable_address() + sendtxid = await self.blockchain.send_to_address(address2, 2) + await self.confirm_tx(sendtxid, daemon2.ledger) + + stream = await self.priced_stream('a', '1.0') + await self.assertBalance(self.account, '9.987893') + self.assertItemCount(await self.daemon.jsonrpc_utxo_list(), 1) + + purchase = await daemon2.jsonrpc_purchase_create(stream.outputs[0].claim_id) + await self.ledger.wait(purchase) + await self.generate(1) + await self.ledger.wait(purchase) + + await self.assertBalance(self.account, '10.987893') + self.assertItemCount(await self.daemon.jsonrpc_utxo_list(), 2) + + spend = await self.daemon.jsonrpc_wallet_send('10.5', address2) + await self.ledger.wait(spend) + await self.generate(1) + await self.ledger.wait(spend) + await self.assertBalance(self.account, '0.487695') + self.assertItemCount(await self.daemon.jsonrpc_utxo_list(), 1)