dogecoin-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 (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.travis.yml +18 -0
  4. data/Gemfile +13 -0
  5. data/README.rdoc +71 -0
  6. data/Rakefile +8 -0
  7. data/dogecoin-client.gemspec +28 -0
  8. data/lib/dogecoin/api.rb +33 -0
  9. data/lib/dogecoin/client.rb +279 -0
  10. data/lib/dogecoin/dsl.rb +270 -0
  11. data/lib/dogecoin/errors.rb +4 -0
  12. data/lib/dogecoin/request.rb +35 -0
  13. data/lib/dogecoin/rpc.rb +51 -0
  14. data/lib/dogecoin/version.rb +12 -0
  15. data/lib/dogecoin-client.rb +1 -0
  16. data/lib/dogecoin.rb +19 -0
  17. data/spec/fixtures/backupwallet_without_params.json +8 -0
  18. data/spec/fixtures/build_fixture.rb +19 -0
  19. data/spec/fixtures/getbalance.json +8 -0
  20. data/spec/fixtures/getbestblockhash.json +8 -0
  21. data/spec/fixtures/getblock.json +8 -0
  22. data/spec/fixtures/getblockcount.json +8 -0
  23. data/spec/fixtures/getblockhash.json +8 -0
  24. data/spec/fixtures/getblocknumber.json +8 -0
  25. data/spec/fixtures/getconnectioncount.json +8 -0
  26. data/spec/fixtures/getdifficulty.json +8 -0
  27. data/spec/fixtures/getgenerate.json +8 -0
  28. data/spec/fixtures/gethashespersec.json +8 -0
  29. data/spec/fixtures/getinfo.json +8 -0
  30. data/spec/fixtures/getmininginfo.json +8 -0
  31. data/spec/fixtures/help.json +8 -0
  32. data/spec/fixtures/listreceivedbyaddress_with_minconf_0.json +8 -0
  33. data/spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json +7 -0
  34. data/spec/fixtures/listreceivedbyaddress_without_params.json +7 -0
  35. data/spec/fixtures/setaccount.json +8 -0
  36. data/spec/fixtures/signmessage_invalid_address.json +8 -0
  37. data/spec/fixtures/signmessage_success.json +8 -0
  38. data/spec/fixtures/verifymessage_failure.json +8 -0
  39. data/spec/fixtures/verifymessage_success.json +8 -0
  40. data/spec/lib/dogecoin/api_spec.rb +28 -0
  41. data/spec/lib/dogecoin/client_spec.rb +196 -0
  42. data/spec/lib/dogecoin/request_spec.rb +19 -0
  43. data/spec/lib/dogecoin_spec.rb +34 -0
  44. data/spec/spec_helper.rb +18 -0
  45. data/spec/support/fixtures_helper.rb +5 -0
  46. data/spec/support/rpc_service_helper.rb +34 -0
  47. metadata +173 -0
@@ -0,0 +1,196 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dogecoin::Client do
4
+ subject { Dogecoin::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 == 22555
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 'getblockhash' do
38
+ it "should get the block hash of a block" do
39
+ result("12345").should == "63a8ab7a46ff31236366de071e72513f8aa7abfee3d23923e3de4ac5c835e0c4"
40
+ end
41
+ end
42
+
43
+ service 'getbestblockhash' do
44
+ it "should get the hash of the best (tip) block on the longest block chain" do
45
+ result.should == "185b973f3db7102fe722b6499f22c4097b2529b520ce532911b6437ad791b15f"
46
+ end
47
+ end
48
+
49
+ service 'getmininginfo' do
50
+ it "should produce the expected result" do
51
+ result.should == {
52
+ 'blocks' => 237338,
53
+ 'currentblocksize' => 0,
54
+ 'currentblocktx' => 0,
55
+ 'difficulty' => 11187257.46136079,
56
+ 'errors' => "",
57
+ 'generate' => false,
58
+ 'genproclimit' => -1,
59
+ 'hashespersec' => 0,
60
+ 'pooledtx' => 0,
61
+ 'testnet' => false
62
+ }
63
+ end
64
+ end
65
+
66
+ service 'getblock' do
67
+ it "should produce the expected result" do
68
+ result("0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a").should == {
69
+ 'hash' => "0000000000000002e004985f39f929d001448623b312185bf5e4ab50e5a8e60a",
70
+ 'confirmations' => 19,
71
+ 'size' => 5227,
72
+ 'height' => 240707,
73
+ 'version' => 2,
74
+ 'merkleroot' => "18b914e2d6bd4c3118a936af75afbd230611edb6929a607302c0d591ef49b24e",
75
+ 'tx' => [
76
+ "cutforsimplicity",
77
+ "27f99033bdcea87b07f8eea4279d7ce24e479fcb49e9f54e9ffb3721e29838ed"
78
+ ],
79
+ 'time' => Time.utc(2013, 6, 10, 5, 40, 3),
80
+ 'nonce' => 3937756309,
81
+ "bits" => "1a011337",
82
+ "difficulty" => 15605632.68128593,
83
+ "previousblockhash" => "000000000000003fa76b2abdd3036d183d7e24cfb6b543781d59cdca289f6053",
84
+ "nextblockhash" => "0000000000000087a1e962f618f757393930e58a745165033fc9d281b7bb568a"
85
+ }
86
+ end
87
+ end
88
+
89
+ service 'getblockcount' do
90
+ it "should produce the expected result" do
91
+ result.should == 141972
92
+ end
93
+ end
94
+
95
+ service 'getblocknumber' do
96
+ it "should produce the expected result" do
97
+ result.should == 141972
98
+ end
99
+ end
100
+
101
+ service 'getconnectioncount' do
102
+ it "should produce the expected result" do
103
+ result.should == 8
104
+ end
105
+ end
106
+
107
+ service 'getdifficulty' do
108
+ it "should produce the expected result" do
109
+ result.should == 1805700.83619367
110
+ end
111
+ end
112
+
113
+ service 'getgenerate' do
114
+ it "should produce the expected result" do
115
+ result.should be_false
116
+ end
117
+ end
118
+
119
+ service 'gethashespersec' do
120
+ it "should produce the expected result" do
121
+ result.should == 0
122
+ end
123
+ end
124
+
125
+ service 'listreceivedbyaddress' do
126
+ context 'without params' do
127
+ it "should produce the expected result" do
128
+ result.should == [{
129
+ 'address' => "1234",
130
+ 'account' => "",
131
+ 'label' => "",
132
+ 'amount' => 0.001,
133
+ 'confirmations' => 180}]
134
+ end
135
+ end
136
+
137
+ context 'with minconf 0' do
138
+ it "should produce the expected result" do
139
+ result(0).should == [{
140
+ 'address' => "1234",
141
+ 'account' => "",
142
+ 'label' => "",
143
+ 'amount' => 0.001,
144
+ 'confirmations' => 180}]
145
+ end
146
+ end
147
+
148
+ context 'with minconf 0 and includeempty true' do
149
+ it "should produce the expected result" do
150
+ result(0, true).should == [{
151
+ 'address' => "1234",
152
+ 'account' => "",
153
+ 'label' => "",
154
+ 'amount' => 0.001,
155
+ 'confirmations' => 180}]
156
+ end
157
+ end
158
+ end
159
+
160
+ service 'setaccount' do
161
+ it 'maps the call correctly' do
162
+ subject.api.should_receive(:request).with(*%w(setaccount dogecoinaddress account))
163
+ result('dogecoinaddress', 'account').should be_nil
164
+ end
165
+ end
166
+
167
+ service 'signmessage' do
168
+ context 'success' do
169
+ it "should produce the expected result" do
170
+ result('valid_address', 'message').should == 'Gwz2BAaqdsLTqJsh5a4'
171
+ end
172
+ end
173
+
174
+ context 'invalid address' do
175
+ it "should produce the expected result" do
176
+ lambda { result('invalid_address', 'message').should }.should \
177
+ raise_error Dogecoin::Errors::RPCError
178
+ end
179
+ end
180
+ end
181
+
182
+ service 'verifymessage' do
183
+ context 'success' do
184
+ it "should produce the expected result" do
185
+ result('address', 'message', 'signature').should be_true
186
+ end
187
+ end
188
+
189
+ context 'failure' do
190
+ it "should produce the expected result" do
191
+ result('address', 'message', 'signature').should be_false
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dogecoin::Request do
4
+ it "should omit null arguments and everything after them" do
5
+ # dogecoin 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 = Dogecoin::Request.new('svc', [1, nil, nil, nil])
11
+ req.params.should == [1]
12
+
13
+ req = Dogecoin::Request.new('svc', [nil])
14
+ req.params.should == []
15
+
16
+ req = Dogecoin::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 Dogecoin do
4
+ before :each do
5
+ FakeWeb.register_uri(:post, "http://user:pass@localhost:22555", :response => fixture('getbalance'))
6
+ end
7
+
8
+ it "as a function" do
9
+ cli = Dogecoin($user, $pass)
10
+ cli.balance.should == 0.001
11
+ end
12
+
13
+ it "DSL, included" do
14
+ class << self
15
+ include Dogecoin
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 Dogecoin
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
+ # dogecoin user settings
7
+ $user = 'user'
8
+ $pass = 'pass'
9
+
10
+ require File.expand_path('../lib/dogecoin-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:22555", :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
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dogecoin-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Eufemio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fakeweb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: 'Provides a Ruby library to the complete Dogecoin JSON-RPC API. '
98
+ email:
99
+ - tymat@pris.im
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - README.rdoc
108
+ - Rakefile
109
+ - dogecoin-client.gemspec
110
+ - lib/dogecoin-client.rb
111
+ - lib/dogecoin.rb
112
+ - lib/dogecoin/api.rb
113
+ - lib/dogecoin/client.rb
114
+ - lib/dogecoin/dsl.rb
115
+ - lib/dogecoin/errors.rb
116
+ - lib/dogecoin/request.rb
117
+ - lib/dogecoin/rpc.rb
118
+ - lib/dogecoin/version.rb
119
+ - spec/fixtures/backupwallet_without_params.json
120
+ - spec/fixtures/build_fixture.rb
121
+ - spec/fixtures/getbalance.json
122
+ - spec/fixtures/getbestblockhash.json
123
+ - spec/fixtures/getblock.json
124
+ - spec/fixtures/getblockcount.json
125
+ - spec/fixtures/getblockhash.json
126
+ - spec/fixtures/getblocknumber.json
127
+ - spec/fixtures/getconnectioncount.json
128
+ - spec/fixtures/getdifficulty.json
129
+ - spec/fixtures/getgenerate.json
130
+ - spec/fixtures/gethashespersec.json
131
+ - spec/fixtures/getinfo.json
132
+ - spec/fixtures/getmininginfo.json
133
+ - spec/fixtures/help.json
134
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0.json
135
+ - spec/fixtures/listreceivedbyaddress_with_minconf_0_and_includeempty_true.json
136
+ - spec/fixtures/listreceivedbyaddress_without_params.json
137
+ - spec/fixtures/setaccount.json
138
+ - spec/fixtures/signmessage_invalid_address.json
139
+ - spec/fixtures/signmessage_success.json
140
+ - spec/fixtures/verifymessage_failure.json
141
+ - spec/fixtures/verifymessage_success.json
142
+ - spec/lib/dogecoin/api_spec.rb
143
+ - spec/lib/dogecoin/client_spec.rb
144
+ - spec/lib/dogecoin/request_spec.rb
145
+ - spec/lib/dogecoin_spec.rb
146
+ - spec/spec_helper.rb
147
+ - spec/support/fixtures_helper.rb
148
+ - spec/support/rpc_service_helper.rb
149
+ homepage: http://github.com/tymat/dogecoin-client
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project: dogecoin-client
169
+ rubygems_version: 2.2.2
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Provides a Ruby library to the complete Dogecoin JSON-RPC API.
173
+ test_files: []