bitcoin_testnet 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -12,7 +12,7 @@ Now, you have access to `BitcoinTestnet`.
12
12
 
13
13
  Second, you have to tell BitcoinTestnet where the testnet in a box directory is. I prefer to keep it in the test folder of my project. For example, with RSpec:
14
14
 
15
- git submodule add https://github.com/freewil/bitcoin-testnet-box testnet
15
+ git submodule add https://github.com/freewil/bitcoin-testnet-box spec/testnet
16
16
 
17
17
  Then, in your `test_helper`/`spec_helper`:
18
18
 
@@ -20,15 +20,13 @@ Then, in your `test_helper`/`spec_helper`:
20
20
 
21
21
  Third, tell `BitcoinTestnet` when to do its work:
22
22
 
23
- - Before the test suite starts, call `BitcoinTestnet.start`. This will start the Testnet and clean it. If you have already started the Testnet yourself manually, it will just clean it.
24
- - Before each spec, call `BitcoinTestnet.clean`. This will reset the Testnet, so it looks like it did the first time you started the Testnet.
25
- - After the test suite is finished, call `BitcoinTestnet.stop`. This turns off the Testnet and cleans if. If you started the Testnet manually, then it just cleans it.
23
+ - Before each spec, call `BitcoinTestnet.start`. This will start and clean the Testnet, so it looks like it did the first time you started the Testnet.
24
+ - After the test suite is finished, call `BitcoinTestnet.stop`. This turns off the Testnet.
26
25
 
27
26
  Sample with RSpec:
28
27
 
29
28
  RSpec.configure do |config|
30
- config.before(:suite) { BitcoinTestnet.start }
31
- config.before(:each) { BitcoinTestnet.clean }
29
+ config.before(:each) { BitcoinTestnet.start }
32
30
  config.after(:suite) { BitcoinTestnet.stop }
33
31
  end
34
32
 
@@ -19,4 +19,5 @@ Gem::Specification.new do |gem|
19
19
  gem.require_paths = ["lib"]
20
20
 
21
21
  gem.add_dependency 'activesupport', '~> 3.0'
22
+ gem.add_dependency 'wait', '~> 0.5.1'
22
23
  end
@@ -7,32 +7,21 @@ module BitcoinTestnet
7
7
 
8
8
  def boot
9
9
  if Detector.exists?
10
- puts "***** Testnet started manually; cleaning only"
11
- BitcoinTestnet.started_manually = true
12
- Cleaner.clean
10
+ Stopper.stop
13
11
  else
14
- puts "***** Starting Testnet. To make boot up faster, start the Testnet manually: `cd #{BitcoinTestnet.dir} && make start`"
15
- thread = Thread.new do
16
- Cleaner.clean
17
- Executor.execute "make start > /dev/null"
18
- end
12
+ Executor.execute "make clean"
13
+ end
14
+
15
+ thread = Thread.new do
16
+ Executor.execute "make start"
17
+ end
19
18
 
20
- # Wait until the bitcoind servers have started and ready to accept. I've
21
- # found that the sweet spot was 2 seconds after the thread's status is
22
- # false
23
- wait_time = 0
24
- until wait_time == 5
25
- if thread.status == false
26
- sleep 2
27
- return
28
- end
29
- sleep 0.1
30
- wait_time += 0.1
31
- end
19
+ Wait.new.until do
20
+ thread.status == false && Executor.execute("make getinfo")
21
+ end
32
22
 
33
- unless Detector.exists?
34
- fail "The bitcoin processes didn't seem to start. Please ensure that the bitcoin testnet servers started at `#{BitcoinTestnet.dir}`"
35
- end
23
+ unless Detector.exists?
24
+ fail "The bitcoin processes didn't seem to start. Please ensure that the bitcoin testnet servers started at `#{BitcoinTestnet.dir}`"
36
25
  end
37
26
  end
38
27
 
@@ -10,7 +10,7 @@ module BitcoinTestnet
10
10
  end
11
11
 
12
12
  def processes
13
- `ps -ef | grep bitcoin | grep -v grep`.split("\n")
13
+ `ps -ef | grep "bitcoind -datadir=" | grep -v grep`.split("\n")
14
14
  end
15
15
 
16
16
  def exists?
@@ -10,8 +10,10 @@ module BitcoinTestnet
10
10
  end
11
11
 
12
12
  def execute
13
- commands = ["cd #{BitcoinTestnet.dir}"] + @commands
14
- system commands.join(' && ')
13
+ Dir.chdir BitcoinTestnet.dir do
14
+ commands = @commands.map { |c| "#{c} > /dev/null"}
15
+ system commands.join(' && ')
16
+ end
15
17
  end
16
18
 
17
19
  end
@@ -0,0 +1,21 @@
1
+ module BitcoinTestnet
2
+ class Stopper
3
+
4
+ def self.stop
5
+ self.new.stop
6
+ end
7
+
8
+ def stop
9
+ kill_bitcoind if Detector.exists?
10
+ Wait.new.until { !Detector.exists? }
11
+ fail "Looks like it didn't stop" if Detector.exists?
12
+ Executor.execute "make clean"
13
+ end
14
+
15
+ private
16
+
17
+ def kill_bitcoind
18
+ system %Q(kill -9 `ps -ef | grep "bitcoind -datadir=" | grep -v grep | awk '{print $2}'`)
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module BitcoinTestnet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,16 +1,13 @@
1
+ require 'wait'
1
2
  require "bitcoin_testnet/version"
2
3
  require 'active_support/core_ext/module'
3
4
 
4
5
  require 'bitcoin_testnet/detector'
5
- require 'bitcoin_testnet/booter'
6
- require 'bitcoin_testnet/cleaner'
7
6
  require 'bitcoin_testnet/executor'
8
- require 'bitcoin_testnet/janitor'
7
+ require 'bitcoin_testnet/booter'
8
+ require 'bitcoin_testnet/stopper'
9
9
 
10
10
  module BitcoinTestnet
11
- mattr_accessor :started_manually
12
- @@started_manually = false
13
-
14
11
  mattr_accessor :dir
15
12
  @@dir = nil
16
13
 
@@ -18,18 +15,13 @@ module BitcoinTestnet
18
15
  Booter.boot
19
16
  end
20
17
 
21
- def self.clean
22
- Cleaner.clean
23
- end
24
-
25
18
  def self.stop
26
- Janitor.sweep
19
+ Stopper.stop
27
20
  end
28
21
 
29
22
  def self.configure_rspec!
30
23
  RSpec.configure do |c|
31
- c.before(:suite) { BitcoinTestnet.start }
32
- c.before(:each) { BitcoinTestnet.clean }
24
+ c.before(:each) { BitcoinTestnet.start }
33
25
  c.after(:suite) { BitcoinTestnet.stop }
34
26
  end
35
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoin_testnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-03 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: wait
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.1
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.1
30
46
  description: A gem of helpers for making integration tests with the Bitcoin testnet
31
47
  a little easier.
32
48
  email:
@@ -44,10 +60,9 @@ files:
44
60
  - bitcoin_testnet.gemspec
45
61
  - lib/bitcoin_testnet.rb
46
62
  - lib/bitcoin_testnet/booter.rb
47
- - lib/bitcoin_testnet/cleaner.rb
48
63
  - lib/bitcoin_testnet/detector.rb
49
64
  - lib/bitcoin_testnet/executor.rb
50
- - lib/bitcoin_testnet/janitor.rb
65
+ - lib/bitcoin_testnet/stopper.rb
51
66
  - lib/bitcoin_testnet/version.rb
52
67
  - testnet/1/bitcoin.conf
53
68
  - testnet/1/testnet3/blk0001.dat
@@ -1,14 +0,0 @@
1
- module BitcoinTestnet
2
- class Cleaner
3
-
4
- def self.clean(*args)
5
- self.new(*args).clean
6
- end
7
-
8
- def clean
9
- commands = ["cd #{BitcoinTestnet.dir}", "make clean > /dev/null"]
10
- system commands.join(' && ')
11
- end
12
-
13
- end
14
- end
@@ -1,20 +0,0 @@
1
- module BitcoinTestnet
2
- class Janitor
3
-
4
- def self.sweep(*args)
5
- self.new(*args).sweep
6
- end
7
-
8
- def sweep
9
- if BitcoinTestnet.started_manually
10
- puts "\n***** Since Testnet started manually; cleaning only. If you want to stop it, run: `cd #{BitcoinTestnet.dir} && make stop`"
11
- Cleaner.clean
12
- else
13
- puts "\n***** Since the BitcoinTestnet started the Testnet, stop and clean"
14
- Executor.execute "make stop > /dev/null"
15
- Cleaner.clean
16
- end
17
- end
18
-
19
- end
20
- end