Skip to content

Commit

Permalink
Merge pull request #86 from crytic/ganache-cmd
Browse files Browse the repository at this point in the history
Ganache cmd
  • Loading branch information
ESultanik authored Sep 16, 2021
2 parents fc1a6da + 205752b commit 84525ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion etheno/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def main(argv=None):
help='Arguments to pass to truffle (default=migrate)')
parser.add_argument('-g', '--ganache', action='store_true', default=False,
help='Run Ganache as a master JSON RPC client (cannot be used in conjunction with --master)')
parser.add_argument('--ganache-cmd', type=str, default=None, help='Specify a command that runs Ganache '
'(default="/usr/bin/env ganache-cli")')
parser.add_argument('--ganache-args', type=str, default=None,
help='Additional arguments to pass to Ganache')
parser.add_argument('--ganache-port', type=int, default=None,
Expand Down Expand Up @@ -239,7 +241,7 @@ def main(argv=None):
if args.ganache_args is not None:
ganache_args += shlex.split(args.ganache_args)

ganache_instance = ganache.Ganache(args=ganache_args, port=args.ganache_port)
ganache_instance = ganache.Ganache(cmd=args.ganache_cmd, args=ganache_args, port=args.ganache_port)

ETHENO.master_client = ganache.GanacheClient(ganache_instance)

Expand Down
11 changes: 9 additions & 2 deletions etheno/ganache.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/usr/bin/env python3

import atexit
import shlex
import shutil
import subprocess
import time

from .client import RpcHttpProxy, SelfPostingClient
from .logger import PtyLogger
from .utils import is_port_free
from .etheno import ETHENO


class Ganache(RpcHttpProxy):
def __init__(self, args=None, port=8546):
def __init__(self, cmd=None, args=None, port=8546):
super().__init__("http://127.0.0.1:%d/" % port)
self.port = port
if cmd is not None:
cmd = shlex.split(cmd)
else:
cmd = ['/usr/bin/env', 'ganache-cli']
if args is None:
args = []
self.args = ['/usr/bin/env', 'ganache-cli', '-d', '-p', str(port)] + args
self.args = cmd + ['-d', '-p', str(port)] + args
self.ganache = None
self._client = None

Expand All @@ -34,6 +40,7 @@ def ganache_errored() -> int:
return self.ganache.exitstatus
return 0
else:
ETHENO.logger.debug(f"Running ganache: {self.args}")
self.ganache = subprocess.Popen(self.args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=1)

def ganache_errored():
Expand Down

0 comments on commit 84525ac

Please sign in to comment.