def deploy_mpy(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in libs: print('deploy ', file_name) src_code = eosapi.mp_compile(os.path.join(src_dir, file_name)) file_name = file_name.replace('.py', '.mpy') src_id = eosapi.hash64(file_name, 0) itr = eoslib.db_find_i64(code, code, code, src_id) if itr >= 0: old_src = eoslib.db_get_i64(itr) if old_src[1:] == src_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(1, 1, 'little') # compiled code msg += src_code print('++++++++++++++++deply:', file_name) r = eosapi.push_message('backyard', 'deploy', msg, {'backyard': 'active'}) assert r producer.produce_block()
def test2(count=100): contracts = [] functions = [] args = [] per = [] for i in range(count): functions.append('setgreeting') arg = str(i) args.append(arg) contracts.append('greeter') per.append({'greeter': 'active'}) ret = eosapi.push_messages(contracts, functions, args, per, True) assert ret cost = ret['cost_time'] print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count))) eosapi.produce_block() code = eosapi.N('greeter') id = eosapi.hash64('greeting', 0) greeting = 0 itr = eoslib.db_find_i64(code, code, code, id) if itr >= 0: greeting = eoslib.db_get_i64(itr) print(greeting[1:])
def test2(count=100): import time import json code = N('counter') counter_id = N('counter') counter_begin = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_begin = eoslib.db_get_i64(itr) counter_begin = int.from_bytes(counter_begin, 'little') print('counter begin: ', counter_begin) actions = [] for i in range(count): action = ['hello', 'sayhello', {'hello': 'active'}, str(i)] actions.append(action) ret, cost = eosapi.push_actions(actions, True) 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))) eosapi.produce_block() actions = [] for i in range(count): action = ['counter', 'count', {'counter': 'active'}, str(i)] actions.append(action) ret, cost = eosapi.push_actions(actions, True) 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))) eosapi.produce_block() counter_end = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_end = eoslib.db_get_i64(itr) counter_end = int.from_bytes(counter_end, 'little') print('counter end: ', counter_end) assert counter_begin + count == counter_end
def test2(count): import time import json if not eosapi.get_account('counter').permissions: init() code = N('counter') counter_id = N('counter') counter_begin = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_begin = eoslib.db_get_i64(itr) counter_begin = int.from_bytes(counter_begin, 'little') print('counter begin: ', counter_begin) contracts = [] functions = [] args = [] per = [] for i in range(count): functions.append('count') arg = str(i) args.append(arg) contracts.append('counter') per.append({'counter': 'active'}) ret = eosapi.push_messages(contracts, functions, args, per, True) assert ret cost = ret['cost_time'] print( 'total cost time:%.3f s, cost per action: %.3f ms, actions per second: %.3f' % (cost / 1e6, cost / count / 1000, 1 * 1e6 / (cost / count))) eosapi.produce_block() counter_end = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_end = eoslib.db_get_i64(itr) counter_end = int.from_bytes(counter_end, 'little') print('counter end: ', counter_end) assert counter_begin + count == counter_end
def test(name=None): code = N('counter') counter_id = N('counter') counter_begin = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_begin = eoslib.db_get_i64(itr) counter_begin = int.from_bytes(counter_begin, 'little') print('counter begin: ', counter_begin) with producer: r = eosapi.push_action('counter', 'count', '', {'counter': 'active'}) assert r counter_end = 0 itr = eoslib.db_find_i64(code, code, code, counter_id) if itr >= 0: counter_end = eoslib.db_get_i64(itr) counter_end = int.from_bytes(counter_end, 'little') print('counter end: ', counter_end) assert counter_begin + 1 == counter_end
def test2(count=100): actions = [] for i in range(count): action = ['greeter', 'setgreeting', {'greeter': 'active'}, str(i)] actions.append(action) ret, cost = eosapi.push_actions(actions, True) 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))) eosapi.produce_block() code = eosapi.N('greeter') id = eosapi.hash64('greeting', 0) greeting = 0 itr = eoslib.db_find_i64(code, code, code, id) if itr >= 0: greeting = eoslib.db_get_i64(itr) print(greeting[1:])
def need_update(self, src_dir, src_file, mpy=False): if mpy: id = eosapi.hash64(src_file.replace('.py', '.mpy')) else: id = eosapi.hash64(src_file) code = eosapi.N(self.account) itr = eoslib.db_find_i64(code, code, code, id) if itr < 0: return True old_src = eoslib.db_get_i64(itr) _full_file_path = os.path.join(src_dir, src_file) if not mpy: with open(_full_file_path, 'rb') as f: if old_src[1:] == f.read(): return False else: src_code = eosapi.mp_compile(_full_file_path) if old_src[1:] == src_code: return False return True
def deploy(): src_dir = os.path.dirname(os.path.abspath(__file__)) code = eosapi.N('backyard') for file_name in libs: src_code = open(os.path.join(src_dir, file_name), 'rb').read() src_id = eosapi.hash64(file_name, 0) itr = eoslib.db_find_i64(code, code, code, src_id) if itr >= 0: old_src = eoslib.db_get_i64(itr) if old_src[1:] == src_code: continue mod_name = file_name msg = int.to_bytes(len(mod_name), 1, 'little') msg += mod_name.encode('utf8') msg += int.to_bytes(0, 1, 'little') # source code msg += src_code print('++++++++++++++++deply:', file_name) r = eosapi.push_action('backyard', 'deploy', msg, {'backyard': 'active'}) assert r producer.produce_block()
import eoslib n = eosapi.N('rpctest') itr = eoslib.db_find_i64(n, n, n, eosapi.N('name')) ret = eoslib.db_get_i64(itr) print(ret)