Integration test for wallet_send (#1395)

This commit is contained in:
hackrush 2018-09-03 21:11:30 +05:30 committed by Lex Berezhny
parent e7634b74c8
commit d99ce5f3d6
2 changed files with 44 additions and 4 deletions

View file

@ -1042,7 +1042,7 @@ class Daemon(AuthJSONRPCServer):
Returns: Returns:
If sending to an address: If sending to an address:
(dict) true if payment successfully scheduled (dict) Dictionary containing the transaction information
{ {
"hex": (str) raw transaction, "hex": (str) raw transaction,
"inputs": (list) inputs(dict) used for the transaction, "inputs": (list) inputs(dict) used for the transaction,
@ -1163,14 +1163,16 @@ class Daemon(AuthJSONRPCServer):
@requires("wallet") @requires("wallet")
@defer.inlineCallbacks @defer.inlineCallbacks
def jsonrpc_account_balance(self, address=None, include_unconfirmed=False): def jsonrpc_account_balance(self, account_id=None, address=None, include_unconfirmed=False):
""" """
Return the balance of an account Return the balance of an account
Usage: Usage:
account_balance [<address> | --address=<address>] [--include_unconfirmed] account_balance [<account_id>] [<address> | --address=<address>] [--include_unconfirmed]
Options: Options:
--account=<account_id> : (str) If provided only the balance for this
account will be given
--address=<address> : (str) If provided only the balance for this --address=<address> : (str) If provided only the balance for this
address will be given address will be given
--include_unconfirmed : (bool) Include unconfirmed --include_unconfirmed : (bool) Include unconfirmed
@ -1180,7 +1182,11 @@ class Daemon(AuthJSONRPCServer):
""" """
if address is not None: if address is not None:
raise NotImplementedError("Limiting by address needs to be re-implemented in new wallet.") raise NotImplementedError("Limiting by address needs to be re-implemented in new wallet.")
dewies = yield self.default_account.get_balance( if account_id is not None:
account = self.get_account_or_error('account', account_id)
else:
account = self.default_account
dewies = yield account.get_balance(
0 if include_unconfirmed else 6 0 if include_unconfirmed else 6
) )
return Decimal(dewies) / COIN return Decimal(dewies) / COIN
@ -1227,6 +1233,7 @@ class Daemon(AuthJSONRPCServer):
self.default_wallet.save() self.default_wallet.save()
result = account.to_dict() result = account.to_dict()
result['id'] = account.id
result['status'] = 'added' result['status'] = 'added'
result.pop('certificates', None) result.pop('certificates', None)
result['is_default'] = self.default_wallet.accounts[0] == account result['is_default'] = self.default_wallet.accounts[0] == account
@ -1262,6 +1269,7 @@ class Daemon(AuthJSONRPCServer):
self.default_wallet.save() self.default_wallet.save()
result = account.to_dict() result = account.to_dict()
result['id'] = account.id
result['status'] = 'created' result['status'] = 'created'
result.pop('certificates', None) result.pop('certificates', None)
result['is_default'] = self.default_wallet.accounts[0] == account result['is_default'] = self.default_wallet.accounts[0] == account
@ -1286,6 +1294,7 @@ class Daemon(AuthJSONRPCServer):
self.default_wallet.accounts.remove(account) self.default_wallet.accounts.remove(account)
self.default_wallet.save() self.default_wallet.save()
result = account.to_dict() result = account.to_dict()
result['id'] = account.id
result['status'] = 'removed' result['status'] = 'removed'
result.pop('certificates', None) result.pop('certificates', None)
return result return result
@ -1346,6 +1355,7 @@ class Daemon(AuthJSONRPCServer):
self.default_wallet.save() self.default_wallet.save()
result = account.to_dict() result = account.to_dict()
result['id'] = account.id
result.pop('certificates', None) result.pop('certificates', None)
result['is_default'] = self.default_wallet.accounts[0] == account result['is_default'] = self.default_wallet.accounts[0] == account
return result return result

View file

@ -80,9 +80,13 @@ class FakeAnalytics:
def send_claim_action(self, action): def send_claim_action(self, action):
pass pass
def send_credits_sent(self):
pass
class CommandTestCase(IntegrationTestCase): class CommandTestCase(IntegrationTestCase):
timeout = 180
WALLET_MANAGER = LbryWalletManager WALLET_MANAGER = LbryWalletManager
async def setUp(self): async def setUp(self):
@ -298,6 +302,32 @@ class EpicAdventuresOfChris45(CommandTestCase):
response = yield self.out(self.daemon.jsonrpc_resolve(uri='lbry://@spam/hovercraft')) response = yield self.out(self.daemon.jsonrpc_resolve(uri='lbry://@spam/hovercraft'))
self.assertNotIn('claim', response['lbry://@spam/hovercraft']) self.assertNotIn('claim', response['lbry://@spam/hovercraft'])
# After abandoning he just waits for his LBCs to be returned to his account
yield self.d_generate(5)
result = yield self.daemon.jsonrpc_account_balance()
self.assertEqual(result, Decimal('8.9693585'))
# Amidst all this Chris45 receives a call from his friend Ramsey54
# who says that it is of utmost urgency that Chris45 transfer him
# 1 LBC to which Chris45 readily obliges
ramsey_account_id = (yield self.daemon.jsonrpc_account_create("Ramsey54"))['id']
ramsey_account = self.daemon.get_account_or_error('', ramsey_account_id)
ramsey_address = yield ramsey_account.receiving.get_or_create_usable_address()
result = yield self.out(self.daemon.jsonrpc_wallet_send(1, ramsey_address))
self.assertIn("txid", result)
yield self.d_confirm_tx(result['txid'])
# Chris45 then eagerly waits for 6 confirmations to check his balance and then calls Ramsey54 to verify whether
# he received it or not
yield self.d_generate(5)
result = yield self.daemon.jsonrpc_account_balance()
# Chris45's balance was correct
self.assertEqual(result, Decimal('7.9692345'))
# Ramsey54 too assured him that he had received the 1 LBC and thanks him
result = yield self.daemon.jsonrpc_account_balance(ramsey_account_id)
self.assertEqual(result, Decimal('1.0'))
class AccountManagement(CommandTestCase): class AccountManagement(CommandTestCase):