Skip to content
Permalink
Browse files

TO SQUASH: more tests

  • Loading branch information...
moneromooo-monero committed Jul 5, 2019
1 parent 2594b76 commit 12f6c35db3a98c2668aedb6fd4ad0b761d02f327
Showing with 71 additions and 1 deletion.
  1. +71 −1 tests/functional_tests/rpc_payment.py
@@ -206,22 +206,92 @@ def test_access_mining(self):
# find a valid one, then check dupes aren't allowed
res = daemon.rpc_access_info(self.public_key)
cookie = res.cookie
old_cookie = cookie # we keep that so can submit a stale later
while True:
nonce += 1
try:
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
found_valid += 1
break
except:
pass
found_invalid += 1
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails

res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
assert len(e) == 1
e = e[0]
assert e.nonces_stale == 0
assert e.nonces_bad == found_invalid
assert e.nonces_good == found_valid
assert e.nonces_dupe == 0

ok = False
try:
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
except:
ok = True
assert ok

res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
assert len(e) == 1
e = e[0]
assert e.nonces_stale == 0
assert e.nonces_bad == found_invalid
assert e.nonces_good == found_valid
assert e.nonces_dupe == 1

# find stales without updating cookie, one within 5 seconds (accepted), one later (rejected)
res = daemon.rpc_access_info(self.public_key)
found_close_stale = 0
found_late_stale = 0
while found_close_stale == 0 or found_late_stale == 0:
nonce += 1
try:
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())
found_close_stale += 1
found_valid += 1
except Exception as e:
if e[0]['error']['code'] == -18: # stale
found_late_stale += 1
else:
found_invalid += 1
assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails

res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
assert len(e) == 1
e = e[0]
assert e.nonces_stale == found_late_stale # close stales are accepted, don't count here
assert e.nonces_bad == found_invalid
assert e.nonces_good == found_valid
assert e.nonces_dupe == 1

# find very stale with old cookie (rejected)
res = daemon.rpc_access_info(self.public_key)
nonce += 1
ok = False
try:
res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = old_cookie, client = self.get_signature())
except:
found_late_stale += 1
ok = True
assert ok

res = daemon.rpc_access_data()
assert len(res.entries) > 0
e = [x for x in res.entries if x['client'] == self.public_key]
assert len(e) == 1
e = e[0]
assert e.nonces_stale == found_late_stale
assert e.nonces_bad == found_invalid
assert e.nonces_good == found_valid
assert e.nonces_dupe == 1

def test_access_payment(self):
print('Testing access payment')
daemon = Daemon(idx=1)

0 comments on commit 12f6c35

Please sign in to comment.
You can’t perform that action at this time.