def setup_class(cls): eosapi.set_node('http://127.0.0.1:9000') eosapi_async = ChainApiAsync('http://127.0.0.1:9000') cls.testnet = Testnet(single_node=True, show_log=False) cls.testnet.run() cls.info = eosapi.get_info() # logger.info(cls.info) cls.chain_id = cls.info['chain_id']
def test_1sign_transaction(self): eosapi.set_node('http://127.0.0.1:9000') args = { 'from': 'helloworld11', 'to': 'b', 'quantity': '1.0000 EOS', 'memo': 'hello' } eosapi.push_action('eosio.token', 'transfer', args, {'helloworld11': 'active'}, indexes=[0])
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 test_deploy_python_code_sync(self): eosapi.set_node('http://127.0.0.1:9000') code = ''' import chain def apply(a, b, c): data = chain.read_action_data() print(data) ''' account = 'helloworld11' config.python_contract = account code = eosapi.mp_compile(account, code) eosapi.deploy_python_contract(account, code, b'') r = eosapi.push_action(account, 'sayhello', b'hellooo,world', {account:'active'}) console = r['processed']['action_traces'][0]['console'] logger.info(console) assert console == "b'hellooo,world'\r\n" r = eosapi.push_action(account, 'sayhello', b'goodbye,world', {account:'active'}) console = r['processed']['action_traces'][0]['console'] logger.info(console) assert console == "b'goodbye,world'\r\n"
def start_nodes(self, wait=False): self.nodes = [] if self.log_config: configs = f'--data-dir ./{self.tmp_dir}/dd --config-dir ./{self.tmp_dir}/cd -l {self.log_config} {self.extra}' else: configs = f'--data-dir ./{self.tmp_dir}/dd --config-dir ./{self.tmp_dir}/cd {self.extra}' args = f'nodeos --verbose-http-errors --http-max-response-time-ms 100 --p2p-listen-endpoint {self.host}:9100 {configs} -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin -e --resource-monitor-space-threshold 99 --http-server-address {self.host}:9000 --contracts-console --access-control-allow-origin="*"' # --backing-store rocksdb' logger.info(args) args = shlex.split(args) # if self.show_log: # f = sys.stdout # else: # f = open('log.txt', 'a') # f = sys.stdout if self.show_log: p = subprocess.Popen(args) else: f = open('log.txt', 'a') p = subprocess.Popen(args, stdout=f, stderr=f) self.nodes.append(p) eosapi.set_node(f'http://{self.host}:9000') while True: time.sleep(0.5) try: info = eosapi.get_info() # logger.info(info) break except Exception as e: logger.info(e) if self.single_node: return self.producer_keys = [{ "public": "EOS7haGjz9YTepY31iZNfP13dzVXvsU5D2VHeJNZZjhxwMVyCrCFL", "private": "5Jyj1Scuwu47yTBbQoYojrvw5xbMoUUGHoV4DzEFsKDjAVrvEhB" }, { "public": "EOS5g4kCpZDYHLrbmkGh3cvnbt9KZs9kK3j95LKjRTT8pYR4dkKE3", "private": "5JrfTriycVJHxnAw2gBEuLXjU2HAqZMwyzw18dNMVfXhkN4vQ4D" }, { "public": "EOS8GGk6a2RU8JCGLEQ4LVhFtMH9PLvcPYrwxviCKr842amwvBWdD", "private": "5Hxz7hbHK9nJg1kV4W2ScMGFCX6Ks4B8MQ5kt1AdmRNRzxymP5X" }, { "public": "EOS56KkFcZ5rtkSQmM9ZbBRV8fmGzdC3GTGrZi7KuQEhJmHSpiMHg", "private": "5KLBi386dgBDHunmoqrEbj6MaydYwEXgx1Awqk4a78rZ7b9S7iN" }, { "public": "EOS5cv6rQ1okdvqktfX8R2SKeyMFZAnFHCc1jAXerbpzUtsu4A9F9", "private": "5JaoiGqLBQ9ASsB946anLJa8hPAm7yaLn4gY1adU7vw9LX8UTtJ" }] start_port = 9001 http_ports = [port for port in range(start_port, start_port + 5)] p2p_ports = [ 9100, ] for http_port in http_ports: p2p_listen_port = http_port + 100 index = http_port - start_port http_ports_copy = copy.copy(http_ports) del http_ports_copy[index] bp = f'genesisbp11{index+1}' logfile = f'{self.tmp_dir}/{bp}.log' pub = self.producer_keys[index]['public'] priv = self.producer_keys[index]['private'] signature_provider = f'--signature-provider={pub}=KEY:{priv}' http_server_address = f'--http-server-address {self.host}:{http_port}' p2p_listen_endpoint = f'--p2p-listen-endpoint {self.host}:{p2p_listen_port}' p2p_peer_address = '' for port in p2p_ports: p2p_peer_address += f'--p2p-peer-address {self.host}:{port} ' dirs = f'--data-dir {self.tmp_dir}/dd-{bp} --config-dir {self.tmp_dir}/cd-{bp} -p {bp}' if http_port == 9001: args = f'nodeos -e {dirs} {signature_provider} {http_server_address} {p2p_listen_endpoint} {p2p_peer_address} --verbose-http-errors --http-max-response-time-ms 100 --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin --resource-monitor-space-threshold 99 --contracts-console --access-control-allow-origin="*"' # --backing-store rocksdb' else: args = f'nodeos {dirs} {signature_provider} {http_server_address} {p2p_listen_endpoint} {p2p_peer_address} --verbose-http-errors --http-max-response-time-ms 100 --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::producer_api_plugin --plugin eosio::history_api_plugin --resource-monitor-space-threshold 99 --contracts-console --access-control-allow-origin="*"' # --backing-store rocksdb' logger.info(args) args = shlex.split(args) f = open(logfile, 'a') p = subprocess.Popen(args, stdout=f, stderr=f) self.nodes.append(p) p2p_ports.append(p2p_listen_port) if wait: p.wait() return p
from pyeoskit import eosapi, wallet eosapi.set_node('https://api.eosn.io') #import your account private key here wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') payer = 'testaccount1' receiver = 'testaccount2' args = { 'payer': payer, 'receiver': receiver, 'quant':'0.1 EOS' } eosapi.push_action('eosio', 'buyram', args, {payer:'active'})
import os import sys import time import pytest import logging import hashlib from pyeoskit import eosapi, config, wallet from pyeoskit.exceptions import ChainException, WalletException logging.basicConfig( level=logging.INFO, format='%(asctime)s %(levelname)s %(lineno)d %(module)s %(message)s') logger = logging.getLogger(__name__) test_dir = os.path.dirname(__file__) eosapi.set_node('http://127.0.0.1:8899') if os.path.exists('mywallet.wallet'): os.remove('mywallet.wallet') psw = wallet.create('mywallet') wallet.import_key('mywallet', '5K463ynhZoCDDa4RDcr63cUwWLTnKqmdcoTKTHBjqoKfv4u5V7p') class Test(object): @classmethod def setup_class(cls): pass @classmethod def teardown_class(cls):
#!/Users/newworld/opt/anaconda3/bin/python3 import os import sys import json import subprocess import logging from pyeoskit import wallet, eosapi import httpx #eosapi.set_node('https://node.eosflare.io') #eosapi.set_node('https://user-api.eoseoul.io') #eosapi.set_node('eos.eoscafeblock.com') #eosapi.set_node('api.hkeos.com') #eosapi.set_node('https://eos.greymass.com') eosapi.set_node('api.hkeos.com') eosapi.set_node('api.eosn.io') logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(module)s %(lineno)d %(message)s') logger=logging.getLogger(__name__) class JsonStore(object): """Replacement of shelve using json, needed for support python 2 and 3. """ def __init__(self, filename): super(JsonStore, self).__init__() self.filename = filename self.data = {} if os.path.exists(filename):