def init(): psw = 'PW5Kd5tv4var9XCzvQWHZVyBMPjHEXwMjH1V19X67kixwxRpPNM4J' wallet.open('mywallet') wallet.unlock('mywallet', psw) key1 = 'EOS61MgZLN7Frbc2J7giU7JdYjy2TqnfWFjZuLXvpHJoKzWAj7Nst' key2 = 'EOS5JuNfuZPATy8oPz9KMZV2asKf9m8fb2bSzftvhW55FKQFakzFL' with producer: if not eosapi.get_account('currency'): r = eosapi.create_account('inita', 'currency', key1, key2) if not eosapi.get_account('test'): r = eosapi.create_account('inita', 'test', key1, key2) assert r with producer: r = eosapi.set_contract('currency', '../../programs/pyeos/contracts/currency/currency.py', '../../contracts/currency/currency.abi', eosapi.py_vm_type) assert r r = eosapi.set_contract('test','../../programs/pyeos/contracts/test/code.py','../../programs/pyeos/contracts/test/test.abi', eosapi.py_vm_type) assert r #transfer some "money" to test account for test with producer: r = eosapi.push_message('currency','transfer','{"from":"currency","to":"test","quantity":1000}',['currency','test'],{'currency':'active'}) assert r #transfer some "money" to test account for test with producer: r = eosapi.push_message('eos','transfer',{"from":"inita","to":"test","amount":1000,"memo":"hello"},['inita','test'],{'inita':'active'}) assert r
def test2(): with producer: if not eosapi.get_account('currency'): r = eosapi.create_account('inita', 'currency', key1, key2) assert r if not eosapi.get_account('test'): if not eosapi.get_account('test'): r = eosapi.create_account('inita', 'test', key1, key2) assert r r = eosapi.set_contract('currency', '../../contracts/currency/currency.py', '../../contracts/currency/currency.abi', 1) start = time.time() ts = PySignedTransaction() ts.reqire_scope(b'test') ts.reqire_scope(b'currency') for i in range(1): data = struct.pack("QQQ", N(b'currency'), N(b'test'), 1) msg = PyMessage() msg.init(b'currency', b'transfer', [[b'currency', b'active']], data) ts.add_message(msg) ctl = chain_controller() ctl.process_transaction(ts) r = eosapi.get_table(b'test', b'currency', b'account') print(r) print('cost:', time.time() - start)
def init(): psw = 'PW5Kd5tv4var9XCzvQWHZVyBMPjHEXwMjH1V19X67kixwxRpPNM4J' wallet.open('mywallet') wallet.unlock('mywallet', psw) key1 = 'EOS61MgZLN7Frbc2J7giU7JdYjy2TqnfWFjZuLXvpHJoKzWAj7Nst' key2 = 'EOS5JuNfuZPATy8oPz9KMZV2asKf9m8fb2bSzftvhW55FKQFakzFL' if not eosapi.get_account('currency'): with producer: r = eosapi.create_account('inita', 'currency', key1, key2) assert r if not eosapi.get_account('exchange'): with producer: r = eosapi.create_account('inita', 'exchange', key1, key2) assert r with producer: r = eosapi.set_contract( 'currency', '../../programs/pyeos/contracts/currency/currency.py', '../../contracts/currency/currency.abi', 1) assert r r = eosapi.set_contract( 'exchange', '../../programs/pyeos/contracts/exchange/exchange.py', '../../contracts/exchange/exchange.abi', 1) assert r
def create_accounts(): step = 500 for i in range(0, len(accounts), step): with producer: for j in range(step): if i+j >= len(accounts): break a = accounts[i+j] print(a, i, j) if not eosapi.get_account(a['name']): eosapi.create_account('eosio', a['name'], a['pub'], a['pub'])
def test(): if not eosapi.get_account('testapi'): eosapi.create_account('eosio', 'testapi', initeos.key1, initeos.key2) act = debug.wasm_test_action('test_types', 'types_size') lib_path = '/Users/newworld/dev/pyeos/build-debug/contracts/test_api/libtest_api_natived.dylib' debug.set_debug_contract('testapi', lib_path) add_test() ret, cost = eosapi.push_actions(actions) print(ret) print(cost)
def init(): with producer: if not eosapi.get_account('micropython'): r = eosapi.create_account('inita', 'micropython', initeos.key1, initeos.key2) assert r if not eosapi.get_account('test'): if not eosapi.get_account('test'): r = eosapi.create_account('inita', 'test', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract('micropython','../../programs/pyeos/contracts/micropython/mp.py','../../contracts/currency/currency.abi',2) # r = eosapi.set_contract('currency', '../../build/contracts/currency/currency.wast', '../../build/contracts/currency/currency.abi',0) assert r
def init(mpy=True): with producer: if not eosapi.get_account('backyard').permissions: r = eosapi.create_account('eosio', 'backyard', initeos.key1, initeos.key2) assert r with producer: if mpy: with open('../../programs/pyeos/contracts/backyard/backyard.mpy', 'wb') as f: f.write( eosapi.mp_compile( '../../programs/pyeos/contracts/backyard/backyard.py')) r = eosapi.set_contract( 'backyard', '../../programs/pyeos/contracts/backyard/backyard.mpy', '../../programs/pyeos/contracts/backyard/backyard.abi', 1) else: r = eosapi.set_contract( 'backyard', '../../programs/pyeos/contracts/backyard/backyard.py', '../../programs/pyeos/contracts/backyard/backyard.abi', 1) # r = eosapi.set_contract('currency', '../../build/contracts/currency/currency.wast', '../../build/contracts/currency/currency.abi',0) assert r
def func_wrapper(*args, **kwargs): if not eosapi.get_account('evm'): print('evm account not exist, create it.') r = eosapi.create_account('eosio', 'evm', initeos.key1, initeos.key2) assert r func(*args, **kwargs)
def init(): with producer: r = eosapi.get_account('evm') if not r: print('evm account not exist, create it.') r = eosapi.create_account('eosio', 'evm', initeos.key1, initeos.key2) assert r
def init(): if not eosapi.get_account('currency'): with producer: r = eosapi.create_account('inita', 'currency', initeos.key1, initeos.key2) assert r if not eosapi.get_account('exchange'): with producer: r = eosapi.create_account('inita', 'exchange', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract('currency', '../../programs/pyeos/contracts/currency/currency.py', '../../contracts/currency/currency.abi', eosapi.py_vm_type) assert r r = eosapi.set_contract('exchange', '../../programs/pyeos/contracts/exchange/exchange.py', '../../contracts/exchange/exchange.abi', eosapi.py_vm_type) assert r
def init(): psw = 'PW5Kk1h8RqDwf8CB8mKcz7WZ8r6MF9of9CYvrC96XdBL5Z1SwBVx9' if not os.path.exists('data-dir/mywallet.wallet'): psw = wallet.create('mywallet') print(psw) wallet.open('mywallet') wallet.unlock('mywallet', psw) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB' ] keys = wallet.list_keys() exist_priv_keys = keys.values() for priv_key in priv_keys: if not priv_key in exist_priv_keys: wallet.import_key('mywallet', priv_key) src_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(os.path.join(src_dir, '/contracts/cryptokitties')) contracts_path = os.path.join(src_dir, '../../build', 'contracts') for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']: if not eosapi.get_account(account).permissions: r = eosapi.create_account('eosio', account, key1, key2) assert r if not eosapi.get_code(account): wast = os.path.join(contracts_path, account, account + '.wast') abi = os.path.join(contracts_path, account, account + '.abi') r = eosapi.set_contract(account, wast, abi, 0) eosapi.produce_block()
def test3(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).permissions: r = eosapi.create_account('eosio', currency, key1, key2) assert r if d: if d==1: r = eosapi.set_contract(currency,'../../programs/pyeos/contracts/currency/currency.py','../../contracts/currency/currency.abi', 1) elif d == 2: with open('../../programs/pyeos/contracts/currency/currency.mpy', 'wb') as f: data = eosapi.mp_compile('../../programs/pyeos/contracts/currency/currency.py') f.write(data) r = eosapi.set_contract(currency,'../../programs/pyeos/contracts/currency/currency.mpy','../../contracts/currency/currency.abi', 1) elif d == 3: wast = '../../build/contracts/currency/currency.wast' key_words = b"hello,world\\00" wast = '../../build/contracts/currency/currency.wast' with open(wast, 'rb') as f: data = f.read() #data.find(key_words) replace_str = b"%s\\00"%(currency.encode('utf8'),) replace_str.zfill(len(key_words)) #replace key works with custom words to break the effect of code cache mechanism data = data.replace(key_words, replace_str) with open('currency2.wast', 'wb') as f: f.write(data) r = eosapi.set_contract(currency, 'currency2.wast', '../../build/contracts/currency/currency.abi',0) else: assert 0 eosapi.produce_block() accounts = [] functions = [] args = [] per = [] for i in range(0, count): currency = 'curre'+n2s(i) accounts.append(currency) per.append({currency:'active'}) functions.append('issue') arg = str(i) args.append({"to":currency,"quantity":"1000.0000 CUR","memo":""}) ret = eosapi.push_messages(accounts, functions, args, per, True, rawargs=False) assert ret if ret: cost = ret['cost_time'] 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 play(): with producer: if not eosapi.get_account('hello').permissions: r = eosapi.create_account('eosio', 'hello', initeos.key1, initeos.key2) assert r with producer: r = eosapi.push_message('hello','play','',{'hello':'active'},rawargs=True) assert r
def init(wasm = False): with producer: if not eosapi.get_account('currency').permissions: r = eosapi.create_account('eosio', 'currency', initeos.key1, initeos.key2) assert r if not eosapi.get_account('test').permissions: if not eosapi.get_account('test'): r = eosapi.create_account('eosio', 'test', initeos.key1, initeos.key2) assert r with producer: if wasm: r = eosapi.set_contract('currency', '../../build/contracts/currency/currency.wast', '../../build/contracts/currency/currency.abi',0) assert r else: r = eosapi.set_contract('currency','../../programs/pyeos/contracts/currency/currency.py','../../contracts/currency/currency.abi', 1) assert r
def create_multisig_account(): #PW5KKNC8zM2KVLrb1cw4YNXZ69NLK7Fr5B35wHmsPt35tyiYkY4RR test_keys = { 'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ': '5KZB2UCfpD3qCEUviXrgMdwDb6TDpuvuWvZKH85u9mBYK85Rqzd', 'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb': '5KM6MvhsNRUtafGCghEYWXYXqWidaGTKqfsida6h5mNg5ouQUTv', 'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi': '5JiwrohmpRR3PjUcf6NpSLBE2QdAUTJZf1tAHYvK7iAUTWnaGgZ', 'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX': '5K6HPpxgq5qFkRpUcaVdZVr4hmT61EzU1AFEfkm428pEQP59neB', } all_keys = wallet.list_keys() for pub in test_keys: priv = test_keys[pub] if not pub in all_keys: wallet.import_key('mywallet', priv) keys = [ [ initeos.key1, initeos.key2 ], [ 'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ', 'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb' ], [ 'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi', 'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX' ] ] accounts = ['test', 'test1', 'test2'] index = 0 for key in keys: a = accounts[index] if not eosapi.get_account(a): eosapi.create_account('eosio', a, key[0], key[1]) index += 1 eosapi.produce_block() #"test2" must come first to satisfy the tricky verifycation in authority.hpp:validate per = '{"threshold" : 100, "keys" : [], "accounts" : [{"permission":{"actor":"test2","permission":"active"},"weight":50},{"permission":{"actor":"test1","permission":"active"},"weight":50}]}' # key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd' auth = eosapi.pack_updateauth('test', 'active', 'owner', per, 0) act = [N('eosio'), N('updateauth'), [[N('test'), N('active')]], auth] r = eosapi.push_transactions2([[act]]) assert r print(r) eosapi.produce_block()
def init(): if not eosapi.get_account('test').permissions: with producer: r = eosapi.create_account('eosio', 'test', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract('test','../../programs/pyeos/contracts/apitest/apitest.py','../../programs/pyeos/contracts/apitest/test.abi', 1) assert r eosapi.produce_block()
def test(name=None): with producer: if not eosapi.get_account('hello').permissions: r = eosapi.create_account('eosio', 'hello', initeos.key1, initeos.key2) assert r with producer: if not name: name = 'mike' r = eosapi.push_message('hello','sayhello',name,{'hello':'active'},rawargs=True) assert r
def func_wrapper(*args, **kwargs): if not eosapi.get_account('test'): r = eosapi.create_account('eosio', 'test', initeos.key1, initeos.key2) assert r eosapi.produce_block() if wasm: prepare('credit', 'credit.wast', 'credit.abi', __file__) else: prepare('credit', 'credit.py', 'credit.abi', __file__) return func(*args, **kwargs)
def init(): if not eosapi.get_account('cache').permissions: with producer: r = eosapi.create_account('eosio', 'cache', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract( 'cache', '../../programs/pyeos/contracts/cache/cache.py', '../../programs/pyeos/contracts/cache/test.abi', 1) assert r
def init(): with producer: if not eosapi.get_account('rpctest').permissions: r = eosapi.create_account('eosio', 'rpctest', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract( 'rpctest', '../../programs/pyeos/contracts/rpctest/rpctest.py', '../../programs/pyeos/contracts/rpctest/rpctest.abi', 3) # r = eosapi.set_contract('currency', '../../build/contracts/currency/currency.wast', '../../build/contracts/currency/currency.abi',0) assert r
def init(): with producer: if not eosapi.get_account('currency'): r = eosapi.create_account('inita', 'currency', initeos.key1, initeos.key2) if not eosapi.get_account('test'): r = eosapi.create_account('inita', 'test', initeos.key1, initeos.key2) assert r with producer: r = eosapi.set_contract( 'currency', '../../programs/pyeos/contracts/currency/currency.py', '../../contracts/currency/currency.abi', eosapi.py_vm_type) assert r r = eosapi.set_contract( 'test', '../../programs/pyeos/contracts/test/code.py', '../../programs/pyeos/contracts/test/test.abi', eosapi.py_vm_type) assert r #transfer some "money" to test account for test with producer: r = eosapi.push_message( 'currency', 'transfer', '{"from":"currency","to":"test","quantity":1000}', ['currency', 'test'], {'currency': 'active'}) assert r #transfer some "money" to test account for test with producer: r = eosapi.push_message('eos', 'transfer', { "from": "inita", "to": "test", "amount": 1000, "memo": "hello" }, ['inita', 'test'], {'inita': 'active'}) assert r
def publish_system_contract(): contracts_path = os.path.join(os.getcwd(), '..', 'contracts') sys.path.append(os.getcwd()) for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']: print('account', account) if not eosapi.get_account(account): with producer: r = eosapi.create_account('eosio', account, key1, key2) assert r old_code = eosapi.get_code(account) if old_code: old_code = old_code[0] need_update = not old_code if old_code: print('+++++++++old_code[:4]', old_code[:4]) if old_code[:4] != b'\x00asm': old_code = eosapi.wast2wasm(old_code) wast = os.path.join(contracts_path, account, account + '.wast') code = open(wast, 'rb').read() code = eosapi.wast2wasm(code) print(len(code), len(old_code), old_code[:20]) if code == old_code: need_update = False if need_update: print('+++++++++code update', account) wast = os.path.join(contracts_path, account, account + '.wast') abi = os.path.join(contracts_path, account, account + '.abi') with producer: r = eosapi.set_contract(account, wast, abi, 0) if account == 'eosio.token': # msg = {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0, "can_whitelist":0} with producer: msg = { "issuer": "eosio", "maximum_supply": "10000000000.0000 EOS" } r = eosapi.push_action('eosio.token', 'create', msg, {'eosio.token': 'active'}) assert r r = eosapi.push_action('eosio.token', 'issue', { "to": "eosio", "quantity": "1000.0000 EOS", "memo": "" }, {'eosio': 'active'}) assert r
def prepare_(name, src, abi, full_src_path): _src_dir = os.path.dirname(os.path.abspath(full_src_path)) if src.endswith('.wast'): code_type = CODE_TYPE_WAST elif src.endswith('.py'): code_type = CODE_TYPE_PY else: raise Exception('unknown code type') if code_type == 0: cpp2wast.set_src_path(_src_dir) cpp_src_file = src.replace('.wast', '.cpp') if not cpp2wast.build(cpp_src_file): raise Exception("build {0} failed".format(cpp_src_file)) if src.find('/') < 0: src = os.path.join(_src_dir, src) if abi and abi.find('/') < 0: abi = os.path.join(_src_dir, abi) if not eosapi.get_account(name): print('*' * 20, 'create_account') r = eosapi.create_account('eosio', name, initeos.key1, initeos.key2) assert r old_code = eosapi.get_code(name) need_update = True if old_code: old_code = old_code[0] with open(src, 'rb') as f: code = f.read() if code_type == CODE_TYPE_WAST: code = eosapi.wast2wasm(code) old_code = eosapi.wast2wasm(old_code) if code == old_code: need_update = False elif CODE_TYPE_PY == code_type: code = eosapi.mp_compile(src) if code == old_code[1:]: need_update = False elif (code == old_code[1:] or code == old_code): need_update = False if need_update: print('Updating contract', src) r = eosapi.set_contract(name, src, abi, code_type) assert r, 'set_contract failed'
def init(): with producer: if not eosapi.get_account('kitties').permissions: r = eosapi.create_account('eosio', 'kitties', initeos.key1, initeos.key2) assert r sync.clean() with producer: r = eosapi.set_contract( 'kitties', '../../programs/pyeos/contracts/cryptokitties/main.py', '../../programs/pyeos/contracts/cryptokitties/cryptokitties.abi', 1) # r = eosapi.set_contract('currency', '../../build/contracts/currency/currency.wast', '../../build/contracts/currency/currency.abi',0) assert r sync.clean()
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 prepare(name, src, abi, code_type, full_src_path): _src_dir = os.path.dirname(os.path.abspath(full_src_path)) if code_type == 0: cpp2wast.set_src_path(_src_dir) cpp_src_file = src.replace('.wast', '.cpp') if not cpp2wast.build(cpp_src_file): raise Exception("build {0} failed".format(cpp_src_file)) if src.find('/') < 0: src = os.path.join(_src_dir, src) if abi and abi.find('/') < 0: abi = os.path.join(_src_dir, abi) if code_type == CODE_TYPE_MPY: mpy_file = src[:-3] + '.mpy' with open(mpy_file, 'wb') as f: f.write(eosapi.mp_compile(src)) src = mpy_file if not eosapi.get_account(name).permissions: r = eosapi.create_account('eosio', name, initeos.key1, initeos.key2) assert r old_code = eosapi.get_code(name) need_update = True if old_code: old_code = old_code[0] with open(src, 'rb') as f: code = f.read() if code_type == CODE_TYPE_WAST: code = eosapi.wast2wasm(code) old_code = eosapi.wast2wasm(old_code) if code == old_code: need_update = False elif (code == old_code[1:] or code == old_code): need_update = False if need_update: with producer: if code_type == 0: r = eosapi.set_contract(name, src, abi, 0) else: r = eosapi.set_contract(name, src, abi, 1) assert r, 'set_contract failed'
def test3(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) actions = [] for i in range(count): currency = 'curre' + n2s(i) action = [ currency, 'issue', { 'currency': 'active' }, { "to": currency, "quantity": "1000.0000 CUD", "memo": "" } ] actions.append(action) ret, cost = eosapi.push_actions(actions, True) assert ret eosapi.produce_block() 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)))
def publish_system_contracts(accounts_map): contracts_path = os.path.join(os.getcwd(), '..', 'contracts') sys.path.append(os.getcwd()) # accounts_map = {'eosio.token':'eosio.token', 'eosio.msig':'eosio.msig', 'eosio':'eosio.system'} for account in accounts_map: print('account', account) if not eosapi.get_account(account): r = eosapi.create_account('eosio', account, key1, key2) assert r _path = os.path.join(contracts_path, accounts_map[account], accounts_map[account]) wast = _path + '.wast' code = open(wast, 'rb').read() code = eosapi.wast2wasm(code) hash = eosapi.sha256(code) old_hash = eosapi.get_code_hash(account) if old_hash != hash: print('+++++++++code update', account) wast = _path + '.wast' abi = _path + '.abi' r = eosapi.set_contract(account, wast, abi, 0) print(wast, abi) time.sleep(1.0) if account == 'eosio.token' and eosapi.get_balance('eosio') <= 0.0: print('issue system token...') # msg = {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0, "can_whitelist":0} msg = { "issuer": "eosio", "maximum_supply": "11000000000000.0000 EOS" } r = eosapi.push_action('eosio.token', 'create', msg, {'eosio.token': 'active'}) assert r r = eosapi.push_action( 'eosio.token', 'issue', { "to": "eosio", "quantity": "10000000000000.0000 EOS", "memo": "" }, {'eosio': 'active'}) assert r
def test3(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).permissions: 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('issue') arg = str(i) args.append({"to": currency, "quantity": "1000.0000 CUD", "memo": ""}) ret = eosapi.push_messages(accounts, functions, args, per, True) assert ret eosapi.produce_block() 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)))
def init(): psw = 'PW5K87AKbRvFFMJJm4dU7Zco4fi6pQtygEU4iyajwyTvmELUDnFBK' if not os.path.exists('data-dir/mywallet.wallet'): psw = wallet.create('mywallet') print('wallet password:'******'mywallet') wallet.unlock('mywallet', psw) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB' ] keys = wallet.list_keys() exist_priv_keys = keys.values() for priv_key in priv_keys: if not priv_key in exist_priv_keys: wallet.import_key('mywallet', priv_key) if eosapi.is_replay(): return src_dir = os.path.dirname(os.path.abspath(__file__)) ''' r = eosapi.push_message('eosio.token', 'create', {"to":"eosio", "quantity":"10000.0000 EOS", "memo":""},{'eosio':'active'}) r = eosapi.push_message('eosio.token','issue',{"to":"hello","quantity":"1000.0000 EOS","memo":""},{'hello':'active'}) assert r msg = {"from":"eosio", "to":"hello", "quantity":"25.0000 EOS", "memo":"m"} r = eosapi.push_message('eosio.token', 'transfer', msg, {'eosio':'active'}) assert r ''' contracts_path = os.path.join(src_dir, '../../build', 'contracts') sys.path.append(os.getcwd()) for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']: print('account', account) if not eosapi.get_account(account).permissions: r = eosapi.create_account('eosio', account, key1, key2) assert r eosapi.produce_block() old_code = eosapi.get_code(account)[0] need_update = not old_code if False: #old_code: print('+++++++++old_code[:4]', old_code[:4]) if old_code[:4] != b'\x00asm': old_code = eosapi.wast2wasm(old_code) wast = os.path.join(contracts_path, account, account + '.wast') code = open(wast, 'rb').read() code = eosapi.wast2wasm(code) print(len(code), len(old_code), old_code[:20]) if code == old_code: need_update = False if need_update: wast = os.path.join(contracts_path, account, account + '.wast') abi = os.path.join(contracts_path, account, account + '.abi') r = eosapi.set_contract(account, wast, abi, 0) eosapi.produce_block() if False: #account == 'eosio.token': msg = { "issuer": "eosio", "maximum_supply": "1000000000.0000 EOS", "can_freeze": 0, "can_recall": 0, "can_whitelist": 0 } r = eosapi.push_message('eosio.token', 'create', msg, {'eosio.token': 'active'}) assert r r = eosapi.push_message('eosio.token', 'issue', { "to": "eosio", "quantity": "1000.0000 EOS", "memo": "" }, {'eosio': 'active'}) assert r eosapi.produce_block() from backyard import t t.deploy_mpy() #load common libraries # t.load_all() console = PyEosConsole(locals=globals()) console.interact(banner='Welcome to PyEos')