Complete token lookups with proofs

This commit is contained in:
nolash 2021-10-09 14:18:10 +02:00
parent 77fe41da4b
commit 21972e9df5
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 45 additions and 14 deletions

View File

@ -526,9 +526,6 @@ def verify_token_info(self, tokens, chain_spec_dict, success_callback, error_cal
s.link(success_callback)
s.on_error(error_callback)
s.apply_async()
#s_group.append(s)
#celery.group(s_group)()
return tokens

View File

@ -1,4 +1,5 @@
# standard imports
import os
import logging
import mmap
@ -13,21 +14,25 @@ logg = logging.getLogger()
celery_app = celery.current_app
class CallbackTask(celery.Task):
mmap_path = tempfile.mkdtemp()
@celery_app.task(bind=True, base=CallbackTask)
def test_error_callback(self, a, b, c):
def test_callback(self, a, b, c):
s = 'ok'
if c > 0:
s = 'err'
fp = os.path.join(self.mmap_path, b)
f = open(fp, 'wb')
m = mmap.mmap(f.fileno(), access=mmap.ACCESS_WRITE, length=1)
f = open(fp, 'wb+')
f.write(b'\x00')
f.seek(0)
m = mmap.mmap(f.fileno(), length=1)
m.write(c.to_bytes(1, 'big'))
m.close()
f.close()
logg.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test callback ({}): {} {} {} -> {}'.format(s, a, b, c, fp))
logg.debug('test callback ({}): {} {} {}'.format(s, a, b, c))

View File

@ -3,6 +3,7 @@ import logging
import os
import uuid
import time
import mmap
# external imports
import celery
@ -72,20 +73,48 @@ def test_tokens(
celery_app = celery.current_app
results = []
targets = []
api_param = str(uuid.uuid4())
api = Api(str(default_chain_spec), queue=None, callback_param=api_param, callback_task='cic_eth.pytest.mock.callback.test_error_callback')
api = Api(str(default_chain_spec), queue=None, callback_param=api_param, callback_task='cic_eth.pytest.mock.callback.test_callback')
bogus_proof = os.urandom(32).hex()
t = api.tokens(['FOO'], proof=[[bogus_proof]])
r = t.get()
logg.debug('r {}'.format(r))
time.sleep(0.1)
assert len(CallbackTask.errs[api_param]) == 1
assert CallbackTask.oks.get(api_param) == None
while True:
fp = os.path.join(CallbackTask.mmap_path, api_param)
try:
f = open(fp, 'rb')
except FileNotFoundError:
time.sleep(0.1)
logg.debug('look for {}'.format(fp))
continue
f = open(fp, 'rb')
m = mmap.mmap(f.fileno(), access=mmap.ACCESS_READ, length=1)
v = m.read(1)
m.close()
f.close()
assert v == b'\x01'
break
api_param = str(uuid.uuid4())
api = Api(str(default_chain_spec), queue=None, callback_param=api_param, callback_task='cic_eth.pytest.mock.callback.test_error_callback')
api = Api(str(default_chain_spec), queue=None, callback_param=api_param, callback_task='cic_eth.pytest.mock.callback.test_callback')
t = api.tokens(['BAR'], proof=[[bar_token_declaration]])
r = t.get()
logg.debug('rr {} {}'.format(r, t.children))
time.sleep(0.1)
assert len(CallbackTask.oks[api_param]) == 1
while True:
fp = os.path.join(CallbackTask.mmap_path, api_param)
try:
f = open(fp, 'rb')
except FileNotFoundError:
time.sleep(0.1)
continue
m = mmap.mmap(f.fileno(), access=mmap.ACCESS_READ, length=1)
v = m.read(1)
m.close()
f.close()
assert v == b'\x00'
break