publish integration test works

This commit is contained in:
Lex Berezhny 2018-07-12 13:23:18 -04:00 committed by Jack Robison
parent 1eaac35a3e
commit c544e26206
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 32 additions and 8 deletions

View file

@ -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):

View file

@ -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:

View file

@ -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)