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
data/spec/a_spec.rb ADDED
@@ -0,0 +1,697 @@
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
+ # describe CLBool do
7
+ # my_bool = CLBool.new(false)
8
+ # cl_type = my_bool.get_cl_type
9
+ # describe "#get_cl_type" do
10
+ # it "Bool should return proper cl_type" do
11
+ # expect(cl_type).to eql('Bool')
12
+ # end
13
+ # end
14
+
15
+ # describe "#get_value" do
16
+ # it "should return proper value by calling get_value" do
17
+ # my_bool1 = CLBool.new(false)
18
+ # my_bool2 = CLBool.new(true)
19
+ # expect(my_bool1.get_value).to eql(false)
20
+ # expect(my_bool2.get_value).to eql(true)
21
+ # end
22
+ # end
23
+
24
+ # it "toBytes() / fromBytes() do proper bytes serialization" do
25
+ # bool1 = CLBool.new(false)
26
+ # bool2 = CLBool.new(true)
27
+
28
+ # bool1_bytes = CLValueBytesParsers::CLBoolBytesParser.to_bytes(bool1)
29
+ # expect(bool1_bytes).to eql([0])
30
+
31
+ # bool2_bytes = CLValueBytesParsers::CLBoolBytesParser.to_bytes(bool2)
32
+ # expect(bool2_bytes).to eql([1])
33
+
34
+ # from_bytes1 = CLValueBytesParsers::CLBoolBytesParser.from_bytes(bool1_bytes)
35
+
36
+ # expect(from_bytes1.get_value).to eql(bool1.get_value)
37
+ # expect(from_bytes1.get_cl_type).to eql(bool1.get_cl_type)
38
+
39
+ # from_bytes2 = CLValueBytesParsers::CLBoolBytesParser.from_bytes(bool2_bytes)
40
+
41
+ # expect(from_bytes2.get_value).to eql(bool2.get_value)
42
+ # expect(from_bytes2.get_cl_type).to eql(bool2.get_cl_type)
43
+ # end
44
+ # end
45
+
46
+ describe CLString do
47
+ cl_string = CLString.new("ABC")
48
+ describe "#get_value" do
49
+ it "should return proper value" do
50
+ expect(cl_string.get_value).to eq("ABC")
51
+ end
52
+ end
53
+
54
+ describe "#get_cl_type" do
55
+ it "should return proper cl_type" do
56
+ expect(cl_string.get_cl_type).to be_an_instance_of(String)
57
+ end
58
+ end
59
+
60
+ describe "#get_cl_type" do
61
+ it "should return String type" do
62
+ expect(cl_string.get_cl_type).to eq('String')
63
+ end
64
+ end
65
+
66
+ describe "#cl_string.get_size" do
67
+ it "should return proper string length" do
68
+ expect(cl_string.get_size).to eq(3)
69
+ end
70
+ end
71
+
72
+ it "should return \'ABC\'" do
73
+ expect(cl_string.from_bytes("03000000414243")).to eql("ABC")
74
+ end
75
+
76
+ it "should to proper string serialization" do
77
+ cl_string2 = CLString.new("Hello, World!")
78
+ puts cl_string2.to_bytes(cl_string2.get_value)
79
+ end
80
+ end
81
+
82
+
83
+ # describe CLi32 do
84
+ # # before :each do
85
+ # # cli32 = CLi32.new
86
+ # # end
87
+ # it "should do proper to_bytes and from_bytes when value is -1" do
88
+ # num1 = CLi32.new(-1)
89
+ # byte_array = CLValueBytesParsers::CLI32BytesParser.to_bytes(num1)
90
+ # expect(CLValueBytesParsers::CLI32BytesParser.from_bytes(byte_array)).to eql(num1.get_value)
91
+ # end
92
+
93
+ # it "should do proper to_bytes and from_bytes when value is 0" do
94
+ # num2 = CLi32.new(0)
95
+ # byte_array = CLValueBytesParsers::CLI32BytesParser.to_bytes(num2)
96
+ # expect(CLValueBytesParsers::CLI32BytesParser.from_bytes(byte_array)).to eql(num2.get_value)
97
+ # end
98
+
99
+ # it "should do proper to_bytes and from_bytes when value is 1" do
100
+ # num3 = CLi32.new(1)
101
+ # byte_array = CLValueBytesParsers::CLI32BytesParser.to_bytes(num3)
102
+ # expect(CLValueBytesParsers::CLI32BytesParser.from_bytes(byte_array)).to eql(num3.get_value)
103
+ # end
104
+
105
+ # it "should do proper to_bytes and from_bytes when value is MIN_I32" do
106
+ # num4 = CLi32.new(MIN_I32)
107
+ # byte_array = CLValueBytesParsers::CLI32BytesParser.to_bytes(num4)
108
+ # expect(CLValueBytesParsers::CLI32BytesParser.from_bytes(byte_array)).to eql(num4.get_value)
109
+ # end
110
+
111
+
112
+ # it "should do proper to_bytes and from_bytes when value is MAX_I32" do
113
+ # num5 = CLi32.new(MAX_I32)
114
+ # byte_array = CLValueBytesParsers::CLI32BytesParser.to_bytes(num5)
115
+ # expect(CLValueBytesParsers::CLI32BytesParser.from_bytes(byte_array)).to eql(num5.get_value)
116
+ # end
117
+ # end
118
+
119
+
120
+ # describe CLi64 do
121
+ # it "should do proper to_bytes and from_bytes when value is -10" do
122
+ # first_cli64 = CLi64.new(-10)
123
+ # num1 = first_cli64.get_value
124
+ # byte_array1 = first_cli64.to_bytes(num1)
125
+ # expect(first_cli64.from_bytes(byte_array1)).to eql(num1)
126
+ # end
127
+
128
+ # it "should do proper to_bytes and from_bytes when value is 0" do
129
+ # second_cli64 = CLi64.new(0)
130
+ # num2 = second_cli64.get_value
131
+ # byte_array2 = second_cli64.to_bytes(num2)
132
+ # expect(second_cli64.from_bytes(byte_array2)).to eql(num2)
133
+ # end
134
+
135
+ # it "should do proper to_bytes and from_bytes when value is 10" do
136
+ # third_cli64 = CLi64.new(10)
137
+ # num3 = third_cli64.get_value
138
+ # byte_array3 = third_cli64.to_bytes(num3)
139
+ # expect(third_cli64.from_bytes(byte_array3)).to eql(num3)
140
+ # end
141
+
142
+ # it "should do proper to_bytes and from_bytes when value is MIN_I64" do
143
+ # fourth_cli64 = CLi64.new(MIN_I64)
144
+ # min = fourth_cli64.get_value
145
+ # byte_array4 = fourth_cli64.to_bytes(min)
146
+ # expect(fourth_cli64.from_bytes(byte_array4)).to eq(min)
147
+ # end
148
+
149
+
150
+ # it "should do proper to_bytes and from_bytes when value is MAX_I64" do
151
+ # fifth_cli64 = CLi64.new(MAX_I64)
152
+ # max = fifth_cli64.get_value
153
+ # byte_array5 = fifth_cli64.to_bytes(max)
154
+ # expect(fifth_cli64.from_bytes(byte_array5)).to eq(max)
155
+ # end
156
+ # end
157
+
158
+ # describe CLu8 do
159
+ # it "should do proper to_bytes and from_bytes when value is MIN_U8" do
160
+ # clu8 = CLu8.new(0)
161
+ # num1 = clu8.get_value
162
+ # byte_array1 = clu8.to_bytes(num1)
163
+ # expect(clu8.from_bytes(byte_array1)).to eql(num1)
164
+ # end
165
+
166
+ # it "should do proper to_bytes and from_bytes when value is MAX_U8" do
167
+ # clu8 = CLu8.new(MAX_U8)
168
+ # num2 = clu8.get_value
169
+ # byte_array2 = clu8.to_bytes(num2)
170
+ # expect(clu8.from_bytes(byte_array2)).to eql(num2)
171
+ # end
172
+
173
+ # it "should raise error. Parameter value '-1' is not in range [0, 255]" do
174
+ # clu8 = CLu8.new(-1)
175
+ # num3 = clu8.get_value
176
+ # err = clu8.to_bytes(num3)
177
+ # expect {raise StandardError, err}.
178
+ # to raise_error(err)
179
+ # end
180
+ # end
181
+
182
+ # describe CLu32 do
183
+ # it "should do proper to_bytes and from_bytes when value is MIN_U32" do
184
+ # clu32 = CLu32.new(0)
185
+ # num1 = clu32.get_value
186
+ # byte_array1 = clu32.to_bytes(num1)
187
+ # expect(clu32.from_bytes(byte_array1)).to eql(num1)
188
+ # end
189
+
190
+ # it "should do proper to_bytes and from_bytes when value is MAX_U32" do
191
+ # clu32 = CLu32.new(MAX_U32)
192
+ # num2 = clu32.get_value
193
+ # byte_array2 = clu32.to_bytes(num2)
194
+ # expect(clu32.from_bytes(byte_array2)).to eql(num2)
195
+ # end
196
+
197
+ # it "should raise error. Parameter value '-1' is out of range [0, MAX_U32]" do
198
+ # clu32 = CLu32.new(-1)
199
+ # num3 = clu32.get_value
200
+ # err = clu32.to_bytes(num3)
201
+ # expect {raise StandardError, err}.
202
+ # to raise_error(err)
203
+ # end
204
+
205
+ # it "should raise error. Parameter value '#{MAX_U32 + 1}' is out of range [0, MAX_U32]" do
206
+ # clu32 = CLu32.new(MAX_U32 + 1)
207
+ # num3 = clu32.get_value
208
+ # err = clu32.to_bytes(num3)
209
+ # expect {raise StandardError, err}.
210
+ # to raise_error(err)
211
+ # end
212
+ # end
213
+
214
+ # describe CLu64 do
215
+ # it "should do proper to_bytes and from_bytes when value is MIN_U64" do
216
+ # clu64 = CLu64.new(0)
217
+ # num1 = clu64.get_value
218
+ # byte_array1 = clu64.to_bytes(num1)
219
+ # expect(clu64.from_bytes(byte_array1)).to eql(num1)
220
+ # end
221
+
222
+ # it "should do proper to_bytes and from_bytes when value is MAX_U64" do
223
+ # clu64 = CLu64.new(MAX_U64)
224
+ # num2 = clu64.get_value
225
+ # byte_array2 = clu64.to_bytes(num2)
226
+ # expect(clu64.from_bytes(byte_array2)).to eql(num2)
227
+ # end
228
+
229
+ # it "should raise error. Parameter value '-1' is out of range [0, MAX_U64]" do
230
+ # clu64 = CLu64.new(-1)
231
+ # num3 = clu64.get_value
232
+ # err = clu64.to_bytes(num3)
233
+ # expect {raise StandardError, err}.
234
+ # to raise_error(err)
235
+ # end
236
+
237
+ # it "should raise error. Parameter value '#{MAX_U64 + 1}' is out of range [0, MAX_U64]" do
238
+ # clu64 = CLu64
239
+ # .new(MAX_U64 + 1)
240
+ # num3 = clu64.get_value
241
+ # err = clu64.to_bytes(num3)
242
+ # expect {raise StandardError, err}.
243
+ # to raise_error(err)
244
+ # end
245
+ # end
246
+
247
+
248
+ # describe CLu128 do
249
+ # it "should do proper to_bytes and from_bytes when value is MIN_U128" do
250
+ # clu128 = CLu128.new(0)
251
+ # num1 = clu128.get_value
252
+ # byte_array1 = clu128.to_bytes(num1)
253
+ # expect(clu128.from_bytes(byte_array1)).to eql(num1)
254
+ # end
255
+
256
+ # it "should do proper to_bytes and from_bytes when value is MAX_U128" do
257
+ # clu128 = CLu128.new(MAX_U128)
258
+ # num2 = clu128.get_value
259
+ # byte_array2 = clu128.to_bytes(num2)
260
+ # expect(clu128.from_bytes(byte_array2)).to eql(num2)
261
+ # end
262
+
263
+ # it "should raise error. Parameter value '-1' is out of range [0, MAX_U128]" do
264
+ # clu128 = CLu128.new(-1)
265
+ # num3 = clu128.get_value
266
+ # err = clu128.to_bytes(num3)
267
+ # expect {raise StandardError, err}.to raise_error(err)
268
+ # end
269
+
270
+ # it "should raise error. Parameter value '#{MAX_U128 + 1}' is out of range [0, MAX_U128]" do
271
+ # clu128 = CLu128.new(MAX_U128 + 1)
272
+ # num3 = clu128.get_value
273
+ # err = clu128.to_bytes(num3)
274
+ # expect {raise StandardError, err}.to raise_error(err)
275
+ # end
276
+ # end
277
+
278
+
279
+ # describe CLu256 do
280
+ # it "should do proper to_bytes and from_bytes when value is MIN_U256" do
281
+ # clu256 = CLu256.new(0)
282
+ # num1 = clu256.get_value
283
+ # byte_array1 = clu256.to_bytes(num1)
284
+ # expect(clu256.from_bytes(byte_array1)).to eql(num1)
285
+ # end
286
+
287
+ # it "should do proper to_bytes and from_bytes when value is MAX_U256" do
288
+ # clu256 = CLu256.new(MAX_U256)
289
+ # num2 = clu256.get_value
290
+ # byte_array2 = clu256.to_bytes(num2)
291
+ # expect(clu256.from_bytes(byte_array2)).to eql(num2)
292
+ # end
293
+
294
+ # it "should raise error. Parameter value '-1' is out of range [0, MAX_U256]" do
295
+ # clu256 = CLu256.new(-1)
296
+ # num3 = clu256.get_value
297
+ # err = clu256.to_bytes(num3)
298
+ # expect {raise StandardError, err}.to raise_error(err)
299
+ # end
300
+
301
+ # it "should raise error. Parameter value '#{MAX_U256 + 1}' is out of range [0, MAX_U256]" do
302
+ # clu256 = CLu256.new(MAX_U256 + 1)
303
+ # num3 = clu256.get_value
304
+ # err = clu256.to_bytes(num3)
305
+ # expect {raise StandardError, err}.to raise_error(err)
306
+ # end
307
+ # end
308
+
309
+
310
+ # describe CLu512 do
311
+ # it "should do proper to_bytes and from_bytes when value is MIN_U512" do
312
+ # clu512 = CLu512.new(0)
313
+ # num1 = clu512.get_value
314
+ # byte_array1 = clu512.to_bytes(num1)
315
+ # expect(clu512.from_bytes(byte_array1)).to eql(num1)
316
+ # end
317
+
318
+ # it "should do proper to_bytes and from_bytes when value is MAX_U512" do
319
+ # clu512 = CLu512.new(MAX_U512)
320
+ # num2 = clu512.get_value
321
+ # byte_array2 = clu512.to_bytes(num2)
322
+ # expect(clu512.from_bytes(byte_array2)).to eql(num2)
323
+ # end
324
+
325
+ # it "should raise error. Parameter value '-1' is out of range [0, MAX_U512]" do
326
+ # clu512 = CLu512.new(-1)
327
+ # num3 = clu512.get_value
328
+ # err = clu512.to_bytes(num3)
329
+ # expect {raise StandardError, err}.to raise_error(err)
330
+ # end
331
+
332
+ # it "should raise error. Parameter value '#{MAX_U512 + 1}' is out of range [0, MAX_U512]" do
333
+ # clu512 = CLu512.new(MAX_U512 + 1)
334
+ # num3 = clu512.get_value
335
+ # err = clu512.to_bytes(num3)
336
+ # expect {raise StandardError, err}.to raise_error(err)
337
+ # end
338
+ # end
339
+
340
+ # describe CLUnit do
341
+ # it "should return proper type" do
342
+ # cl = CLUnit.new()
343
+ # expect(cl.get_cl_type).to eql("Unit")
344
+ # end
345
+
346
+ # it "should return proper value" do
347
+ # cl = CLUnit.new()
348
+ # expect(cl.get_value).to eql(nil)
349
+ # end
350
+
351
+ # it "to_json / from_json" do
352
+ # cl = CLUnit.new()
353
+ # json = cl.to_json
354
+ # expected_json = '{"bytes":"","cl_type":"Unit"}'
355
+ # expect(json).to eql(expected_json)
356
+ # expect(cl.from_json(json)).to eql(cl.get_hash)
357
+ # end
358
+ # end
359
+
360
+ # describe CLTuple do
361
+ # describe CLTuple1 do
362
+ # it "should return proper CLType" do
363
+ # bool = CLBool.new(true)
364
+ # t1 = CLTuple1.new([bool])
365
+ # expect(t1.get_cl_type).to eql("Tuple1 (Bool)")
366
+
367
+ # str = CLString.new("ABC")
368
+ # t2 = CLTuple1.new([str])
369
+ # expect(t2.get_cl_type).to eql("Tuple1 (String)")
370
+
371
+ # i32 = CLi32.new(99)
372
+ # t3 = CLTuple1.new([i32])
373
+ # expect(t3.get_cl_type).to eql("Tuple1 (I32)")
374
+ # end
375
+
376
+ # it "should throw an error when tuple elements are not in a correct format" do
377
+ # # tuple = CLTuple1.new([CLBool.new(true), CLBool.new(false)])
378
+ # tuple = CLTuple1.new(['a'])
379
+ # err = tuple.get_cl_type
380
+ # expect {raise err }.to raise_error(StandardError, "Invalid data type(s) provided.")
381
+ # end
382
+ # it "should return error when tuple is not correctly built" do
383
+ # bool = CLBool.new(false)
384
+ # tuple1 = CLTuple1.new([bool, bool])
385
+ # err = tuple1.get_cl_type
386
+ # expect {raise err}.to raise_error(StandardError, "Too many elements!")
387
+ # end
388
+
389
+ # it "should do proper to_bytes and from_bytes for Tuple1" do
390
+ # bool1 = CLBool.new(false)
391
+ # tuple = CLTuple1.new([bool1])
392
+
393
+ # bool_bytes = CLValueBytesParsers::CLTupleBytesParser.to_bytes(tuple)
394
+ # bool2 = CLValueBytesParsers::CLTupleBytesParser.from_bytes([bool1.get_cl_type], bool_bytes)
395
+
396
+ # expect(bool2.get_value).to eql(bool1.get_value)
397
+
398
+ # i32 = CLi32.new(10)
399
+ # tuple = CLTuple1.new([i32])
400
+
401
+ # i32_bytes = CLValueBytesParsers::CLTupleBytesParser.to_bytes(tuple)
402
+ # i32_value = CLValueBytesParsers::CLTupleBytesParser.from_bytes([i32.get_cl_type], i32_bytes)
403
+ # expect(i32_value).to eql(i32.get_value)
404
+ # end
405
+ # end
406
+
407
+ # describe CLTuple2 do
408
+ # it "should return proper CLType" do
409
+ # bool = CLBool.new(true)
410
+ # str = CLString.new("ABC")
411
+ # t1 = CLTuple2.new([bool, str])
412
+ # expect(t1.get_cl_type).to eql("Tuple2 (Bool, String)")
413
+
414
+
415
+ # str2 = CLString.new("XYZ")
416
+ # u512 = CLu512.new(MAX_U512)
417
+ # t2 = CLTuple2.new([str,u512])
418
+ # expect(t2.get_cl_type).to eql("Tuple2 (String, U512)")
419
+ # end
420
+
421
+ # it "should throw an error when tuple elements are not in a correct format" do
422
+ # tuple = CLTuple2.new(['a', 10])
423
+ # err = tuple.get_cl_type
424
+ # expect {raise err }.to raise_error(StandardError, "Invalid data type(s) provided.")
425
+ # end
426
+
427
+ # it "should return error when tuple is not correctly built" do
428
+ # bool = CLBool.new(false)
429
+ # tuple2 = CLTuple2.new([bool, bool, bool])
430
+ # err = tuple2.get_cl_type
431
+ # expect {raise err}.to raise_error(StandardError, "Too many elements!")
432
+ # end
433
+
434
+ # it "should do proper to_bytes and from_bytes for Tuple2" do
435
+ # bool1 = CLBool.new(true)
436
+ # bool2 = CLBool.new(false)
437
+ # tuple = CLTuple2.new([bool1, bool2])
438
+ # tuple_bytes = CLValueBytesParsers::CLTupleBytesParser.to_bytes(tuple)
439
+ # end
440
+ # end
441
+
442
+ # describe CLTuple3 do
443
+ # it "should return proper CLType" do
444
+ # bool = CLBool.new(true)
445
+ # str = CLString.new("ABC")
446
+ # u512 = CLu512.new(MAX_U512)
447
+ # t1 = CLTuple3.new([bool, str, u512])
448
+ # expect(t1.get_cl_type).to eql("Tuple3 (Bool, String, U512)")
449
+ # end
450
+
451
+ # it "should throw an error when tuple elements are not in a correct format" do
452
+ # tuple = CLTuple3.new(['a', 10, true])
453
+ # err = tuple.get_cl_type
454
+ # expect {raise err }.to raise_error(StandardError, "Invalid data type(s) provided.")
455
+ # end
456
+
457
+ # it "should return error when tuple is not correctly built" do
458
+ # bool = CLBool.new(false)
459
+ # tuple3 = CLTuple3.new([bool, bool, bool, bool])
460
+ # err = tuple3.get_cl_type
461
+ # expect {raise err}.to raise_error(StandardError, "Too many elements!")
462
+ # end
463
+ # end
464
+ # end
465
+
466
+ # describe CLURef do
467
+ # uref_addr1 = "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"
468
+ # decoded1 = CLValueBytesParsers::CLURefBytesParser.decode_base_16(uref_addr1)
469
+ # encoded1 = CLValueBytesParsers::CLURefBytesParser.encode_base_16(decoded1)
470
+ # uref1 = CLURef.new(decoded1, AccessRights[:READ_ADD_WRITE])
471
+ # str = "uref-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-007"
472
+
473
+ # it "should return proper CLType" do
474
+ # expect(uref1.get_cl_type).to eql('URef')
475
+ # expect(uref1).to be_an_instance_of(CLURef)
476
+ # end
477
+
478
+ # it "should return proper value" do
479
+ # expect(uref1.get_value).to eql(decoded1)
480
+ # end
481
+
482
+ # it "should return proper AccessRights" do
483
+ # expect(uref1.get_access_rights).to eql(AccessRights[:READ_ADD_WRITE])
484
+ # end
485
+
486
+ # it "should do proper to_bytes and from_bytes" do
487
+ # to_bytes = CLValueBytesParsers::CLURefBytesParser.to_bytes(uref1)
488
+ # # p to_bytes
489
+ # from_bytes = CLValueBytesParsers::CLURefBytesParser.from_bytes(to_bytes)
490
+ # # p from_bytes
491
+ # expect(uref1.get_value).to eql(from_bytes.get_value)
492
+ # expect(uref1.get_access_rights).to eql(from_bytes.get_access_rights)
493
+ # end
494
+
495
+ # it "should return error when CLUref is not correctly built" do
496
+ # uref_addr2 = "4b4b4b"
497
+ # decoded2 = CLValueBytesParsers::CLURefBytesParser.decode_base_16(uref_addr2)
498
+ # uref2 = CLURef.new(decoded2, 0)
499
+ # expect {raise 'The length of URefAddr should be 32'}.to raise_error(RuntimeError, 'The length of URefAddr should be 32')
500
+ # # expect {raise 'The length of URefAddr should be 32'}.to raise_error('The length of URefAddr should be 32')
501
+ # # expect {raise 'The length of URefAddr should be 32'}.to raise_error(ArgumentError, 'The length of URefAddr should be 32')
502
+ # end
503
+
504
+ # describe "#parse_uref_address" do
505
+ # # str = "uref-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-007"
506
+ # it "should raise an error when string does not begin with \'uref-\'" do
507
+ # bad_formatted_str = "xxx-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-007"
508
+ # expect {CLURef.parse_uref_address(bad_formatted_str)}.to raise_error(ArgumentError)
509
+ # end
510
+
511
+ # it "should raise an error when string does not begin with prefix: \'uref-\'" do
512
+ # bad_formatted_str = "ureffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-007"
513
+ # expect {CLURef.parse_uref_address(bad_formatted_str)}.to raise_error(ArgumentError)
514
+ # end
515
+
516
+ # it "should raise an error when uref bytes length is not equal to 32" do
517
+ # bad_formatted_str = "uref-fff-007"
518
+ # expect {CLURef.parse_uref_address("uref-fff-007")}.to raise_error(ArgumentError)
519
+ # end
520
+
521
+ # it "should raise an error when given parameter has lack of suffix which represents AccessRights" do
522
+ # bad_formatted_str = "uref-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
523
+ # expect {CLURef.parse_uref_address(bad_formatted_str)}.to raise_error(ArgumentError)
524
+ # end
525
+
526
+ # it "should raise an error when AccessRights is not within a range [0, 7]" do
527
+ # bad_formatted_str = "uref-ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff-008"
528
+ # expect {CLURef.parse_uref_address(bad_formatted_str)}.to raise_error(ArgumentError)
529
+ # end
530
+ # it "should convert to_json and from_json properly" do
531
+ # uref_addr1 = "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"
532
+ # decoded1 = CLValueBytesParsers::CLURefBytesParser.decode_base_16(uref_addr1)
533
+ # uref1 = CLURef.new(decoded1, 7)
534
+
535
+ # expect(CLURef.to_json(uref1)).to eql('{"bytes":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a07","cl_type":"URef"}')
536
+
537
+ # json = '{"bytes":"2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a07","cl_type":"URef"}'
538
+
539
+ # expect(CLURef.from_json(json).get_value).to eql(uref1.get_value)
540
+ # expect(CLURef.from_json(json).get_access_rights).to eql(uref1.get_access_rights)
541
+ # end
542
+ # end
543
+
544
+ # end
545
+
546
+
547
+ # describe CLPublicKey do
548
+ # pub_key_hex_ed25519 = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
549
+ # pub_key_hex_secp256K1 = "024ae7d5b66b2fd0f66fb0efcceecb673b3762595b30ae1cac48ae8f09d34c952ee4"
550
+ # pub_raw_ed25519 = [
551
+ # 10, 245, 169, 67, 186, 205, 42, 142,
552
+ # 145, 121, 46, 180, 233, 162, 94, 50,
553
+ # 213, 54, 171, 16, 51, 114, 245, 127,
554
+ # 137, 235, 202, 223, 197, 152, 32, 209
555
+ # ]
556
+ # pub_raw_secp256K1 = [
557
+ # 74, 231, 213, 182, 107, 47, 208, 246,
558
+ # 111, 176, 239, 204, 238, 203, 103, 59,
559
+ # 55, 98, 89, 91, 48, 174, 28, 172, 72,
560
+ # 174, 143, 9, 211, 76, 149, 46, 228
561
+ # ]
562
+ # it "should return error when CLPublicKey is not correctly built" do
563
+ # public_key_ed25519 = CLPublicKey.new(pub_raw_ed25519, CLPublicKeyTag[:ED25519])
564
+ # public_key_secp256K1 = CLPublicKey.new(pub_raw_secp256K1, CLPublicKeyTag[:SECP256K1])
565
+
566
+ # expect(public_key_ed25519).to be_an_instance_of(CLPublicKey)
567
+ # expect(public_key_secp256K1).to be_an_instance_of(CLPublicKey)
568
+ # end
569
+
570
+ # it "should raise error when CLPublicKey is not properly constructed" do
571
+ # expect {CLPublicKey.new(pub_raw_ed25519, 3)}.to raise_error(ArgumentError)
572
+ # expect {CLPublicKey.new(pub_raw_secp256K1, 3)}.to raise_error(ArgumentError)
573
+ # end
574
+
575
+ # it "should return proper CLType" do
576
+ # public_key1 = CLPublicKey.new(pub_raw_ed25519, 1)
577
+ # public_key2 = CLPublicKey.new(pub_raw_secp256K1, 2)
578
+
579
+ # expect(public_key1.get_cl_type).to eql("PublicKey")
580
+ # expect(public_key2.get_cl_type).to eql("PublicKey")
581
+ # end
582
+
583
+ # it "to_hex / from_hex work properly for ed25519" do
584
+ # pub_raw_ed25519 = [
585
+ # 10, 245, 169, 67, 186, 205, 42, 142,
586
+ # 145, 121, 46, 180, 233, 162, 94, 50,
587
+ # 213, 54, 171, 16, 51, 114, 245, 127,
588
+ # 137, 235, 202, 223, 197, 152, 32, 209
589
+ # ]
590
+ # public_key = CLPublicKey.new(pub_raw_ed25519, 1)
591
+ # expected_hex_result = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
592
+ # expect(public_key.to_hex).to eql(expected_hex_result)
593
+
594
+ # hex_value = public_key.to_hex
595
+ # result_public_key = public_key.from_hex(hex_value)
596
+
597
+ # expect(result_public_key.get_value).to eql([10, 245, 169, 67, 186, 205, 42, 142, 145, 121, 46,
598
+ # 180, 233, 162, 94, 50, 213, 54, 171, 16, 51, 114, 245, 127, 137, 235, 202, 223, 197, 152, 32, 209])
599
+ # expect(result_public_key.get_cl_public_key_tag).to eql(1)
600
+ # expect(result_public_key.ed25519?).to eql(true)
601
+ # expect(result_public_key.get_signature_algorithm).to eql("ed25519")
602
+ # end
603
+
604
+ # it "to_hex / from_hex work properly for secp256K1" do
605
+ # pub_raw_secp256K1 = [74, 231, 213, 182, 107, 47, 208, 246, 111, 176, 239, 204, 238, 203, 103, 59, 55,
606
+ # 98, 89, 91, 48, 174, 28, 172, 72, 174, 143, 9, 211, 76, 149, 46, 228]
607
+ # public_key = CLPublicKey.new(pub_raw_secp256K1, 2)
608
+ # expected_hex_result = "024ae7d5b66b2fd0f66fb0efcceecb673b3762595b30ae1cac48ae8f09d34c952ee4"
609
+ # expect(public_key.to_hex).to eql(expected_hex_result)
610
+
611
+ # hex_value = public_key.to_hex
612
+ # result_public_key = public_key.from_hex(hex_value)
613
+
614
+ # expect(result_public_key.get_value).to eql([74, 231, 213, 182, 107, 47, 208, 246, 111, 176, 239, 204,
615
+ # 238, 203, 103, 59, 55, 98, 89, 91, 48, 174, 28, 172, 72, 174, 143, 9, 211, 76, 149, 46, 228])
616
+ # expect(result_public_key.get_cl_public_key_tag).to eql(2)
617
+ # expect(result_public_key.secp256k1?).to eql(true)
618
+ # expect(result_public_key.get_signature_algorithm).to eql("secp256k1")
619
+ # end
620
+
621
+ # it "to_account_hash_byte_array works properly" do
622
+ # account_key = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
623
+ # public_key = CLPublicKey.from_hex(account_key)
624
+ # # puts account_key
625
+ # # puts public_key.to_hex
626
+ # # puts public_key.get_value.inspect
627
+ # # puts public_key.get_cl_public_key_tag
628
+ # expected_result = [217, 84, 5, 56, 40, 230, 253, 7, 122, 223, 214, 81, 224, 24, 172, 125,
629
+ # 213, 28, 170, 162, 61, 8, 23, 104, 77, 183, 110, 48, 67, 209, 9, 3]
630
+ # expect(public_key.to_account_hash_byte_array).to eql(expected_result)
631
+ # end
632
+
633
+ # it "to_account_hash_hex works properly" do
634
+ # account_key = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
635
+ # public_key = CLPublicKey.from_hex(account_key)
636
+ # expected_hex_result = "account-hash-d954053828e6fd077adfd651e018ac7dd51caaa23d0817684db76e3043d10903"
637
+ # expect(public_key.to_account_hash_hex).to eql(expected_hex_result)
638
+ # end
639
+
640
+ # it "should do proper to_bytes and from_bytes serialization for CLPublicKey" do
641
+ # public_key1 = CLPublicKey.from_ed25519(Array.new(32, 50))
642
+ # expected_ed25519_result = [
643
+ # 1, 50, 50, 50, 50, 50, 50, 50, 50,
644
+ # 50, 50, 50, 50, 50, 50, 50, 50,
645
+ # 50, 50, 50, 50, 50, 50, 50, 50,
646
+ # 50, 50, 50, 50, 50, 50, 50, 50
647
+ # ]
648
+
649
+ # bytes = CLValueBytesParsers::CLPublicKeyBytesParser.to_bytes(public_key1)
650
+ # expect(bytes).to eql(expected_ed25519_result)
651
+
652
+ # expected_raw_public_key1 = Array.new(32, 50)
653
+
654
+ # expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_value).to eql(expected_raw_public_key1)
655
+ # expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_cl_public_key_tag).to eql(1)
656
+
657
+ # public_key2 = CLPublicKey.from_secp256k1(Array.new(33, 100))
658
+ # expected_secp256k1_result = [
659
+ # 2, 100, 100, 100, 100, 100, 100, 100, 100,
660
+ # 100, 100, 100, 100, 100, 100, 100, 100, 100,
661
+ # 100, 100, 100, 100, 100, 100, 100, 100,
662
+ # 100, 100, 100, 100, 100, 100, 100, 100
663
+ # ]
664
+
665
+ # bytes = CLValueBytesParsers::CLPublicKeyBytesParser.to_bytes(public_key2)
666
+ # expect(bytes).to eql(expected_secp256k1_result)
667
+
668
+ # expected_raw_public_key2 = Array.new(33, 100)
669
+
670
+ # expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_value).to eql(expected_raw_public_key2)
671
+ # expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_cl_public_key_tag).to eql(2)
672
+ # end
673
+
674
+ # it "to_json / from_json for CLPublicKey" do
675
+ # public_key_hex1 = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
676
+ # # account_hash_hex = "14b94d33a1be1a2741ddefa7ae68a28cd1956e3801730bea617bf529d50f8aea"
677
+
678
+ # public_key1 = CLPublicKey.from_hex(public_key_hex1)
679
+ # raw_public_key1 = public_key1.get_value
680
+ # tag1 = public_key1.get_cl_public_key_tag
681
+
682
+ # expect(CLPublicKey.to_json(public_key1)).to eql('{"bytes":"01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2","cl_type":"PublicKey"}')
683
+
684
+ # json = CLPublicKey.to_json(public_key1)
685
+
686
+ # public_key2 = CLPublicKey.from_json(json)
687
+
688
+ # raw_public_key2 = public_key2.get_value
689
+ # tag2 = public_key2.get_cl_public_key_tag
690
+ # public_key_hex2 = public_key2.to_hex
691
+
692
+ # expect(raw_public_key2).to eql(raw_public_key1)
693
+ # expect(tag2).to eql(tag1)
694
+ # expect(public_key_hex2).to eql(public_key_hex1)
695
+ # end
696
+ # end
697
+