def initialize(self): self.geth_server = self.settings.get('geth_server') if self.geth_server is None: self.geth_server = get_path_of('geth') self.difficulty = self.settings.get('difficulty') if self.difficulty is None: self.difficulty = 1024 p = subprocess.Popen([self.geth_server, 'version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) outs, errs = p.communicate(timeout=15) for line in outs.split(b'\n'): m = re.match("^Version:\s([0-9.]+)(?:-[a-z]+)?$", line.decode('utf-8')) if m: v = tuple(int(i) for i in m.group(1).split('.')) break else: raise Exception("Unable to figure out Geth version") self.version = v self.chainfile = os.path.join(self.base_dir, 'chain.json') self.author = self.settings.get('author')
def initialize(self): self.parity_server = self.settings.get('parity_server') if self.parity_server is None: self.parity_server = get_path_of('parity') p = subprocess.Popen([self.parity_server, '-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) outs, errs = p.communicate(timeout=15) for line in errs.split(b'\n') + outs.split(b'\n'): m = re.match("^\s+version\sParity\/v([0-9.]+).*$", line.decode('utf-8')) if m: v = tuple(int(i) for i in m.group(1).split('.')) break else: raise Exception("Unable to figure out Parity version") self.version = v self.chainfile = os.path.join(self.base_dir, 'chain.json') self.faucet = self.settings.get('faucet') self.author = self.settings.get('author') self.difficulty = self.settings.get('difficulty') if self.difficulty is None: self.difficulty = 1024
def find_program(name, subdirs): path = get_path_of(name) if path: return path mysql_paths = [os.path.join(dir, 'bin', 'mysql') for dir in SEARCH_PATHS] + \ [get_path_of('mysql')] for mysql_path in mysql_paths: if mysql_path and os.path.exists(mysql_path): for subdir in subdirs: replace = '/%s/%s' % (subdir, name) path = re.sub('/bin/mysql$', replace, mysql_path) if os.path.exists(path): return path raise RuntimeError("command not found: %s" % name)
class FaucetTest(FaucetMixin, AsyncHandlerTest): def get_urls(self): return [(r'^/(0x.+)$', Handler)] @gen_test(timeout=30) @requires_parity async def test_parity_faucet_connection(self): addr = '0x39bf9e501e61440b4b268d7b2e9aa2458dd201bb' val = 761751855997712 await self.faucet(addr, val) resp = await self.fetch('/{}'.format(addr)) self.assertEqual(resp.body.decode('utf-8'), str(val)) @unittest.skipIf( get_path_of("geth") is None, "couldn't find solc compiler, skipping test") @gen_test(timeout=30) @requires_geth async def test_geth_faucet(self): addr = '0x39bf9e501e61440b4b268d7b2e9aa2458dd201bb' val = 761751855997712 await self.faucet(addr, val) resp = await self.fetch('/{}'.format(addr)) self.assertEqual(resp.body.decode('utf-8'), str(val))
class ContractTest(FaucetMixin, AsyncHandlerTest): def get_urls(self): return [] @unittest.skipIf( get_path_of("solc") is None, "couldn't find solc compiler, skipping test") @gen_test(timeout=60) @requires_parity(pass_parity='node') async def test_deploy_contract(self, *, node): client = JsonRPCClient(node.dsn()['url']) sourcecode = b"contract greeter{string greeting;function greeter(string _greeting) public{greeting=_greeting;}function greet() constant returns (string){return greeting;}}" #source_fn = os.path.join(node.get_data_directory(), 'greeting.sol') #with open(source_fn, 'wb') as wf: # wf.write(sourcecode) source_fn = '<stdin>' contract_name = 'greeter' constructor_args = [b'hello world!'] args = ['solc', '--combined-json', 'bin,abi', '--add-std'] # , source_fn] #output = subprocess.check_output(args, stderr=subprocess.PIPE) process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, stderrdata = process.communicate(input=sourcecode) output = json_decode(output) contract = output['contracts']['{}:{}'.format(source_fn, contract_name)] bytecode = data_decoder(contract['bin']) contract_interface = json_decode(contract['abi']) translator = ContractTranslator(contract_interface) constructor_call = translator.encode_constructor_arguments( constructor_args) bytecode += constructor_call tx_hash, contract_address = await self.deploy_contract(bytecode) tx_receipt = await client.eth_getTransactionReceipt(tx_hash) self.assertIsNotNone(tx_receipt) code = await client.eth_getCode(contract_address) self.assertIsNotNone(code) self.assertNotEqual(data_decoder(code), b'') # call the contract and check the result res = await client.eth_call( from_address='0x39bf9e501e61440b4b268d7b2e9aa2458dd201bb', to_address=contract_address, data=sha3('greet()')) result = translator.decode_function_result('greet', data_decoder(res)) self.assertEqual(result[0], constructor_args[0])
def initialize(self): self.ethminer = self.settings.get('ethminer_cmd') if self.ethminer is None: self.ethminer = get_path_of('ethminer') self.jsonrpc_url = self.settings.get( 'jsonrpc_url') or 'http://127.0.0.1:8545' self.home = self.settings.get('home') or os.path.expanduser("~")
def initialize(self): self.redis_server = self.settings.get('redis_server') if self.redis_server is None: self.redis_server = get_path_of('redis-server') if self.redis_server is None: raise RuntimeError("command not found: redis-server") self.redis_conf = self.settings.get('redis_conf', {}) self.redis_conf['bind'] = '127.0.0.1' self.redis_conf['dir'] = os.path.join(self.base_dir, 'data') self.redis_conf['dbfilename'] = 'dump.rdb'
def initialize(self): self.java_bin = self.settings.get('java_bin') if self.java_bin is None: self.java_bin = get_path_of('java') self.zookeeper_home = self.settings.get('zookeeper_home') if self.zookeeper_home is None: self.zookeeper_home = '/usr/share/java/zookeeper' self.log_dir = os.path.join(self.base_dir, 'log') self.cfg_dir = os.path.join(self.base_dir, 'cfg') self.data_dir = os.path.join(self.base_dir, 'data')
def find_program(name, subdirs): path = get_path_of(name) if path: return path for base_dir in SEARCH_PATHS: for subdir in subdirs: path = os.path.join(base_dir, subdir, name) if os.path.exists(path): return path raise RuntimeError("command not found: %s" % name)
class GethTest(AsyncHandlerTest): def get_urls(self): return [] @unittest.skipIf(get_path_of("geth") is None, "couldn't find solc compiler, skipping test") @gen_test(timeout=10) @requires_geth(ws=True, pass_server=True) async def test_geth_ws(self, *, geth): ws_con = await geth_websocket_connect(geth.dsn()['ws']) ws_con.write_message('{"id": 1, "method": "eth_subscribe", "params": ["newHeads", {}]}') await ws_con.read_message() ws_con.close()
def initialize(self): self.java_bin = self.settings.get('java_bin') if self.java_bin is None: self.java_bin = get_path_of('java') self.log_dir = os.path.join(self.base_dir, 'log') self.cfg_dir = os.path.join(self.base_dir, 'cfg') self.data_dir = os.path.join(self.base_dir, 'data') os.mkdir(self.log_dir) self.zookeeper_url = self.settings.get('zookeeper_url') if self.zookeeper_url is None: raise Exception("Missing required zookeeper_url") self.kafka_home = self.settings.get('kafka_home') if self.kafka_home is None: self.kafka_home = '/usr/share/java/kafka'
def find_program(self, name, subdirs): paths = [] for base_dir in SEARCH_PATHS: for subdir in subdirs: path = os.path.join(base_dir, subdir, name) if os.path.exists(path): paths.append(path) for version in self.preferred_versions: for path in paths: if version in os.path.normpath(path).split(os.path.sep): return path path = get_path_of(name) if path: return path if paths: return paths[0] raise RuntimeError("command not found: %s" % name)
def search_server(self): if not get_path_of('redis-server'): raise RuntimeError()
def initialize(self): self.moto_server = self.settings.get('moto_server') if self.moto_server is None: self.moto_server = get_path_of('moto_server')
class ContractTest(FaucetMixin, AsyncHandlerTest): def get_urls(self): return [] @unittest.skipIf(get_path_of("solc") is None, "couldn't find solc compiler, skipping test") @gen_test(timeout=60) @requires_parity(pass_parity='node') async def test_deploy_contract(self, *, node): os.environ['ETHEREUM_NODE_URL'] = node.dsn()['url'] sourcecode = b"contract greeter{string greeting;function greeter(string _greeting) public{greeting=_greeting;}function greet() constant returns (string){return greeting;}}" contract_name = 'greeter' constructor_data = [b'hello world!'] contract = await Contract.from_source_code(sourcecode, contract_name, constructor_data=constructor_data, deployer_private_key=FAUCET_PRIVATE_KEY) # call the contract and check the result result = await contract.greet() self.assertEqual(result, constructor_data[0].decode('utf-8')) sourcecode = b"contract adder { function adder() public {} function add(int a, int b) constant returns (int) { return a + b; } }" contract_name = 'adder' constructor_data = [] contract = await Contract.from_source_code(sourcecode, contract_name, constructor_data=constructor_data, deployer_private_key=FAUCET_PRIVATE_KEY) # call the contract and check the result result = await contract.add(1, 2) self.assertEqual(result, 3) @unittest.skipIf(get_path_of("solc") is None, "couldn't find solc compiler, skipping test") @gen_test(timeout=60) @requires_parity(pass_parity='node') async def test_complex_contract(self, *, node): os.environ['ETHEREUM_NODE_URL'] = node.dsn()['url'] sourcecode = VOTER_CONTRACT_SOURCECODE.encode('utf-8') contract_name = 'Ballot' proposals = [b'James', b'Frank', b'Bob', b'Dave'] constructor_data = [proposals] contract = await Contract.from_source_code(sourcecode, contract_name, constructor_data=constructor_data, deployer_private_key=FAUCET_PRIVATE_KEY) voter1 = ("0xc505998dcc54a5b6424c69b615ef8a7b9ee9881b3a4596dd889ba626c5dd9f9f", "0x0100267048677a95cf91b487d9b65708c105dfe6") voter2 = ("0xe17c72f9b49ea9bd7f1690d2b885da0abc5c1cf735306f7ecbcc611e6eb597ef", "0x0200d3013d64c48d1948f0bc8631056df5fc1e7e") voter3 = ("0xef50367e453f942827e1b8600424865f05740610e45fb0c320f319e32f757153", "0x030086615f23c951306728d8cc0a9004b47de00b") voter4 = ("0xec67294146bbfbfa0d8a2643c7620c24a2fa4a289e123e261fbd6cdc0dc4033b", "0x0400078b1733da5cfd0c48203ae9afdac7f79702") voter5 = ("0xba68ad719b30f63ae35118762983602169fe4c5215b7ad7036a6f8c186498897", "0x050011b88ef2a919c49a6d8961744ae9bc658079") wei = 10 ** 18 await self.faucet(voter1[1], wei) await self.faucet(voter2[1], wei) await self.faucet(voter3[1], wei) await self.faucet(voter4[1], wei) await self.faucet(voter5[1], wei) await contract.giveRightToVote.set_sender(FAUCET_PRIVATE_KEY)(voter1[1]) await contract.giveRightToVote.set_sender(FAUCET_PRIVATE_KEY)(voter2[1]) await contract.giveRightToVote.set_sender(FAUCET_PRIVATE_KEY)(voter3[1]) await contract.giveRightToVote.set_sender(FAUCET_PRIVATE_KEY)(voter4[1]) await contract.giveRightToVote.set_sender(FAUCET_PRIVATE_KEY)(voter5[1]) await contract.vote.set_sender(voter1[0])(1) await contract.vote.set_sender(voter2[0])(1) await contract.delegate.set_sender(voter3[0])(voter4[1]) await contract.vote.set_sender(voter4[0])(2) await contract.vote.set_sender(voter5[0])(2) winner = await contract.winnerName() self.assertEqual(winner, as_byte32(proposals[2]))