def setup_eos_test_network(url = 'https://api.testnet.eos.io', deploy_type=1): global main_token global system_contract global main_token_contract global python_contract global network_url global code_permission_name global contract_deploy_type import os from pyeoskit import eosapi, wallet contract_deploy_type = deploy_type network_url = url main_token = 'TNT' system_contract = 'eosio' main_token_contract = 'eosio.token' python_contract = 'ceyelqpjeeia' code_permission_name = 'eosio.code' eosapi.set_public_key_prefix('EOS') if os.path.exists('test.wallet'): os.remove('test.wallet') wallet.create('test') # import active key for hello wallet.import_key('test', '5JRYimgLBrRLCBAcjHUWCYRv3asNedTYYzVgmiU4q2ZVxMBiJXL') # import active key for helloworld11 wallet.import_key('test', '5Jbb4wuwz8MAzTB9FJNmrVYGXo4ABb7wqPVoWGcZ6x8V2FwNeDo') # active key of ceyelqpjeeia wallet.import_key('test', '5JfZz1kXF8TXsxQgwfsvZCUBeTQefYSsCLDSbSPmnbKQfFmtBny') # active key of ebvjmdibybgq wallet.import_key('test', '5KiVDjfHMHXzxrcLqZxGENrhCcCXBMSXP7paPbJWiMCDRMbStsF')
def test_basic(self): mywallet = 'mywallet2' if os.path.exists(f'{mywallet}.wallet'): os.remove(f'{mywallet}.wallet') psw = wallet.create(mywallet) key = eosapi.create_key() logger.info(key) priv_key = key['private'] r = wallet.import_key(mywallet, priv_key) assert r r = wallet.import_key(mywallet, priv_key) assert not r logger.error(eosapi.get_last_error()) wallet.save(mywallet) wallet.set_timeout(1) time.sleep(2) priv_key = eosapi.create_key()['private'] r = wallet.import_key(mywallet, priv_key) assert not r logger.error(eosapi.get_last_error()) r = wallet.unlock(mywallet, psw) assert r priv_key = eosapi.create_key()['private'] r = wallet.import_key(mywallet, priv_key) assert r with pytest.raises(WalletException): psw = wallet.create('a/mywallet2') wallets = wallet.list_wallets() logger.info(wallets) assert wallets keys = wallet.list_keys(mywallet, psw) assert keys logger.info(keys) pub_keys = wallet.get_public_keys() assert pub_keys logger.info(pub_keys) wallet.lock_all() wallets = wallet.list_wallets() logger.info(wallets) assert wallets == ['mywallet', 'mywallet2']
async def api_test(self): if os.path.exists('test.wallet'): os.remove('test.wallet') wallet.create('test') wallet.import_key( 'test', '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3') api = ChainApiAsync('UUOS', 'http://127.0.0.1:8989') r = await api.get_info() logger.info(r) r = await api.get_account(config.system_contract) logger.info(r) r = await api.push_action(config.system_contract, 'sayhello', b'', {config.system_contract: 'active'}) logger.info(r)
def __init__(self, host='127.0.0.1', single_node=True, show_log=False, log_config='', extra=''): self.host = host self.single_node = single_node self.show_log = show_log self.log_config = log_config self.extra = extra self.tmp_dir = '.eos-testnet' self.nodes = [] self.test_accounts = ( 'hello', 'helloworld11', 'helloworld12', 'helloworld13', 'helloworld14', 'helloworld15', 'helloworld33', ) self.producer_accounts = ('genesisbp111', 'genesisbp112', 'genesisbp113', 'genesisbp114', 'genesisbp115') self.cur_dir = os.path.dirname(__file__) if not os.path.exists(self.tmp_dir): os.mkdir(self.tmp_dir) wallet.set_dir(self.tmp_dir) test_wallet = os.path.join(self.tmp_dir, 'test.wallet') if os.path.exists(test_wallet): os.remove(test_wallet) psw = wallet.create('test') print(psw) priv_keys = [ '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', #EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV '5JEcwbckBCdmji5j8ZoMHLEUS8TqQiqBG1DRx1X9DN124GUok9s', #EOS61MgZLN7Frbc2J7giU7JdYjy2TqnfWFjZuLXvpHJoKzWAj7Nst '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB', #EOS5JuNfuZPATy8oPz9KMZV2asKf9m8fb2bSzftvhW55FKQFakzFL '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p', #EOS8Znrtgwt8TfpmbVpTKvA2oB8Nqey625CLN8bCN3TEbgx86Dsvr '5KH8vwQkP4QoTwgBtCV5ZYhKmv8mx56WeNrw9AZuhNRXTrPzgYc', #EOS7ent7keWbVgvptfYaMYeF2cenMBiwYKcwEuc11uCbStsFKsrmV '5KT26sGXAywAeUSrQjaRiX9uk9uDGNqC1CSojKByLMp7KRp8Ncw', #EOS8Ep2idd8FkvapNfgUwFCjHBG4EVNAjfUsRRqeghvq9E91tkDaj '5JRYimgLBrRLCBAcjHUWCYRv3asNedTYYzVgmiU4q2ZVxMBiJXL', #EOS6AjF6hvF7GSuSd4sCgfPKq5uWaXvGM2aQtEUCwmEHygQaqxBSV '5Jbb4wuwz8MAzTB9FJNmrVYGXo4ABb7wqPVoWGcZ6x8V2FwNeDo', #EOS7sPDxfw5yx5SZgQcVb57zS1XeSWLNpQKhaGjjy2qe61BrAQ49o '5JHRxntHapUryUetZgWdd3cg6BrpZLMJdqhhXnMaZiiT4qdJPhv', #EOS89jesRgvvnFVuNtLg4rkFXcBg2Qq26wjzppssdHj2a8PSoWMhx '5Jbh1Dn57DKPUHQ6F6eExX55S2nSFNxZhpZUxNYFjJ1arKGK9Q3', #EOS73ECcVHVWvuxJVm5ATnqBTCFMtA6WUsdDovdWH5NFHaXNq1hw1 '5JJYrXzjt47UjHyo3ud5rVnNEPTCqWvf73yWHtVHtB1gsxtComG', #EOS8h8TmXCU7Pzo5XQKqyWwXAqLpPj4DPZCv5Wx9Y4yjRrB6R64ok '5J9PozRVudGYf2D4b8JzvGxPBswYbtJioiuvYaiXWDYaihNFGKP', #EOS65jj8NPh2EzLwje3YRy4utVAATthteZyhQabpQubxHNJ44mem9 '5K9AZWR2wEwtZii52vHigrxcSwCzLhhJbNpdXpVFKHP5fgFG5Tx', #EOS5fVw435RSwW3YYWAX9qz548JFTWuFiBcHT3PGLryWaAMmxgjp1 ] for priv_key in priv_keys: wallet.import_key('test', priv_key, False)
async def set_contract_async(): if os.path.exists('test.wallet'): os.remove('test.wallet') psw = wallet.create('test') wallet.import_key( 'test', '5Jbb4wuwz8MAzTB9FJNmrVYGXo4ABb7wqPVoWGcZ6x8V2FwNeDo') #eosapi.set_nodes(['https://nodes.uuos.network:8443']) api = ChainApiAsync('http://127.0.0.1:8888', 'UUOS') account_name = 'helloworld11' code = ''' def apply(receiver, code, action): print('hello,world, async') ''' code = await api.compile(account_name, code, 1) r = await api.deploy_contract(account_name, code, g_abi, 1) print('done!')
def test_set_contract(self): if os.path.exists('test.wallet'): os.remove('test.wallet') psw = wallet.create('test') wallet.import_key( 'test', '5Jbb4wuwz8MAzTB9FJNmrVYGXo4ABb7wqPVoWGcZ6x8V2FwNeDo') #eosapi.set_nodes(['https://nodes.uuos.network:8443']) eosapi.set_node('http://127.0.0.1:8888') eosapi.db.reset() account_name = 'helloworld11' code = ''' def apply(receiver, code, action): print('hello,worldd') ''' code = eosapi.compile(account_name, code, 1) r = eosapi.deploy_contract(account_name, code, g_abi, 1) print('done!')
def commit(commit_id=None): user_path = os.path.expanduser('~') user_path = os.path.join(user_path, '.cm') if not os.path.exists(user_path): os.mkdir(user_path) wallet.set_dir(user_path) properties_path = os.path.join(user_path, '.properties') commit_path = os.path.join(user_path, '.commit') js = JsonStore(properties_path) psw = js.get('psw') if not psw: psw = wallet.create('.commit') if not psw: raise Exception('create wallet failed!') # print('+++psw:', psw) wallet.import_key('.commit', '5JkRtzuX6JBbfnxkf9iRrqYonhQEaqqCMgRThJpxMsSnAxqBzkJ') js['psw'] = psw else: # print(psw) wallet.unlock('.commit', psw) wallet.import_key('.commit', '5JkRtzuX6JBbfnxkf9iRrqYonhQEaqqCMgRThJpxMsSnAxqBzkJ') try: id = 'aabbccdd' # eosapi.set_node('https://user-api.eoseoul.io') # eosapi.set_node('https://node.eosflare.io') try: r = eosapi.push_action('learnforever', 'sayhello', bytes.fromhex(id), {'learnforever':'sayhello'}) print(r) except Exception as e: import time;time.sleep(3.0) r = httpx.get('https://api.eospowerup.io/freePowerup/learnforever') print(e) except subprocess.CalledProcessError as e: print(e.output.decode('utf8'))
from pyeoskit import db info = db.get_abi('hello') print(info) import os from pyeoskit import eosapi from pyeoskit import wallet from pyeoskit import db from pyeoskit import hello db.reset() if os.path.exists('mywallet.wallet'): os.remove('mywallet.wallet') psw = wallet.create('mywallet') wallet.unlock('mywallet', psw) wallet.import_key('mywallet', '5JbDP55GXN7MLcNYKCnJtfKi9aD2HvHAdY7g8m67zFTAFkY1uBB') code = b''' import db from eoslib import N, read_action, send_inline, transfer_inline def sayHello(): n = N('hello') id = N('name') name = read_action() print('hello', name) code = n
import sys import shutil import hashlib import marshal import subprocess from pyeoskit import eosapi, wallet, db from pyeoskit import config from pyeoskit._hello import _eosapi db.reset() config.main_token = 'UUOS' default_vm_type = 1 if os.path.exists('test.wallet'): os.remove('test.wallet') psw = wallet.create('test') wallet.import_key('test', '5KH8vwQkP4QoTwgBtCV5ZYhKmv8mx56WeNrw9AZuhNRXTrPzgYc') wallet.import_key('test', '5JMXaLz5xnVvwrnvAGaZKQZFCDdeU6wjmuJY1rDnXiUZz7Gyi1o') #eosapi.set_nodes(['https://nodes.uuos.network:8443']) eosapi.set_nodes(['http://127.0.0.1:8888']) def run_test_code(code, abi='', account_name='helloworld11'): publish_contract(account_name, code, abi) try: r = eosapi.push_action(account_name, 'sayhello', b'hello,world', {account_name: 'active'})
with open('abi.py', 'r') as f: abi = f.read() return code, abi def _run(future): loop = asyncio.get_event_loop() loop.run_until_complete(future) load_code = _load_code run = _run sys.path.append('..') if os.path.exists('test.wallet'): os.remove('test.wallet') wallet.create('test') def print_console(r): print('\n===================== CONSOLE OUTPUT BEGIN =====================\n') print(r['processed']['action_traces'][0]['console']) print('\n===================== CONSOLE OUTPUT END =====================\n') def run_test(): global test_account1 global test_account2 test_account1 = 'ceyelqpjeeia' test_account2 = 'ebvjmdibybgq' import os import sys import asyncio