2018-07-05 04:16:02 +02:00
|
|
|
import types
|
|
|
|
|
2018-07-06 07:17:20 +02:00
|
|
|
from twisted.internet import defer
|
2018-07-05 04:16:02 +02:00
|
|
|
from orchstr8.testcase import IntegrationTestCase, d2f
|
|
|
|
from torba.constants import COIN
|
|
|
|
|
|
|
|
import lbryschema
|
|
|
|
lbryschema.BLOCKCHAIN_NAME = 'lbrycrd_regtest'
|
|
|
|
|
|
|
|
from lbrynet import conf as lbry_conf
|
|
|
|
from lbrynet.daemon.Daemon import Daemon
|
|
|
|
from lbrynet.wallet.manager import LbryWalletManager
|
2018-07-12 05:18:59 +02:00
|
|
|
from lbrynet.daemon.Components import WalletComponent, FileManager, SessionComponent
|
|
|
|
from lbrynet.file_manager.EncryptedFileManager import EncryptedFileManager
|
2018-07-05 04:16:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FakeAnalytics:
|
|
|
|
def send_new_channel(self):
|
|
|
|
pass
|
|
|
|
|
2018-07-12 05:18:59 +02:00
|
|
|
def shutdown(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class FakeSession:
|
|
|
|
storage = None
|
|
|
|
|
2018-07-05 04:16:02 +02:00
|
|
|
|
|
|
|
class CommandTestCase(IntegrationTestCase):
|
|
|
|
|
|
|
|
WALLET_MANAGER = LbryWalletManager
|
|
|
|
|
|
|
|
async def setUp(self):
|
|
|
|
await super().setUp()
|
|
|
|
|
|
|
|
lbry_conf.settings = None
|
|
|
|
lbry_conf.initialize_settings(load_conf_file=False)
|
|
|
|
lbry_conf.settings['data_dir'] = self.stack.wallet.data_path
|
|
|
|
lbry_conf.settings['lbryum_wallet_dir'] = self.stack.wallet.data_path
|
|
|
|
lbry_conf.settings['download_directory'] = self.stack.wallet.data_path
|
|
|
|
lbry_conf.settings['use_upnp'] = False
|
|
|
|
lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
|
|
|
|
lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
|
|
|
|
lbry_conf.settings['known_dht_nodes'] = []
|
|
|
|
lbry_conf.settings.node_id = None
|
|
|
|
|
|
|
|
await d2f(self.account.ensure_address_gap())
|
|
|
|
address = (await d2f(self.account.receiving.get_usable_addresses(1)))[0]
|
|
|
|
sendtxid = await self.blockchain.send_to_address(address.decode(), 10)
|
|
|
|
await self.on_transaction_id(sendtxid)
|
|
|
|
await self.blockchain.generate(1)
|
|
|
|
await self.on_transaction_id(sendtxid)
|
|
|
|
self.daemon = Daemon(FakeAnalytics())
|
2018-07-06 07:17:20 +02:00
|
|
|
self.daemon.wallet = self.manager
|
|
|
|
wallet_component = WalletComponent(self.daemon.component_manager)
|
|
|
|
wallet_component.wallet = self.manager
|
|
|
|
wallet_component._running = True
|
|
|
|
self.daemon.component_manager.components.add(wallet_component)
|
2018-07-12 05:18:59 +02:00
|
|
|
session_component = SessionComponent(self.daemon.component_manager)
|
|
|
|
session_component.session = FakeSession()
|
|
|
|
session_component._running = True
|
|
|
|
self.daemon.component_manager.components.add(session_component)
|
|
|
|
file_manager = FileManager(self.daemon.component_manager)
|
|
|
|
file_manager.file_manager = EncryptedFileManager(session_component.session, True)
|
|
|
|
file_manager._running = True
|
|
|
|
self.daemon.component_manager.components.add(file_manager)
|
2018-07-05 04:16:02 +02:00
|
|
|
|
|
|
|
|
2018-07-10 06:20:37 +02:00
|
|
|
class ChannelNewCommandTests(CommandTestCase):
|
2018-07-05 04:16:02 +02:00
|
|
|
|
2018-07-12 05:18:59 +02:00
|
|
|
VERBOSE = True
|
2018-07-05 04:16:02 +02:00
|
|
|
|
2018-07-06 07:17:20 +02:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_new_channel(self):
|
|
|
|
result = yield self.daemon.jsonrpc_channel_new('@bar', 1*COIN)
|
2018-07-05 04:16:02 +02:00
|
|
|
self.assertIn('txid', result)
|
2018-07-06 07:17:20 +02:00
|
|
|
yield self.ledger.on_transaction.deferred_where(
|
|
|
|
lambda e: e.tx.hex_id.decode() == result['txid']
|
|
|
|
)
|
|
|
|
|
2018-07-10 06:20:37 +02:00
|
|
|
|
|
|
|
class WalletBalanceCommandTests(CommandTestCase):
|
|
|
|
|
|
|
|
VERBOSE = True
|
|
|
|
|
2018-07-06 07:17:20 +02:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_wallet_balance(self):
|
|
|
|
result = yield self.daemon.jsonrpc_wallet_balance()
|
|
|
|
self.assertEqual(result, 10*COIN)
|
|
|
|
|
2018-07-10 06:20:37 +02:00
|
|
|
|
|
|
|
class PublishCommandTests(CommandTestCase):
|
|
|
|
|
|
|
|
VERBOSE = True
|
|
|
|
|
2018-07-06 07:17:20 +02:00
|
|
|
@defer.inlineCallbacks
|
|
|
|
def test_publish(self):
|
2018-07-12 18:38:45 +02:00
|
|
|
result = yield self.daemon.jsonrpc_publish('foo', 1)
|
2018-07-10 06:20:37 +02:00
|
|
|
print(result)
|