fixup balance tests and other stuff
This commit is contained in:
parent
1c941a355b
commit
46d89929ba
3 changed files with 97 additions and 56 deletions
|
@ -1959,10 +1959,10 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
txo.generate_channel_private_key()
|
txo.generate_channel_private_key()
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await tx.sign([account])
|
await tx.sign(funding_accounts)
|
||||||
account.add_channel_private_key(txo.private_key)
|
account.add_channel_private_key(txo.private_key)
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, txo, claim_address, claim, name, dewies_to_lbc(amount)
|
tx, txo, claim_address, claim, name, dewies_to_lbc(amount)
|
||||||
)])
|
)])
|
||||||
|
@ -2102,10 +2102,10 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
new_txo.script.generate()
|
new_txo.script.generate()
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await tx.sign([account])
|
await tx.sign(funding_accounts)
|
||||||
account.add_channel_private_key(new_txo.private_key)
|
account.add_channel_private_key(new_txo.private_key)
|
||||||
self.default_wallet.save()
|
self.default_wallet.save()
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
||||||
)])
|
)])
|
||||||
|
@ -2155,7 +2155,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.analytics_manager.send_claim_action('abandon')
|
await self.analytics_manager.send_claim_action('abandon')
|
||||||
else:
|
else:
|
||||||
await account.ledger.release_tx(tx)
|
await account.ledger.release_tx(tx)
|
||||||
|
@ -2498,10 +2498,10 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
if channel:
|
if channel:
|
||||||
new_txo.sign(channel)
|
new_txo.sign(channel)
|
||||||
await tx.sign([account])
|
await tx.sign(funding_accounts)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, new_txo, claim_address, claim, name, dewies_to_lbc(amount)
|
tx, new_txo, claim_address, claim, name, dewies_to_lbc(amount)
|
||||||
)])
|
)])
|
||||||
|
@ -2694,10 +2694,10 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
if channel:
|
if channel:
|
||||||
new_txo.sign(channel)
|
new_txo.sign(channel)
|
||||||
await tx.sign([account])
|
await tx.sign(funding_accounts)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.storage.save_claims([self._old_get_temp_claim_info(
|
await self.storage.save_claims([self._old_get_temp_claim_info(
|
||||||
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
tx, new_txo, claim_address, new_txo.claim, new_txo.claim_name, dewies_to_lbc(amount)
|
||||||
)])
|
)])
|
||||||
|
@ -2749,7 +2749,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.analytics_manager.send_claim_action('abandon')
|
await self.analytics_manager.send_claim_action('abandon')
|
||||||
else:
|
else:
|
||||||
await account.ledger.release_tx(tx)
|
await account.ledger.release_tx(tx)
|
||||||
|
@ -2827,12 +2827,12 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
Returns: {Transaction}
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
|
||||||
funding_accounts = self.get_accounts_or_all(funding_account_ids)
|
funding_accounts = self.get_accounts_or_all(funding_account_ids)
|
||||||
amount = self.get_dewies_or_error("amount", amount)
|
amount = self.get_dewies_or_error("amount", amount)
|
||||||
claim = await self.ledger.get_claim_by_claim_id(claim_id)
|
claim = await self.ledger.get_claim_by_claim_id(claim_id)
|
||||||
claim_address = claim.get_address(self.ledger)
|
claim_address = claim.get_address(self.ledger)
|
||||||
if not tip:
|
if not tip:
|
||||||
|
account = self.get_account_or_default(account_id)
|
||||||
claim_address = await account.receiving.get_or_create_usable_address()
|
claim_address = await account.receiving.get_or_create_usable_address()
|
||||||
|
|
||||||
tx = await Transaction.support(
|
tx = await Transaction.support(
|
||||||
|
@ -2840,8 +2840,8 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await tx.sign([account])
|
await tx.sign(funding_accounts)
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.storage.save_supports({claim_id: [{
|
await self.storage.save_supports({claim_id: [{
|
||||||
'txid': tx.id,
|
'txid': tx.id,
|
||||||
'nout': tx.position,
|
'nout': tx.position,
|
||||||
|
@ -2851,7 +2851,7 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
}]})
|
}]})
|
||||||
await self.analytics_manager.send_claim_action('new_support')
|
await self.analytics_manager.send_claim_action('new_support')
|
||||||
else:
|
else:
|
||||||
await account.ledger.release_tx(tx)
|
await self.ledger.release_tx(tx)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
@ -2903,12 +2903,18 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
|
|
||||||
Returns: {Transaction}
|
Returns: {Transaction}
|
||||||
"""
|
"""
|
||||||
account = self.get_account_or_default(account_id)
|
if account_id:
|
||||||
|
account = self.get_account_or_error(account_id)
|
||||||
|
funding_accounts = [account]
|
||||||
|
get_supports = account.get_supports
|
||||||
|
else:
|
||||||
|
funding_accounts = self.ledger.accounts
|
||||||
|
get_supports = self.ledger.get_supports
|
||||||
|
|
||||||
if txid is not None and nout is not None:
|
if txid is not None and nout is not None:
|
||||||
supports = await account.get_supports(**{'txo.txid': txid, 'txo.position': nout})
|
supports = await get_supports(**{'txo.txid': txid, 'txo.position': nout})
|
||||||
elif claim_id is not None:
|
elif claim_id is not None:
|
||||||
supports = await account.get_supports(claim_id=claim_id)
|
supports = await get_supports(claim_id=claim_id)
|
||||||
else:
|
else:
|
||||||
raise Exception('Must specify claim_id, or txid and nout')
|
raise Exception('Must specify claim_id, or txid and nout')
|
||||||
|
|
||||||
|
@ -2929,14 +2935,14 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
]
|
]
|
||||||
|
|
||||||
tx = await Transaction.create(
|
tx = await Transaction.create(
|
||||||
[Input.spend(txo) for txo in supports], outputs, [account], account
|
[Input.spend(txo) for txo in supports], outputs, funding_accounts, funding_accounts[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
await self.broadcast_or_release(account, tx, blocking)
|
await self.broadcast_or_release(tx, blocking)
|
||||||
await self.analytics_manager.send_claim_action('abandon')
|
await self.analytics_manager.send_claim_action('abandon')
|
||||||
else:
|
else:
|
||||||
await account.ledger.release_tx(tx)
|
await self.ledger.release_tx(tx)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
|
@ -3567,13 +3573,13 @@ class Daemon(metaclass=JSONRPCServerType):
|
||||||
comment_client.sign_comment(abandon_comment_body, channel, abandon=True)
|
comment_client.sign_comment(abandon_comment_body, channel, abandon=True)
|
||||||
return await comment_client.jsonrpc_post(self.conf.comment_server, 'delete_comment', abandon_comment_body)
|
return await comment_client.jsonrpc_post(self.conf.comment_server, 'delete_comment', abandon_comment_body)
|
||||||
|
|
||||||
async def broadcast_or_release(self, account, tx, blocking=False):
|
async def broadcast_or_release(self, tx, blocking=False):
|
||||||
try:
|
try:
|
||||||
await account.ledger.broadcast(tx)
|
await self.ledger.broadcast(tx)
|
||||||
if blocking:
|
if blocking:
|
||||||
await account.ledger.wait(tx)
|
await self.ledger.wait(tx)
|
||||||
except:
|
except:
|
||||||
await account.ledger.release_tx(tx)
|
await self.ledger.release_tx(tx)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def valid_address_or_error(self, address):
|
def valid_address_or_error(self, address):
|
||||||
|
|
|
@ -38,42 +38,77 @@ class TransactionCommandsTestCase(CommandTestCase):
|
||||||
await self.assertBalance(self.account, '11.0')
|
await self.assertBalance(self.account, '11.0')
|
||||||
|
|
||||||
async def test_granular_balances(self):
|
async def test_granular_balances(self):
|
||||||
initial_balance = await self.daemon.jsonrpc_account_balance(reserved_subtotals=True)
|
account_balance = self.daemon.jsonrpc_account_balance
|
||||||
self.assertEqual({
|
|
||||||
|
self.assertEqual(await account_balance(reserved_subtotals=False), {
|
||||||
|
'total': '10.0',
|
||||||
|
'available': '10.0',
|
||||||
|
'reserved': '0.0',
|
||||||
|
'reserved_subtotals': None
|
||||||
|
})
|
||||||
|
|
||||||
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
'total': '10.0',
|
'total': '10.0',
|
||||||
'available': '10.0',
|
'available': '10.0',
|
||||||
'reserved': '0.0',
|
'reserved': '0.0',
|
||||||
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
'reserved_subtotals': {'claims': '0.0', 'supports': '0.0', 'tips': '0.0'}
|
||||||
}, initial_balance)
|
})
|
||||||
first_claim_id = self.get_claim_id(await self.stream_create('granularity', bid='3.0'))
|
|
||||||
await self.stream_update(first_claim_id, data=b'news', bid='1.0')
|
# claim with update + supporting our own claim
|
||||||
await self.support_create(first_claim_id, bid='2.0')
|
stream1 = await self.stream_create('granularity', '3.0')
|
||||||
second_account_id = (await self.out(self.daemon.jsonrpc_account_create("Tip-er")))['id']
|
await self.stream_update(self.get_claim_id(stream1), data=b'news', bid='1.0')
|
||||||
second_accound_address = await self.daemon.jsonrpc_address_unused(second_account_id)
|
await self.support_create(self.get_claim_id(stream1), '2.0')
|
||||||
await self.confirm_tx((await self.daemon.jsonrpc_account_send('1.0', second_accound_address)).id)
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
self.assertEqual({
|
'total': '9.977534',
|
||||||
|
'available': '6.977534',
|
||||||
|
'reserved': '3.0',
|
||||||
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||||
|
})
|
||||||
|
|
||||||
|
account2 = await self.daemon.jsonrpc_account_create("Tip-er")
|
||||||
|
address2 = await self.daemon.jsonrpc_address_unused(account2.id)
|
||||||
|
|
||||||
|
# send lbc to someone else
|
||||||
|
tx = await self.daemon.jsonrpc_account_send('1.0', address2)
|
||||||
|
await self.confirm_tx(tx.id)
|
||||||
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
'total': '8.97741',
|
'total': '8.97741',
|
||||||
'available': '5.97741',
|
'available': '5.97741',
|
||||||
'reserved': '3.0',
|
'reserved': '3.0',
|
||||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||||
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=True))
|
})
|
||||||
second_claim_id = self.get_claim_id(await self.stream_create(
|
|
||||||
name='granularity-is-cool', account_id=second_account_id, bid='0.1'))
|
# tip received
|
||||||
await self.daemon.jsonrpc_support_create(second_claim_id, '0.5', tip=True)
|
support1 = await self.support_create(
|
||||||
first_account_tip_txid = await self.confirm_tx((await self.daemon.jsonrpc_support_create(
|
self.get_claim_id(stream1), '0.3', tip=True, funding_account_ids=[account2.id]
|
||||||
first_claim_id, '0.3', tip=True, account_id=second_account_id)).id)
|
)
|
||||||
for with_subtotals in (True, False):
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
self.assertEqual({
|
'total': '9.27741',
|
||||||
'total': '8.777264',
|
'available': '5.97741',
|
||||||
'available': '5.477264',
|
|
||||||
'reserved': '3.3',
|
'reserved': '3.3',
|
||||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'} if with_subtotals else None
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.3'}
|
||||||
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=with_subtotals))
|
})
|
||||||
await self.confirm_tx((await self.daemon.jsonrpc_support_abandon(txid=first_account_tip_txid, nout=0)).id)
|
|
||||||
for with_subtotals in (True, False):
|
# tip claimed
|
||||||
self.assertEqual({
|
tx = await self.daemon.jsonrpc_support_abandon(txid=support1['txid'], nout=0)
|
||||||
'total': '8.777157',
|
await self.confirm_tx(tx.id)
|
||||||
'available': '5.777157',
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
|
'total': '9.277303',
|
||||||
|
'available': '6.277303',
|
||||||
'reserved': '3.0',
|
'reserved': '3.0',
|
||||||
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'} if with_subtotals else None
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||||
}, await self.daemon.jsonrpc_account_balance(reserved_subtotals=with_subtotals))
|
})
|
||||||
|
|
||||||
|
stream2 = await self.stream_create(
|
||||||
|
'granularity-is-cool', '0.1', account_id=account2.id, funding_account_ids=[account2.id]
|
||||||
|
)
|
||||||
|
|
||||||
|
# tip another claim
|
||||||
|
await self.support_create(
|
||||||
|
self.get_claim_id(stream2), '0.2', tip=True, funding_account_ids=[self.account.id])
|
||||||
|
self.assertEqual(await account_balance(reserved_subtotals=True), {
|
||||||
|
'total': '9.077157',
|
||||||
|
'available': '6.077157',
|
||||||
|
'reserved': '3.0',
|
||||||
|
'reserved_subtotals': {'claims': '1.0', 'supports': '2.0', 'tips': '0.0'}
|
||||||
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue