def test3(name='mike'): acts = [] for i in range(100): act = ['inspector', 'sayhello', str(i), {'inspector': 'active'}] acts.append([act]) r, cost = eosapi.push_transactions(acts) print('cost time:', cost)
def test3(count=1000, msg='wasm'): import time import json code = N('counter') counter_id = N('counter') counter_begin = 0 itr = db.find_i64(code, code, code, counter_id) if itr >= 0: counter_begin = db.get_i64(itr) counter_begin = int.from_bytes(counter_begin, 'little') print('counter begin: ', counter_begin) transactions = [] for i in range(count): action = ['counter', 'count', msg+':'+str(i), {'counter':'active'}] transactions.append([action]) ret, cost = eosapi.push_transactions(transactions) assert ret print('total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f'%(cost/1e6, cost/count/1000, 1*1e6/(cost/count))) counter_end = 0 itr = db.find_i64(code, code, code, counter_id) if itr >= 0: counter_end = db.get_i64(itr) counter_end = int.from_bytes(counter_end, 'little') print('counter end: ', counter_end) itr = db.find_i64(code, code, code, N('msg')) if itr >= 0: msg = db.get_i64(itr) print('msg', msg)
def test3(count=100): actions = [] for i in range(count): act = [N('storagetest'), N('sayhello'), [[N('storagetest'), N('active')]], b'hello,world%d'%(i,)] actions.append([act]) r, cost = eosapi.push_transactions(actions, True) print('total cost time:%.3f s, cost per TS: %.3f ms, TS per second: %.3f'%(cost/1e6, cost/count/1000, 1*1e6/(cost/count)))
def activatevm(): msg = int.to_bytes(N('vm.py.1'), 8, 'little') #vm name, include platform id msg += int.to_bytes(1, 8, 'little') #type: py msg += int.to_bytes(V, 8, 'little') #type: version act = [N('eosio'), N('activatevm'), [[N('eosio'), N('active')]], msg] r = eosapi.push_transactions([[act]]) assert r[0]
def test3(count=100): _from = 'eosio' _to = 'hello' print(eosapi.get_balance(_from), eosapi.get_balance(_to)) actions = [] for i in range(count): action = [ 'eosio.token', 'transfer', { "from": _from, "to": _to, "quantity": "0.0010 EOS", "memo": str(i) }, { _from: 'active' } ] actions.append([action]) ret, cost = eosapi.push_transactions(actions) print(eosapi.get_balance(_from), eosapi.get_balance(_to)) print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def test3(count=200): main_class = '<stdin>:Greeter' greeter = os.path.join(os.path.dirname(__file__), 'greeter.sol') with open(greeter, 'r') as f: contract_source_code = f.read() contract_interface = compile(contract_source_code, main_class) # deploy(contract_interface) contract_abi = contract_interface['abi'] fn_identifier = 'getValue' for abi in contract_abi: if 'name' in abi and abi['name'] == fn_identifier: fn_abi = abi break args = () kwargs = {} data = web3.utils.contracts.encode_transaction_data( web3, fn_identifier, contract_abi, fn_abi, args, kwargs) print(data) data = data[2:] transactions = [] for i in range(count): args = {'from': 'eosio', 'to': 'evm', 'amount': i, 'data': data} args = eosapi.pack_args('evm', 'ethtransfer', args) action = ['evm', 'ethtransfer', args, {'eosio': 'active'}] transactions.append([ action, ]) ret, cost = eosapi.push_transactions(transactions) assert ret print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def test2(count=100): actions = [] for i in range(count): args = '55241077' args += int.to_bytes(i, 32, 'big').hex() args = bytes.fromhex(args) act = [eosapi.s2n('evm'), N('call'), [[N('evm'), N('active')]], args] actions.append(act) outputs, cost_time = eosapi.push_transactions([actions], True) print(1e6/(cost_time/count))
def publish(): contracts_path = os.path.join(os.getcwd(), '..', 'contracts') _path = os.path.join(contracts_path, 'eosio.system', 'eosio.system') abi = _path + '.abi' setabi = eosapi.pack_setabi(abi, eosapi.N('eosio')) assert setabi setabi_action = [N('eosio'), N('setabi'), [[N('eosio'), N('active')]], setabi] r = eosapi.push_transactions([[setabi_action]]) assert r[0]
def test3(count=100): actions = [] for i in range(count): act = [ N('hello'), N('sayhello'), [[N('hello'), N('active')]], b'hello,world%d' % (i, ) ] actions.append([act]) r, cost_time = eosapi.push_transactions(actions, True) print(1e6 / (cost_time / count), cost_time)
def test3(count=200): transactions = [] for i in range(count): data =generate_call_params('testSetValue', (i,)) args = {'from':'eosio', 'to':'evm', 'amount':0, 'data':data} args = eosapi.pack_args('evm', 'transfer', args) action = ['evm', 'transfer', args, {'eosio':'active'}] transactions.append([action,]) ret, cost = eosapi.push_transactions(transactions) assert ret print('total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f'%(cost/1e6, cost/count/1000, 1*1e6/(cost/count)))
def test2(count=100): actions = [] for i in range(count): act = [ N('storagetest'), N('sayhello'), [[N('storagetest'), N('active')]], b'hello,world%d' % (i, ) ] actions.append([act]) cost_time = eosapi.push_transactions(actions, True) print(1.0 / (cost_time / 1e6 / 100.0), cost_time)
def test3(count=200): actions = [] for i in range(count): action = ['counter', 'count', str(i), [['counter', 'active']]] actions.append([action]) ret, cost = eosapi.push_transactions(actions) assert ret print( 'total cost time:%.3f s, cost per action: %.3f ms, transaction per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def test3(count=100): actions = [] for i in range(count): act = [ 'hellolua', 'sayhello', b'hello,world%d' % (i, ), { 'hellolua': 'active' } ] actions.append([act]) r, cost = eosapi.push_transactions(actions, True) print( 'total cost time:%.3f s, cost per action: %.3f ms, transaction per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def ttt(count=200): actions = [] for i in range(count): args = { "from": 'eosio', "to": 'eosio.ram', "quantity": '%.4f EOS' % (0.01, ), "memo": str(i) } args = eosapi.pack_args('eosio.token', 'transfer', args) action = ['eosio.token', 'transfer', args, {'eosio': 'active'}] actions.append([action]) ret, cost = eosapi.push_transactions(actions) print( 'total cost time:%.3f s, cost per action: %.3f ms, transaction per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def test4(count, d=0): keys = list(wallet.list_keys().keys()) for i in range(0, count): currency = 'curre' + n2s(i) # currency = 'currency' key1 = keys[i] key2 = keys[10000 + i] if not eosapi.get_account(currency): r = eosapi.create_account('eosio', currency, key1, key2) assert r deploy_contract(currency, d) eosapi.produce_block() time.sleep(0.5) accounts = [] functions = [] args = [] per = [] for i in range(0, count): currency = 'curre' + n2s(i) accounts.append(currency) per.append({currency: 'active'}) functions.append('create') arg = str(i) msg = { "issuer": "eosio", "maximum_supply": "1000000000.0000 EOK", "can_freeze": 0, "can_recall": 0, "can_whitelist": 0 } #{"to":currency,"quantity":"1000.0000 CUR","memo":""} args.append(msg) cost = eosapi.push_transactions(accounts, functions, args, per, True) eosapi.produce_block() print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def test3(count=100): actions = [] for i in range(count): msg = { "from": "eosio", "to": "eosio.token", "quantity": "0.0001 EOS", "memo": str(i) } msg = eosapi.pack_args('eosio.token', 'transfer', msg) act = [ N('eosio.token'), N('transfer'), [[N('eosio'), N('active')]], msg ] actions.append([act]) r, cost = eosapi.push_transactions(actions, True) print('total cost time:%.3f s, cost per TS: %.3f ms, TS per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count)))
def set_contract(account, src_file, abi_file, vmtype=1, sign=True): '''Set code and abi for the account Args: account (str) : account name src_file (str) : source file path abi_file (str) : abi file path vmtype : virtual machine type, 0 for wasm, 1 for micropython, 2 for evm sign (bool) : True to sign transaction Returns: JsonStruct|None: ''' account = eosapi.N(account) code = struct.pack('QBB', account, vmtype, 0) if vmtype == 0: with open(src_file, 'rb') as f: wasm = eosapi.wast2wasm(f.read()) code += eosapi.pack_bytes(wasm) setcode = [N('eosio'), N('setcode'), [[account, N('active')]], code] return push_transactions([[setcode]], sign, compress = True)
def change_active_key(): key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd' auth = eosapi.pack_updateauth('test', 'active', 'owner', key, 0) act = ['eosio', 'updateauth', [['test', 'active']], auth] r = eosapi.push_transactions([[act]]) assert r