def setUp(self): self.configdir = nuxhash.settings.DEFAULT_CONFIGDIR self.settings = nuxhash.settings.DEFAULT_SETTINGS self.settings['nicehash']['wallet'] = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23' self.device = devices[0] self.excavator = Excavator(self.configdir, nuxhash.settings.DEFAULT_SETTINGS) self.equihash = next(a for a in self.excavator.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.excavator.algorithms if a.algorithms == ['neoscrypt']) make_miners(self.configdir) self.excavator.load()
def setUp(self): self.configdir = nuxhash.settings.DEFAULT_CONFIGDIR self.device = devices[0] self.settings = nuxhash.settings.DEFAULT_SETTINGS self.settings['nicehash']['wallet'] = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23' self.alt_settings = nuxhash.settings.DEFAULT_SETTINGS self.alt_settings['nicehash']['wallet'] = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' self.alt_settings['nicehash']['workername'] = 'nuxhashtest' self.excavator = Excavator(self.configdir) self.excavator.settings = self.settings self.equihash = next(a for a in self.excavator.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.excavator.algorithms if a.algorithms == ['neoscrypt']) make_miners(self.configdir) self.excavator.load()
def setUp(self): self.configdir = nuxhash.settings.DEFAULT_CONFIGDIR self.device = devices[0] self.settings = nuxhash.settings.DEFAULT_SETTINGS self.settings['nicehash']['wallet'] = DONATE_ADDRESS self.alt_settings = nuxhash.settings.DEFAULT_SETTINGS self.alt_settings['nicehash']['wallet'] = '3Ffa4sDFimVnGRBBLdqfZkUgxaF3jR8PL9' self.alt_settings['nicehash']['workername'] = 'nuxhashtest' self.excavator = Excavator(self.configdir) self.excavator.settings = self.settings self.equihash = next(a for a in self.excavator.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.excavator.algorithms if a.algorithms == ['neoscrypt']) make_miners(self.configdir) self.excavator.load()
def setUp(self): settings = nuxhash.settings.DEFAULT_SETTINGS settings['switching']['threshold'] = 0.5 self.devices = tests.get_test_devices() self.benchmarks = tests.get_test_benchmarks() self.miner = Excavator(Path('/'), settings) self.equihash = next(a for a in self.miner.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.miner.algorithms if a.algorithms == ['neoscrypt']) self.switcher = NaiveSwitcher(settings) self.switcher.reset()
def run(self): # Initialize miners. stratums = None while stratums is None: try: payrates, stratums = nicehash.simplemultialgo_info( self._settings) except (socket.error, socket.timeout, SSLError, URLError): time.sleep(5) self._miners = [Excavator(CONFIG_DIR, self._settings)] for miner in self._miners: miner.stratums = stratums self._algorithms = sum([miner.algorithms for miner in self._miners], []) # Initialize profit-switching. self._profit_switch = NaiveSwitcher(self._settings) self._profit_switch.reset() self._scheduler.enter(0, MiningThread.PROFIT_PRIORITY, self._switch_algos) self._scheduler.enter(0, MiningThread.STATUS_PRIORITY, self._read_status) self._scheduler.run()
class TestExcavator(unittest.TestCase): def setUp(self): self.configdir = nuxhash.settings.DEFAULT_CONFIGDIR self.device = devices[0] self.settings = nuxhash.settings.DEFAULT_SETTINGS self.settings['nicehash']['wallet'] = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23' self.alt_settings = nuxhash.settings.DEFAULT_SETTINGS self.alt_settings['nicehash']['wallet'] = '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa' self.alt_settings['nicehash']['workername'] = 'nuxhashtest' self.excavator = Excavator(self.configdir) self.excavator.settings = self.settings self.equihash = next(a for a in self.excavator.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.excavator.algorithms if a.algorithms == ['neoscrypt']) make_miners(self.configdir) self.excavator.load() def tearDown(self): self.excavator.unload() def _get_workers(self): response = self.excavator.server.send_command('worker.list', []) def algorithms(worker): return [a['name'] for a in worker['algorithms']] return [{ 'device_uuid': w['device_uuid'], 'algorithms': algorithms(w) } for w in response['workers']] def _get_algorithms(self): response = self.excavator.server.send_command('algorithm.list', []) return [a['name'] for a in response['algorithms']] def test_add_worker(self): self.equihash.set_devices([self.device]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['equihash'] }]) def test_add_algorithm(self): self.equihash.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['equihash']) def test_remove_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), []) def test_remove_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_algorithms(), []) def test_report_speed(self): self.equihash.set_devices([self.device]) self.assertEqual(len(self.equihash.current_speeds()), 1) def test_switch_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.neoscrypt.set_devices([self.device]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['neoscrypt'] }]) def test_switch_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.neoscrypt.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['neoscrypt']) def test_simultaneous_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.neoscrypt.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['neoscrypt'] }]) def test_simultaneous_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.neoscrypt.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_algorithms(), ['neoscrypt']) def test_set_twice(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['equihash']) def test_benchmark_mode(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.benchmarking = True self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['equihash'] }]) def test_benchmark_stop(self): self.equihash.benchmarking = True self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), []) def test_bad_device(self): device = get_test_devices()[0] self.assertFalse(self.equihash.accepts(device)) def test_set_bad_device(self): devices = get_test_devices() self.assertRaises(AssertionError, lambda: self.equihash.set_devices(devices)) def test_settings_switch(self): self.equihash.set_devices([self.device]) sleep(1) self.excavator.settings = self.alt_settings self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['equihash'] }]) def test_settings_switch_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.excavator.settings = self.alt_settings self.assertEqual(self._get_algorithms(), ['equihash']) def test_settings_switch_back(self): self.equihash.set_devices([self.device]) sleep(1) status = (self._get_workers(), self._get_algorithms()) self.excavator.settings = self.alt_settings sleep(1) self.excavator.settings = self.settings sleep(1) self.assertEqual(status, (self._get_workers(), self._get_algorithms()))
class TestExcavator(unittest.TestCase): def setUp(self): self.configdir = nuxhash.settings.DEFAULT_CONFIGDIR self.settings = nuxhash.settings.DEFAULT_SETTINGS self.settings['nicehash']['wallet'] = '3Qe7nT9hBSVoXr8rM2TG6pq82AmLVKHy23' self.device = devices[0] self.excavator = Excavator(self.configdir, nuxhash.settings.DEFAULT_SETTINGS) self.equihash = next(a for a in self.excavator.algorithms if a.algorithms == ['equihash']) self.neoscrypt = next(a for a in self.excavator.algorithms if a.algorithms == ['neoscrypt']) make_miners(self.configdir) self.excavator.load() def tearDown(self): self.excavator.unload() def _get_workers(self): response = self.excavator.server.send_command('worker.list', []) def algorithms(worker): return [a['name'] for a in worker['algorithms']] return [{ 'device_uuid': w['device_uuid'], 'algorithms': algorithms(w) } for w in response['workers']] def _get_algorithms(self): response = self.excavator.server.send_command('algorithm.list', []) return [a['name'] for a in response['algorithms']] def test_add_worker(self): self.equihash.set_devices([self.device]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['equihash'] }]) def test_add_algorithm(self): self.equihash.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['equihash']) def test_remove_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), []) def test_remove_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_algorithms(), []) def test_report_speed(self): self.equihash.set_devices([self.device]) self.assertEqual(len(self.equihash.current_speeds()), 1) def test_switch_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.neoscrypt.set_devices([self.device]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['neoscrypt'] }]) def test_switch_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.neoscrypt.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['neoscrypt']) def test_simultaneous_worker(self): self.equihash.set_devices([self.device]) sleep(1) self.neoscrypt.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['neoscrypt'] }]) def test_simultaneous_algorithm(self): self.equihash.set_devices([self.device]) sleep(1) self.neoscrypt.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_algorithms(), ['neoscrypt']) def test_set_twice(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([self.device]) self.assertEqual(self._get_algorithms(), ['equihash']) def test_benchmark_mode(self): self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_benchmarking(True) self.assertEqual(self._get_workers(), [{ 'device_uuid': self.device.uuid, 'algorithms': ['equihash'] }]) def test_benchmark_stop(self): self.equihash.set_benchmarking(True) self.equihash.set_devices([self.device]) sleep(1) self.equihash.set_devices([]) self.assertEqual(self._get_workers(), [])
def main(): argp = argparse.ArgumentParser( description='Sell GPU hash power on the NiceHash market.') argp_benchmark = argp.add_mutually_exclusive_group() argp_benchmark.add_argument( '--benchmark-all', action='store_true', help='benchmark all algorithms on all devices') argp_benchmark.add_argument( '--benchmark-missing', action='store_true', help='benchmark algorithm-device combinations not measured') argp.add_argument('--list-devices', action='store_true', help='list all devices') argp.add_argument('-v', '--verbose', action='store_true', help='print more information to the console log') argp.add_argument('--show-mining', action='store_true', help='print output from mining processes, implies --verbose') argp.add_argument( '-c', '--configdir', nargs=1, default=[settings.DEFAULT_CONFIGDIR], help=('directory for configuration and benchmark files' + ' (default: ~/.config/nuxhash/)')) args = argp.parse_args() config_dir = Path(args.configdir[0]) if args.show_mining: log_level = logging.DEBUG elif args.verbose: log_level = logging.INFO else: log_level = logging.WARN logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=log_level) all_devices = nvidia_devices() nx_settings, nx_benchmarks = settings.load_persistent_data(config_dir, all_devices) # If no wallet configured, do initial setup prompts. if nx_settings['nicehash']['wallet'] == '': wallet, workername, region = initial_setup() nx_settings['nicehash']['wallet'] = wallet nx_settings['nicehash']['workername'] = workername nx_settings['nicehash']['region'] = region # Download and initialize miners. downloadables = make_miners(config_dir) for d in downloadables: if not d.verify(): logging.info('Downloading %s' % d.name) d.download() nx_miners = [Excavator(config_dir, nx_settings)] # Select code path(s), benchmarks and/or mining. if args.benchmark_all: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, defaultdict(lambda: {})) elif args.benchmark_missing: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, nx_benchmarks) elif args.list_devices: list_devices(all_devices) else: nx_benchmarks = run_missing_benchmarks( nx_miners, nx_settings, all_devices, defaultdict(lambda: {})) do_mining(nx_miners, nx_settings, nx_benchmarks, all_devices) settings.save_persistent_data(config_dir, nx_settings, nx_benchmarks)