ruby-client 1.1.5 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,304 @@
1
+ =begin
2
+ Copyright 2020 Nimiq community.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
18
+ require "ruby-client"
19
+
20
+ describe "Nimiq", type: :request do
21
+
22
+ # Initialize
23
+ before(:all) do
24
+ options = {
25
+ # host: "https://rpc.nimiq.observer/",
26
+ # port: 433,
27
+
28
+ host: "localhost",
29
+ port: 8005,
30
+ user: "user",
31
+ pass: "pass",
32
+ # dev: true,
33
+ }
34
+ @main_addr = "NQ70 46LN 1SKC KGFN VV8U G92N XC4X 9VFB SBVJ" # Node address
35
+ @seco_addr = "NQ27 B9ED 98G5 3VH7 FY8D BFP0 XNF4 BD8L TN4B" # Some address
36
+ @signed_transaction = "000000.......1A84FA23" # get this by running Makes @signed_transaction
37
+ @nimiq = Nimiq::Client.new(options)
38
+ end
39
+
40
+ # Test suite for client
41
+ describe "RPC Client" do
42
+
43
+ # Test suite for client version
44
+ it "Must have a version." do
45
+ expect(::Nimiq::VERSION).not_to eq(nil)
46
+ end
47
+
48
+ # Test suite for client connection
49
+ it "Must be able to connect to the Nimiq node." do
50
+ expect(@nimiq.ping).to eq(200)
51
+ end
52
+
53
+ # Test suite for client to send raw requests
54
+ it "Must be able to send raw requests." do
55
+ expect(@nimiq.request("consensus")).to be_a_kind_of(String)
56
+ end
57
+ end
58
+
59
+ # Test suite for API
60
+ describe "Api" do
61
+
62
+ # Test suite for client to retrieve the addresses owned by client.
63
+ it "Must be able to retrieve addresses owned by client." do
64
+ expect(@nimiq.accounts()).to be_a_kind_of(Object)
65
+ end
66
+
67
+ # Test suite for client to retrieve height of most recent block.
68
+ it "Must be able to retrieve height of most recent block." do
69
+ expect(@nimiq.block_number()).to be_a_kind_of(Object)
70
+ end
71
+
72
+ # Test suite for client to retrieve the consensus status.
73
+ it "Must be able to retrieve the consensus status." do
74
+ expect(@nimiq.consensus()).to be_a_kind_of(String)
75
+ end
76
+
77
+ # Test suite for client to override a constant value.
78
+ it "Must be able to override a constant value." do
79
+ constant_value = 10
80
+ expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH", constant_value)).to eq(constant_value)
81
+ end
82
+
83
+ # Test suite for client to retrieve a constant value.
84
+ it "Must be able to retrieve a constant value." do
85
+ expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH")).to eq(10)
86
+ end
87
+
88
+ # Test suite for client to create a new account.
89
+ it "Must be able to create a new account." do
90
+ expect(@nimiq.create_account()).to be_a_kind_of(Object)
91
+ end
92
+
93
+ # Test suite for client to retrieve information related to an account.
94
+ it "Must be able to retrieve information related to an account." do
95
+ expect(@nimiq.get_account(@seco_addr)).to be_a_kind_of(Object)
96
+ end
97
+
98
+ # Test suite for client to retrieve balance of account.
99
+ it "Must be able to retrieve balance of account." do
100
+ expect(@nimiq.get_balance(@main_addr)).to be_a_kind_of(Integer)
101
+ end
102
+
103
+ # Test suite for client to retrieve block by hash.
104
+ it "Must be able to retrieve block by hash." do
105
+ expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", false)).to be_a_kind_of(Object)
106
+ end
107
+
108
+ # Test suite for client to retrieve block by hash, full transactions included.
109
+ it "Must be able to retrieve block by hash, full transactions included." do
110
+ expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", true)).to be_a_kind_of(Object)
111
+ end
112
+
113
+ # Test suite for client to retrieve block by number.
114
+ it "Must be able to retrieve block by number." do
115
+ expect(@nimiq.get_block_by_number(76415, false)).to be_a_kind_of(Object)
116
+ end
117
+
118
+ # Test suite for client to retrieve block by number, full transactions included.
119
+ it "Must be able to retrieve block by number, full transactions included." do
120
+ expect(@nimiq.get_block_by_number(76415, true)).to be_a_kind_of(Object)
121
+ end
122
+
123
+ # Test suite for client to retrieve block template.
124
+ it "Must be able to retrieve block template." do
125
+ expect(@nimiq.get_block_template()).to be_a_kind_of(Object)
126
+ end
127
+
128
+ # Test suite for client to retrieve the number of transactions in a block by block hash.
129
+ it "Must be able to retrieve the number of transactions in a block by block hash." do
130
+ expect(@nimiq.get_block_transaction_count_by_hash("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f")).to be_a_kind_of(Integer)
131
+ end
132
+
133
+ # Test suite for client to retrieve the number of transactions in a block by block number.
134
+ it "Must be able to retrieve the number of transactions in a block by block number." do
135
+ expect(@nimiq.get_block_transaction_count_by_number(76415)).to be_a_kind_of(Integer)
136
+ end
137
+
138
+ # Test suite for client to retrieve information about a transaction by block hash and transaction index position.
139
+ it "Must be able to retrieve information about a transaction by block hash and transaction index position." do
140
+ expect(@nimiq.get_transaction_by_block_hash_and_index("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f", 20)).to be_a_kind_of(Object)
141
+ end
142
+
143
+ # Test suite for client to retrieve information about a transaction by block number and transaction index position.
144
+ it "Must be able to retrieve information about a transaction by block number and transaction index position." do
145
+ expect(@nimiq.get_transaction_by_block_number_and_index(76415, 20)).to be_a_kind_of(Object)
146
+ end
147
+
148
+ # Test suite for client to retrieve the information about a transaction requested by transaction hash.
149
+ it "Must be able to retrieve the information about a transaction requested by transaction hash." do
150
+ expect(@nimiq.get_transaction_by_hash("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554")).to be_a_kind_of(Object)
151
+ end
152
+
153
+ # Test suite for client to retrieve the receipt of a transaction by transaction hash.
154
+ it "Must be able to retrieve the receipt of a transaction by transaction hash." do
155
+ expect(@nimiq.get_transaction_receipt("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554")).to be_a_kind_of(Object)
156
+ end
157
+
158
+ # Test suite for client to retrieve the latest transactions successfully performed by or for an address.
159
+ it "Must be able to retrieve the latest transactions successfully performed by or for an address." do
160
+ expect(@nimiq.get_transactions_by_address("NQ699A4AMB83HXDQ4J46BH5R4JFFQMA9C3GN", 100)).to be_a_kind_of(Object)
161
+ end
162
+
163
+ # Test suite for client to retrieve instructions to mine the next block.
164
+ it "Must be able to retrieve instructions to mine the next block." do
165
+ expect(@nimiq.get_work()).to be_a_kind_of(Object)
166
+ end
167
+
168
+ # Test suite for client to retrieve the number of hashes per second that the node is mining with.
169
+ it "Must be able to retrieve the number of hashes per second that the node is mining with." do
170
+ expect(@nimiq.hashrate()).to be_a_kind_of(Integer)
171
+ end
172
+
173
+ # Test suite for client to set the log level of the node.
174
+ it "Must be able to set the log level of the node." do
175
+ expect(@nimiq.log("BaseConsensus", "debug")).to be(true).or be(false)
176
+ end
177
+
178
+ # Test suite for client to retrieve information on the current mempool situation.
179
+ it "Must be able to retrieve information on the current mempool situation." do
180
+ expect(@nimiq.mempool()).to be_a_kind_of(Object)
181
+ end
182
+
183
+ # Test suite for client to retrieve transactions that are currently in the mempool.
184
+ it "Must be able to retrieve transactions that are currently in the mempool." do
185
+ expect(@nimiq.mempool_content()).to be_a_kind_of(Object)
186
+ end
187
+
188
+ # Test suite for client to retrieve miner address.
189
+ it "Must be able to retrieve miner address." do
190
+ expect(@nimiq.miner_address()).to be_a_kind_of(String)
191
+ end
192
+
193
+ # Test suite for client to set the number of CPU threads for the miner.
194
+ it "Must be able to set the number of CPU threads for the miner." do
195
+ expect(@nimiq.miner_threads(2)).to be_a_kind_of(Integer)
196
+ end
197
+
198
+ # Test suite for client to retrieve the number of CPU threads for the miner.
199
+ it "Must be able to retrieve the number of CPU threads for the miner." do
200
+ expect(@nimiq.miner_threads()).to be_a_kind_of(Integer)
201
+ end
202
+
203
+ # Test suite for client to set the minimum fee per byte.
204
+ it "Must be able to set the minimum fee per byte." do
205
+ expect(@nimiq.min_fee_per_byte(1)).to be_a_kind_of(Integer)
206
+ end
207
+
208
+ # Test suite for client to retrieve the minimum fee per byte.
209
+ it "Must be able to retrieve the minimum fee per byte." do
210
+ expect(@nimiq.min_fee_per_byte()).to be_a_kind_of(Integer)
211
+ end
212
+
213
+ # Test suite for client to retrieve if client is actively mining new blocks.
214
+ it "Must be able to retrieve if client is actively mining new blocks." do
215
+ expect(@nimiq.mining()).to be(true).or be(false)
216
+ end
217
+
218
+ # Test suite for client to retrieve the number of peers currently connected to the client.
219
+ it "Must be able to retrieve the number of peers currently connected to the client." do
220
+ expect(@nimiq.peer_count()).to be_a_kind_of(Integer)
221
+ end
222
+
223
+ # Test suite for client to retrieve the list of peers known to the client.
224
+ it "Must be able to retrieve the list of peers known to the client." do
225
+ expect(@nimiq.peer_list()).to be_a_kind_of(Object)
226
+ end
227
+
228
+ # Test suite for client to retrieve the state of the peer.
229
+ it "Must be able to retrieve the state of the peer." do
230
+ expect(@nimiq.peer_state("wss://seed-1.nimiq.com:8443/dfd55fe967d6c0ca707d3a73ec31e4ac")).to be_a_kind_of(Object)
231
+ end
232
+
233
+ # Test suite for client to set the mining pool.
234
+ it "Must be able to set the mining pool." do
235
+ expect(@nimiq.pool("eu.nimpool.io:8444")).to be_a_kind_of(String).or be(nil)
236
+ end
237
+
238
+ # Test suite for client to retrieve the mining pool.
239
+ it "Must be able to retrieve the mining pool." do
240
+ expect(@nimiq.pool()).to be_a_kind_of(String).or be(nil)
241
+ end
242
+
243
+ # Test suite for client to retrieve the confirmed mining pool balance.
244
+ it "Must be able to retrieve the confirmed mining pool balance." do
245
+ expect(@nimiq.pool_confirmed_balance()).to be_a_kind_of(Integer)
246
+ end
247
+
248
+ # Test suite for client to retrieve the connection state to mining pool.
249
+ it "Must be able to retrieve the connection state to mining pool." do
250
+ expect(@nimiq.pool_connection_state()).to be_a_kind_of(Integer)
251
+ end
252
+
253
+ # Makes @signed_transaction
254
+ # Test suite for client to create a transaction without sending it.
255
+ it "Must be able to create a transaction without sending it." do
256
+ transaction = {
257
+ "from": @main_addr,
258
+ "to": @seco_addr,
259
+ "value": 100,
260
+ "fee": 0,
261
+ }
262
+ @signed_transaction = @nimiq.create_raw_transaction(transaction)
263
+ expect(@signed_transaction).to be_a_kind_of(Object)
264
+ end
265
+
266
+ # NEW
267
+ # Test suite for client to retrieve a transaction information.
268
+ it "Must be able to retrieve a transaction information." do
269
+ # expect(@nimiq.get_raw_transaction_info(@signed_transaction)).to be_a_kind_of(Object)
270
+ expect(@nimiq.get_raw_transaction_info("009de5aeefe9fa3b4017cbf460e863831808d121b614ae034337a69cdabbeeb4185a5cd4a2051f6277fd0d5bee0f59e45b514dd88b000000000000006400000000000000000007f8642afa9861e3dd9c708318aba517f0d40882af99579841cc78afd395927de3913b88c87990659a6c55b2ee28c073559520fe685c051f2daa7cc63ffb9caa9ac9e20f")).to be_a_kind_of(Object)
271
+ end
272
+
273
+ # Test suite for client to retrieve an object with data about the sync status.
274
+ it "Must be able to retrieve an object with data about the sync status." do
275
+ expect(@nimiq.syncing()[:startingBlock]).to be > 0
276
+ end
277
+
278
+ # # Must have at least some NIM to be able to send it to another address
279
+ # # Test suite for client to send a signed message call transaction or a contract creation, if the data field contains code.
280
+ # it "Must be able to send a signed message call transaction or a contract creation, if the data field contains code." do
281
+ # expect(@nimiq.send_raw_transaction(@signed_transaction)).to be_a_kind_of(Object)
282
+ # end
283
+
284
+ # # Must have at least some NIM to be able to send it to another address
285
+ # # Test suite for client to create new message call transaction or a contract creation, if the data field contains code.
286
+ # it "Must be able to create new message call transaction or a contract creation, if the data field contains code." do
287
+ # transaction = {
288
+ # "from": @main_addr,
289
+ # "to": @seco_addr,
290
+ # "value": 100,
291
+ # "fee": 0,
292
+ # }
293
+ # expect(@nimiq.send_transaction(transaction)).to be_a_kind_of(Object)
294
+ # end
295
+
296
+ # # Must have a valid generated block for the blockchain to accept, returns nothing if block is valid
297
+ # # Test suite for client to submit a block to the node.
298
+ # it "Must be able to submit a block to the node." do
299
+ # block = "14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87"
300
+ # expect(@nimiq.submit_block(block)).to be("")
301
+ # end
302
+
303
+ end
304
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jxdv
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -24,37 +24,21 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.15'
27
- description:
27
+ description: Ruby implementation of the Nimiq RPC client specification.
28
28
  email:
29
29
  - root@localhost
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - Gemfile
35
- - Gemfile.lock
36
- - LICENSE
37
- - README.md
38
- - Rakefile
39
34
  - bin/console
40
35
  - bin/setup
41
36
  - lib/api.rb
42
37
  - lib/nimiq/version.rb
43
- - lib/rpcclient.rb
38
+ - lib/rpc.rb
44
39
  - lib/ruby-client.rb
45
- - main.rb
46
- - ruby-client-1.0.0.gem
47
- - ruby-client-1.0.1.gem
48
- - ruby-client-1.0.2.gem
49
- - ruby-client-1.0.3.gem
50
- - ruby-client-1.0.4.gem
51
- - ruby-client-1.0.5.gem
52
- - ruby-client-1.1.1.gem
53
- - ruby-client-1.1.2.gem
54
- - ruby-client-1.1.3.gem
55
- - ruby-client-1.1.4.gem
56
- - ruby-client.gemspec
57
- - rubyclient-1.0.0.gem
40
+ - lib/types.rb
41
+ - spec/client_spec.rb
58
42
  homepage: https://github.com/jxdv/ruby-client
59
43
  licenses:
60
44
  - Apache-2.0
@@ -80,5 +64,5 @@ requirements: []
80
64
  rubygems_version: 3.1.4
81
65
  signing_key:
82
66
  specification_version: 4
83
- summary: Ruby implementation of the Nimiq RPC client specifications.
67
+ summary: Ruby implementation of the Nimiq RPC client specification.
84
68
  test_files: []
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem "minitest", "~> 5.0"
6
- gem "rspec-rails", "~> 3.5"
@@ -1,92 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ruby-client (1.0.2)
5
- oj (~> 2.15)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- actionpack (6.0.3.2)
11
- actionview (= 6.0.3.2)
12
- activesupport (= 6.0.3.2)
13
- rack (~> 2.0, >= 2.0.8)
14
- rack-test (>= 0.6.3)
15
- rails-dom-testing (~> 2.0)
16
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (6.0.3.2)
18
- activesupport (= 6.0.3.2)
19
- builder (~> 3.1)
20
- erubi (~> 1.4)
21
- rails-dom-testing (~> 2.0)
22
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activesupport (6.0.3.2)
24
- concurrent-ruby (~> 1.0, >= 1.0.2)
25
- i18n (>= 0.7, < 2)
26
- minitest (~> 5.1)
27
- tzinfo (~> 1.1)
28
- zeitwerk (~> 2.2, >= 2.2.2)
29
- builder (3.2.4)
30
- concurrent-ruby (1.1.6)
31
- crass (1.0.6)
32
- diff-lcs (1.4.4)
33
- erubi (1.9.0)
34
- i18n (1.8.4)
35
- concurrent-ruby (~> 1.0)
36
- loofah (2.6.0)
37
- crass (~> 1.0.2)
38
- nokogiri (>= 1.5.9)
39
- method_source (1.0.0)
40
- mini_portile2 (2.4.0)
41
- minitest (5.14.1)
42
- nokogiri (1.10.10-x64-mingw32)
43
- mini_portile2 (~> 2.4.0)
44
- oj (2.18.5)
45
- rack (2.2.3)
46
- rack-test (1.1.0)
47
- rack (>= 1.0, < 3)
48
- rails-dom-testing (2.0.3)
49
- activesupport (>= 4.2.0)
50
- nokogiri (>= 1.6)
51
- rails-html-sanitizer (1.3.0)
52
- loofah (~> 2.3)
53
- railties (6.0.3.2)
54
- actionpack (= 6.0.3.2)
55
- activesupport (= 6.0.3.2)
56
- method_source
57
- rake (>= 0.8.7)
58
- thor (>= 0.20.3, < 2.0)
59
- rake (13.0.1)
60
- rspec-core (3.9.2)
61
- rspec-support (~> 3.9.3)
62
- rspec-expectations (3.9.2)
63
- diff-lcs (>= 1.2.0, < 2.0)
64
- rspec-support (~> 3.9.0)
65
- rspec-mocks (3.9.1)
66
- diff-lcs (>= 1.2.0, < 2.0)
67
- rspec-support (~> 3.9.0)
68
- rspec-rails (3.9.1)
69
- actionpack (>= 3.0)
70
- activesupport (>= 3.0)
71
- railties (>= 3.0)
72
- rspec-core (~> 3.9.0)
73
- rspec-expectations (~> 3.9.0)
74
- rspec-mocks (~> 3.9.0)
75
- rspec-support (~> 3.9.0)
76
- rspec-support (3.9.3)
77
- thor (1.0.1)
78
- thread_safe (0.3.6)
79
- tzinfo (1.2.7)
80
- thread_safe (~> 0.1)
81
- zeitwerk (2.4.0)
82
-
83
- PLATFORMS
84
- x64-mingw32
85
-
86
- DEPENDENCIES
87
- minitest (~> 5.0)
88
- rspec-rails (~> 3.5)
89
- ruby-client!
90
-
91
- BUNDLED WITH
92
- 2.1.4