integration test fix
This commit is contained in:
parent
93fc883b90
commit
d6d83a5c76
4 changed files with 43 additions and 33 deletions
|
@ -454,7 +454,7 @@ class Account:
|
|||
|
||||
def get_balance(self, confirmations=0, include_claims=False, read_only=False, **constraints):
|
||||
if not include_claims:
|
||||
constraints.update({'txo_type__in': (0, TXO_TYPES['purchase'])})
|
||||
constraints.update({'txo_type__in': (TXO_TYPES['other'], TXO_TYPES['purchase'])})
|
||||
if confirmations > 0:
|
||||
height = self.ledger.headers.height - (confirmations-1)
|
||||
constraints.update({'height__lte': height, 'height__gt': 0})
|
||||
|
@ -569,14 +569,13 @@ class Account:
|
|||
total = await get_total_balance()
|
||||
if reserved_subtotals:
|
||||
claims_balance = await get_total_balance(txo_type__in=CLAIM_TYPES)
|
||||
for amount, spent, from_me, to_me, height in await self.get_support_summary():
|
||||
if confirmations > 0 and not 0 < height <= self.ledger.headers.height - (confirmations - 1):
|
||||
for txo in await self.get_support_summary():
|
||||
if confirmations > 0 and not 0 < txo.tx_ref.height <= self.ledger.headers.height - (confirmations - 1):
|
||||
continue
|
||||
if not spent and to_me:
|
||||
if from_me:
|
||||
supports_balance += amount
|
||||
if txo.is_my_input:
|
||||
supports_balance += txo.amount
|
||||
else:
|
||||
tips_balance += amount
|
||||
tips_balance += txo.amount
|
||||
reserved = claims_balance + supports_balance + tips_balance
|
||||
else:
|
||||
reserved = await self.get_balance(
|
||||
|
@ -634,7 +633,7 @@ class Account:
|
|||
return self.ledger.get_support_count(wallet=self.wallet, accounts=[self], **constraints)
|
||||
|
||||
def get_support_summary(self):
|
||||
return self.ledger.db.get_supports_summary(account_id=self.id)
|
||||
return self.ledger.db.get_supports_summary(wallet=self.wallet, accounts=[self])
|
||||
|
||||
async def release_all_outputs(self):
|
||||
await self.ledger.db.release_all_outputs(self)
|
||||
|
|
|
@ -839,7 +839,7 @@ class Database(SQLiteMixin):
|
|||
|
||||
return txos
|
||||
|
||||
async def get_txo_count(self, unspent=False, **constraints):
|
||||
def _clean_txo_constraints_for_aggregation(self, unspent, constraints):
|
||||
constraints.pop('include_is_my_input', None)
|
||||
constraints.pop('include_is_my_output', None)
|
||||
constraints.pop('wallet', None)
|
||||
|
@ -849,9 +849,17 @@ class Database(SQLiteMixin):
|
|||
constraints.pop('order_by', None)
|
||||
if unspent:
|
||||
self.constrain_unspent(constraints)
|
||||
|
||||
async def get_txo_count(self, unspent=False, **constraints):
|
||||
self._clean_txo_constraints_for_aggregation(unspent, constraints)
|
||||
count = await self.select_txos('COUNT(*) as total', **constraints)
|
||||
return count[0]['total']
|
||||
|
||||
async def get_txo_sum(self, unspent=False, **constraints):
|
||||
self._clean_txo_constraints_for_aggregation(unspent, constraints)
|
||||
result = await self.select_txos('SUM(amount) as total', **constraints)
|
||||
return result[0]['total']
|
||||
|
||||
def get_utxos(self, read_only=False, **constraints):
|
||||
return self.get_txos(unspent=True, read_only=read_only, **constraints)
|
||||
|
||||
|
@ -1019,13 +1027,11 @@ class Database(SQLiteMixin):
|
|||
" )", (account.public_key.address, )
|
||||
)
|
||||
|
||||
def get_supports_summary(self, account_id, read_only=False):
|
||||
return self.db.execute_fetchall(f"""
|
||||
select txo.amount, exists(select * from txi where txi.txoid=txo.txoid) as spent,
|
||||
(txo.txid in
|
||||
(select txi.txid from txi join account_address a on txi.address = a.address
|
||||
where a.account = ?)) as from_me,
|
||||
(txo.address in (select address from account_address where account=?)) as to_me,
|
||||
tx.height
|
||||
from txo join tx using (txid) where txo_type={TXO_TYPES['support']}
|
||||
""", (account_id, account_id), read_only=read_only)
|
||||
def get_supports_summary(self, read_only=False, **constraints):
|
||||
return self.get_txos(
|
||||
txo_type=TXO_TYPES['support'],
|
||||
unspent=True, is_my_output=True,
|
||||
include_is_my_input=True,
|
||||
no_tx=True, read_only=read_only,
|
||||
**constraints
|
||||
)
|
||||
|
|
|
@ -122,13 +122,13 @@ class BasicTransactionTests(IntegrationTestCase):
|
|||
await self.blockchain.generate(1)
|
||||
await self.ledger.wait(tx) # confirmed
|
||||
|
||||
tx = (await account1.get_transactions())[1]
|
||||
tx = (await account1.get_transactions(include_is_my_input=True, include_is_my_output=True))[1]
|
||||
self.assertEqual(satoshis_to_coins(tx.inputs[0].amount), '1.1')
|
||||
self.assertEqual(satoshis_to_coins(tx.inputs[1].amount), '1.1')
|
||||
self.assertEqual(satoshis_to_coins(tx.outputs[0].amount), '2.0')
|
||||
self.assertEqual(tx.outputs[0].get_address(self.ledger), address2)
|
||||
self.assertFalse(tx.outputs[0].is_change)
|
||||
self.assertTrue(tx.outputs[1].is_change)
|
||||
self.assertTrue(tx.outputs[0].is_internal_transfer)
|
||||
self.assertTrue(tx.outputs[1].is_internal_transfer)
|
||||
|
||||
async def test_history_edge_cases(self):
|
||||
await self.blockchain.generate(300)
|
||||
|
|
|
@ -82,6 +82,11 @@ class WalletCommands(CommandTestCase):
|
|||
|
||||
async def test_granular_balances(self):
|
||||
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||
wallet2 = await self.daemon.jsonrpc_wallet_create('foo', create_account=True)
|
||||
account3 = wallet2.default_account
|
||||
address3 = await self.daemon.jsonrpc_address_unused(account3.id, wallet2.id)
|
||||
await self.confirm_tx(await self.blockchain.send_to_address(address3, 1))
|
||||
await self.generate(1)
|
||||
|
||||
account_balance = self.daemon.jsonrpc_account_balance
|
||||
wallet_balance = self.daemon.jsonrpc_wallet_balance
|
||||
|
@ -128,7 +133,7 @@ class WalletCommands(CommandTestCase):
|
|||
|
||||
# tip received
|
||||
support1 = await self.support_create(
|
||||
self.get_claim_id(stream1), '0.3', tip=True, funding_account_ids=[account2.id]
|
||||
self.get_claim_id(stream1), '0.3', tip=True, wallet_id=wallet2.id
|
||||
)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '9.27741',
|
||||
|
@ -137,8 +142,8 @@ class WalletCommands(CommandTestCase):
|
|||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.977268',
|
||||
'available': '6.677268',
|
||||
'total': '10.27741',
|
||||
'available': '6.97741',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||
})
|
||||
|
@ -153,8 +158,8 @@ class WalletCommands(CommandTestCase):
|
|||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.977161',
|
||||
'available': '6.977161',
|
||||
'total': '10.277303',
|
||||
'available': '7.277303',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
|
@ -165,17 +170,17 @@ class WalletCommands(CommandTestCase):
|
|||
|
||||
# tip another claim
|
||||
await self.support_create(
|
||||
self.get_claim_id(stream2), '0.2', tip=True, funding_account_ids=[self.account.id]
|
||||
self.get_claim_id(stream2), '0.2', tip=True, wallet_id=wallet2.id
|
||||
)
|
||||
self.assertEqual(await account_balance(), {
|
||||
'total': '9.077157',
|
||||
'available': '6.077157',
|
||||
'total': '9.277303',
|
||||
'available': '6.277303',
|
||||
'reserved': '3.0',
|
||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||
})
|
||||
self.assertEqual(await wallet_balance(), {
|
||||
'total': '9.938908',
|
||||
'available': '6.638908',
|
||||
'total': '10.439196',
|
||||
'available': '7.139196',
|
||||
'reserved': '3.3',
|
||||
'reserved_subtotals': {'claims': '1.1', 'supports': '2.0', 'tips': '0.2'}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue