test_sdk1 1.0.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.
Files changed (140) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +1 -0
  3. data/LICENSE +201 -0
  4. data/README.md +147 -0
  5. data/SECURITY.md +12 -0
  6. data/lib/crypto/00_asymmetric_key.rb +95 -0
  7. data/lib/crypto/01_ed25519.rb +67 -0
  8. data/lib/crypto/asymmetric_key.rb +87 -0
  9. data/lib/crypto/ed25519_key.rb +44 -0
  10. data/lib/crypto/key_pair.rb +40 -0
  11. data/lib/crypto/keys.rb +7 -0
  12. data/lib/crypto/secp256k1_key.rb +0 -0
  13. data/lib/crypto/test_ed25519_key.rb +44 -0
  14. data/lib/entity/account.rb +45 -0
  15. data/lib/entity/action_thresholds.rb +25 -0
  16. data/lib/entity/associated_key.rb +24 -0
  17. data/lib/entity/auction_state.rb +36 -0
  18. data/lib/entity/bid.rb +24 -0
  19. data/lib/entity/bid_info.rb +51 -0
  20. data/lib/entity/contract.rb +47 -0
  21. data/lib/entity/contract_package.rb +41 -0
  22. data/lib/entity/contract_version.rb +33 -0
  23. data/lib/entity/delegator.rb +37 -0
  24. data/lib/entity/deploy.rb +44 -0
  25. data/lib/entity/deploy_approval.rb +24 -0
  26. data/lib/entity/deploy_executable.rb +162 -0
  27. data/lib/entity/deploy_executable_item_internal.rb +26 -0
  28. data/lib/entity/deploy_executable_transfer.rb +50 -0
  29. data/lib/entity/deploy_hash.rb +16 -0
  30. data/lib/entity/deploy_header.rb +60 -0
  31. data/lib/entity/deploy_info.rb +44 -0
  32. data/lib/entity/deploy_named_argument.rb +19 -0
  33. data/lib/entity/deploy_transfer.rb +10 -0
  34. data/lib/entity/disabled_version.rb +26 -0
  35. data/lib/entity/era_info.rb +18 -0
  36. data/lib/entity/era_summary.rb +44 -0
  37. data/lib/entity/era_validator.rb +23 -0
  38. data/lib/entity/executable_deploy_item.rb +11 -0
  39. data/lib/entity/group.rb +25 -0
  40. data/lib/entity/module_bytes.rb +50 -0
  41. data/lib/entity/peer.rb +25 -0
  42. data/lib/entity/seigniorage_allocation.rb +18 -0
  43. data/lib/entity/stored_contract_by_hash.rb +50 -0
  44. data/lib/entity/stored_contract_by_name.rb +50 -0
  45. data/lib/entity/stored_value.rb +57 -0
  46. data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
  47. data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
  48. data/lib/entity/transfer.rb +65 -0
  49. data/lib/entity/validator_weight.rb +23 -0
  50. data/lib/entity/vesting_schedule.rb +22 -0
  51. data/lib/include.rb +18 -0
  52. data/lib/rpc/rpc.rb +227 -0
  53. data/lib/rpc/rpc_client.rb +233 -0
  54. data/lib/rpc/rpc_error.rb +79 -0
  55. data/lib/serialization/cl_type_serializer.rb +76 -0
  56. data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
  57. data/lib/serialization/cl_value_serializer.rb +259 -0
  58. data/lib/serialization/deploy_approval_serializer.rb +15 -0
  59. data/lib/serialization/deploy_executable_serializer.rb +27 -0
  60. data/lib/serialization/deploy_header_serializer.rb +49 -0
  61. data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
  62. data/lib/serialization/deploy_serializer.rb +268 -0
  63. data/lib/serialization/test.rb +431 -0
  64. data/lib/test_sdk1.rb +289 -0
  65. data/lib/types/cl_account_hash.rb +24 -0
  66. data/lib/types/cl_account_hash_type.rb +22 -0
  67. data/lib/types/cl_any.rb +25 -0
  68. data/lib/types/cl_any_type.rb +22 -0
  69. data/lib/types/cl_bool.rb +32 -0
  70. data/lib/types/cl_bool_type.rb +35 -0
  71. data/lib/types/cl_byte_array.rb +25 -0
  72. data/lib/types/cl_byte_array_type.rb +27 -0
  73. data/lib/types/cl_i32.rb +26 -0
  74. data/lib/types/cl_i32_type.rb +26 -0
  75. data/lib/types/cl_i64.rb +26 -0
  76. data/lib/types/cl_i64_type.rb +27 -0
  77. data/lib/types/cl_key.rb +39 -0
  78. data/lib/types/cl_key_type.rb +27 -0
  79. data/lib/types/cl_list.rb +25 -0
  80. data/lib/types/cl_list_type.rb +26 -0
  81. data/lib/types/cl_map.rb +25 -0
  82. data/lib/types/cl_map_type.rb +26 -0
  83. data/lib/types/cl_option.rb +33 -0
  84. data/lib/types/cl_option_type.rb +52 -0
  85. data/lib/types/cl_public_key.rb +152 -0
  86. data/lib/types/cl_public_key_type.rb +26 -0
  87. data/lib/types/cl_result.rb +25 -0
  88. data/lib/types/cl_result_type.rb +26 -0
  89. data/lib/types/cl_string.rb +39 -0
  90. data/lib/types/cl_string_type.rb +32 -0
  91. data/lib/types/cl_tuple.rb +151 -0
  92. data/lib/types/cl_tuple_type.rb +108 -0
  93. data/lib/types/cl_type.rb +94 -0
  94. data/lib/types/cl_type_tag.rb +51 -0
  95. data/lib/types/cl_u128.rb +26 -0
  96. data/lib/types/cl_u128_type.rb +26 -0
  97. data/lib/types/cl_u256.rb +26 -0
  98. data/lib/types/cl_u256_type.rb +26 -0
  99. data/lib/types/cl_u32.rb +26 -0
  100. data/lib/types/cl_u32_type.rb +26 -0
  101. data/lib/types/cl_u512.rb +26 -0
  102. data/lib/types/cl_u512_type.rb +26 -0
  103. data/lib/types/cl_u64.rb +26 -0
  104. data/lib/types/cl_u64_type.rb +27 -0
  105. data/lib/types/cl_u8.rb +26 -0
  106. data/lib/types/cl_u8_type.rb +26 -0
  107. data/lib/types/cl_unit.rb +38 -0
  108. data/lib/types/cl_unit_type.rb +22 -0
  109. data/lib/types/cl_uref.rb +120 -0
  110. data/lib/types/cl_uref_type.rb +46 -0
  111. data/lib/types/cl_value.rb +10 -0
  112. data/lib/types/constants.rb +50 -0
  113. data/lib/types/error.rb +7 -0
  114. data/lib/utils/base_16.rb +18 -0
  115. data/lib/utils/byte_utils.rb +107 -0
  116. data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
  117. data/lib/utils/hash_utils.rb +19 -0
  118. data/lib/utils/hex_utils.rb +12 -0
  119. data/lib/utils/time_utils.rb +85 -0
  120. data/lib/utils/utils.rb +2 -0
  121. data/lib/version.rb +3 -0
  122. data/spec/a_spec.rb +697 -0
  123. data/spec/byte_utils_spec.rb +72 -0
  124. data/spec/cl_public_spec.rb +169 -0
  125. data/spec/cl_types_spec.rb +715 -0
  126. data/spec/cl_value_serializer_spec.rb +140 -0
  127. data/spec/client_spec.rb +25 -0
  128. data/spec/crypto_spec.rb +42 -0
  129. data/spec/deploy_approval_serializer_spec.rb +26 -0
  130. data/spec/deploy_executable_serializer_spec.rb +0 -0
  131. data/spec/deploy_header_serializer_spec.rb +21 -0
  132. data/spec/deploy_named_arg_serializer_spec.rb +49 -0
  133. data/spec/deploy_serializer_spec.rb +77 -0
  134. data/spec/deploy_serializer_test_spec.rb +225 -0
  135. data/spec/mainnet_spec.rb +452 -0
  136. data/spec/spec_helper.rb +100 -0
  137. data/spec/string_spec.rb +68 -0
  138. data/spec/testnet_spec.rb +498 -0
  139. data/spec/time_utils_spec.rb +87 -0
  140. metadata +198 -0
@@ -0,0 +1,498 @@
1
+ # mainnet_spec.rb
2
+ require './lib/rpc/rpc_client.rb'
3
+
4
+ # Ip Address taken from Testnet
5
+ # client = Casper::RpcClient.new("138.201.54.44")
6
+ # Ip Address taken from Testnet
7
+ # client = Casper::RpcClient.new("65.21.227.101") # IP is taken from "TestNet"
8
+ # client = Casper::RpcClient.new("138.201.54.44") # IP is taken from "TestNet"
9
+ client = Casper::RpcClient.new("5.9.23.55") # IP is taken from "TestNet"
10
+
11
+ # block_Hash taken from Testnet
12
+ block_hash = "71e19e2e9629c716dc9578066cfeceace559d32fe51b08245ddd4d218f8c18da"
13
+ # deploy_Hash taken from Testnet
14
+ deploy_hash = "d3e0a1bd85ee74916e096cf4b18df391ada414d0915aeb865eff0ba75f04c3d8"
15
+ state_root_hash = "2a62440a1e1e57bff71344aac8a7de169f6dd08d29cffe83b2fb5d6648971855"
16
+ item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
17
+ uref = "uref-9199d08ff4ca4d52cd7a05ba0d2694204b7ebff963fec1c216f81bf654e0e59f-007"
18
+ describe Casper::RpcClient do
19
+ url = "65.21.0.X"
20
+ client2 = Casper::RpcClient.new(url)
21
+ it "fails, wrong ip format : #{url}" do
22
+ expect(client2.get_error).to eql("SocketError")
23
+ end
24
+
25
+ url2 = "65.21.0.0"
26
+ client3 = Casper::RpcClient.new(url2)
27
+ it "fails, #{url2} is not available in network" do
28
+ expect(client3.get_error).to eql("Errno::ECONNREFUSED")
29
+ end
30
+
31
+ # Test info_get_peers()
32
+ describe "#info_get_peers" do
33
+ peers = client.info_get_peers
34
+ context "Peers Array" do
35
+ it "passes, peers array is not nil" do
36
+ expect(peers).to be_truthy
37
+ end
38
+ # it "fails, connecting non existing node" do
39
+ # client2 = Casper::RpcClient.new("12.2.2.2")
40
+ # end
41
+ it "passes, peers array is not empty" do
42
+ expect(peers).not_to be_empty
43
+ end
44
+
45
+ # it "passes, size of both peer arrays are equal" do
46
+ # # Check the length of the peers array
47
+ # client2 = Casper::RpcClient.new("34.192.231.34")
48
+ # other_peers = client2.info_get_peers
49
+ # expect(peers.size).to eql(other_peers.size)
50
+ # end
51
+
52
+ it "passes, peers object is a type of Array" do
53
+ # Check whether ıt is an array or not
54
+ expect(client.info_get_peers).to be_an(Array)
55
+ # Check the length of the peers array
56
+ expect(client.info_get_peers.length).to be > 0
57
+ end
58
+
59
+ it "passes, peers member are types of Hash" do
60
+ # Check type of peers elements
61
+ expect(peers[0]).to be_an_instance_of(Hash)
62
+ end
63
+
64
+ peer = peers[0]
65
+ first_item = peer["node_id"]
66
+ second_item = peer["address"]
67
+ it "passes, peer members are types of String" do
68
+ expect(first_item).to be_an_instance_of(String)
69
+ expect(second_item).to be_an_instance_of(String)
70
+ expect(first_item.length).to eq(14)
71
+ end
72
+
73
+ it "passes, length of first_item equal #{first_item.length}" do
74
+ expect(first_item.length).to eq(14)
75
+ end
76
+
77
+ peer.deep_symbolize_keys!
78
+ it "passes, peer includes node_id key" do
79
+ expect(peer).to have_key(:node_id)
80
+ end
81
+
82
+ it "passes, peer includes address key" do
83
+ expect(peer).to have_key(:address)
84
+ end
85
+ end
86
+ context "When called info_get_peers with invalid ip address" do
87
+ client4 = Casper::RpcClient.new("65.21.227.X")
88
+ # puts client4.info_get_peers
89
+ it "fails, \"#{client4.info_get_peers}\"" do
90
+ expect(client4.info_get_peers).to eql("SocketError")
91
+ end
92
+ end
93
+ end
94
+
95
+ # Test chain_get_StateRootHash
96
+ describe "#chain_get_StateRootHash" do
97
+ context "Without a block_hash parameter" do
98
+ current_state_root_hash = client.chain_get_StateRootHash("")
99
+ it "passes, current state_root_hash is a type of String" do
100
+ expect(current_state_root_hash).to be_an(String)
101
+ end
102
+
103
+ it "passes, current state_root_hash is not nil" do
104
+ expect(current_state_root_hash).to be_truthy
105
+ end
106
+
107
+ it "passes, current state_root_hash is not empty" do
108
+ expect(current_state_root_hash).not_to be_empty
109
+ end
110
+
111
+ it "passes, current state_root_hash is 64 characters long" do
112
+ expect(current_state_root_hash.length).to eq(64)
113
+ end
114
+ end
115
+
116
+ context "With a block_hash parameter" do
117
+ current_state_root_hash = client.chain_get_StateRootHash(state_root_hash)
118
+ it "passes, current state_root_hash is a type of String" do
119
+ expect(current_state_root_hash).to be_an(String)
120
+ end
121
+
122
+ it "passes, current state_root_hash is not nil" do
123
+ expect(current_state_root_hash).to be_truthy
124
+ end
125
+
126
+ it "passes, current state_root_hash is not empty" do
127
+ expect(current_state_root_hash).not_to be_empty
128
+ end
129
+
130
+ it "passes, current state_root_hash is 64 characters long" do
131
+ expect(current_state_root_hash.length).to eq(64)
132
+ end
133
+ end
134
+ end
135
+
136
+ # Test info_get_deploy(deploy_hash)
137
+ describe "#info_get_deploy" do
138
+ context "When info_get_deploy method is called with deploy hash parameter" do
139
+ deploy_hash = "68265220148756e85e9b1dc2e774f9b8c40e5cf1782abe321ea95a8f58a670ae"
140
+ deploy = client.info_get_deploy(deploy_hash)
141
+ deploy.deep_symbolize_keys!
142
+ payment = deploy[:payment]
143
+ session = deploy[:session]
144
+ approvals = deploy[:approvals]
145
+
146
+ it "passes, Deploy type is a Hash" do
147
+ expect(deploy).to be_a(Hash)
148
+ end
149
+
150
+ it "passes, hash value of Deploy is equal to the deploy_hash value" do
151
+ hash_value = deploy[:hash]
152
+ expect(hash_value).to eql(deploy_hash)
153
+ end
154
+
155
+ it "passes, header is not nil" do
156
+ header = deploy[:header]
157
+ expect(header).to be_truthy
158
+ end
159
+
160
+ it "passes, payment is not nil" do
161
+ expect(payment).to be_truthy
162
+ end
163
+
164
+ it "passes, payment includes ModuleBytes key" do
165
+ # module_bytes = payment[:ModuleBytes]
166
+ # key_variable = :ModuleBytes
167
+ expect(payment).to have_key(:ModuleBytes)
168
+ end
169
+
170
+ it "passes, session is not nil" do
171
+ expect(session).to be_truthy
172
+ expect(session).to be_an_instance_of(Hash)
173
+ end
174
+
175
+ it "passes, session includes StoredContractByHash key" do
176
+ expect(session).to have_key(:StoredContractByHash)
177
+ end
178
+
179
+ it "passes, approvals is not nil" do
180
+ expect(approvals).to be_truthy
181
+ expect(approvals).to be_an_instance_of(Array)
182
+ end
183
+
184
+ it "passes, approvals includes signer" do
185
+ expect(approvals[0]).to have_key(:signer)
186
+ end
187
+
188
+ it "passes, approvals includes signature" do
189
+ expect(approvals[0]).to have_key(:signature)
190
+ end
191
+ end
192
+
193
+ context "When info_get_deploy is called with an empty deploy hash parameter" do
194
+ it "fails, ServerError: Invalid params " do
195
+ err = client.info_get_deploy("")
196
+ # err = "Server error -32602: Invalid params (Jimson::Client::Error::ServerError)"
197
+ expect {raise StandardError, err}.
198
+ to raise_error(err)
199
+ end
200
+ end
201
+ context "When info_get_deploy is called with an invalid parameter" do
202
+ it "fails, ServerError: Invalid params " do
203
+ err = client.info_get_deploy("AAAAAAA146419d036d13b83f37e7580df1ddfd925fbe4b36ee90f9d6fd63b9bb")
204
+ expect {raise StandardError, err}.
205
+ to raise_error(err)
206
+ end
207
+ it "fails, ServerError: Invalid params " do
208
+ err = client.info_get_deploy("asdsadsadsa")
209
+ expect {raise StandardError, err}.
210
+ to raise_error(err)
211
+ end
212
+ end
213
+ end
214
+
215
+ # Test info_get_status()
216
+ describe "#info_get_status" do
217
+ node_status = client.info_get_status
218
+ node_status.deep_symbolize_keys!
219
+ context "Returns the current status of the node" do
220
+ it "passes, node includes api_version, chainspec_name, starting_state_root_hash, peers, last_added_block_info, our_public_signing_key, round_length, next_upgrade, build_version, uptime keys" do
221
+ expect(node_status).to have_key(:api_version)
222
+ expect(node_status).to have_key(:chainspec_name)
223
+ expect(node_status).to have_key(:starting_state_root_hash)
224
+ expect(node_status).to have_key(:peers)
225
+ expect(node_status).to have_key(:last_added_block_info)
226
+ expect(node_status).to have_key(:our_public_signing_key)
227
+ expect(node_status).to have_key(:round_length)
228
+ expect(node_status).to have_key(:next_upgrade)
229
+ expect(node_status).to have_key(:build_version)
230
+ expect(node_status).to have_key(:uptime)
231
+ end
232
+
233
+ it "passes, network is casper" do
234
+ chainspec_name = node_status[:chainspec_name]
235
+ expect(chainspec_name).to eql("casper-test")
236
+ end
237
+
238
+ it "passes, last added block includes hash, timestamp, era_id, height, state_root_hash, creator keys" do
239
+ last_block = node_status[:last_added_block_info]
240
+ expect(last_block).to have_key(:hash)
241
+ expect(last_block).to have_key(:timestamp)
242
+ expect(last_block).to have_key(:era_id)
243
+ expect(last_block).to have_key(:state_root_hash)
244
+ expect(last_block).to have_key(:creator)
245
+ end
246
+
247
+ it "passes, the number of peers are equal" do
248
+ peers_from_info_get_peers = client.info_get_peers
249
+ peers_from_info_get_status = node_status[:peers]
250
+ expect(peers_from_info_get_status.size).to be > 0
251
+ end
252
+
253
+ it "passes, node public key is : 018597e78805200d5469105024d7741894c2c1eac69fb9c15e718e1824261722a2" do
254
+ our_public_signing_key = "018597e78805200d5469105024d7741894c2c1eac69fb9c15e718e1824261722a2"
255
+ expect(node_status[:our_public_signing_key]).to eql(our_public_signing_key)
256
+ end
257
+ end
258
+ end
259
+
260
+ # Test chain_get_block_transfers(block_hash)
261
+ describe "#chain_get_block_transfers" do
262
+ block_hash1 = "7aaacec3c4abdbd8766a5f0fc29ee54c18b16a19b0efc2685c44d75e1dff4eed"
263
+ transfers = client.chain_get_block_transfers(block_hash1)
264
+ transfers[0].deep_symbolize_keys!
265
+
266
+ context "Returns all transfers for a Block from the network" do
267
+ it "passes, transfers is not empty and the number of transfers is #{transfers.size}" do
268
+ expect(transfers).not_to be_empty
269
+ expect(transfers.size).to eql(1)
270
+ end
271
+
272
+ it "passes, all keys in transfers are \'deploy_hash\', \'from\', \'to\',
273
+ \'source\', \'target\', \'amount\', \'gas\', \'id\' respectively" do
274
+ transfers = transfers[0]
275
+ transfers.deep_symbolize_keys!
276
+ expect(transfers).to have_key(:deploy_hash)
277
+ expect(transfers).to have_key(:from)
278
+ expect(transfers).to have_key(:to)
279
+ expect(transfers).to have_key(:source)
280
+ expect(transfers).to have_key(:target)
281
+ expect(transfers).to have_key(:amount)
282
+ expect(transfers).to have_key(:gas)
283
+ expect(transfers).to have_key(:id)
284
+ end
285
+
286
+ it "passes, amount of the first transaction is 100000000000 motes" do
287
+ first_transaction = transfers
288
+ first_transfer_amount = 100000000000
289
+ expect(first_transaction[:amount].to_i).to eql(first_transfer_amount)
290
+ end
291
+
292
+ block_hash2 = "6d728385f84ca94d33729890f41420a9cd203f2ca6460d1f8a761d9753f578d7"
293
+ transfer2 = client.chain_get_block_transfers(block_hash2)
294
+
295
+ it "passes, amount of the second transaction is 120000000000 motes" do
296
+ second_transaction = transfer2[0].deep_symbolize_keys!
297
+ second_transfer_amount = 120000000000
298
+ expect(second_transaction[:amount].to_i).to eql(second_transfer_amount)
299
+ end
300
+
301
+ # it "fails, when called with invalid parameter" do
302
+ # response = client.chain_get_block_transfers("sasdsdsd")
303
+ # expect {raise StandardError, response}.to raise_error(response)
304
+ # # expect { response }.to raise_error(Casper::RpcError::InvalidParameter.error)
305
+ # end
306
+
307
+ end
308
+ end
309
+
310
+ # Test chain_get_block(block_hash)
311
+ describe "#chain_get_block" do
312
+ block_hash = "7e89d689b1604280e1c4c83c743f58ecef1f2177f5307580313122ab11595f4b"
313
+ block = client.chain_get_block(block_hash)
314
+ block.deep_symbolize_keys!
315
+ header = block[:header]
316
+ body = block[:body]
317
+ describe "Returns a Block from the network" do
318
+ context "When chain_get_block method is called with deploy hash parameter" do
319
+ it "passes, block hash : #{block[:hash]}" do
320
+ expect(block[:hash]).to be_truthy
321
+ expect(block[:hash]).to be_a(String)
322
+ expect(block[:hash]).not_to be_empty
323
+ expect(block[:hash].length).to eql(64)
324
+ end
325
+
326
+ it "passes, hash value of block is equal to the block hash given as parameter" do
327
+ expect(block[:hash]).to eq(block_hash)
328
+ end
329
+
330
+ it "passes, block includes \'hash\', \'header\', \'body\' and \'proofs\' respectively" do
331
+ expect(block).to have_key(:hash)
332
+ expect(block).to have_key(:header)
333
+ expect(block).to have_key(:body)
334
+ # expect(block).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
335
+ end
336
+
337
+ it "passes, header includes \'parent_hash\', \'state_root_hash\', \'body_hash\', \'random_bit\',
338
+ \'accumulated_seed\', \'era_end\', \'timestamp\', \'era_id\', \'height\', \'protocol_version\' keys respectively" do
339
+ expect(header).to have_key(:parent_hash)
340
+ expect(header[:parent_hash]).not_to be_empty # parent_hash is not empty
341
+ expect(header).to have_key(:state_root_hash)
342
+ expect(header[:state_root_hash]).not_to be_empty # state_root_hash is not empty
343
+ expect(header).to have_key(:body_hash)
344
+ expect(header[:body_hash]).not_to be_empty # body_hash is not empty
345
+ expect(header).to have_key(:random_bit)
346
+ expect(header[:random_bit]).to be_truthy # random_bit is true
347
+ expect(header).to have_key(:accumulated_seed)
348
+ expect(header[:accumulated_seed]).not_to be_empty # accumulated_seed is not empty
349
+ expect(header).to have_key(:era_end)
350
+ expect(header[:era_end]).to be_falsey # era_end is not nil
351
+ expect(header).to have_key(:timestamp)
352
+ expect(header[:timestamp]).not_to be_empty # timestamp is not nil
353
+ expect(header).to have_key(:height)
354
+ expect(header[:height]).to be_truthy # height is not nil
355
+ expect(header).to have_key(:protocol_version)
356
+ expect(header[:protocol_version]).to be_truthy # protocol_version is not nil
357
+ # expect(header).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
358
+ end
359
+
360
+ it "passes, body includes \'proposer\', \'deploy_hashes\' and \'transfer_hashes\' keys respectively" do
361
+ expect(body).to have_key(:proposer)
362
+ expect(body[:proposer]).not_to be_empty
363
+ expect(body).to have_key(:deploy_hashes)
364
+ expect(body[:deploy_hashes]).to be_a_kind_of(Array)
365
+ expect(body).to have_key(:transfer_hashes)
366
+ expect(body[:transfer_hashes]).to be_a_kind_of(Array)
367
+ # expect(body).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
368
+ end
369
+
370
+ it "includes public_key and signature keys" do
371
+ proofs = block[:proofs]
372
+ proof_item = proofs[0]
373
+ expect(proof_item).to have_key(:public_key)
374
+ expect(proof_item[:public_key]).not_to be_empty
375
+ expect(proof_item).to have_key(:signature)
376
+ expect(proof_item[:signature]).not_to be_empty
377
+ # expect(proof_item).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
378
+ end
379
+ end
380
+ context "When chain_get_block method is called without deploy hash parameter" do
381
+ # Add tests
382
+ end
383
+ end
384
+ end
385
+
386
+ # Test chain_get_eraInfo_by_SwitchBlock(block_hash)
387
+ describe "#chain_get_eraInfo_by_SwitchBlock" do
388
+ context "Returns an EraInfo from the network" do
389
+ switch_block_hash = "9e30104581a492f5c6faad4cdfb098311e3bf0e93897ebbfb47c3df62f5e6375"
390
+ era_summary = client.chain_get_eraInfo_by_SwitchBlock(switch_block_hash)
391
+ if era_summary.class == Hash
392
+ era_summary.deep_symbolize_keys!
393
+
394
+ era_id = 3921
395
+ it "passes, era_ids are equal" do
396
+ expect(era_summary[:era_id]).to eql(era_id)
397
+ end
398
+
399
+ state_root_hash = "6ec5bfba7d7bad174209f80f63820e671ca0dc8d22cb365a45c2b84fb1e4bf46"
400
+ it "passes, state_root_hashes are equal" do
401
+ expect(era_summary[:state_root_hash]).to eql(state_root_hash)
402
+ end
403
+ end
404
+ end
405
+ end
406
+
407
+ # Test state_get_item(state_root_hash, key, path)
408
+ describe "#state_get_item" do
409
+ context "Returns a stored value from the network" do
410
+ stored_value = client.state_get_item("420b18a9cb47f1f60b332a7d6376b700cc68fba8a24603b6550fd178cfabdf70", "account-hash-b0032b1c87261c9a440705762876a64354d37a2c57be269bae69bb450e6b8c2b", [])
411
+ stored_value.deep_symbolize_keys!
412
+ account = stored_value[:Account]
413
+ associated_keys = account[:associated_keys]
414
+ action_thresholds = account[:action_thresholds]
415
+
416
+ it "passes, Account includes account_hash, named_keys, main_purse, associated_keys, action_thresholds keys" do
417
+ expect(stored_value[:Account]).to have_key(:account_hash)
418
+ expect(stored_value[:Account]).to have_key(:named_keys)
419
+ expect(stored_value[:Account]).to have_key(:main_purse)
420
+ expect(stored_value[:Account]).to have_key(:associated_keys)
421
+ expect(stored_value[:Account]).to have_key(:action_thresholds)
422
+ end
423
+
424
+ it "passes, account hash = account-hash-b0032b1c87261c9a440705762876a64354d37a2c57be269bae69bb450e6b8c2b" do
425
+ account_hash_value = "account-hash-b0032b1c87261c9a440705762876a64354d37a2c57be269bae69bb450e6b8c2b"
426
+ account_hash = stored_value[:Account][:account_hash]
427
+ # account_hash.slice!("account-hash-")
428
+ expect(account_hash).to eql(account_hash_value)
429
+ end
430
+
431
+ it "passes, main_purse is not nil" do
432
+ expect(account[:main_purse]).to be_truthy
433
+ end
434
+
435
+ it "passes, main_purse : uref-f4d4d840464dd8934fcca9758d64cb514f52285ae0b79d706436f2cfe87e34fd-007" do
436
+ expect(account[:main_purse]).to eql("uref-f4d4d840464dd8934fcca9758d64cb514f52285ae0b79d706436f2cfe87e34fd-007")
437
+ end
438
+
439
+ it "passes, named_keys is not empty" do
440
+ expect(account[:named_keys]).not_to be_empty
441
+ end
442
+
443
+ it "passes, deployment of action_thresholds is equal to 1" do
444
+ expect(action_thresholds[:deployment]).to eql(1)
445
+ end
446
+
447
+ it "passes, weight of associated keys is equal to 1" do
448
+ expect(associated_keys[0][:weight]).to eql(1)
449
+ end
450
+
451
+ end
452
+ end
453
+
454
+ # Test state_get_dictionary_item(state_root_hash, item_key, uref)
455
+ describe "#state_get_dictionary_item" do
456
+ stored_value = client.state_get_dictionary_item("146b860f82359ced6e801cbad31015b5a9f9eb147ab2a449fd5cdb950e961ca8",
457
+ "abc_name",
458
+ "uref-30074a46a79b2d80cff437594d2422383f6c754de453b732448cc711b9f7e129-007")
459
+ stored_value.deep_symbolize_keys!
460
+ it "checks that CLValue should not be nil" do
461
+ expect(stored_value[:CLValue]).to be_truthy
462
+ end
463
+
464
+ it "checks that cl_type should equal to String" do
465
+ expect(stored_value[:CLValue][:cl_type]).to eql("String")
466
+ end
467
+
468
+ it "checks that CLValue parsed equals to \"abc_value\"" do
469
+ expect(stored_value[:CLValue][:parsed]).to eql("abc_value")
470
+ end
471
+ end
472
+
473
+ # Test state_get_balance(state_root_hash, balance_uref)
474
+ describe "#state_get_balance" do
475
+ balance = client.state_get_balance("146b860f82359ced6e801cbad31015b5a9f9eb147ab2a449fd5cdb950e961ca8", "uref-f4d4d840464dd8934fcca9758d64cb514f52285ae0b79d706436f2cfe87e34fd-007")
476
+
477
+ it "is equal to 390000000000" do
478
+ expect(balance.to_i).to eql(390000000000)
479
+ end
480
+ end
481
+
482
+ # Test state_get_AuctionInfo
483
+ describe "#state_get_AuctionInfo" do
484
+ auction_state = client.state_get_AuctionInfo
485
+ if auction_state.class == Hash
486
+ auction_state.deep_symbolize_keys!
487
+ it "checks state root hash equality and they should be equal" do
488
+ expect(auction_state[:state_root_hash]).to eql(client.chain_get_StateRootHash)
489
+ end
490
+
491
+ it "checks that era_validators is not empty" do
492
+ # puts auction_state[:era_validators]
493
+ expect(auction_state[:era_validators]).not_to be_empty
494
+ end
495
+ end
496
+ end
497
+
498
+ end
@@ -0,0 +1,87 @@
1
+ require_relative '../lib/utils/time_utils.rb'
2
+ require_relative '../lib/utils/byte_utils.rb'
3
+
4
+ RSpec.describe Utils::TimeUtils do
5
+ let(:time_utils) { Utils::TimeUtils }
6
+ let(:byte_utils) { Utils::ByteUtils }
7
+
8
+ it "serialize 1603994401469 ms to 0xbd3a847575010000" do
9
+ expect("0x"+ byte_utils.to_u64(1603994401469)).to eql("0xbd3a847575010000")
10
+ expect(byte_utils.to_u64(1603994401469)).to eql("bd3a847575010000")
11
+ end
12
+
13
+ it "should convert iso datetime to ms from unix epoch" do
14
+ date = "2020-11-17T00:39:24.072Z"
15
+ expect(time_utils.to_epoc_ms(date)).to eql(1605573564072)
16
+ end
17
+
18
+ it "should convert miliseconds to iso datetime" do
19
+ date = "2020-11-17T00:39:24.072Z"
20
+ milliseconds = 1605573564072
21
+ expect(time_utils.to_iso_string(milliseconds)).to eql("2020-11-17T00:39:24.072Z")
22
+ end
23
+
24
+ it "should convert ttl to milliseconds" do
25
+ time1 = time_utils.ttl_to_milliseconds("1d")
26
+ expect(time1).to eql(86400000)
27
+
28
+ time2 = time_utils.ttl_to_milliseconds("1h")
29
+ expect(time2).to eql(3600000)
30
+
31
+ time3 = time_utils.ttl_to_milliseconds("30m")
32
+ expect(time3).to eql(1800000)
33
+
34
+ time4 = time_utils.ttl_to_milliseconds("50s")
35
+ expect(time4).to eql(50000)
36
+
37
+ time5 = time_utils.ttl_to_milliseconds("90ms")
38
+ expect(time5).to eql(90)
39
+
40
+ time6 = time_utils.ttl_to_milliseconds("1d 1h 30m 50s 90ms")
41
+ expect(time6).to eql(91850090)
42
+
43
+ time7 = time_utils.ttl_to_milliseconds("1h 30m 50s 90ms")
44
+ expect(time7).to eql(5450090)
45
+
46
+ time8 = time_utils.ttl_to_milliseconds("30m 50s 90ms")
47
+ expect(time8).to eql(1850090)
48
+
49
+ time9 = time_utils.ttl_to_milliseconds("50s 90ms")
50
+ expect(time9).to eql(50090)
51
+
52
+ time10 = time_utils.ttl_to_milliseconds("90ms")
53
+ expect(time10).to eql(90)
54
+ end
55
+
56
+ it "should convert milliseconds to ttl" do
57
+ ttl1 = time_utils.milliseconds_to_ttl(86400000)
58
+ expect(ttl1).to eql("1d")
59
+
60
+ ttl2 = time_utils.milliseconds_to_ttl(3600000)
61
+ expect(ttl2).to eql("1h")
62
+
63
+ ttl3 = time_utils.milliseconds_to_ttl(1800000)
64
+ expect(ttl3).to eql("30m")
65
+
66
+ ttl4 = time_utils.milliseconds_to_ttl(50000)
67
+ expect(ttl4).to eql("50s")
68
+
69
+ ttl5 = time_utils.milliseconds_to_ttl(90)
70
+ expect(ttl5).to eql("90ms")
71
+
72
+ ttl6 = time_utils.milliseconds_to_ttl(91850090)
73
+ expect(ttl6).to eql("1d 1h 30m 50s 90ms")
74
+
75
+ ttl7 = time_utils.milliseconds_to_ttl(5450090)
76
+ expect(ttl7).to eql("1h 30m 50s 90ms")
77
+
78
+ ttl8 = time_utils.milliseconds_to_ttl(1850090)
79
+ expect(ttl8).to eql("30m 50s 90ms")
80
+
81
+ ttl9 = time_utils.milliseconds_to_ttl(50090)
82
+ expect(ttl9).to eql("50s 90ms")
83
+
84
+ ttl10 = time_utils.milliseconds_to_ttl(90)
85
+ expect(ttl10).to eql("90ms")
86
+ end
87
+ end