Class: RSpec::Eth::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/eth/server.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ganache_pidObject

Returns the value of attribute ganache_pid.



5
6
7
# File 'lib/rspec/eth/server.rb', line 5

def ganache_pid
  @ganache_pid
end

.ganache_read_outputObject

Returns the value of attribute ganache_read_output.



5
6
7
# File 'lib/rspec/eth/server.rb', line 5

def ganache_read_output
  @ganache_read_output
end

Class Method Details

.restartObject



30
31
32
33
# File 'lib/rspec/eth/server.rb', line 30

def restart
  start
  stop
end

.start(wait_until_ready: true) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rspec/eth/server.rb', line 7

def start(wait_until_ready: true)
  if !ganache_pid
    self.ganache_read_output, ganache_write_output = IO.pipe
    options = ["--quiet", "--account_keys_path #{Config.account_keys_path}", "-p #{Config.port}", "-h #{Config.host}"]
    self.ganache_pid = Process.spawn("ganache-cli #{options.join(" ")}", out: ganache_write_output, err: STDOUT)

    # Enough to understand that that server is ready
    ganache_read_output.read(60) if wait_until_ready
  else
    warn("Server already runnin")
  end
end

.stopObject



20
21
22
23
24
25
26
27
28
# File 'lib/rspec/eth/server.rb', line 20

def stop
  if ganache_pid
    Process.kill("TERM", ganache_pid)
    self.ganache_pid = nil
    self.ganache_read_output = nil
  else
    warn("Server isn't running")
  end
end