From c544e262061610de58ee82a79a2eb7812ee7030e Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Thu, 12 Jul 2018 13:23:18 -0400 Subject: [PATCH] publish integration test works --- lbrynet/daemon/Daemon.py | 20 +++++++++++++++----- lbrynet/wallet/manager.py | 4 +++- tests/integration/wallet/test_commands.py | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/lbrynet/daemon/Daemon.py b/lbrynet/daemon/Daemon.py index f026525da..778e942df 100644 --- a/lbrynet/daemon/Daemon.py +++ b/lbrynet/daemon/Daemon.py @@ -371,19 +371,29 @@ class Daemon(AuthJSONRPCServer): if not file_path: stream_hash = yield self.storage.get_stream_hash_for_sd_hash( claim_dict['stream']['source']['source']) - claim_out = yield publisher.publish_stream(name, bid, claim_dict, stream_hash, claim_address, + tx = yield publisher.publish_stream(name, bid, claim_dict, stream_hash, claim_address, change_address) else: - claim_out = yield publisher.create_and_publish_stream(name, bid, claim_dict, file_path, + tx = yield publisher.create_and_publish_stream(name, bid, claim_dict, file_path, claim_address, change_address) if conf.settings['reflect_uploads']: d = reupload.reflect_file(publisher.lbry_file) d.addCallbacks(lambda _: log.info("Reflected new publication to lbry://%s", name), log.exception) self.analytics_manager.send_claim_action('publish') - log.info("Success! Published to lbry://%s txid: %s nout: %d", name, claim_out['txid'], - claim_out['nout']) - defer.returnValue(claim_out) + nout = 0 + script = tx.outputs[nout].script + log.info("Success! Published to lbry://%s txid: %s nout: %d", name, tx.hex_id.decode(), nout) + defer.returnValue({ + "success": True, + "txid": tx.hex_id.decode(), + "nout": nout, + "tx": hexlify(tx.raw), + "fee": str(Decimal(tx.fee) / COIN), + "claim_id": tx.get_claim_id(0), + "value": hexlify(script.values['claim']), + "claim_address": self.ledger.hash160_to_address(script.values['pubkey_hash']) + }) @defer.inlineCallbacks def _resolve(self, *uris, **kwargs): diff --git a/lbrynet/wallet/manager.py b/lbrynet/wallet/manager.py index 0c383ea4d..3353fcf60 100644 --- a/lbrynet/wallet/manager.py +++ b/lbrynet/wallet/manager.py @@ -7,6 +7,7 @@ from torba.wallet import WalletStorage from lbryschema.uri import parse_lbry_uri from lbryschema.error import URIParseError +from lbryschema.claim import ClaimDict from .ledger import MainNetLedger # pylint: disable=unused-import from .account import generate_certificate @@ -148,8 +149,9 @@ class LbryWalletManager(BaseWalletManager): return defer.succeed([]) @defer.inlineCallbacks - def claim_name(self, name, amount, claim, certificate=None, claim_address=None): + def claim_name(self, name, amount, claim_dict, certificate=None, claim_address=None): account = self.default_account + claim = ClaimDict.load_dict(claim_dict) if not claim_address: claim_address = yield account.receiving.get_or_create_usable_address() if certificate: diff --git a/tests/integration/wallet/test_commands.py b/tests/integration/wallet/test_commands.py index bc8089d90..447af0ed3 100644 --- a/tests/integration/wallet/test_commands.py +++ b/tests/integration/wallet/test_commands.py @@ -10,7 +10,7 @@ lbryschema.BLOCKCHAIN_NAME = 'lbrycrd_regtest' from lbrynet import conf as lbry_conf from lbrynet.daemon.Daemon import Daemon from lbrynet.wallet.manager import LbryWalletManager -from lbrynet.daemon.Components import WalletComponent, FileManager, SessionComponent +from lbrynet.daemon.Components import WalletComponent, FileManager, SessionComponent, DatabaseComponent from lbrynet.file_manager.EncryptedFileManager import EncryptedFileManager @@ -21,6 +21,9 @@ class FakeAnalytics: def shutdown(self): pass + def send_claim_action(self, action): + pass + class FakeSession: storage = None @@ -64,6 +67,10 @@ class CommandTestCase(IntegrationTestCase): file_manager.file_manager = EncryptedFileManager(session_component.session, True) file_manager._running = True self.daemon.component_manager.components.add(file_manager) + storage_component = DatabaseComponent(self.daemon.component_manager) + await d2f(storage_component.start()) + self.daemon.component_manager.components.add(storage_component) + self.daemon.storage = storage_component.storage class ChannelNewCommandTests(CommandTestCase): @@ -95,5 +102,10 @@ class PublishCommandTests(CommandTestCase): @defer.inlineCallbacks def test_publish(self): - result = yield self.daemon.jsonrpc_publish('foo', 1) + result = yield self.daemon.jsonrpc_publish('foo', 1, sources={ + 'version': '_0_0_1', + 'sourceType': 'lbry_sd_hash', + 'source': '0' * 96, + 'contentType': '' + }) print(result)