2020-03-16 07:28:41 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from lan.getip import best_ip
|
|
|
|
|
2020-03-19 06:44:44 +00:00
|
|
|
from onionrblocks import insert, onionrblockapi
|
2020-03-21 06:14:35 +00:00
|
|
|
from gevent import sleep
|
|
|
|
from coredb import blockmetadb
|
|
|
|
from onionrutils.epoch import get_epoch
|
|
|
|
import logger
|
2020-03-19 06:44:44 +00:00
|
|
|
|
2020-03-16 07:28:41 +00:00
|
|
|
def test_lan_server(testmanager):
|
2020-03-21 06:14:35 +00:00
|
|
|
start_time = get_epoch()
|
2020-06-19 06:08:39 +00:00
|
|
|
for i in range(1337, 1340):
|
2020-03-16 07:28:41 +00:00
|
|
|
try:
|
2020-04-06 13:51:20 +00:00
|
|
|
if requests.get(f"http://{best_ip}:{i}/ping").text == 'onionr!':
|
2020-03-19 06:44:44 +00:00
|
|
|
bl = insert('test data')
|
2020-03-21 06:14:35 +00:00
|
|
|
sleep(10)
|
2020-03-20 08:50:48 +00:00
|
|
|
bl2 = insert('test data2')
|
2020-03-21 06:14:35 +00:00
|
|
|
sleep(30)
|
|
|
|
bl3 = insert('test data3')
|
|
|
|
l = requests.get(f"http://{best_ip}:{i}/blist/0").text.split('\n')
|
|
|
|
if bl not in l or bl2 not in l or bl3 not in l:
|
|
|
|
logger.error('blocks not in blist ' + '-'.join(l), terminal=True)
|
|
|
|
raise ValueError
|
|
|
|
time = blockmetadb.get_block_date(bl3) - 1
|
|
|
|
l = requests.get(f"http://{best_ip}:{i}/blist/{time}").text.split('\n')
|
|
|
|
|
|
|
|
if (bl in l and bl2 in l and bl3 in l) or len(l) == 0:
|
|
|
|
logger.error('Failed to get appopriate time' + '-'.join(l), terminal=True)
|
2020-03-19 06:44:44 +00:00
|
|
|
raise ValueError
|
|
|
|
if onionrblockapi.Block(bl).raw != requests.get(f"http://{best_ip}:{i}/get/{bl}").content:
|
|
|
|
raise ValueError
|
2020-03-21 06:14:35 +00:00
|
|
|
|
2020-03-16 07:28:41 +00:00
|
|
|
break
|
2020-03-20 08:50:48 +00:00
|
|
|
|
2020-03-16 07:28:41 +00:00
|
|
|
except requests.exceptions.ConnectionError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise ValueError
|