def test_build(self): client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 256) # 256K client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated)) client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 512) # 512K config = client.config() client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated) == 4) result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmers for farmers in result['farmers'] if farmers['btc_addr'] == config['payout_address'] ] last_seen = result[0]['last_seen'] reg_time = result[0]['reg_time'] result = json.dumps(result, sort_keys=True) expected = json.dumps([{ 'height': 4, 'btc_addr': config['payout_address'], 'last_seen': last_seen, 'payout_addr': config['payout_address'], 'reg_time': reg_time, 'uptime': 100.0 }], sort_keys=True) self.assertEqual(result, expected)
def test_persistance(self): config_path = tempfile.mktemp() a = api.Client(config_path=config_path).config() b = api.Client(config_path=config_path).config() c = api.Client(config_path=config_path).config() self.assertEqual(a, b, c) self.assertTrue(c["wallet"] is not None)
def test_build(self): client = api.Client(address_pi, url=url, debug=True, max_size=1024*1024*256) # 256MB client.register() hashes = client.build(cleanup=True) self.assertTrue(len(hashes) == 2) client = api.Client(address_omicron, url=url, debug=True, max_size=1024*1024*512) # 512MB client.register() hashes = client.build(cleanup=True) self.assertTrue(len(hashes) == 4)
def test_build(self): client = api.Client(url=url, debug=True, config_path=tempfile.mktemp(), max_size=1024*1024*256) # 256MB client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated)) client = api.Client(url=url, debug=True, config_path=tempfile.mktemp(), max_size=1024*1024*512) # 512MB client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated) == 4)
def callback(): client = api.Client(url="http://invalid.url", connection_retry_limit=0, connection_retry_delay=0, config_path=tempfile.mktemp(), debug=True) client.register()
def test_farm_registered(self): client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 256) # 256K config = client.config() client.register() befor = datetime.datetime.now() self.assertTrue(client.farm(delay=2, limit=2)) # check farm return true after = datetime.datetime.now() # check that farm did 2 pings with 2 sec delay self.assertTrue(datetime.timedelta(seconds=2) <= (after - befor)) result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmers for farmers in result['farmers'] if farmers['btc_addr'] == config['payout_address'] ] last_seen = result[0]['last_seen'] reg_time = result[0]['reg_time'] result = json.dumps(result, sort_keys=True) expected = json.dumps([{ 'height': 2, 'btc_addr': config['payout_address'], 'last_seen': last_seen, 'payout_addr': config['payout_address'], 'reg_time': reg_time, 'uptime': 100.0 }], sort_keys=True) self.assertEqual(result, expected)
def test_build(self): client = api.Client(addresses["pi"], url=url, debug=True, max_size=1024 * 1024 * 256) # 256MB client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated)) client = api.Client(addresses["omicron"], url=url, debug=True, max_size=1024 * 1024 * 512) # 512MB client.register() generated = client.build(cleanup=True) self.assertTrue(len(generated) == 4)
def test_register_payout(self): client = api.Client(url=url, config_path=tempfile.mktemp()) config = client.config() self.assertTrue(client.register()) result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmer for farmer in result['farmers'] if farmer['payout_addr'] == config['payout_address'] ] last_seen = result[0]['last_seen'] reg_time = result[0]['reg_time'] result = json.dumps(result, sort_keys=True) expected = json.dumps( [{ 'height': 0, 'nodeid': common.address2nodeid(config['payout_address']), 'last_seen': last_seen, 'payout_addr': config['payout_address'], 'reg_time': reg_time, 'bandwidth_upload': 0, 'bandwidth_download': 0, "ip": "", 'uptime': 100.0 }], sort_keys=True) self.assertEqual(result, expected)
def callback(): client = api.Client(url="http://127.0.0.257", config_path=tempfile.mktemp(), connection_retry_limit=2000, connection_retry_delay=0, quiet=True) client.register()
def test_show(self): payout_wif = self.btctxstore.create_key() hwif = self.btctxstore.create_wallet() payout_address = self.btctxstore.get_address(payout_wif) client = api.Client(config_path=tempfile.mktemp()) config = client.config(set_wallet=hwif, set_payout_address=payout_address) self.assertEqual(config["wallet"], hwif) self.assertEqual(config["payout_address"], payout_address)
def main(args): command_name, arguments = _parse_args(args) client = api.Client( url=arguments.pop("url"), debug=arguments.pop("debug"), max_size=arguments.pop("max_size"), store_path=arguments.pop("store_path"), config_path=arguments.pop("config_path"), ) return getattr(client, command_name)(**arguments)
def test_poll(self): client = api.Client(url=url, config_path=tempfile.mktemp()) client.register() before = datetime.datetime.now() self.assertTrue(client.poll(delay=2, limit=2)) after = datetime.datetime.now() # check that poll did 2 pings with 2 sec delay self.assertTrue(datetime.timedelta(seconds=2) <= (after - before))
def test_show(self): payout_wif = self.btctxstore.create_key() master_secret = "testmastersecret" payout_address = self.btctxstore.get_address(payout_wif) client = api.Client(debug=True, set_master_secret=master_secret, set_payout_address=payout_address, config_path=tempfile.mktemp()) config = client.show_config() self.assertEqual(config["master_secret"], master_secret) self.assertEqual(config["payout_address"], payout_address)
def test_farm(self): client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 256) # 256K befor = datetime.datetime.now() self.assertTrue(client.farm(delay=2, limit=2)) # check farm return true after = datetime.datetime.now() # check that farm did 2 pings with 2 sec delay self.assertTrue(datetime.timedelta(seconds=2) <= (after - befor))
def main(args): client = None try: command_name, arguments = _parse_args(args) client = api.Client( url=arguments.pop("url"), debug=arguments.pop("debug"), quiet=arguments.pop("quiet"), use_folder_tree=arguments.pop("use_folder_tree"), max_size=arguments.pop("max_size"), min_free_size=arguments.pop("min_free_size"), store_path=arguments.pop("store_path"), config_path=arguments.pop("config_path"), ) return getattr(client, command_name)(**arguments) except KeyboardInterrupt: logger.warning("Caught KeyboardInterrupt")
def test_farm_registered(self): client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 256) # 256K config = client.config() client.register() befor = datetime.datetime.now() self.assertTrue(client.farm(delay=2, limit=2)) # check farm return true after = datetime.datetime.now() # check that farm did 2 pings with 2 sec delay self.assertTrue(datetime.timedelta(seconds=2) <= (after - befor)) result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmer for farmer in result['farmers'] if farmer['payout_addr'] == config['payout_address'] ] last_seen = result[0]['last_seen'] reg_time = result[0]['reg_time'] # check bandwidth and pop as expected result cannot be know bandwidth_upload = result[0].pop('bandwidth_upload') bandwidth_download = result[0].pop('bandwidth_download') self.assertGreater(bandwidth_upload, 0) self.assertGreater(bandwidth_download, 0) result = json.dumps(result, sort_keys=True) expected = json.dumps( [{ 'height': 2, 'nodeid': common.address2nodeid(config['payout_address']), 'last_seen': last_seen, 'payout_addr': config['payout_address'], 'reg_time': reg_time, "ip": "", 'uptime': 100.0 }], sort_keys=True) self.assertEqual(result, expected)
def test_register(self): client = api.Client(url=url, config_path=tempfile.mktemp()) config = client.config() self.assertTrue(client.register()) result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmers for farmers in result['farmers'] if farmers['btc_addr'] == config['payout_address'] ] result = json.dumps(result, sort_keys=True) expected = json.dumps([{ 'height': 0, 'btc_addr': config['payout_address'], 'last_seen': 0, 'payout_addr': config['payout_address'] }], sort_keys=True) self.assertEqual( result, expected) #check that register add height=0 to server list
def test_build_min_free_space(self): store_path = tempfile.mktemp() os.mkdir(store_path) my_free_size = psutil.disk_usage(store_path).free - (1024 * 256) # 256 client = api.Client(url=url, config_path=tempfile.mktemp(), store_path=store_path, max_size=1024 * 1024 * 2, min_free_size=my_free_size) # 256 config = client.config() client.register() generated = client.build() self.assertTrue(len(generated) > 0) # build at least 1 shard self.assertTrue(len(generated) < 16) # stoped cause of free Space result = json.loads( urlopen(url + '/api/online/json').read().decode('utf8')) result = [ farmer for farmer in result['farmers'] if farmer['payout_addr'] == config['payout_address'] ] last_seen = result[0]['last_seen'] reg_time = result[0]['reg_time'] result = json.dumps(result, sort_keys=True) expected = json.dumps( [{ 'height': len(generated), 'nodeid': common.address2nodeid(config['payout_address']), 'last_seen': last_seen, 'payout_addr': config['payout_address'], 'reg_time': reg_time, 'bandwidth_upload': 0, 'bandwidth_download': 0, "ip": "", 'uptime': 100.0 }], sort_keys=True) self.assertEqual(result, expected)
def main(args): client = None try: command_name, arguments = _parse_args(args) client = api.Client( url=arguments.pop("url"), debug=arguments.pop("debug"), quiet=arguments.pop("quiet"), use_folder_tree=arguments.pop("use_folder_tree"), max_size=arguments.pop("max_size"), min_free_size=arguments.pop("min_free_size"), store_path=arguments.pop("store_path"), config_path=arguments.pop("config_path"), nop2p=arguments.pop("nop2p"), ) return getattr(client, command_name)(**arguments) except KeyboardInterrupt: logger.warning("Caught KeyboardInterrupt") if client is not None and client.storjnode is not None: client.storjnode.stop() except Exception as e: logger.exception(e) raise e
def callback(): client = api.Client(url=url + "/xyz", config_path=tempfile.mktemp()) client.ping()
def test_ping(self): client = api.Client(url=url, config_path=tempfile.mktemp()) self.assertTrue(client.register()) self.assertTrue(client.ping())
def callback(): client = api.Client(url=url, config_path=tempfile.mktemp()) client.register() client.register()
def test_register(self): # register without createing a config client = api.Client(url=url) self.assertTrue(client.register())
def callback(): client = api.Client(config_path=tempfile.mktemp()) client.config(set_payout_address="invalid")
def callback(): client = api.Client(config_path=tempfile.mktemp()) client.audit(delay=-1, limit=0)
def callback(): client = api.Client(config_path=tempfile.mktemp()) client.build(set_height_interval=0)
def callback(): client = api.Client(url="http://ServerNotFound.url", config_path=tempfile.mktemp(), connection_retry_limit=2, connection_retry_delay=2) client.register()
def callback(): client = api.Client(config_path=tempfile.mktemp()) client.build(workers=-1)
def test_audit(self): client = api.Client(url=url, config_path=tempfile.mktemp(), max_size=1024 * 256) # 256K client.register() self.assertTrue(client.audit(delay=1, limit=1))
def callback(): client = api.Client(config_path=tempfile.mktemp()) client.farm(workers=0)