mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
Merge pull request #6309
e69acff
functional_tests: update cookie at 10 seconds interval (moneromooo-monero)f5a11f0
functional_tests: speed up signature generation (moneromooo-monero)
This commit is contained in:
commit
0bd2c14bbb
@ -33,9 +33,9 @@
|
|||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
TRY_ENTRY();
|
TRY_ENTRY();
|
||||||
if (argc > 2)
|
if (argc > 3)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s <secret_key>\n", argv[0]);
|
fprintf(stderr, "usage: %s [<secret_key> [N]]\n", argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +55,22 @@ int main(int argc, const char **argv)
|
|||||||
fprintf(stderr, "invalid secret key\n");
|
fprintf(stderr, "invalid secret key\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::string signature = cryptonote::make_rpc_payment_signature(skey);
|
uint32_t count = 1;
|
||||||
printf("%s\n", signature.c_str());
|
if (argc == 3)
|
||||||
|
{
|
||||||
|
int i = atoi(argv[2]);
|
||||||
|
if (i <= 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "invalid count\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
count = (uint32_t)i;
|
||||||
|
}
|
||||||
|
while (count--)
|
||||||
|
{
|
||||||
|
std::string signature = cryptonote::make_rpc_payment_signature(skey);
|
||||||
|
printf("%s\n", signature.c_str());
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
CATCH_ENTRY_L0("main()", 1);
|
CATCH_ENTRY_L0("main()", 1);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
"""Test daemon RPC payment calls
|
"""Test daemon RPC payment calls
|
||||||
"""
|
"""
|
||||||
@ -43,6 +44,7 @@ class RPCPaymentTest():
|
|||||||
self.make_test_signature = os.environ['MAKE_TEST_SIGNATURE']
|
self.make_test_signature = os.environ['MAKE_TEST_SIGNATURE']
|
||||||
assert len(self.make_test_signature) > 0
|
assert len(self.make_test_signature) > 0
|
||||||
self.secret_key, self.public_key = self.get_keys()
|
self.secret_key, self.public_key = self.get_keys()
|
||||||
|
self.signatures = []
|
||||||
self.reset()
|
self.reset()
|
||||||
self.test_access_tracking()
|
self.test_access_tracking()
|
||||||
self.test_access_mining()
|
self.test_access_mining()
|
||||||
@ -56,8 +58,17 @@ class RPCPaymentTest():
|
|||||||
assert len(fields) == 2
|
assert len(fields) == 2
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
|
def refill_signatures(self):
|
||||||
|
signatures = subprocess.check_output([self.make_test_signature, self.secret_key, '256']).decode('utf-8')
|
||||||
|
for line in signatures.split():
|
||||||
|
self.signatures.append(line.rstrip())
|
||||||
|
|
||||||
def get_signature(self):
|
def get_signature(self):
|
||||||
return subprocess.check_output([self.make_test_signature, self.secret_key]).decode('utf-8').rstrip()
|
if len(self.signatures) == 0:
|
||||||
|
self.refill_signatures()
|
||||||
|
s = self.signatures[0]
|
||||||
|
self.signatures = self.signatures[1:]
|
||||||
|
return s
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
print('Resetting blockchain')
|
print('Resetting blockchain')
|
||||||
@ -143,6 +154,7 @@ class RPCPaymentTest():
|
|||||||
found_valid = 0
|
found_valid = 0
|
||||||
found_invalid = 0
|
found_invalid = 0
|
||||||
last_credits = 0
|
last_credits = 0
|
||||||
|
loop_time = time.time()
|
||||||
while found_valid == 0 or found_invalid == 0:
|
while found_valid == 0 or found_invalid == 0:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
try:
|
try:
|
||||||
@ -152,10 +164,17 @@ class RPCPaymentTest():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
found_invalid += 1
|
found_invalid += 1
|
||||||
res = daemon.rpc_access_info(client = self.get_signature())
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
cookie = res.cookie
|
||||||
|
loop_time = time.time()
|
||||||
assert res.credits < last_credits or res.credits == 0
|
assert res.credits < last_credits or res.credits == 0
|
||||||
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
||||||
last_credits = res.credits
|
last_credits = res.credits
|
||||||
|
|
||||||
|
if time.time() >= loop_time + 10:
|
||||||
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
cookie = res.cookie
|
||||||
|
loop_time = time.time()
|
||||||
|
|
||||||
# we should now have 1 valid nonce, and a number of bad ones
|
# we should now have 1 valid nonce, and a number of bad ones
|
||||||
res = daemon.rpc_access_info(client = self.get_signature())
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
assert len(res.hashing_blob) > 39
|
assert len(res.hashing_blob) > 39
|
||||||
@ -176,6 +195,7 @@ class RPCPaymentTest():
|
|||||||
assert e.nonces_dupe == 0
|
assert e.nonces_dupe == 0
|
||||||
|
|
||||||
# Try random nonces till we find one that's valid so we get a load of credits
|
# Try random nonces till we find one that's valid so we get a load of credits
|
||||||
|
loop_time = time.time()
|
||||||
while last_credits == 0:
|
while last_credits == 0:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
try:
|
try:
|
||||||
@ -186,6 +206,10 @@ class RPCPaymentTest():
|
|||||||
except:
|
except:
|
||||||
found_invalid += 1
|
found_invalid += 1
|
||||||
assert nonce < 1000 # can't find a valid none -> the RPC probably fails
|
assert nonce < 1000 # can't find a valid none -> the RPC probably fails
|
||||||
|
if time.time() >= loop_time + 10:
|
||||||
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
cookie = res.cookie
|
||||||
|
loop_time = time.time()
|
||||||
|
|
||||||
# we should now have at least 5000
|
# we should now have at least 5000
|
||||||
res = daemon.rpc_access_info(client = self.get_signature())
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
@ -208,6 +232,7 @@ class RPCPaymentTest():
|
|||||||
res = daemon.rpc_access_info(client = self.get_signature())
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
cookie = res.cookie
|
cookie = res.cookie
|
||||||
old_cookie = cookie # we keep that so can submit a stale later
|
old_cookie = cookie # we keep that so can submit a stale later
|
||||||
|
loop_time = time.time()
|
||||||
while True:
|
while True:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
try:
|
try:
|
||||||
@ -218,6 +243,11 @@ class RPCPaymentTest():
|
|||||||
found_invalid += 1
|
found_invalid += 1
|
||||||
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
||||||
|
|
||||||
|
if time.time() >= loop_time + 10:
|
||||||
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
cookie = res.cookie
|
||||||
|
loop_time = time.time()
|
||||||
|
|
||||||
res = daemon.rpc_access_data()
|
res = daemon.rpc_access_data()
|
||||||
assert len(res.entries) > 0
|
assert len(res.entries) > 0
|
||||||
e = [x for x in res.entries if x['client'] == self.public_key]
|
e = [x for x in res.entries if x['client'] == self.public_key]
|
||||||
@ -247,14 +277,17 @@ class RPCPaymentTest():
|
|||||||
|
|
||||||
# find stales without updating cookie, one within 5 seconds (accepted), one later (rejected)
|
# find stales without updating cookie, one within 5 seconds (accepted), one later (rejected)
|
||||||
res = daemon.rpc_access_info(client = self.get_signature())
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
cookie = res.cookie # let the daemon update its timestamp, but use old cookie
|
||||||
found_close_stale = 0
|
found_close_stale = 0
|
||||||
found_late_stale = 0
|
found_late_stale = 0
|
||||||
|
loop_time = time.time()
|
||||||
while found_close_stale == 0 or found_late_stale == 0:
|
while found_close_stale == 0 or found_late_stale == 0:
|
||||||
nonce += 1
|
nonce += 1
|
||||||
try:
|
try:
|
||||||
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
|
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
|
||||||
found_close_stale += 1
|
found_close_stale += 1
|
||||||
found_valid += 1
|
found_valid += 1
|
||||||
|
time.sleep(15) # now we've got an early stale, wait till they become late stales
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#if e[0]['error']['code'] == -18: # stale
|
#if e[0]['error']['code'] == -18: # stale
|
||||||
if "'code': -18" in str(e): # stale (ugly version, but also works with python 3)
|
if "'code': -18" in str(e): # stale (ugly version, but also works with python 3)
|
||||||
@ -263,6 +296,11 @@ class RPCPaymentTest():
|
|||||||
found_invalid += 1
|
found_invalid += 1
|
||||||
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails
|
||||||
|
|
||||||
|
if time.time() >= loop_time + 10:
|
||||||
|
res = daemon.rpc_access_info(client = self.get_signature())
|
||||||
|
# cookie = res.cookie # let the daemon update its timestamp, but use old cookie
|
||||||
|
loop_time = time.time()
|
||||||
|
|
||||||
res = daemon.rpc_access_data()
|
res = daemon.rpc_access_data()
|
||||||
assert len(res.entries) > 0
|
assert len(res.entries) > 0
|
||||||
e = [x for x in res.entries if x['client'] == self.public_key]
|
e = [x for x in res.entries if x['client'] == self.public_key]
|
||||||
|
Loading…
Reference in New Issue
Block a user