Beispiel #1
0
 def test_cannot_set_options_passed_by_command_line(self):
     fake_read_user = lambda _: {"electrum_path": "b"}
     read_user_dir = lambda: self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.set_key("electrum_path", "c")
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
 def test_cannot_set_options_passed_by_command_line(self):
     fake_read_user = lambda _: {"electrum_path": "b"}
     read_user_dir = lambda : self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.set_key("electrum_path", "c")
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
 def test_can_set_options_set_in_user_config(self):
     another_path = tempfile.mkdtemp()
     fake_read_user = lambda _: {"electrum_path": self.electrum_dir}
     read_user_dir = lambda : self.user_dir
     config = SimpleConfig(options={},
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.set_key("electrum_path", another_path)
     self.assertEqual(another_path, config.get("electrum_path"))
Beispiel #4
0
 def test_can_set_options_set_in_user_config(self):
     another_path = tempfile.mkdtemp()
     fake_read_user = lambda _: {"electrum_path": self.electrum_dir}
     read_user_dir = lambda: self.user_dir
     config = SimpleConfig(options={},
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.set_key("electrum_path", another_path)
     self.assertEqual(another_path, config.get("electrum_path"))
 def test_simple_config_command_line_overrides_everything(self):
     """Options passed by command line override all other configuration
     sources"""
     fake_read_user = lambda _: {"electrum_path": "b"}
     read_user_dir = lambda : self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
Beispiel #6
0
 def test_simple_config_command_line_overrides_everything(self):
     """Options passed by command line override all other configuration
     sources"""
     fake_read_user = lambda _: {"electrum_path": "b"}
     read_user_dir = lambda: self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
Beispiel #7
0
 def test_simple_config_user_config_is_used_if_others_arent_specified(self):
     """If no system-wide configuration and no command-line options are
     specified, the user configuration is used instead."""
     fake_read_user = lambda _: {"electrum_path": self.electrum_dir}
     read_user_dir = lambda: self.user_dir
     config = SimpleConfig(options={},
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
 def test_simple_config_user_config_is_used_if_others_arent_specified(self):
     """If no system-wide configuration and no command-line options are
     specified, the user configuration is used instead."""
     fake_read_user = lambda _: {"electrum_path": self.electrum_dir}
     read_user_dir = lambda : self.user_dir
     config = SimpleConfig(options={},
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(self.options.get("electrum_path"),
                      config.get("electrum_path"))
 def test_fee_to_depth(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100000], [10, 120000], [6, 150000], [5, 125000], [1, 36000000]]
     self.assertEqual(100000, config.fee_to_depth(500))
     self.assertEqual(100000, config.fee_to_depth(50))
     self.assertEqual(100000, config.fee_to_depth(49))
     self.assertEqual(220000, config.fee_to_depth(48))
     self.assertEqual(220000, config.fee_to_depth(10))
     self.assertEqual(370000, config.fee_to_depth(9))
     self.assertEqual(370000, config.fee_to_depth(6.5))
     self.assertEqual(370000, config.fee_to_depth(6))
     self.assertEqual(495000, config.fee_to_depth(5.5))
     self.assertEqual(36495000, config.fee_to_depth(0.5))
 def test_user_config_is_not_written_with_read_only_config(self):
     """The user config does not contain command-line options when saved."""
     fake_read_user = lambda _: {"something": "a"}
     read_user_dir = lambda : self.user_dir
     self.options.update({"something": "c"})
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.save_user_config()
     contents = None
     with open(os.path.join(self.electrum_dir, "config"), "r") as f:
         contents = f.read()
     result = ast.literal_eval(contents)
     result.pop('config_version', None)
     self.assertEqual({"something": "a"}, result)
Beispiel #11
0
 def test_user_config_is_not_written_with_read_only_config(self):
     """The user config does not contain command-line options when saved."""
     fake_read_user = lambda _: {"something": "a"}
     read_user_dir = lambda: self.user_dir
     self.options.update({"something": "c"})
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     config.save_user_config()
     contents = None
     with open(os.path.join(self.electrum_dir, "config"), "r") as f:
         contents = f.read()
     result = ast.literal_eval(contents)
     result.pop('config_version', None)
     self.assertEqual({"something": "a"}, result)
Beispiel #12
0
    def setUp(self):
        super(WalletTestCase, self).setUp()
        self.user_dir = tempfile.mkdtemp()
        self.config = SimpleConfig({'electrum_path': self.user_dir})

        self.wallet_path = os.path.join(self.user_dir, "somewallet")

        self._saved_stdout = sys.stdout
        self._stdout_buffer = StringIO()
        sys.stdout = self._stdout_buffer
Beispiel #13
0
 def test_simple_config_key_rename(self):
     """auto_cycle was renamed auto_connect"""
     fake_read_user = lambda _: {"auto_cycle": True}
     read_user_dir = lambda: self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(config.get("auto_connect"), True)
     self.assertEqual(config.get("auto_cycle"), None)
     fake_read_user = lambda _: {"auto_connect": False, "auto_cycle": True}
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(config.get("auto_connect"), False)
     self.assertEqual(config.get("auto_cycle"), None)
 def test_simple_config_key_rename(self):
     """auto_cycle was renamed auto_connect"""
     fake_read_user = lambda _: {"auto_cycle": True}
     read_user_dir = lambda : self.user_dir
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(config.get("auto_connect"), True)
     self.assertEqual(config.get("auto_cycle"), None)
     fake_read_user = lambda _: {"auto_connect": False, "auto_cycle": True}
     config = SimpleConfig(options=self.options,
                           read_user_config_function=fake_read_user,
                           read_user_dir_function=read_user_dir)
     self.assertEqual(config.get("auto_connect"), False)
     self.assertEqual(config.get("auto_cycle"), None)
 def setUp(self):
     super(BaseWizardTestCase, self).setUp()
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
     self.wallet_path = os.path.join(self.electrum_path, "somewallet")
     self.wizard = SimpleWizard(self.config, None)
 def setUp(self):
     super().setUp()
     self.data_dir = self.electrum_path
     make_dir(os.path.join(self.data_dir, 'forks'))
     self.config = SimpleConfig({'electrum_path': self.data_dir})
     blockchain.blockchains = {}
Beispiel #17
0
 def setUp(self):
     self.config = SimpleConfig({'electrum_path': tempfile.mkdtemp(prefix="test_network")})
     self.interface = MockInterface(self.config)
 def setUp(self):
     super().setUp()
     self.asyncio_loop, self._stop_loop, self._loop_thread = create_and_start_event_loop()
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
Beispiel #19
0
 def test_fee_to_depth(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100000], [10, 120000], [6, 150000],
                            [5, 125000], [1, 36000000]]
     self.assertEqual(100000, config.fee_to_depth(500))
     self.assertEqual(100000, config.fee_to_depth(50))
     self.assertEqual(100000, config.fee_to_depth(49))
     self.assertEqual(220000, config.fee_to_depth(48))
     self.assertEqual(220000, config.fee_to_depth(10))
     self.assertEqual(370000, config.fee_to_depth(9))
     self.assertEqual(370000, config.fee_to_depth(6.5))
     self.assertEqual(370000, config.fee_to_depth(6))
     self.assertEqual(495000, config.fee_to_depth(5.5))
     self.assertEqual(36495000, config.fee_to_depth(0.5))
Beispiel #20
0
 def test_depth_target_to_fee(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100110], [10, 121301], [6, 153731],
                            [5, 125872], [1, 36488810]]
     self.assertEqual(2 * 1000, config.depth_target_to_fee(1000000))
     self.assertEqual(6 * 1000, config.depth_target_to_fee(500000))
     self.assertEqual(7 * 1000, config.depth_target_to_fee(250000))
     self.assertEqual(11 * 1000, config.depth_target_to_fee(200000))
     self.assertEqual(15 * 1000, config.depth_target_to_fee(100000))
     config.mempool_fees = []
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**7))
     config.mempool_fees = [[1, 36488810]]
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**7))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**8))
     config.mempool_fees = [[5, 125872], [1, 36488810]]
     self.assertEqual(6 * 1000, config.depth_target_to_fee(10**5))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**6))
     self.assertEqual(2 * 1000, config.depth_target_to_fee(10**7))
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**8))
     config.mempool_fees = []
     self.assertEqual(1 * 1000, config.depth_target_to_fee(10**5))
     config.mempool_fees = None
     self.assertEqual(None, config.depth_target_to_fee(10**5))
Beispiel #21
0
#!/usr/bin/env python3
import sys
import asyncio

from electrum_dash.network import filter_protocol, Network
from electrum_dash.util import create_and_start_event_loop, log_exceptions
from electrum_dash.simple_config import SimpleConfig

try:
    txid = sys.argv[1]
except:
    print("usage: txradar txid")
    sys.exit(1)

config = SimpleConfig()

loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()


@log_exceptions
async def f():
    try:
        peers = await network.get_peers()
        peers = filter_protocol(peers)
        results = await network.send_multiple_requests(
            peers, 'blockchain.transaction.get', [txid])
        r1, r2 = [], []
        for k, v in results.items():
            (r1 if not isinstance(v, Exception) else r2).append(k)
Beispiel #22
0
 def setUp(self):
     super().setUp()
     self.config = SimpleConfig({'electrum_path': self.electrum_path})
     self.interface = MockInterface(self.config)
Beispiel #23
0
import os

from electrum_dash.simple_config import SimpleConfig
from electrum_dash import constants
from electrum_dash.daemon import Daemon
from electrum_dash.storage import WalletStorage
from electrum_dash.wallet import Wallet, create_new_wallet
from electrum_dash.commands import Commands


config = SimpleConfig({"testnet": True})  # to use ~/.electrum-dash/testnet as datadir
constants.set_testnet()  # to set testnet magic bytes
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

# get wallet on disk
wallet_dir = os.path.dirname(config.get_wallet_path())
wallet_path = os.path.join(wallet_dir, "test_wallet")
if not os.path.exists(wallet_path):
    create_new_wallet(path=wallet_path)

# open wallet
storage = WalletStorage(wallet_path)
wallet = Wallet(storage)
wallet.start_network(network)

# you can use ~CLI commands by accessing command_runner
command_runner = Commands(config, wallet=None, network=network)
command_runner.wallet = wallet
print("balance", command_runner.getbalance())
Beispiel #24
0
#!/usr/bin/env python3
import json
import asyncio

from electrum_dash.simple_config import SimpleConfig
from electrum_dash.network import filter_version, Network
from electrum_dash.util import create_and_start_event_loop, log_exceptions
from electrum_dash import constants

# testnet?
#constants.set_testnet()
config = SimpleConfig({'testnet': False})

loop, stopping_fut, loop_thread = create_and_start_event_loop()
network = Network(config)
network.start()

@log_exceptions
async def f():
    try:
        peers = await network.get_peers()
        peers = filter_version(peers)
        print(json.dumps(peers, sort_keys=True, indent=4))
    finally:
        stopping_fut.set_result(1)

asyncio.run_coroutine_threadsafe(f(), loop)
Beispiel #25
0
}

_logger = get_logger(__name__)

if __name__ == '__main__':
    passphrase = os.getenv("WALLET_PASSPHRASE")
    seed = os.getenv("WALLET_SEED")
    gap_limit = int(os.getenv("GAP_LIMIT", "20"))

    if passphrase is None:
        raise Exception("WALLET_PASSPHRASE unset")

    if cmdline_options["testnet"]:
        constants.set_testnet()

    config = SimpleConfig(cmdline_options)
    logging.configure_logging(config)
    fd, server = daemon.get_fd_or_server(config)

    if fd is not None:
        init_plugins(config, 'cmdline')
        d = daemon.Daemon(config, fd)
        path = config.get_wallet_path()
        if os.path.exists(path) is False:
            _logger.warn("Wallet doesn't exist, creating")
            if seed is not None:
                restore_wallet_from_text(seed,
                                         path=path,
                                         password=passphrase,
                                         encrypt_file=True)
            else:
 def test_depth_target_to_fee(self):
     config = SimpleConfig(self.options)
     config.mempool_fees = [[49, 100110], [10, 121301], [6, 153731], [5, 125872], [1, 36488810]]
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(1000000))
     self.assertEqual( 6 * 1000, config.depth_target_to_fee( 500000))
     self.assertEqual( 7 * 1000, config.depth_target_to_fee( 250000))
     self.assertEqual(11 * 1000, config.depth_target_to_fee( 200000))
     self.assertEqual(50 * 1000, config.depth_target_to_fee( 100000))
     config.mempool_fees = []
     self.assertEqual( 1 * 1000, config.depth_target_to_fee(10 ** 5))
     self.assertEqual( 1 * 1000, config.depth_target_to_fee(10 ** 6))
     self.assertEqual( 1 * 1000, config.depth_target_to_fee(10 ** 7))
     config.mempool_fees = [[1, 36488810]]
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(10 ** 5))
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(10 ** 6))
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(10 ** 7))
     self.assertEqual( 1 * 1000, config.depth_target_to_fee(10 ** 8))
     config.mempool_fees = [[5, 125872], [1, 36488810]]
     self.assertEqual( 6 * 1000, config.depth_target_to_fee(10 ** 5))
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(10 ** 6))
     self.assertEqual( 2 * 1000, config.depth_target_to_fee(10 ** 7))
     self.assertEqual( 1 * 1000, config.depth_target_to_fee(10 ** 8))