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.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +1 -0
- data/LICENSE +201 -0
- data/README.md +147 -0
- data/SECURITY.md +12 -0
- data/lib/crypto/00_asymmetric_key.rb +95 -0
- data/lib/crypto/01_ed25519.rb +67 -0
- data/lib/crypto/asymmetric_key.rb +87 -0
- data/lib/crypto/ed25519_key.rb +44 -0
- data/lib/crypto/key_pair.rb +40 -0
- data/lib/crypto/keys.rb +7 -0
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +44 -0
- data/lib/entity/account.rb +45 -0
- data/lib/entity/action_thresholds.rb +25 -0
- data/lib/entity/associated_key.rb +24 -0
- data/lib/entity/auction_state.rb +36 -0
- data/lib/entity/bid.rb +24 -0
- data/lib/entity/bid_info.rb +51 -0
- data/lib/entity/contract.rb +47 -0
- data/lib/entity/contract_package.rb +41 -0
- data/lib/entity/contract_version.rb +33 -0
- data/lib/entity/delegator.rb +37 -0
- data/lib/entity/deploy.rb +44 -0
- data/lib/entity/deploy_approval.rb +24 -0
- data/lib/entity/deploy_executable.rb +162 -0
- data/lib/entity/deploy_executable_item_internal.rb +26 -0
- data/lib/entity/deploy_executable_transfer.rb +50 -0
- data/lib/entity/deploy_hash.rb +16 -0
- data/lib/entity/deploy_header.rb +60 -0
- data/lib/entity/deploy_info.rb +44 -0
- data/lib/entity/deploy_named_argument.rb +19 -0
- data/lib/entity/deploy_transfer.rb +10 -0
- data/lib/entity/disabled_version.rb +26 -0
- data/lib/entity/era_info.rb +18 -0
- data/lib/entity/era_summary.rb +44 -0
- data/lib/entity/era_validator.rb +23 -0
- data/lib/entity/executable_deploy_item.rb +11 -0
- data/lib/entity/group.rb +25 -0
- data/lib/entity/module_bytes.rb +50 -0
- data/lib/entity/peer.rb +25 -0
- data/lib/entity/seigniorage_allocation.rb +18 -0
- data/lib/entity/stored_contract_by_hash.rb +50 -0
- data/lib/entity/stored_contract_by_name.rb +50 -0
- data/lib/entity/stored_value.rb +57 -0
- data/lib/entity/stored_versioned_contract_by_hash.rb +61 -0
- data/lib/entity/stored_versioned_contract_by_name.rb +61 -0
- data/lib/entity/transfer.rb +65 -0
- data/lib/entity/validator_weight.rb +23 -0
- data/lib/entity/vesting_schedule.rb +22 -0
- data/lib/include.rb +18 -0
- data/lib/rpc/rpc.rb +227 -0
- data/lib/rpc/rpc_client.rb +233 -0
- data/lib/rpc/rpc_error.rb +79 -0
- data/lib/serialization/cl_type_serializer.rb +76 -0
- data/lib/serialization/cl_value_bytes_parsers.rb +498 -0
- data/lib/serialization/cl_value_serializer.rb +259 -0
- data/lib/serialization/deploy_approval_serializer.rb +15 -0
- data/lib/serialization/deploy_executable_serializer.rb +27 -0
- data/lib/serialization/deploy_header_serializer.rb +49 -0
- data/lib/serialization/deploy_named_arg_serializer.rb +19 -0
- data/lib/serialization/deploy_serializer.rb +268 -0
- data/lib/serialization/test.rb +431 -0
- data/lib/test_sdk1.rb +289 -0
- data/lib/types/cl_account_hash.rb +24 -0
- data/lib/types/cl_account_hash_type.rb +22 -0
- data/lib/types/cl_any.rb +25 -0
- data/lib/types/cl_any_type.rb +22 -0
- data/lib/types/cl_bool.rb +32 -0
- data/lib/types/cl_bool_type.rb +35 -0
- data/lib/types/cl_byte_array.rb +25 -0
- data/lib/types/cl_byte_array_type.rb +27 -0
- data/lib/types/cl_i32.rb +26 -0
- data/lib/types/cl_i32_type.rb +26 -0
- data/lib/types/cl_i64.rb +26 -0
- data/lib/types/cl_i64_type.rb +27 -0
- data/lib/types/cl_key.rb +39 -0
- data/lib/types/cl_key_type.rb +27 -0
- data/lib/types/cl_list.rb +25 -0
- data/lib/types/cl_list_type.rb +26 -0
- data/lib/types/cl_map.rb +25 -0
- data/lib/types/cl_map_type.rb +26 -0
- data/lib/types/cl_option.rb +33 -0
- data/lib/types/cl_option_type.rb +52 -0
- data/lib/types/cl_public_key.rb +152 -0
- data/lib/types/cl_public_key_type.rb +26 -0
- data/lib/types/cl_result.rb +25 -0
- data/lib/types/cl_result_type.rb +26 -0
- data/lib/types/cl_string.rb +39 -0
- data/lib/types/cl_string_type.rb +32 -0
- data/lib/types/cl_tuple.rb +151 -0
- data/lib/types/cl_tuple_type.rb +108 -0
- data/lib/types/cl_type.rb +94 -0
- data/lib/types/cl_type_tag.rb +51 -0
- data/lib/types/cl_u128.rb +26 -0
- data/lib/types/cl_u128_type.rb +26 -0
- data/lib/types/cl_u256.rb +26 -0
- data/lib/types/cl_u256_type.rb +26 -0
- data/lib/types/cl_u32.rb +26 -0
- data/lib/types/cl_u32_type.rb +26 -0
- data/lib/types/cl_u512.rb +26 -0
- data/lib/types/cl_u512_type.rb +26 -0
- data/lib/types/cl_u64.rb +26 -0
- data/lib/types/cl_u64_type.rb +27 -0
- data/lib/types/cl_u8.rb +26 -0
- data/lib/types/cl_u8_type.rb +26 -0
- data/lib/types/cl_unit.rb +38 -0
- data/lib/types/cl_unit_type.rb +22 -0
- data/lib/types/cl_uref.rb +120 -0
- data/lib/types/cl_uref_type.rb +46 -0
- data/lib/types/cl_value.rb +10 -0
- data/lib/types/constants.rb +50 -0
- data/lib/types/error.rb +7 -0
- data/lib/utils/base_16.rb +18 -0
- data/lib/utils/byte_utils.rb +107 -0
- data/lib/utils/find_byte_parser_by_cl_type.rb +53 -0
- data/lib/utils/hash_utils.rb +19 -0
- data/lib/utils/hex_utils.rb +12 -0
- data/lib/utils/time_utils.rb +85 -0
- data/lib/utils/utils.rb +2 -0
- data/lib/version.rb +3 -0
- data/spec/a_spec.rb +697 -0
- data/spec/byte_utils_spec.rb +72 -0
- data/spec/cl_public_spec.rb +169 -0
- data/spec/cl_types_spec.rb +715 -0
- data/spec/cl_value_serializer_spec.rb +140 -0
- data/spec/client_spec.rb +25 -0
- data/spec/crypto_spec.rb +42 -0
- data/spec/deploy_approval_serializer_spec.rb +26 -0
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_header_serializer_spec.rb +21 -0
- data/spec/deploy_named_arg_serializer_spec.rb +49 -0
- data/spec/deploy_serializer_spec.rb +77 -0
- data/spec/deploy_serializer_test_spec.rb +225 -0
- data/spec/mainnet_spec.rb +452 -0
- data/spec/spec_helper.rb +100 -0
- data/spec/string_spec.rb +68 -0
- data/spec/testnet_spec.rb +498 -0
- data/spec/time_utils_spec.rb +87 -0
- metadata +198 -0
@@ -0,0 +1,452 @@
|
|
1
|
+
# mainnet_spec.rb
|
2
|
+
require './lib/rpc/rpc_client.rb'
|
3
|
+
|
4
|
+
# Ip Address taken from Mainnet
|
5
|
+
# client = Casper::RpcClient.new("5.161.68.4")
|
6
|
+
client = Casper::RpcClient.new("65.108.78.120")
|
7
|
+
# block_Hash taken from MainNet
|
8
|
+
block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
|
9
|
+
# deploy_Hash taken from MainNet
|
10
|
+
deploy_hash = "52a40996a88523c475c12e5370ff90b0ae4ec051cfaa57cd048c136b1a83319d"
|
11
|
+
state_root_hash = "7b605ad991c949832fd966495afc3f97a2b8122a1a6afc2610b545a8c07e3456"
|
12
|
+
item_key = "f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743"
|
13
|
+
uref = "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007"
|
14
|
+
describe Casper::RpcClient do
|
15
|
+
url = "65.21.0.X"
|
16
|
+
client2 = Casper::RpcClient.new(url)
|
17
|
+
it "fails, wrong ip format : #{url}" do
|
18
|
+
expect(client2.get_error).to eql("SocketError")
|
19
|
+
end
|
20
|
+
url = "65.21.0.0"
|
21
|
+
client3 = Casper::RpcClient.new(url)
|
22
|
+
it "fails, #{url} is not available in network" do
|
23
|
+
expect(client3.get_error).to eql("Errno::ECONNREFUSED")
|
24
|
+
end
|
25
|
+
# Test info_get_peers()
|
26
|
+
describe "#info_get_peers" do
|
27
|
+
peers = client.info_get_peers
|
28
|
+
context "Peers Array" do
|
29
|
+
it "passes, peers array is not nil" do
|
30
|
+
expect(peers).to be_truthy
|
31
|
+
end
|
32
|
+
|
33
|
+
it "passes, peers array is not empty" do
|
34
|
+
expect(peers).not_to be_empty
|
35
|
+
end
|
36
|
+
|
37
|
+
# it "passes, size of both peer arrays are equal" do
|
38
|
+
# # Check the length of the peers array
|
39
|
+
# client2 = Casper::RpcClient.new("34.192.231.34")
|
40
|
+
# other_peers = client2.info_get_peers
|
41
|
+
# expect(peers.size).to eql(other_peers.size)
|
42
|
+
# end
|
43
|
+
|
44
|
+
it "passes, peers object is a type of Array" do
|
45
|
+
# Check whether ıt is an array or not
|
46
|
+
expect(client.info_get_peers).to be_an(Array)
|
47
|
+
# Check the length of the peers array
|
48
|
+
expect(client.info_get_peers.length).to be > 0
|
49
|
+
end
|
50
|
+
|
51
|
+
it "passes, peers member are types of Hash" do
|
52
|
+
# Check type of peers elements
|
53
|
+
expect(peers[0]).to be_an_instance_of(Hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
peer = peers[0]
|
57
|
+
first_item = peer["node_id"]
|
58
|
+
second_item = peer["address"]
|
59
|
+
it "passes, peer members are types of String" do
|
60
|
+
expect(first_item).to be_an_instance_of(String)
|
61
|
+
expect(second_item).to be_an_instance_of(String)
|
62
|
+
expect(first_item.length).to eq(14)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "passes, length of first_item equal #{first_item.length}" do
|
66
|
+
expect(first_item.length).to eq(14)
|
67
|
+
end
|
68
|
+
|
69
|
+
peer.deep_symbolize_keys!
|
70
|
+
it "passes, peer includes node_id key" do
|
71
|
+
expect(peer).to have_key(:node_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "passes, peer includes address key" do
|
75
|
+
expect(peer).to have_key(:address)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context "When called info_get_peers with invalid ip address" do
|
79
|
+
client4 = Casper::RpcClient.new("65.21.227.X")
|
80
|
+
# puts client4.info_get_peers
|
81
|
+
it "fails, \"#{client4.info_get_peers}\"" do
|
82
|
+
expect(client4.info_get_peers).to eql("SocketError")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Test chain_get_StateRootHash
|
88
|
+
describe "#chain_get_StateRootHash" do
|
89
|
+
context "Without a block_hash parameter" do
|
90
|
+
current_state_root_hash = client.chain_get_StateRootHash("")
|
91
|
+
it "passes, current state_root_hash is a type of String" do
|
92
|
+
expect(current_state_root_hash).to be_an(String)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "passes, current state_root_hash is not nil" do
|
96
|
+
expect(current_state_root_hash).to be_truthy
|
97
|
+
end
|
98
|
+
|
99
|
+
it "passes, current state_root_hash is not empty" do
|
100
|
+
expect(current_state_root_hash).not_to be_empty
|
101
|
+
end
|
102
|
+
|
103
|
+
it "passes, current state_root_hash is 64 characters long" do
|
104
|
+
expect(current_state_root_hash.length).to eq(64)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "With a block_hash parameter" do
|
109
|
+
current_state_root_hash = client.chain_get_StateRootHash(state_root_hash)
|
110
|
+
it "passes, current state_root_hash is a type of String" do
|
111
|
+
expect(current_state_root_hash).to be_an(String)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "passes, current state_root_hash is not nil" do
|
115
|
+
expect(current_state_root_hash).to be_truthy
|
116
|
+
end
|
117
|
+
|
118
|
+
it "passes, current state_root_hash is not empty" do
|
119
|
+
expect(current_state_root_hash).not_to be_empty
|
120
|
+
end
|
121
|
+
|
122
|
+
it "passes, current state_root_hash is 64 characters long" do
|
123
|
+
expect(current_state_root_hash.length).to eq(64)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# Test info_get_deploy(deploy_hash)
|
129
|
+
describe "#info_get_deploy" do
|
130
|
+
context "When info_get_deploy method is called with deploy hash parameter" do
|
131
|
+
deploy = client.info_get_deploy(deploy_hash)
|
132
|
+
deploy.deep_symbolize_keys!
|
133
|
+
payment = deploy[:payment]
|
134
|
+
session = deploy[:session]
|
135
|
+
approvals = deploy[:approvals]
|
136
|
+
it "passes, Deploy type is a Hash" do
|
137
|
+
expect(deploy).to be_a(Hash)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "passes, hash value of Deploy is equal to the deploy_hash value" do
|
141
|
+
hash_value = deploy[:hash]
|
142
|
+
expect(hash_value).to eql(deploy_hash)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "passes, header is not nil" do
|
146
|
+
header = deploy[:header]
|
147
|
+
expect(header).to be_truthy
|
148
|
+
end
|
149
|
+
|
150
|
+
it "passes, payment is not nil" do
|
151
|
+
expect(payment).to be_truthy
|
152
|
+
end
|
153
|
+
|
154
|
+
it "passes, payment includes ModuleBytes key" do
|
155
|
+
# module_bytes = payment[:ModuleBytes]
|
156
|
+
# key_variable = :ModuleBytes
|
157
|
+
expect(payment).to have_key(:ModuleBytes)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "passes, session is not nil" do
|
161
|
+
expect(session).to be_truthy
|
162
|
+
expect(session).to be_an_instance_of(Hash)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "passes, session includes StoredContractByHash key" do
|
166
|
+
expect(session).to have_key(:StoredContractByHash)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "passes, approvals is not nil" do
|
170
|
+
expect(approvals).to be_truthy
|
171
|
+
expect(approvals).to be_an_instance_of(Array)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "passes, approvals includes signer" do
|
175
|
+
expect(approvals[0]).to have_key(:signer)
|
176
|
+
end
|
177
|
+
|
178
|
+
it "passes, approvals includes signature" do
|
179
|
+
expect(approvals[0]).to have_key(:signature)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "When info_get_deploy is called with an empty deploy hash parameter" do
|
184
|
+
it "fails, ServerError: Invalid params " do
|
185
|
+
err = client.info_get_deploy("")
|
186
|
+
# err = "Server error -32602: Invalid params (Jimson::Client::Error::ServerError)"
|
187
|
+
expect {raise StandardError, err}.
|
188
|
+
to raise_error(err)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "When info_get_deploy is called with an invalid parameter" do
|
193
|
+
it "fails, ServerError: Invalid params " do
|
194
|
+
err = client.info_get_deploy("AAAAAAA146419d036d13b83f37e7580df1ddfd925fbe4b36ee90f9d6fd63b9bb")
|
195
|
+
expect {raise StandardError, err}.
|
196
|
+
to raise_error(err)
|
197
|
+
end
|
198
|
+
it "fails, ServerError: Invalid params " do
|
199
|
+
err = client.info_get_deploy("asdsadsadsa")
|
200
|
+
expect {raise StandardError, err}.
|
201
|
+
to raise_error(err)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Test info_get_status()
|
207
|
+
describe "#info_get_status" do
|
208
|
+
node_status = client.info_get_status
|
209
|
+
node_status.deep_symbolize_keys!
|
210
|
+
context "Returns the current status of the node" do
|
211
|
+
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
|
212
|
+
expect(node_status).to have_key(:api_version)
|
213
|
+
expect(node_status).to have_key(:chainspec_name)
|
214
|
+
expect(node_status).to have_key(:starting_state_root_hash)
|
215
|
+
expect(node_status).to have_key(:peers)
|
216
|
+
expect(node_status).to have_key(:last_added_block_info)
|
217
|
+
expect(node_status).to have_key(:our_public_signing_key)
|
218
|
+
expect(node_status).to have_key(:round_length)
|
219
|
+
expect(node_status).to have_key(:next_upgrade)
|
220
|
+
expect(node_status).to have_key(:build_version)
|
221
|
+
expect(node_status).to have_key(:uptime)
|
222
|
+
end
|
223
|
+
|
224
|
+
it "passes, network is casper" do
|
225
|
+
chainspec_name = node_status[:chainspec_name]
|
226
|
+
expect(chainspec_name).to eql("casper")
|
227
|
+
end
|
228
|
+
|
229
|
+
it "passes, last added block includes hash, timestamp, era_id, height, state_root_hash, creator keys" do
|
230
|
+
last_block = node_status[:last_added_block_info]
|
231
|
+
expect(last_block).to have_key(:hash)
|
232
|
+
expect(last_block).to have_key(:timestamp)
|
233
|
+
expect(last_block).to have_key(:era_id)
|
234
|
+
expect(last_block).to have_key(:state_root_hash)
|
235
|
+
expect(last_block).to have_key(:creator)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "passes, the number of peers are equal" do
|
239
|
+
peers_from_info_get_peers = client.info_get_peers
|
240
|
+
peers_from_info_get_status = node_status[:peers]
|
241
|
+
expect(peers_from_info_get_status.size).to be > 0
|
242
|
+
expect(peers_from_info_get_peers.size).to be > 0
|
243
|
+
end
|
244
|
+
|
245
|
+
it "passes, node public key is : 014382d46e2543ab2832c04936f8c205847040426abb56065bbf7b2f7e1d33f200" do
|
246
|
+
our_public_signing_key = "014382d46e2543ab2832c04936f8c205847040426abb56065bbf7b2f7e1d33f200"
|
247
|
+
expect(node_status[:our_public_signing_key]).to eql(our_public_signing_key)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# Test chain_get_block_transfers(block_hash)
|
253
|
+
describe "#chain_get_block_transfers" do
|
254
|
+
transfers = client.chain_get_block_transfers(block_hash)
|
255
|
+
context "Returns all transfers for a Block from the network" do
|
256
|
+
it "passes, transfers is not empty and the number of transfers is #{transfers.size}" do
|
257
|
+
expect(transfers).not_to be_empty
|
258
|
+
expect(transfers.size).to eql(2)
|
259
|
+
end
|
260
|
+
|
261
|
+
it "passes, amount of the first transaction is 6000000000000 motes" do
|
262
|
+
first_transaction = transfers[0].deep_symbolize_keys!
|
263
|
+
first_transfer_amount = 6000000000000
|
264
|
+
expect(first_transaction[:amount].to_i).to eql(first_transfer_amount)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "passes, amount of the second transaction is 3997300000000 motes" do
|
268
|
+
second_transaction = transfers[1].deep_symbolize_keys!
|
269
|
+
second_transfer_amount = 3997300000000
|
270
|
+
expect(second_transaction[:amount].to_i).to eql(second_transfer_amount)
|
271
|
+
end
|
272
|
+
|
273
|
+
it "passes, all keys in transfers are \'deploy_hash\', \'from\', \'to\',
|
274
|
+
\'source\', \'target\', \'amount\', \'gas\', \'id\' respectively" do
|
275
|
+
transfers = transfers[0]
|
276
|
+
transfers.deep_symbolize_keys!
|
277
|
+
expect(transfers).to have_key(:deploy_hash)
|
278
|
+
expect(transfers).to have_key(:from)
|
279
|
+
expect(transfers).to have_key(:to)
|
280
|
+
expect(transfers).to have_key(:source)
|
281
|
+
expect(transfers).to have_key(:target)
|
282
|
+
expect(transfers).to have_key(:amount)
|
283
|
+
expect(transfers).to have_key(:gas)
|
284
|
+
expect(transfers).to have_key(:id)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Test chain_get_block(block_hash)
|
290
|
+
describe "#chain_get_block" do
|
291
|
+
block_hash = "5fdbdf3fa70d37821aa2d1752743e9653befc15e65e40c2655e1ce93a807260f"
|
292
|
+
block = client.chain_get_block(block_hash)
|
293
|
+
block.deep_symbolize_keys!
|
294
|
+
header = block[:header]
|
295
|
+
body = block[:body]
|
296
|
+
describe "Returns a Block from the network" do
|
297
|
+
context "When chain_get_block method is called with deploy hash parameter" do
|
298
|
+
it "passes, block hash : #{block[:hash]}" do
|
299
|
+
expect(block[:hash]).to be_truthy
|
300
|
+
expect(block[:hash]).to be_a(String)
|
301
|
+
expect(block[:hash]).not_to be_empty
|
302
|
+
expect(block[:hash].length).to eql(64)
|
303
|
+
end
|
304
|
+
|
305
|
+
it "passes, hash value of block is equal to the block hash given as parameter" do
|
306
|
+
expect(block[:hash]).to eq(block_hash)
|
307
|
+
end
|
308
|
+
|
309
|
+
it "passes, block includes \'hash\', \'header\', \'body\' and \'proofs\' respectively" do
|
310
|
+
expect(block).to have_key(:hash)
|
311
|
+
expect(block).to have_key(:header)
|
312
|
+
expect(block).to have_key(:body)
|
313
|
+
# expect(block).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
|
314
|
+
end
|
315
|
+
|
316
|
+
it "passes, header includes \'parent_hash\', \'state_root_hash\', \'body_hash\', \'random_bit\',
|
317
|
+
\'accumulated_seed\', \'era_end\', \'timestamp\', \'era_id\', \'height\', \'protocol_version\' keys respectively" do
|
318
|
+
expect(header).to have_key(:parent_hash)
|
319
|
+
expect(header[:parent_hash]).not_to be_empty # parent_hash is not empty
|
320
|
+
expect(header).to have_key(:state_root_hash)
|
321
|
+
expect(header[:state_root_hash]).not_to be_empty # state_root_hash is not empty
|
322
|
+
expect(header).to have_key(:body_hash)
|
323
|
+
expect(header[:body_hash]).not_to be_empty # body_hash is not empty
|
324
|
+
expect(header).to have_key(:random_bit)
|
325
|
+
expect(header[:random_bit]).to be_truthy # random_bit is true
|
326
|
+
expect(header).to have_key(:accumulated_seed)
|
327
|
+
expect(header[:accumulated_seed]).not_to be_empty # accumulated_seed is not empty
|
328
|
+
expect(header).to have_key(:era_end)
|
329
|
+
expect(header[:era_end]).to be_falsey # era_end is not nil
|
330
|
+
expect(header).to have_key(:timestamp)
|
331
|
+
expect(header[:timestamp]).not_to be_empty # timestamp is not nil
|
332
|
+
expect(header).to have_key(:height)
|
333
|
+
expect(header[:height]).to be_truthy # height is not nil
|
334
|
+
expect(header).to have_key(:protocol_version)
|
335
|
+
expect(header[:protocol_version]).to be_truthy # protocol_version is not nil
|
336
|
+
# expect(header).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
|
337
|
+
end
|
338
|
+
|
339
|
+
it "passes, body includes \'proposer\', \'deploy_hashes\' and \'transfer_hashes\' keys respectively" do
|
340
|
+
expect(body).to have_key(:proposer)
|
341
|
+
expect(body[:proposer]).not_to be_empty
|
342
|
+
expect(body).to have_key(:deploy_hashes)
|
343
|
+
expect(body[:deploy_hashes]).to be_a_kind_of(Array)
|
344
|
+
expect(body).to have_key(:transfer_hashes)
|
345
|
+
expect(body[:transfer_hashes]).to be_a_kind_of(Array)
|
346
|
+
# expect(body).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
|
347
|
+
end
|
348
|
+
|
349
|
+
it "includes public_key and signature keys" do
|
350
|
+
proofs = block[:proofs]
|
351
|
+
proof_item = proofs[0]
|
352
|
+
expect(proof_item).to have_key(:public_key)
|
353
|
+
expect(proof_item[:public_key]).not_to be_empty
|
354
|
+
expect(proof_item).to have_key(:signature)
|
355
|
+
expect(proof_item[:signature]).not_to be_empty
|
356
|
+
# expect(proof_item).to have_key(:testtest) # Negative test, uncomment and test again to see the result.
|
357
|
+
end
|
358
|
+
end
|
359
|
+
context "When chain_get_block method is called without deploy hash parameter" do
|
360
|
+
# Add tests
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
# Test chain_get_eraInfo_by_SwitchBlock(block_hash)
|
366
|
+
describe "#chain_get_eraInfo_by_SwitchBlock" do
|
367
|
+
context "Returns an EraInfo from the network" do
|
368
|
+
switch_block_hash = "4696285db1ca6572f425cada612257f85a58a6a4034c09846afe360ba40e5df0"
|
369
|
+
era_summary = client.chain_get_eraInfo_by_SwitchBlock(switch_block_hash)
|
370
|
+
|
371
|
+
if era_summary.class == Hash
|
372
|
+
era_summary.deep_symbolize_keys!
|
373
|
+
|
374
|
+
era_id = 3663
|
375
|
+
it "checks whether era_ids are equal or not" do
|
376
|
+
expect(era_summary[:era_id]).to eql(era_id)
|
377
|
+
end
|
378
|
+
|
379
|
+
state_root_hash = "4f9929288b885bb4eae3c27aaf13c974e1fc79eb12be5c6064e316e5797ca4ec"
|
380
|
+
it "checks whether state_root_hashes are equal or not" do
|
381
|
+
expect(era_summary[:state_root_hash]).to eql(state_root_hash)
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
# Test state_get_item(state_root_hash, key, path)
|
388
|
+
describe "#state_get_item" do
|
389
|
+
context "Returns a stored value from the network" do
|
390
|
+
stored_value = client.state_get_item("647C28545316E913969B032Cf506d5D242e0F857061E70Fb3DF55980611ace86", "bid-24b6D5Aabb8F0AC17D272763A405E9CECa9166B75B745Cf200695E172857c2dD", [])
|
391
|
+
stored_value.deep_symbolize_keys!
|
392
|
+
|
393
|
+
validator_public_key = "012bac1d0ff9240ff0b7b06d555815640497861619ca12583ddef434885416e69b"
|
394
|
+
stored_value[:Bid][:validator_public_key]
|
395
|
+
|
396
|
+
it "checks validator_public_key equality" do
|
397
|
+
expect(stored_value[:Bid][:validator_public_key]).to eql(validator_public_key)
|
398
|
+
end
|
399
|
+
|
400
|
+
staked_amount = 208330980103513
|
401
|
+
it "checks staked_amount which is 208330980103513" do
|
402
|
+
expect(stored_value[:Bid][:staked_amount].to_i).to eql(208330980103513)
|
403
|
+
end
|
404
|
+
|
405
|
+
it "includes initial_release_timestamp_millis keys" do
|
406
|
+
expect(stored_value[:Bid][:vesting_schedule]).to have_key(:initial_release_timestamp_millis)
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
# Test state_get_dictionary_item(state_root_hash, item_key, uref)
|
412
|
+
describe "#state_get_dictionary_item" do
|
413
|
+
stored_value = client.state_get_dictionary_item("d5811c438982f231a9152011c0f6ce9ae9c716e8075a6edec8390f10072ecd29","f870e3cadfde21d7d7686fdf3d1a8413838274d363ca7b27ae71fc9125eb6743", "uref-0d689e987db7ee5be246282c3a7badf0411e34baeeab8e9d73c1223ae4ad02e5-007")
|
414
|
+
stored_value.deep_symbolize_keys!
|
415
|
+
it "checks that CLValue should not be nil" do
|
416
|
+
expect(stored_value[:CLValue]).to be_truthy
|
417
|
+
end
|
418
|
+
|
419
|
+
it "checks that cl_type should equal to String" do
|
420
|
+
expect(stored_value[:CLValue][:cl_type]).to eql("String")
|
421
|
+
end
|
422
|
+
|
423
|
+
it "checks that CLValue parsed equals to \"https://caspercommunity.io\"" do
|
424
|
+
expect(stored_value[:CLValue][:parsed]).to eql("https://caspercommunity.io")
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
428
|
+
# Test state_get_balance(state_root_hash, balance_uref)
|
429
|
+
describe "#state_get_balance" do
|
430
|
+
balance = client.state_get_balance("610e932aef10d3e1fa04940c79a4a2789ee79c17046f1a9b45a2919f3600f3d5", "uref-7de5e973b7d70bc2b328814411f2009aafd8dba901cfc2c588ba65088dcd22bb-007")
|
431
|
+
|
432
|
+
it "is equal to 29269647684075" do
|
433
|
+
expect(balance.to_i).to eql(29269647684075)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
|
437
|
+
# Test state_get_AuctionInfo
|
438
|
+
describe "#state_get_AuctionInfo" do
|
439
|
+
auction_state = client.state_get_AuctionInfo
|
440
|
+
if auction_state.class == Hash
|
441
|
+
auction_state.deep_symbolize_keys!
|
442
|
+
it "checks state root hash equality and they should be equal" do
|
443
|
+
expect(auction_state[:state_root_hash]).to eql(client.chain_get_StateRootHash)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "checks that era_validators is not empty" do
|
447
|
+
expect(auction_state[:era_validators]).not_to be_empty
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
35
|
+
# a real object. This is generally recommended, and will default to
|
36
|
+
# `true` in RSpec 4.
|
37
|
+
mocks.verify_partial_doubles = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
41
|
+
# have no way to turn it off -- the option exists only for backwards
|
42
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
43
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
44
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
45
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
=begin
|
50
|
+
# This allows you to limit a spec run to individual examples or groups
|
51
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
52
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
53
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
54
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
55
|
+
config.filter_run_when_matching :focus
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
65
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
66
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
67
|
+
config.disable_monkey_patching!
|
68
|
+
|
69
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
70
|
+
# be too noisy due to issues in dependencies.
|
71
|
+
config.warnings = true
|
72
|
+
|
73
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
74
|
+
# file, and it's useful to allow more verbose output when running an
|
75
|
+
# individual spec file.
|
76
|
+
if config.files_to_run.one?
|
77
|
+
# Use the documentation formatter for detailed output,
|
78
|
+
# unless a formatter has already been configured
|
79
|
+
# (e.g. via a command-line flag).
|
80
|
+
config.default_formatter = "doc"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Print the 10 slowest examples and example groups at the
|
84
|
+
# end of the spec run, to help surface which specs are running
|
85
|
+
# particularly slow.
|
86
|
+
config.profile_examples = 10
|
87
|
+
|
88
|
+
# Run specs in random order to surface order dependencies. If you find an
|
89
|
+
# order dependency and want to debug it, you can fix the order by providing
|
90
|
+
# the seed, which is printed after each run.
|
91
|
+
# --seed 1234
|
92
|
+
config.order = :random
|
93
|
+
|
94
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
95
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
96
|
+
# test failures related to randomization by passing the same `--seed` value
|
97
|
+
# as the one that triggered the failure.
|
98
|
+
Kernel.srand config.seed
|
99
|
+
=end
|
100
|
+
end
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require_relative '../lib/types/cl_string.rb'
|
2
|
+
require_relative '../lib/types/constants.rb'
|
3
|
+
require_relative '../lib/serialization/cl_value_bytes_parsers.rb'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
=begin
|
7
|
+
Strings serialize as a 32-bit integer representing the length in bytes
|
8
|
+
(note: this might be different than the number of characters since special characters, such as emojis, take more than one byte),
|
9
|
+
followed by the UTF-8 encoding of the characters in the string.
|
10
|
+
E.g. "Hello, World!" serializes as 0x0d00000048656c6c6f2c20576f726c6421
|
11
|
+
=end
|
12
|
+
describe CLString do
|
13
|
+
cl_string = CLString.new("ABC")
|
14
|
+
describe "#get_value" do
|
15
|
+
it "should return proper value" do
|
16
|
+
expect(cl_string.get_value).to eq("ABC")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#get_cl_type" do
|
21
|
+
it "should return proper cl_type" do
|
22
|
+
expect(cl_string.get_cl_type).to be_an_instance_of(String)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#get_cl_type" do
|
27
|
+
it "should return String type" do
|
28
|
+
expect(cl_string.get_cl_type).to eq('String')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#cl_string.get_size" do
|
33
|
+
it "should return proper string length" do
|
34
|
+
expect(cl_string.get_size).to eq(3)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should return \'ABC\'" do
|
39
|
+
expect(cl_string.from_bytes("03000000414243")).to eql("ABC")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should do to_bytes / from_bytes string serialization" do
|
43
|
+
string = CLString.new("Hello, World!")
|
44
|
+
value = string.get_value
|
45
|
+
bytes = string.to_bytes(value)
|
46
|
+
result_string = string.from_bytes(bytes)
|
47
|
+
puts value, bytes, result_string
|
48
|
+
expect(value).to eql("Hello, World!")
|
49
|
+
expect(bytes).to eql("0d00000048656c6c6f2c20576f726c6421")
|
50
|
+
expect(value).to eql(result_string)
|
51
|
+
end
|
52
|
+
it "to_bytes / from_bytes" do
|
53
|
+
str = "pclphXwfYmCmdITj8hnh"
|
54
|
+
len = str.length
|
55
|
+
hex1 = len.to_s(16).rjust(8, '0').scan(/../).reverse.join('')
|
56
|
+
hex2 = str.unpack("H*").first
|
57
|
+
hex3 = hex1 + hex2
|
58
|
+
expected_hex1 = "14000000"
|
59
|
+
expected_hex2 = "70636c7068587766596d436d6449546a38686e68"
|
60
|
+
expected_hex3 = "1400000070636c7068587766596d436d6449546a38686e68"
|
61
|
+
puts str
|
62
|
+
puts hex3
|
63
|
+
puts CLValueBytesParsers::CLStringBytesParser.to_bytes(str)
|
64
|
+
puts CLValueBytesParsers::CLStringBytesParser.from_bytes(hex3)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|