def core(contracts_dir, contracts_docs_dir, init_data_file, output, timestamp, prevhash): # pylint: disable=too-many-arguments replaceLogRecord() if solidity.get_solidity() is None: print('Solidity not found!') sys.exit(1) if contracts_docs_dir: contracts_docs_dir = os.path.abspath(contracts_docs_dir) genesis_data = GenesisData( os.path.abspath(contracts_dir), contracts_docs_dir, os.path.abspath(init_data_file), timestamp, prevhash, ) with open(init_data_file, 'r') as stream: data = yaml.load(stream) address = data['Contracts'][2]['NodeManager'][0]['nodes'] super_admin = data['Contracts'][6]['Admin'][0]['admin'] address.append(super_admin) value = '0xffffffffffffffffffffffffff' genesis_data.init_normal_contracts() genesis_data.init_permission_contracts() genesis_data.set_account_value(address, value) genesis_data.save_to_file(output)
def load_or_create_smoketest_config(): # get the contract and compiler (if available) versions versions = dict() for file in os.listdir(get_contract_path('')): if file.endswith('.sol'): versions[file] = contract_checksum(get_contract_path(file)) # if solc is available, record its version, too if get_solidity() is not None: solc_version_out, _ = subprocess.Popen( [get_solidity().compiler_available(), '--version'], stdout=subprocess.PIPE ).communicate() versions['solc'] = solc_version_out.split()[-1].decode() smoketest_config_path = os.path.join( get_project_root(), 'smoketest_config.json' ) # try to load an existing smoketest genesis config smoketest_config = dict() if os.path.exists(smoketest_config_path): with open(smoketest_config_path) as handler: smoketest_config = json.load(handler) # if the file versions still fit, return the genesis config (ignore solc if not available) config_matches = [ versions[key] == smoketest_config['versions'][key] for key in versions.keys() ] if all(config_matches): return smoketest_config # something did not fit -- we will create the genesis smoketest_config['versions'] = versions raiden_config, smoketest_genesis = complete_genesis() smoketest_config['genesis'] = smoketest_genesis smoketest_config.update(raiden_config) with open(os.path.join(get_project_root(), 'smoketest_config.json'), 'w') as handler: json.dump(smoketest_config, handler) return smoketest_config
def load_or_create_smoketest_config(): # get the contract and compiler (if available) versions versions = dict() for file in os.listdir(get_contract_path('')): if file.endswith('.sol'): versions[file] = contract_checksum(get_contract_path(file)) # if solc is available, record its version, too if get_solidity() is not None: solc_version_out, _ = subprocess.Popen( [get_solidity().compiler_available(), '--version'], stdout=subprocess.PIPE).communicate() versions['solc'] = solc_version_out.split()[-1].decode() smoketest_config_path = os.path.join(get_project_root(), 'smoketest_config.json') # try to load an existing smoketest genesis config smoketest_config = dict() if os.path.exists(smoketest_config_path): with open(smoketest_config_path) as handler: smoketest_config = json.load(handler) # if the file versions still fit, return the genesis config (ignore solc if not available) config_matches = [ versions[key] == smoketest_config['versions'][key] for key in versions.keys() ] if all(config_matches): return smoketest_config # something did not fit -- we will create the genesis smoketest_config['versions'] = versions raiden_config, smoketest_genesis = complete_genesis() smoketest_config['genesis'] = smoketest_genesis smoketest_config.update(raiden_config) with open(os.path.join(get_project_root(), 'smoketest_config.json'), 'w') as handler: json.dump(smoketest_config, handler) return smoketest_config
def validate_solc(): if _solidity.get_solidity() is None: raise RuntimeError( "Couldn't find the solc in the current $PATH.\n" "Make sure the solidity compiler is installed and available on your $PATH." ) try: _solidity.compile_contract( get_contract_path('HumanStandardToken.sol'), 'HumanStandardToken', combined='abi', optimize=False, ) except subprocess.CalledProcessError as e: msg = ( 'The solidity compiler failed to execute. Please make sure that you\n' 'are using the binary version of the compiler (solc-js is not compatible)\n' 'and that the version is >= {}'.format(MIN_REQUIRED_SOLC) ) if e.output: msg += ( '\n' 'Output: ' + e.output ) raise RuntimeError(msg) except OSError as e: msg = ( 'The solidity compiler failed to execute. Please make sure the\n' 'binary is compatible with your architecture and you can execute it.' ) child_traceback = getattr(e, 'child_traceback', None) if child_traceback: msg += ( '\n' 'Traceback: ' + child_traceback ) raise RuntimeError(msg)
def validate_solc(): if _solidity.get_solidity() is None: raise RuntimeError( "Couldn't find the solc in the current $PATH.\n" "Make sure the solidity compiler is installed and available on your $PATH." ) try: _solidity.compile_contract( get_contract_path('HumanStandardToken.sol'), 'HumanStandardToken', combined='abi', optimize=False, ) except subprocess.CalledProcessError as e: msg = ( 'The solidity compiler failed to execute. Please make sure that you\n' 'are using the binary version of the compiler (solc-js is not compatible)\n' ) if e.output: msg += ( '\n' 'Output: ' + e.output ) raise RuntimeError(msg) except OSError as e: msg = ( 'The solidity compiler failed to execute. Please make sure the\n' 'binary is compatible with your architecture and you can execute it.' ) child_traceback = getattr(e, 'child_traceback', None) if child_traceback: msg += ( '\n' 'Traceback: ' + child_traceback ) raise RuntimeError(msg)
def console_name_reg_contract(app, solidity_code, reg_id, sender_id, receiver_id): """ exercise the console service with the NameReg contract found in The_Console wiki https://github.com/ethereum/pyethapp/wiki/The_Console#creating-contracts """ from ethereum.tools import _solidity solidity = _solidity.get_solidity() if solidity is None: pytest.xfail("solidity not installed, not tested") else: # create the NameReg contract # evm_code = _solidity.compile_code(solidity_code) evm_code = solidity.compile(solidity_code) abi = solidity.mk_full_signature(solidity_code) sender = app.services.accounts.unlocked_accounts[0].address eth = app.services.console.console_locals['eth'] print(evm_code) tx = eth.transact(to='', data=evm_code, startgas=500000, sender=sender) app.mine_next_block() # creates = chain.head.transactions[0].creates # interact with the NameReg contract # abi = solidity.mk_full_signature(solidity_code) namereg = eth.new_contract(abi, tx.creates, sender) tx = namereg.register('alice') print(eth.find_transaction(tx)) app.mine_next_block() print(eth.find_transaction(tx)) result = namereg.resolve(sender) print(result.encode('hex')) return tx, result
for i in range(1, 9): base_alloc[int_to_addr(i)] = {'balance': 1} minimal_alloc[int_to_addr(i)] = {'balance': 1} minimal_alloc[accounts[0]] = {'balance': 10**18} # Initialize languages languages = {} try: import serpent languages['serpent'] = serpent except ImportError: pass from ethereum.tools._solidity import get_solidity _solidity = get_solidity() if _solidity: languages['solidity'] = _solidity try: from viper import compiler languages['viper'] = compiler except (ImportError, TypeError): pass try: from vyper import compiler languages['vyper'] = compiler except (ImportError, TypeError): pass
from ethereum.tools import tester # Eason: move to tools/ from ethereum import utils from ethereum.tools._solidity import get_solidity # Eason: move to tools/ SOLIDITY_AVAILABLE = get_solidity() is not None import bitcoin # Logging from ethereum import slogging slogging.configure(':INFO,eth.vm:INFO') #slogging.configure(':DEBUG') #slogging.configure(':DEBUG,eth.vm:TRACE') xor = lambda (x, y): chr(ord(x) ^ ord(y)) xors = lambda x, y: ''.join(map(xor, zip(x, y))) zfill = lambda s: (32 - len(s)) * '\x00' + s flatten = lambda x: [z for y in x for z in y] def broadcast(p, r, h, sig): print 'player[%d]' % p.i, 'broadcasts' print '\tround', r print '\th', h.encode('hex') print '\tsignature', sig def broadcastCommitment(p, r, m): print 'player[%d]' % p.i, 'opens' print '\tround', r print '\tm', m.encode('hex')
import pytest from ethereum.tools import _solidity from ethereum.tools._solidity import compile_file from eth_utils import to_canonical_address from raiden import waiting from raiden.api.python import RaidenAPI from raiden.blockchain.abi import CONTRACT_MANAGER, CONTRACT_CHANNEL_MANAGER from raiden.exceptions import AddressWithoutCode, SamePeerAddress from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.transactions import check_transaction_threw from raiden.tests.utils.blockchain import wait_until_block from raiden.transfer import views from raiden.utils import privatekey_to_address, get_contract_path, topic_decoder solidity = _solidity.get_solidity() # pylint: disable=invalid-name @pytest.mark.parametrize('number_of_nodes', [3]) @pytest.mark.parametrize('channels_per_node', [0]) @pytest.mark.parametrize('number_of_tokens', [0]) def test_new_netting_contract(raiden_network, token_amount, settle_timeout): # pylint: disable=line-too-long,too-many-statements,too-many-locals app0, app1, app2 = raiden_network peer0_address = app0.raiden.address peer1_address = app1.raiden.address peer2_address = app2.raiden.address blockchain_service0 = app0.raiden.chain registry = app0.raiden.default_registry
def console_name_reg_contract_v2(app, solidity_code, sender_id, receiver_id, hashData, name, age, time_stamp): """ :param app: :param solidity_code: :param reg_id: :param sender_id: :param receiver_id: :return: {'req_addr': str(addr[0]) + ':' + str(addr[1]), 'data': {'hash': hash(str(cnnOut)), 'sol': {'name': 'hello', 'age': 'goodmorning'} }, 'time_stamp': '201821199' } """ from ethereum.tools import _solidity solidity = _solidity.get_solidity() if solidity is None: pytest.xfail("solidity not installed, not tested") else: # create the NameReg contract chain = app.services.chain.chain # sender: requester id sender = app.services.accounts.unlocked_accounts[sender_id].address receiver = app.services.accounts.unlocked_accounts[receiver_id].address evm_code = solidity.compile(solidity_code) abi = solidity.mk_full_signature(solidity_code) eth = app.services.console.console_locals['eth'] tx = eth.transact(to='', data=evm_code, startgas=500000, sender=sender.encode('hex')) app.mine_next_block() print(sender) print(sender.encode('hex')) print(receiver) print(receiver.encode('hex')) # Bug in the tx.address error # https://github.com/ethereum/pyethapp/issues/76 # please modify the code in console_service.py in pyethapp # interact with the NameReg contract # abi = solidity.mk_full_signature(solidity_code) namereg = eth.new_contract(abi, tx.creates, sender) tx = namereg.writeResult(hashData, name, age, time_stamp) txp = send_transaction(app, sender_id, receiver_id, 100000000000000000000000) # print(address_test) app.mine_next_block() # result = namereg.resolve(sender) return tx
import pytest from ethereum.tools import _solidity from ethereum.tools._solidity import compile_file from ethereum.utils import denoms, normalize_address from raiden.blockchain.abi import CONTRACT_MANAGER, CONTRACT_CHANNEL_MANAGER from raiden.exceptions import AddressWithoutCode, SamePeerAddress from raiden.network.rpc.client import JSONRPCClient from raiden.network.rpc.transactions import check_transaction_threw from raiden.settings import GAS_PRICE from raiden.tests.utils.blockchain import wait_until_block from raiden.utils import privatekey_to_address, get_contract_path, topic_decoder solidity = _solidity.get_solidity() # pylint: disable=invalid-name @pytest.mark.parametrize('privatekey_seed', ['blockchain:{}']) @pytest.mark.parametrize('number_of_nodes', [3]) @pytest.mark.parametrize('channels_per_node', [0]) @pytest.mark.parametrize('number_of_tokens', [0]) def test_new_netting_contract(raiden_network, token_amount, settle_timeout): # pylint: disable=line-too-long,too-many-statements,too-many-locals app0, app1, app2 = raiden_network peer0_address = app0.raiden.address peer1_address = app1.raiden.address peer2_address = app2.raiden.address blockchain_service0 = app0.raiden.chain