startcoin-client 0.0.3

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +13 -0
  5. data/README.rdoc +78 -0
  6. data/Rakefile +8 -0
  7. data/lib/startcoin_client/api.rb +33 -0
  8. data/lib/startcoin_client/client.rb +340 -0
  9. data/lib/startcoin_client/dsl.rb +307 -0
  10. data/lib/startcoin_client/errors.rb +4 -0
  11. data/lib/startcoin_client/request.rb +35 -0
  12. data/lib/startcoin_client/rpc.rb +51 -0
  13. data/lib/startcoin_client/version.rb +12 -0
  14. data/lib/startcoin_client.rb +19 -0
  15. data/spec/fixtures/backupwallet_without_params.json +8 -0
  16. data/spec/fixtures/build_fixture.rb +19 -0
  17. data/spec/fixtures/getbalance.json +8 -0
  18. data/spec/fixtures/getbestblockhash.json +8 -0
  19. data/spec/fixtures/getblock.json +8 -0
  20. data/spec/fixtures/getblockcount.json +8 -0
  21. data/spec/fixtures/getblocknumber.json +8 -0
  22. data/spec/fixtures/getconnectioncount.json +8 -0
  23. data/spec/fixtures/getdifficulty.json +8 -0
  24. data/spec/fixtures/getgenerate.json +8 -0
  25. data/spec/fixtures/gethashespersec.json +8 -0
  26. data/spec/fixtures/getinfo.json +8 -0
  27. data/spec/fixtures/getmininginfo.json +8 -0
  28. data/spec/fixtures/help.json +8 -0
  29. data/spec/fixtures/listreceivedbyaddress_with_minconf_0.json +8 -0
  30. data/spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json +7 -0
  31. data/spec/fixtures/listreceivedbyaddress_without_params.json +7 -0
  32. data/spec/fixtures/setaccount.json +8 -0
  33. data/spec/fixtures/signmessage_invalid_address.json +8 -0
  34. data/spec/fixtures/signmessage_success.json +8 -0
  35. data/spec/fixtures/verifymessage_failure.json +8 -0
  36. data/spec/fixtures/verifymessage_success.json +8 -0
  37. data/spec/lib/startcoin_client/api_spec.rb +28 -0
  38. data/spec/lib/startcoin_client/client_spec.rb +184 -0
  39. data/spec/lib/startcoin_client/request_spec.rb +19 -0
  40. data/spec/lib/startcoin_client_spec.rb +34 -0
  41. data/spec/spec_helper.rb +18 -0
  42. data/spec/support/fixtures_helper.rb +5 -0
  43. data/spec/support/rpc_service_helper.rb +34 -0
  44. data/startcoin-client.gemspec +32 -0
  45. metadata +205 -0
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe StartcoinClient::API do
4
+ subject { StartcoinClient::API.new(:user => $user, :pass => $pass) }
5
+
6
+ it "should have default host, port, ssl" do
7
+ subject.host.should == 'localhost'
8
+ subject.port.should == 8332
9
+ subject.ssl?.should be_false
10
+ end
11
+
12
+ it "should accept host, port, ssl options" do
13
+ req = StartcoinClient::API.new(:user => $user, :pass => $pass, :host => 'example.com', :port => 1234, :ssl => true)
14
+ req.host.should == 'example.com'
15
+ req.port.should == 1234
16
+ req.ssl?.should be_true
17
+ end
18
+
19
+ it "should build an options hash" do
20
+ subject.to_hash.should == {
21
+ :user => $user,
22
+ :pass => $pass,
23
+ :host => 'localhost',
24
+ :port => 8332,
25
+ :ssl => false,
26
+ }
27
+ end
28
+ end
@@ -0,0 +1,184 @@
1
+ require 'spec_helper'
2
+
3
+ describe StartcoinClient::Client do
4
+ subject { StartcoinClient::Client.new($user, $pass) }
5
+
6
+ it "defaults" do
7
+ subject.user.should == $user
8
+ subject.pass.should == $pass
9
+ subject.host.should == 'localhost'
10
+ subject.port.should == 8332
11
+ subject.should_not be_ssl
12
+ end
13
+
14
+ context "RPC" do
15
+ extend RPCServiceHelper
16
+
17
+ service 'getinfo' do
18
+ it "should produce the expected result" do
19
+ result.should == {
20
+ 'version' => 32400,
21
+ 'balance' => 0.001,
22
+ 'blocks' => 141957,
23
+ 'connections' => 8,
24
+ 'proxy' => "",
25
+ 'generate' => false,
26
+ 'genproclimit' => -1,
27
+ 'difficulty' => 1805700.83619367,
28
+ 'hashespersec' => 0,
29
+ 'testnet' => false,
30
+ 'keypoololdest' => 1313766189,
31
+ 'paytxfee' => 0.0,
32
+ 'errors' => ""
33
+ }
34
+ end
35
+ end
36
+
37
+ service 'getmininginfo' do
38
+ it "should produce the expected result" do
39
+ result.should == {
40
+ 'blocks' => 237338,
41
+ 'currentblocksize' => 0,
42
+ 'currentblocktx' => 0,
43
+ 'difficulty' => 11187257.46136079,
44
+ 'errors' => "",
45
+ 'generate' => false,
46
+ 'genproclimit' => -1,
47
+ 'hashespersec' => 0,
48
+ 'pooledtx' => 0,
49
+ 'testnet' => false
50
+ }
51
+ end
52
+ end
53
+
54
+ service 'getblock' do
55
+ it "should produce the expected result" do
56
+ result("0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a").should == {
57
+ 'hash' => "0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a",
58
+ 'confirmations' => 19,
59
+ 'size' => 5227,
60
+ 'height' => 240707,
61
+ 'version' => 2,
62
+ 'merkleroot' => "18b914e2d6bd4c3118a936af75afbd230611edb6929a607302c0d591ef49b24e",
63
+ 'tx' => [
64
+ "cutforsimplicity",
65
+ "27f99033bdcea87b07f8eea4279d7ce24e479fcb49e9f54e9ffb3721e29838ed"
66
+ ],
67
+ 'time' => Time.utc(2013, 6, 10, 5, 40, 3),
68
+ 'nonce' => 3937756309,
69
+ "bits" => "1a011337",
70
+ "difficulty" => 15605632.68128593,
71
+ "previousblockhash" => "000000000000003fa76b2abdd3036d183d7e24cfb6b543781d59cdca289f6053",
72
+ "nextblockhash" => "0000000000000087a1e962f618f757393930e58a745165033fc9d281b7bb568a"
73
+ }
74
+ end
75
+ end
76
+
77
+ service 'getblockcount' do
78
+ it "should produce the expected result" do
79
+ result.should == 141972
80
+ end
81
+ end
82
+
83
+ service 'getblocknumber' do
84
+ it "should produce the expected result" do
85
+ result.should == 141972
86
+ end
87
+ end
88
+
89
+ service 'getconnectioncount' do
90
+ it "should produce the expected result" do
91
+ result.should == 8
92
+ end
93
+ end
94
+
95
+ service 'getdifficulty' do
96
+ it "should produce the expected result" do
97
+ result.should == 1805700.83619367
98
+ end
99
+ end
100
+
101
+ service 'getgenerate' do
102
+ it "should produce the expected result" do
103
+ result.should be_false
104
+ end
105
+ end
106
+
107
+ service 'gethashespersec' do
108
+ it "should produce the expected result" do
109
+ result.should == 0
110
+ end
111
+ end
112
+
113
+ service 'listreceivedbyaddress' do
114
+ context 'without params' do
115
+ it "should produce the expected result" do
116
+ result.should == [{
117
+ 'address' => "1234",
118
+ 'account' => "",
119
+ 'label' => "",
120
+ 'amount' => 0.001,
121
+ 'confirmations' => 180}]
122
+ end
123
+ end
124
+
125
+ context 'with minconf 0' do
126
+ it "should produce the expected result" do
127
+ result(0).should == [{
128
+ 'address' => "1234",
129
+ 'account' => "",
130
+ 'label' => "",
131
+ 'amount' => 0.001,
132
+ 'confirmations' => 180}]
133
+ end
134
+ end
135
+
136
+ context 'with minconf 0 and includeempty true' do
137
+ it "should produce the expected result" do
138
+ result(0, true).should == [{
139
+ 'address' => "1234",
140
+ 'account' => "",
141
+ 'label' => "",
142
+ 'amount' => 0.001,
143
+ 'confirmations' => 180}]
144
+ end
145
+ end
146
+ end
147
+
148
+ service 'setaccount' do
149
+ it 'maps the call correctly' do
150
+ subject.api.should_receive(:request).with(*%w(setaccount bitcoinaddress account))
151
+ result('bitcoinaddress', 'account').should be_nil
152
+ end
153
+ end
154
+
155
+ service 'signmessage' do
156
+ context 'success' do
157
+ it "should produce the expected result" do
158
+ result('valid_address', 'message').should == 'Gwz2BAaqdsLTqJsh5a4'
159
+ end
160
+ end
161
+
162
+ context 'invalid address' do
163
+ it "should produce the expected result" do
164
+ lambda { result('invalid_address', 'message').should }.should \
165
+ raise_error StartcoinClient::Errors::RPCError
166
+ end
167
+ end
168
+ end
169
+
170
+ service 'verifymessage' do
171
+ context 'success' do
172
+ it "should produce the expected result" do
173
+ result('address', 'message', 'signature').should be_true
174
+ end
175
+ end
176
+
177
+ context 'failure' do
178
+ it "should produce the expected result" do
179
+ result('address', 'message', 'signature').should be_false
180
+ end
181
+ end
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe StartcoinClient::Request do
4
+ it "should omit null arguments and everything after them" do
5
+ # bitcoin rejects null values even for optional params. Since
6
+ # even params following those may have default non-nil values,
7
+ # we'll assume the first non-nil value marks a set of optional
8
+ # params, and drop it and everything following it.
9
+
10
+ req = StartcoinClient::Request.new('svc', [1, nil, nil, nil])
11
+ req.params.should == [1]
12
+
13
+ req = StartcoinClient::Request.new('svc', [nil])
14
+ req.params.should == []
15
+
16
+ req = StartcoinClient::Request.new('svc', [1, nil, nil, 1, nil])
17
+ req.params.should == [1]
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe StartcoinClient do
4
+ before :each do
5
+ FakeWeb.register_uri(:post, "http://user:pass@localhost:8332", :response => fixture('getbalance'))
6
+ end
7
+
8
+ it "as a function" do
9
+ cli = StartcoinClient($user, $pass)
10
+ cli.balance.should == 0.001
11
+ end
12
+
13
+ it "DSL, included" do
14
+ class << self
15
+ include StartcoinClient
16
+ end
17
+
18
+ username $user
19
+ password $pass
20
+
21
+ balance.should == 0.001
22
+ end
23
+
24
+ it "DSL, extended" do
25
+ class << self
26
+ include StartcoinClient
27
+
28
+ username $user
29
+ password $pass
30
+
31
+ balance.should == 0.001
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+
4
+ require 'fakeweb'
5
+
6
+ # bitcoin user settings
7
+ $user = 'user'
8
+ $pass = 'pass'
9
+
10
+ require File.expand_path('../lib/startcoin_client', File.dirname(__FILE__))
11
+
12
+ Dir[File.expand_path("support/**/*.rb", File.dirname(__FILE__))].each { |f| require f }
13
+
14
+ RSpec.configure do |c|
15
+ c.include FixturesHelper
16
+ c.before { FakeWeb.allow_net_connect = false }
17
+ c.after { FakeWeb.allow_net_connect = true }
18
+ end
@@ -0,0 +1,5 @@
1
+ module FixturesHelper
2
+ def fixture(name)
3
+ File.read(File.expand_path("../fixtures/#{name}.json", File.dirname(__FILE__)))
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ module RPCServiceHelper
2
+ def service(name, &block)
3
+ context "'#{name}'" do
4
+ define_method :fixture_name do
5
+ suffix = self.class.fixture_suffix.gsub(/\s/, '_')
6
+ if suffix.length > 0
7
+ "#{name}_#{suffix}"
8
+ else
9
+ name
10
+ end
11
+ end
12
+
13
+ define_method :result do |*args|
14
+ FakeWeb.register_uri(:post, "http://user:pass@localhost:8332", :response => fixture(fixture_name))
15
+ subject.send(name, *args)
16
+ end
17
+
18
+ class << self
19
+ def fixture_suffix
20
+ @fixture_suffix ||= ""
21
+ end
22
+
23
+ def context(desc, &block)
24
+ super desc do
25
+ fixture_suffix.concat desc
26
+ instance_eval &block
27
+ end
28
+ end
29
+ end
30
+
31
+ instance_eval &block
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'startcoin_client/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.licenses = ['MIT']
7
+ s.name = 'startcoin-client'
8
+ s.version = StartcoinClient::VERSION
9
+ s.authors = ['Colin MacKenzie IV', 'Krzysztof Szromek']
10
+ s.email = ['sinisterchipmunk@gmail.com', 'k.szromek@exlabs.co.uk']
11
+ s.homepage = 'http://github.com/szromek/startcoin-client'
12
+ s.summary = %q{Provides a Ruby library to the complete Startcoin JSON-RPC API.}
13
+ s.description = 'Provides a Ruby library to the complete Startcoin JSON-RPC API. ' +
14
+ 'Implements all methods listed at ' +
15
+ 'https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list ' +
16
+ 'which is the same as Startcoin API. ' +
17
+ 'Lets you set options such as the host and port number, and whether to use SSL.'
18
+
19
+ s.rubyforge_project = 'startcoin-client'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
23
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
+ s.require_paths = ['lib']
25
+
26
+ s.add_development_dependency "rake", '~> 0.9'
27
+ s.add_development_dependency "bundler"
28
+ s.add_development_dependency "rspec", '~> 2.6'
29
+ s.add_development_dependency "fakeweb", '~> 1.3'
30
+ s.add_development_dependency "coveralls"
31
+ s.add_runtime_dependency "rest-client"
32
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: startcoin-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Colin MacKenzie IV
8
+ - Krzysztof Szromek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.9'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.9'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fakeweb
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: coveralls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rest-client
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Provides a Ruby library to the complete Startcoin JSON-RPC API. Implements
99
+ all methods listed at https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_Calls_list
100
+ which is the same as Startcoin API. Lets you set options such as the host and port
101
+ number, and whether to use SSL.
102
+ email:
103
+ - sinisterchipmunk@gmail.com
104
+ - k.szromek@exlabs.co.uk
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".travis.yml"
111
+ - Gemfile
112
+ - README.rdoc
113
+ - Rakefile
114
+ - lib/startcoin_client.rb
115
+ - lib/startcoin_client/api.rb
116
+ - lib/startcoin_client/client.rb
117
+ - lib/startcoin_client/dsl.rb
118
+ - lib/startcoin_client/errors.rb
119
+ - lib/startcoin_client/request.rb
120
+ - lib/startcoin_client/rpc.rb
121
+ - lib/startcoin_client/version.rb
122
+ - spec/fixtures/backupwallet_without_params.json
123
+ - spec/fixtures/build_fixture.rb
124
+ - spec/fixtures/getbalance.json
125
+ - spec/fixtures/getbestblockhash.json
126
+ - spec/fixtures/getblock.json
127
+ - spec/fixtures/getblockcount.json
128
+ - spec/fixtures/getblocknumber.json
129
+ - spec/fixtures/getconnectioncount.json
130
+ - spec/fixtures/getdifficulty.json
131
+ - spec/fixtures/getgenerate.json
132
+ - spec/fixtures/gethashespersec.json
133
+ - spec/fixtures/getinfo.json
134
+ - spec/fixtures/getmininginfo.json
135
+ - spec/fixtures/help.json
136
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0.json
137
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json
138
+ - spec/fixtures/listreceivedbyaddress_without_params.json
139
+ - spec/fixtures/setaccount.json
140
+ - spec/fixtures/signmessage_invalid_address.json
141
+ - spec/fixtures/signmessage_success.json
142
+ - spec/fixtures/verifymessage_failure.json
143
+ - spec/fixtures/verifymessage_success.json
144
+ - spec/lib/startcoin_client/api_spec.rb
145
+ - spec/lib/startcoin_client/client_spec.rb
146
+ - spec/lib/startcoin_client/request_spec.rb
147
+ - spec/lib/startcoin_client_spec.rb
148
+ - spec/spec_helper.rb
149
+ - spec/support/fixtures_helper.rb
150
+ - spec/support/rpc_service_helper.rb
151
+ - startcoin-client.gemspec
152
+ homepage: http://github.com/szromek/startcoin-client
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project: startcoin-client
172
+ rubygems_version: 2.6.4
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Provides a Ruby library to the complete Startcoin JSON-RPC API.
176
+ test_files:
177
+ - spec/fixtures/backupwallet_without_params.json
178
+ - spec/fixtures/build_fixture.rb
179
+ - spec/fixtures/getbalance.json
180
+ - spec/fixtures/getbestblockhash.json
181
+ - spec/fixtures/getblock.json
182
+ - spec/fixtures/getblockcount.json
183
+ - spec/fixtures/getblocknumber.json
184
+ - spec/fixtures/getconnectioncount.json
185
+ - spec/fixtures/getdifficulty.json
186
+ - spec/fixtures/getgenerate.json
187
+ - spec/fixtures/gethashespersec.json
188
+ - spec/fixtures/getinfo.json
189
+ - spec/fixtures/getmininginfo.json
190
+ - spec/fixtures/help.json
191
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0.json
192
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json
193
+ - spec/fixtures/listreceivedbyaddress_without_params.json
194
+ - spec/fixtures/setaccount.json
195
+ - spec/fixtures/signmessage_invalid_address.json
196
+ - spec/fixtures/signmessage_success.json
197
+ - spec/fixtures/verifymessage_failure.json
198
+ - spec/fixtures/verifymessage_success.json
199
+ - spec/lib/startcoin_client/api_spec.rb
200
+ - spec/lib/startcoin_client/client_spec.rb
201
+ - spec/lib/startcoin_client/request_spec.rb
202
+ - spec/lib/startcoin_client_spec.rb
203
+ - spec/spec_helper.rb
204
+ - spec/support/fixtures_helper.rb
205
+ - spec/support/rpc_service_helper.rb