def test_evt_link_for_trx_id4(self): symbol = base.Symbol( sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) pay_link = evt_link.EvtLink() pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) req = { 'link_id': 'd1680fea21a3c3d8ef555afd8fd8c903' } url = 'http://127.0.0.1:8888/v1/evt_link/get_trx_id_for_link_id' tasks = [] for i in range(10240): pay_link.set_link_id_rand() req['link_id'] = pay_link.get_link_id().hex() tasks.append(grequests.post(url, data=json.dumps(req))) i = 0 for resp in grequests.imap(tasks, size=900): self.assertEqual(resp.status_code, 500, msg=resp.content) i += 1 if i % 100 == 0: print('Received {} responses'.format(i))
def test_evt_link_for_trx_id(self): symbol = base.Symbol( sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) pay_link = evt_link.EvtLink() pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) everipay = AG.new_action('everipay', payee=pub2, number=asset( 1), link=pay_link.to_string()) trx = TG.new_trx() trx.add_action(everipay) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) req = { 'link_id': 'ddc101c51318d51733d682e80b8ea2bc' } req['link_id'] = pay_link.get_link_id().hex() for i in range(1000): resp = api.get_trx_id_for_link_id(json.dumps(req)).text self._test_evt_link_response(resp)
def test_evt_link_for_trx_id2(self): symbol = base.Symbol( sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) pay_link = evt_link.EvtLink() pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) everipay = AG.new_action('everipay', payee=pub2, number=asset( 1), link=pay_link.to_string()) trx = TG.new_trx() trx.add_action(everipay) trx.add_sign(user.priv_key) req = { 'link_id': 'd1680fea21a3c3d8ef555afd8fd8c903' } req['link_id'] = pay_link.get_link_id().hex() def get_response(req): return api.get_trx_id_for_link_id(json.dumps(req)).text executor = ThreadPoolExecutor(max_workers=2) f = executor.submit(get_response, req) time.sleep(1) api.push_transaction(trx.dumps()) resp = f.result() self._test_evt_link_response(resp)
def prepare_for_debug(filename): TG = TrxGenerator('http://127.0.0.1:8897', payer=None) Api = api.Api('http://127.0.0.1:8897') boss = base.User() # issue fungible DBG_Symbol = base.Symbol('DBG', 666, 5) DBG_Asset = base.new_asset(DBG_Symbol) act_newf = AG.new_action('newfungible', name='DBG', sym_name='DBG', sym=DBG_Symbol, creator=boss.pub_key, total_supply=DBG_Asset(1000000)) trx = TG.new_trx() trx.add_action(act_newf) trx.add_sign(boss.priv_key) trx.set_payer(boss.pub_key.to_string()) resp = Api.push_transaction(trx.dumps()) print(resp) with open(filename, 'r') as f: tmp = json.load(f) users = [base.User.from_string( each['pub_key'], each['priv_key']) for each in tmp] trx = TG.new_trx() for user in users: act_issue = AG.new_action('issuefungible', address=base.Address( ).set_public_key(user.pub_key), number=DBG_Asset(1000), memo='') trx.add_action(act_issue) trx.add_sign(boss.priv_key) trx.set_payer(boss.pub_key.to_string()) resp = Api.push_transaction(trx.dumps()) print(resp)
def fake_symbol(prefix, syms): while True: sym = prefix.upper() + ''.join(random.choice(string.ascii_letters[26:]) for _ in range(5)) if sym in syms: continue syms.add(sym) prec = random.randint(5, 10) break return base.Symbol(name=sym, precision=prec)
def __init__(self, freq, users, watch_pool, sym='5,S#1', amount=10, nodes=None): self.freq = freq self.users = self.load_users(users) self.linkids = set([]) self.nodes = nodes self.sym = sym self.symbol_id = int(sym.split('#')[1]) self.balance = {} DBG_Symbol = base.Symbol('DBG', 666, 5) self.asset = base.new_asset(DBG_Symbol) self.amount = amount self.wp = watch_pool
def pre_action(): newdomain = AG.new_action( 'newdomain', name=domain_name, creator=user.pub_key) issuetoken = AG.new_action('issuetoken', domain=domain_name, names=[ token1_name, token2_name, token3_name], owner=[base.Address().set_public_key(user.pub_key)]) destroytoken = AG.new_action( 'destroytoken', domain=domain_name, name=token2_name) pass_link = evt_link.EvtLink() pass_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPass.value | evt_link.HeaderType.destroy.value) pass_link.set_domain(domain_name) pass_link.set_token(token3_name) pass_link.set_timestamp(int(time.time())) pass_link.sign(user.priv_key) everipass = AG.new_action( 'everipass', link=pass_link.to_string()) group_json = json.loads(group_json_raw) group_json['name'] = group_name group_json['group']['name'] = group_name group_json['group']['key'] = str(user.pub_key) newgroup = AG.new_action_from_json('newgroup', json.dumps(group_json)) symbol = base.Symbol( sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action( 'newfungible', name=sym_name, sym_name=sym_name, sym=symbol, creator=user.pub_key, total_supply=asset(10000000)) issuefungible1 = AG.new_action( 'issuefungible', address=base.Address().set_public_key(user.pub_key), number=asset(100), memo='goodluck') asset_evt = base.new_asset(base.Symbol( sym_name=sym_name, sym_id=1, precision=5)) issuefungible2 = AG.new_action( 'issuefungible', address=base.Address().set_public_key(user.pub_key), number=asset_evt(100), memo='goodluck') e2p = AG.new_action( 'evt2pevt', _from=base.Address().set_public_key(user.pub_key), to=base.Address().set_public_key(user.pub_key), number=asset_evt(100), memo='goodluck') pay_link = evt_link.EvtLink() pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) everipay = AG.new_action('everipay', payee=pub2, number=asset( 1), link=pay_link.to_string()) trx = TG.new_trx() trx.add_action(newdomain) trx.add_sign(user.priv_key) trx.add_action(newgroup) trx.add_action(newfungible) api.push_transaction(trx.dumps()) trx = TG.new_trx() trx.add_action(issuetoken) trx.add_action(issuefungible1) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) trx = TG.new_trx() trx.add_action(issuefungible2) trx.add_sign(priv_evt) api.push_transaction(trx.dumps()) trx = TG.new_trx() trx.add_action(e2p) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) trx = TG.new_trx() trx.add_action(destroytoken) trx.add_action(everipass) trx.add_action(everipay) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) time.sleep(2)
def test_block(self): symbol = base.Symbol(sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) pay_link = evt_link.EvtLink() pay_link.set_timestamp(int(time.time())) pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) everipay = AG.new_action('everipay', payee=pub2, number=asset(1), link=pay_link.to_string()) req = {'link_id': 'ddc101c51318d51733d682e80b8ea2bc'} req['link_id'] = pay_link.get_link_id().hex() for i in range(10000): pay_link.set_link_id_rand() everipay = AG.new_action('everipay', payee=pub2, number=asset(1), link=pay_link.to_string()) trx = TG.new_trx() trx.add_action(everipay) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) api.push_transaction(trx.dumps()) time.sleep(0.1) req = { 'block_num_or_id': '5', } resp = api.get_block(json.dumps(req)).text res_dict = json.loads(resp) self.assertTrue('block_num' in res_dict.keys(), msg=resp) self.assertEqual(res_dict['block_num'], 5, msg=resp) url = 'http://127.0.0.1:8888/v1/chain/get_block' tasks = [] for i in range(1024): req['block_num_or_id'] = random.randint(1, 100) tasks.append(grequests.post(url, data=json.dumps(req))) i = 0 for resp in grequests.imap(tasks, size=128): self.assertEqual(resp.status_code, 200, msg=resp.content) res_dict = json.loads(resp.text) req = { 'id': 'f0c789933e2b381e88281e8d8e750b561a4d447725fb0eb621f07f219fe2f738' } for trx in res_dict['transactions']: req['id'] = trx['trx']['id'] resp = api.get_history_transaction(json.dumps(req)).text i += 1 if i % 100 == 0: print('Received {} responses'.format(i))
def pre_action(): prodvote = AG.new_action('prodvote', producer='evt', key="action-everipay", value=2) newdomain = AG.new_action('newdomain', name=domain_name, creator=user.pub_key) auth_A = base.AuthorizerWeight(base.AuthorizerRef('A', evt_pub), 1) updatedomain = AG.new_action('updatedomain', name=domain_name, manage=base.PermissionDef( 'manage', 1, [auth_A])) issuetoken = AG.new_action( 'issuetoken', domain=domain_name, names=[token1_name, token2_name, token3_name], owner=[base.Address().set_public_key(user.pub_key)]) destroytoken = AG.new_action('destroytoken', domain=domain_name, name=token2_name) pass_link = evt_link.EvtLink() pass_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPass.value | evt_link.HeaderType.destroy.value) pass_link.set_domain(domain_name) pass_link.set_token(token3_name) pass_link.set_timestamp(int(time.time())) pass_link.sign(user.priv_key) everipass = AG.new_action('everipass', link=pass_link.to_string()) group_json = json.loads(group_json_raw) group_json['name'] = group_name group_json['group']['name'] = group_name group_json['group']['key'] = str(user.pub_key) newgroup = AG.new_action_from_json('newgroup', json.dumps(group_json)) group_json['group']['root']['threshold'] = 5 updategroup = AG.new_action_from_json('updategroup', json.dumps(group_json)) symbol = base.Symbol(sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action('newfungible', name=sym_name, sym_name=sym_name, sym=symbol, creator=user.pub_key, total_supply=asset(10000000)) issuefungible1 = AG.new_action('issuefungible', address=base.Address().set_public_key( user.pub_key), number=asset(100), memo='goodluck') issuefungible2 = AG.new_action('issuefungible', address=base.Address().set_public_key( user.pub_key), number=base.EvtAsset(1000), memo='goodluck') e2p = AG.new_action('evt2pevt', _from=base.Address().set_public_key(user.pub_key), to=base.Address().set_public_key(user.pub_key), number=base.EvtAsset(100), memo='goodluck') pay_link = evt_link.EvtLink() pay_link.set_timestamp(int(time.time())) pay_link.set_max_pay(999999999) pay_link.set_header(evt_link.HeaderType.version1.value | evt_link.HeaderType.everiPay.value) pay_link.set_symbol_id(sym_id) pay_link.set_link_id_rand() pay_link.sign(user.priv_key) everipay = AG.new_action('everipay', payee=pub2, number=asset(1), link=pay_link.to_string()) bonus_json = json.loads(bonus_json_raw) setpsvbonus = AG.new_action_from_json('setpsvbonus', json.dumps(bonus_json)) addmeta = AG.new_action('addmeta', meta_key='sdf', meta_value='sdfsadf', creator=base.AuthorizerRef('A', user.pub_key), domain=domain_name, key=token1_name) trx = TG.new_trx() trx.add_action(issuefungible2) trx.add_sign(priv_evt) trx.add_sign(user.priv_key) newsuspend = AG.new_action('newsuspend', name='suspend', proposer=user.pub_key, trx=trx) newsuspend2 = AG.new_action('newsuspend', name='suspend2', proposer=user.pub_key, trx=trx) cancelsuspend = AG.new_action('cancelsuspend', name='suspend2') aprvsuspend = AG.new_action('aprvsuspend', name='suspend', signatures=json.loads( trx.dumps())['signatures']) execsuspend = AG.new_action('execsuspend', name='suspend', executor=user.pub_key) lock_json = json.loads(lock_json_raw) lock_json['proposer'] = str(user.pub_key) lock_json['assets'][0]['data']['from'] = str(user.pub_key) lock_json['condition']['data']['cond_keys'] = [str(user.pub_key)] lock_json['succeed'] = [str(user.pub_key)] lock_json['failed'] = [str(user.pub_key)] newlock = AG.new_action_from_json('newlock', json.dumps(lock_json)) trx = TG.new_trx() trx.add_action(issuefungible2) trx.add_sign(priv_evt) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() # trx.add_action(prodvote) trx.add_action(newdomain) trx.add_action(newsuspend) trx.add_action(newsuspend2) trx.add_action(newgroup) trx.add_action(newfungible) trx.add_sign(user.priv_key) trx.add_sign(priv_evt) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() trx.add_action(updatedomain) trx.add_action(cancelsuspend) trx.add_action(aprvsuspend) trx.add_action(updategroup) trx.add_action(issuetoken) trx.add_action(issuefungible1) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() trx.add_action(e2p) trx.add_action(addmeta) trx.add_action(execsuspend) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() trx.add_action(setpsvbonus) trx.add_sign(priv_evt) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() trx.add_action(destroytoken) trx.add_action(everipass) trx.add_action(everipay) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) trx = TG.new_trx() trx.add_action(newlock) trx.add_sign(user.priv_key) trx.set_payer(user.pub_key.to_string()) resp = api.push_transaction(trx.dumps()) print(resp) time.sleep(2)