Complete token lookups with proofs
This commit is contained in:
parent
77fe41da4b
commit
21972e9df5
@ -526,9 +526,6 @@ def verify_token_info(self, tokens, chain_spec_dict, success_callback, error_cal
|
|||||||
s.link(success_callback)
|
s.link(success_callback)
|
||||||
s.on_error(error_callback)
|
s.on_error(error_callback)
|
||||||
s.apply_async()
|
s.apply_async()
|
||||||
#s_group.append(s)
|
|
||||||
|
|
||||||
#celery.group(s_group)()
|
|
||||||
|
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# standard imports
|
# standard imports
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
import mmap
|
import mmap
|
||||||
|
|
||||||
@ -13,21 +14,25 @@ logg = logging.getLogger()
|
|||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
|
|
||||||
|
|
||||||
class CallbackTask(celery.Task):
|
class CallbackTask(celery.Task):
|
||||||
|
|
||||||
mmap_path = tempfile.mkdtemp()
|
mmap_path = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
|
||||||
@celery_app.task(bind=True, base=CallbackTask)
|
@celery_app.task(bind=True, base=CallbackTask)
|
||||||
def test_error_callback(self, a, b, c):
|
def test_callback(self, a, b, c):
|
||||||
s = 'ok'
|
s = 'ok'
|
||||||
if c > 0:
|
if c > 0:
|
||||||
s = 'err'
|
s = 'err'
|
||||||
|
|
||||||
fp = os.path.join(self.mmap_path, b)
|
fp = os.path.join(self.mmap_path, b)
|
||||||
f = open(fp, 'wb')
|
f = open(fp, 'wb+')
|
||||||
m = mmap.mmap(f.fileno(), access=mmap.ACCESS_WRITE, length=1)
|
f.write(b'\x00')
|
||||||
|
f.seek(0)
|
||||||
|
m = mmap.mmap(f.fileno(), length=1)
|
||||||
m.write(c.to_bytes(1, 'big'))
|
m.write(c.to_bytes(1, 'big'))
|
||||||
m.close()
|
m.close()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
logg.debug('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> test callback ({}): {} {} {} -> {}'.format(s, a, b, c, fp))
|
logg.debug('test callback ({}): {} {} {}'.format(s, a, b, c))
|
||||||
|
@ -3,6 +3,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
import time
|
import time
|
||||||
|
import mmap
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import celery
|
import celery
|
||||||
@ -72,20 +73,48 @@ def test_tokens(
|
|||||||
|
|
||||||
celery_app = celery.current_app
|
celery_app = celery.current_app
|
||||||
|
|
||||||
|
results = []
|
||||||
|
targets = []
|
||||||
|
|
||||||
api_param = str(uuid.uuid4())
|
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()
|
bogus_proof = os.urandom(32).hex()
|
||||||
t = api.tokens(['FOO'], proof=[[bogus_proof]])
|
t = api.tokens(['FOO'], proof=[[bogus_proof]])
|
||||||
r = t.get()
|
r = t.get()
|
||||||
logg.debug('r {}'.format(r))
|
logg.debug('r {}'.format(r))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
fp = os.path.join(CallbackTask.mmap_path, api_param)
|
||||||
|
try:
|
||||||
|
f = open(fp, 'rb')
|
||||||
|
except FileNotFoundError:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
assert len(CallbackTask.errs[api_param]) == 1
|
logg.debug('look for {}'.format(fp))
|
||||||
assert CallbackTask.oks.get(api_param) == None
|
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_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]])
|
t = api.tokens(['BAR'], proof=[[bar_token_declaration]])
|
||||||
r = t.get()
|
r = t.get()
|
||||||
logg.debug('rr {} {}'.format(r, t.children))
|
logg.debug('rr {} {}'.format(r, t.children))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
fp = os.path.join(CallbackTask.mmap_path, api_param)
|
||||||
|
try:
|
||||||
|
f = open(fp, 'rb')
|
||||||
|
except FileNotFoundError:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
assert len(CallbackTask.oks[api_param]) == 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
|
||||||
|
Loading…
Reference in New Issue
Block a user