casper_network 1.0.1 → 1.1.2
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 +4 -4
- data/README.md +490 -89
- data/lib/casper_network.rb +28 -10
- data/lib/crypto/asymmetric_key.rb +19 -18
- data/lib/crypto/ed25519.rb +114 -0
- data/lib/crypto/ed25519_key.rb +111 -10
- data/lib/crypto/keys.rb +1 -2
- data/lib/crypto/keys_util.rb +20 -0
- data/lib/entity/auction_state.rb +56 -8
- data/lib/entity/bid.rb +1 -1
- data/lib/entity/bid_info.rb +1 -1
- data/lib/entity/block.rb +39 -0
- data/lib/entity/block_body.rb +35 -0
- data/lib/entity/block_header.rb +81 -0
- data/lib/entity/block_info.rb +56 -0
- data/lib/entity/block_proof.rb +24 -0
- data/lib/entity/deploy.rb +154 -1
- data/lib/entity/deploy_executable.rb +50 -7
- data/lib/entity/deploy_executable_item_internal.rb +1 -1
- data/lib/entity/deploy_header.rb +17 -0
- data/lib/entity/deploy_named_argument.rb +61 -2
- data/lib/entity/era_summary.rb +13 -12
- data/lib/entity/module_bytes.rb +9 -2
- data/lib/entity/status.rb +80 -0
- data/lib/entity/stored_value.rb +86 -11
- data/lib/entity/transfer.rb +7 -7
- data/lib/include.rb +2 -0
- data/lib/serialization/cl_value_serializer.rb +69 -12
- data/lib/serialization/deploy_serializer.rb +129 -15
- data/lib/types/cl_option.rb +9 -1
- data/lib/types/cl_public_key.rb +2 -0
- data/lib/types/cl_value.rb +8 -0
- data/lib/utils/byte_utils.rb +28 -0
- data/lib/utils/helpers.rb +10 -0
- data/lib/version.rb +1 -1
- data/spec/cl_value_serializer_spec.rb +15 -1
- data/spec/client_spec.rb +3 -3
- data/spec/deploy_executable_spec.rb +90 -0
- data/spec/testnet_spec.rb +5 -3
- metadata +13 -24
- data/lib/crypto/00_asymmetric_key.rb +0 -95
- data/lib/crypto/01_ed25519.rb +0 -67
- data/lib/crypto/key_pair.rb +0 -40
- data/lib/crypto/secp256k1_key.rb +0 -0
- data/lib/crypto/test_ed25519_key.rb +0 -44
- data/lib/entity/executable_deploy_item.rb +0 -11
- data/lib/serialization/test.rb +0 -431
- data/lib/types/cl_account_hash.rb +0 -24
- data/lib/types/cl_account_hash_type.rb +0 -22
- data/lib/utils/utils.rb +0 -2
- data/spec/a_spec.rb +0 -697
- data/spec/cl_public_spec.rb +0 -169
- data/spec/crypto_spec.rb +0 -42
- data/spec/deploy_executable_serializer_spec.rb +0 -0
- data/spec/deploy_serializer_test_spec.rb +0 -225
- data/spec/string_spec.rb +0 -68
data/spec/cl_public_spec.rb
DELETED
@@ -1,169 +0,0 @@
|
|
1
|
-
require_relative '../lib/types/cl_string.rb'
|
2
|
-
require_relative '../lib/types/cl_bool.rb'
|
3
|
-
require_relative '../lib/types/cl_i32.rb'
|
4
|
-
require_relative '../lib/types/cl_i64.rb'
|
5
|
-
require_relative '../lib/types/cl_u8.rb'
|
6
|
-
require_relative '../lib/types/cl_u32.rb'
|
7
|
-
require_relative '../lib/types/cl_u64.rb'
|
8
|
-
require_relative '../lib/types/cl_u128.rb'
|
9
|
-
require_relative '../lib/types/cl_u256.rb'
|
10
|
-
require_relative '../lib/types/cl_u512.rb'
|
11
|
-
require_relative '../lib/types/cl_unit.rb'
|
12
|
-
require_relative '../lib/types/cl_tuple.rb'
|
13
|
-
require_relative '../lib/types/cl_uref.rb'
|
14
|
-
require_relative '../lib/types/cl_option.rb'
|
15
|
-
require_relative '../lib/types/cl_public_key.rb'
|
16
|
-
require_relative '../lib/types/constants.rb'
|
17
|
-
require_relative '../lib/serialization/cl_value_bytes_parsers.rb'
|
18
|
-
require 'json'
|
19
|
-
|
20
|
-
describe CLPublicKey do
|
21
|
-
pub_key_hex_ed25519 = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
|
22
|
-
pub_key_hex_secp256K1 = "024ae7d5b66b2fd0f66fb0efcceecb673b3762595b30ae1cac48ae8f09d34c952ee4"
|
23
|
-
pub_raw_ed25519 = [
|
24
|
-
10, 245, 169, 67, 186, 205, 42, 142,
|
25
|
-
145, 121, 46, 180, 233, 162, 94, 50,
|
26
|
-
213, 54, 171, 16, 51, 114, 245, 127,
|
27
|
-
137, 235, 202, 223, 197, 152, 32, 209
|
28
|
-
]
|
29
|
-
pub_raw_secp256K1 = [
|
30
|
-
74, 231, 213, 182, 107, 47, 208, 246,
|
31
|
-
111, 176, 239, 204, 238, 203, 103, 59,
|
32
|
-
55, 98, 89, 91, 48, 174, 28, 172, 72,
|
33
|
-
174, 143, 9, 211, 76, 149, 46, 228
|
34
|
-
]
|
35
|
-
it "should return error when CLPublicKey is not correctly built" do
|
36
|
-
public_key_ed25519 = CLPublicKey.new(pub_raw_ed25519, CLPublicKeyTag[:ED25519])
|
37
|
-
public_key_secp256K1 = CLPublicKey.new(pub_raw_secp256K1, CLPublicKeyTag[:SECP256K1])
|
38
|
-
|
39
|
-
expect(public_key_ed25519).to be_an_instance_of(CLPublicKey)
|
40
|
-
expect(public_key_secp256K1).to be_an_instance_of(CLPublicKey)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should raise error when CLPublicKey is not properly constructed" do
|
44
|
-
expect {CLPublicKey.new(pub_raw_ed25519, 3)}.to raise_error(ArgumentError)
|
45
|
-
expect {CLPublicKey.new(pub_raw_secp256K1, 3)}.to raise_error(ArgumentError)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return proper CLType" do
|
49
|
-
public_key1 = CLPublicKey.new(pub_raw_ed25519, 1)
|
50
|
-
public_key2 = CLPublicKey.new(pub_raw_secp256K1, 2)
|
51
|
-
|
52
|
-
expect(public_key1.get_cl_type).to eql("PublicKey")
|
53
|
-
expect(public_key2.get_cl_type).to eql("PublicKey")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "to_hex / from_hex work properly for ed25519" do
|
57
|
-
pub_raw_ed25519 = [
|
58
|
-
10, 245, 169, 67, 186, 205, 42, 142,
|
59
|
-
145, 121, 46, 180, 233, 162, 94, 50,
|
60
|
-
213, 54, 171, 16, 51, 114, 245, 127,
|
61
|
-
137, 235, 202, 223, 197, 152, 32, 209
|
62
|
-
]
|
63
|
-
public_key = CLPublicKey.new(pub_raw_ed25519, 1)
|
64
|
-
expected_hex_result = "010af5a943bacd2a8e91792eb4e9a25e32d536ab103372f57f89ebcadfc59820d1"
|
65
|
-
expect(public_key.to_hex).to eql(expected_hex_result)
|
66
|
-
|
67
|
-
hex_value = public_key.to_hex
|
68
|
-
result_public_key = public_key.from_hex(hex_value)
|
69
|
-
|
70
|
-
expect(result_public_key.get_value).to eql([10, 245, 169, 67, 186, 205, 42, 142, 145, 121, 46,
|
71
|
-
180, 233, 162, 94, 50, 213, 54, 171, 16, 51, 114, 245, 127, 137, 235, 202, 223, 197, 152, 32, 209])
|
72
|
-
expect(result_public_key.get_cl_public_key_tag).to eql(1)
|
73
|
-
expect(result_public_key.ed25519?).to eql(true)
|
74
|
-
expect(result_public_key.get_signature_algorithm).to eql("ed25519")
|
75
|
-
end
|
76
|
-
|
77
|
-
it "to_hex / from_hex work properly for secp256K1" do
|
78
|
-
pub_raw_secp256K1 = [74, 231, 213, 182, 107, 47, 208, 246, 111, 176, 239, 204, 238, 203, 103, 59, 55,
|
79
|
-
98, 89, 91, 48, 174, 28, 172, 72, 174, 143, 9, 211, 76, 149, 46, 228]
|
80
|
-
public_key = CLPublicKey.new(pub_raw_secp256K1, 2)
|
81
|
-
expected_hex_result = "024ae7d5b66b2fd0f66fb0efcceecb673b3762595b30ae1cac48ae8f09d34c952ee4"
|
82
|
-
expect(public_key.to_hex).to eql(expected_hex_result)
|
83
|
-
|
84
|
-
hex_value = public_key.to_hex
|
85
|
-
result_public_key = public_key.from_hex(hex_value)
|
86
|
-
|
87
|
-
expect(result_public_key.get_value).to eql([74, 231, 213, 182, 107, 47, 208, 246, 111, 176, 239, 204,
|
88
|
-
238, 203, 103, 59, 55, 98, 89, 91, 48, 174, 28, 172, 72, 174, 143, 9, 211, 76, 149, 46, 228])
|
89
|
-
expect(result_public_key.get_cl_public_key_tag).to eql(2)
|
90
|
-
expect(result_public_key.secp256k1?).to eql(true)
|
91
|
-
expect(result_public_key.get_signature_algorithm).to eql("secp256k1")
|
92
|
-
end
|
93
|
-
|
94
|
-
it "to_account_hash_byte_array works properly" do
|
95
|
-
account_key = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
|
96
|
-
public_key = CLPublicKey.from_hex(account_key)
|
97
|
-
# puts account_key
|
98
|
-
# puts public_key.to_hex
|
99
|
-
# puts public_key.get_value.inspect
|
100
|
-
# puts public_key.get_cl_public_key_tag
|
101
|
-
expected_result = [217, 84, 5, 56, 40, 230, 253, 7, 122, 223, 214, 81, 224, 24, 172, 125,
|
102
|
-
213, 28, 170, 162, 61, 8, 23, 104, 77, 183, 110, 48, 67, 209, 9, 3]
|
103
|
-
expect(public_key.to_account_hash_byte_array).to eql(expected_result)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "to_account_hash_hex works properly" do
|
107
|
-
account_key = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
|
108
|
-
public_key = CLPublicKey.from_hex(account_key)
|
109
|
-
expected_hex_result = "account-hash-d954053828e6fd077adfd651e018ac7dd51caaa23d0817684db76e3043d10903"
|
110
|
-
expect(public_key.to_account_hash_hex).to eql(expected_hex_result)
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should do proper to_bytes and from_bytes serialization for CLPublicKey" do
|
114
|
-
public_key1 = CLPublicKey.from_ed25519(Array.new(32, 50))
|
115
|
-
expected_ed25519_result = [
|
116
|
-
1, 50, 50, 50, 50, 50, 50, 50, 50,
|
117
|
-
50, 50, 50, 50, 50, 50, 50, 50,
|
118
|
-
50, 50, 50, 50, 50, 50, 50, 50,
|
119
|
-
50, 50, 50, 50, 50, 50, 50, 50
|
120
|
-
]
|
121
|
-
|
122
|
-
bytes = CLValueBytesParsers::CLPublicKeyBytesParser.to_bytes(public_key1)
|
123
|
-
expect(bytes).to eql(expected_ed25519_result)
|
124
|
-
|
125
|
-
expected_raw_public_key1 = Array.new(32, 50)
|
126
|
-
|
127
|
-
expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_value).to eql(expected_raw_public_key1)
|
128
|
-
expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_cl_public_key_tag).to eql(1)
|
129
|
-
|
130
|
-
public_key2 = CLPublicKey.from_secp256k1(Array.new(33, 100))
|
131
|
-
expected_secp256k1_result = [
|
132
|
-
2, 100, 100, 100, 100, 100, 100, 100, 100,
|
133
|
-
100, 100, 100, 100, 100, 100, 100, 100, 100,
|
134
|
-
100, 100, 100, 100, 100, 100, 100, 100,
|
135
|
-
100, 100, 100, 100, 100, 100, 100, 100
|
136
|
-
]
|
137
|
-
|
138
|
-
bytes = CLValueBytesParsers::CLPublicKeyBytesParser.to_bytes(public_key2)
|
139
|
-
expect(bytes).to eql(expected_secp256k1_result)
|
140
|
-
|
141
|
-
expected_raw_public_key2 = Array.new(33, 100)
|
142
|
-
|
143
|
-
expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_value).to eql(expected_raw_public_key2)
|
144
|
-
expect(CLValueBytesParsers::CLPublicKeyBytesParser.from_bytes(bytes).get_cl_public_key_tag).to eql(2)
|
145
|
-
end
|
146
|
-
|
147
|
-
it "to_json / from_json for CLPublicKey" do
|
148
|
-
public_key_hex1 = "01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2"
|
149
|
-
# account_hash_hex = "14b94d33a1be1a2741ddefa7ae68a28cd1956e3801730bea617bf529d50f8aea"
|
150
|
-
|
151
|
-
public_key1 = CLPublicKey.from_hex(public_key_hex1)
|
152
|
-
raw_public_key1 = public_key1.get_value
|
153
|
-
tag1 = public_key1.get_cl_public_key_tag
|
154
|
-
|
155
|
-
expect(CLPublicKey.to_json(public_key1)).to eql('{"bytes":"01e23d200eb0f3c8a3dacc8453644e6fcf4462585a68234ebb1c3d6cc8971148c2","cl_type":"PublicKey"}')
|
156
|
-
|
157
|
-
json = CLPublicKey.to_json(public_key1)
|
158
|
-
|
159
|
-
public_key2 = CLPublicKey.from_json(json)
|
160
|
-
|
161
|
-
raw_public_key2 = public_key2.get_value
|
162
|
-
tag2 = public_key2.get_cl_public_key_tag
|
163
|
-
public_key_hex2 = public_key2.to_hex
|
164
|
-
|
165
|
-
expect(raw_public_key2).to eql(raw_public_key1)
|
166
|
-
expect(tag2).to eql(tag1)
|
167
|
-
expect(public_key_hex2).to eql(public_key_hex1)
|
168
|
-
end
|
169
|
-
end
|
data/spec/crypto_spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# require_relative '../lib/crypto/asymmetric_key.rb'
|
2
|
-
# require_relative '../lib/crypto/ed25519_key.rb'
|
3
|
-
# require_relative '../lib/types/cl_public_key.rb'
|
4
|
-
|
5
|
-
# $pub_raw_ed25519 = [
|
6
|
-
# 10, 245, 169, 67, 186, 205, 42, 142,
|
7
|
-
# 145, 121, 46, 180, 233, 162, 94, 50,
|
8
|
-
# 213, 54, 171, 16, 51, 114, 245, 127,
|
9
|
-
# 137, 235, 202, 223, 197, 152, 32, 209
|
10
|
-
# ]
|
11
|
-
# $private_key = [
|
12
|
-
# 233, 167, 59, 188, 240, 81, 151, 35, 145, 66, 150,
|
13
|
-
# 154, 239, 229, 16, 106, 66, 19, 86, 89, 193, 209,
|
14
|
-
# 176, 51, 125, 113, 212, 6, 27, 193, 145, 49, 201,
|
15
|
-
# 121, 63, 103, 146, 81, 130, 70, 221, 206, 116, 15,
|
16
|
-
# 62, 0, 1, 142, 227, 69, 220, 130, 20, 162, 253,
|
17
|
-
# 39, 171, 238, 197, 211, 17, 155, 253, 177
|
18
|
-
# ]
|
19
|
-
|
20
|
-
# $pub_raw_secp256K1 = [
|
21
|
-
# 74, 231, 213, 182, 107, 47, 208, 246,
|
22
|
-
# 111, 176, 239, 204, 238, 203, 103, 59,
|
23
|
-
# 55, 98, 89, 91, 48, 174, 28, 172, 72,
|
24
|
-
# 174, 143, 9, 211, 76, 149, 46, 228
|
25
|
-
# ]
|
26
|
-
# describe Ed25519Key do
|
27
|
-
# let(:public_key) {CLPublicKey.new($pub_raw_ed25519, 1)}
|
28
|
-
# let(:ed25519) {Ed25519Key.new(public_key, $private_key)}
|
29
|
-
# it "print raw_public_key" do
|
30
|
-
# # p public_key
|
31
|
-
# # p public_key.to_account_hash_byte_array
|
32
|
-
# # p public_key.to_account_hash_hex
|
33
|
-
|
34
|
-
# # p ed25519.account_hash
|
35
|
-
# # p ed25519.get_public_key
|
36
|
-
|
37
|
-
# # p ed25519.account_hex(ed25519.get_public_key)
|
38
|
-
# p ed25519.get_public_key_hex
|
39
|
-
# # p ed25519.account_hex
|
40
|
-
# p ed25519.account_hex(public_key)
|
41
|
-
# end
|
42
|
-
# end
|
File without changes
|
@@ -1,225 +0,0 @@
|
|
1
|
-
require_relative '../lib/types/cl_string.rb'
|
2
|
-
require_relative '../lib/serialization/cl_value_bytes_parsers.rb'
|
3
|
-
require_relative '../lib/utils/time_utils.rb'
|
4
|
-
require_relative '../lib/utils/byte_utils.rb'
|
5
|
-
require_relative '../lib/types/cl_i32.rb'
|
6
|
-
require_relative '../lib/serialization/cl_value_serializer.rb'
|
7
|
-
|
8
|
-
|
9
|
-
RSpec.describe Utils::TimeUtils do
|
10
|
-
let(:time_utils) { Utils::TimeUtils }
|
11
|
-
let(:byte_utils) { Utils::ByteUtils }
|
12
|
-
|
13
|
-
it "should serialize Deploy" do
|
14
|
-
ms = time_utils.to_epoc_ms("2020-11-17T00:39:24.072Z")
|
15
|
-
timestamp_serialized = byte_utils.to_u64(ms)
|
16
|
-
puts "timestamp_serialized: #{timestamp_serialized}"
|
17
|
-
|
18
|
-
ttl_serialized = byte_utils.to_u64(3600000)
|
19
|
-
# ttl_serialized = byte_utils.to_u64(1603994401469)
|
20
|
-
puts "ttl_serialized: #{ttl_serialized}"
|
21
|
-
|
22
|
-
gas_price_serialized = byte_utils.to_u64(1)
|
23
|
-
puts "gas_price_serialized: #{gas_price_serialized}"
|
24
|
-
|
25
|
-
|
26
|
-
# payment *******************************************************************************************
|
27
|
-
str1 = CLString.new("casper-example")
|
28
|
-
bytes1 = str1.to_bytes(str1.get_value)
|
29
|
-
puts "#{str1.get_value}: #{bytes1}"
|
30
|
-
puts "#{CLValueBytesParsers::CLStringBytesParser.from_bytes("0e0000006361737065722d6578616d706c65")}: 0e0000006361737065722d6578616d706c65"
|
31
|
-
|
32
|
-
str2 = CLString.new("example-entry-point")
|
33
|
-
bytes2 = str2.to_bytes(str2.get_value)
|
34
|
-
puts "#{str2.get_value}: #{bytes2}"
|
35
|
-
puts "#{CLValueBytesParsers::CLStringBytesParser.from_bytes("130000006578616d706c652d656e7472792d706f696e74")}: 130000006578616d706c652d656e7472792d706f696e74"
|
36
|
-
|
37
|
-
# result_string = string.from_bytes(bytes)
|
38
|
-
|
39
|
-
num1 = CLi32.new(1000)
|
40
|
-
num1_bytes = byte_utils.to_i32(1000)
|
41
|
-
puts "#{num1.get_value}: #{num1_bytes}"
|
42
|
-
# num1_bytes = CLValueBytesParsers::CLI32BytesParser.to_bytes(num1)
|
43
|
-
|
44
|
-
# serialized_quantity = "080000007175616e74697479"
|
45
|
-
serialized_quantity = CLValueBytesParsers::CLStringBytesParser.to_bytes("quantity")
|
46
|
-
puts "quantity: #{serialized_quantity}"
|
47
|
-
# deserialized_quantity = "quantity"
|
48
|
-
deserialized_quantity = CLValueBytesParsers::CLStringBytesParser.from_bytes(serialized_quantity)
|
49
|
-
puts "deserialized_quantity: #{deserialized_quantity}"
|
50
|
-
puts "?????: #{CLValueBytesParsers::CLStringBytesParser.from_bytes("080000007175616e74697479")}"
|
51
|
-
|
52
|
-
#serialized_amount = "06000000616d6f756e74"
|
53
|
-
serialized_amount = CLValueBytesParsers::CLStringBytesParser.to_bytes("amount")
|
54
|
-
puts "amount: #{serialized_quantity}"
|
55
|
-
|
56
|
-
# deserialized_amount = "06000000616d6f756e74"
|
57
|
-
deserialized_amount = CLValueBytesParsers::CLStringBytesParser.from_bytes(serialized_amount)
|
58
|
-
puts "deserialized_amount: #{deserialized_amount}"
|
59
|
-
|
60
|
-
# "cl_type": "I32", "bytes": "e8030000", "parsed": 1000
|
61
|
-
serialized_i32 = byte_utils.to_i32(3)
|
62
|
-
# expect(byte_utils.to_u64(3600000)).to eql("80ee360000000000")
|
63
|
-
puts "# => #{CLValueBytesParsers::CLStringBytesParser.from_bytes("06000000616d6f756e74")}"
|
64
|
-
puts "# => #{CLValueBytesParsers::CLStringBytesParser.from_bytes("06000000616d6f756e74")}"
|
65
|
-
# puts "# => #{CLValueBytesParsers::CLStringBytesParser.from_bytes("0101000000")}"
|
66
|
-
puts "# => #{byte_utils.to_i32(1000)}"
|
67
|
-
puts "e8030000"
|
68
|
-
|
69
|
-
puts "********** U512 serialization ***********"
|
70
|
-
value = 3000000000
|
71
|
-
value = 123456789101112131415
|
72
|
-
# value = 7
|
73
|
-
str = value.to_s(16)
|
74
|
-
arr = str.scan(/[0-9a-f]{4}/).map { |x| x.to_i(16) }
|
75
|
-
packed = arr.pack("n*").unpack("C*").reverse()
|
76
|
-
packed = arr.pack("n*").unpack1("H*")
|
77
|
-
p "packed: " + packed
|
78
|
-
|
79
|
-
# ********************************************************************************************************
|
80
|
-
# It is not done yet!!!
|
81
|
-
ModuleBytes = {
|
82
|
-
module_bytes: "[72 bytes]",
|
83
|
-
args: "434705a38470ec2b008bb693426f47f330802f3bd63588ee275e943407649d3bab1898897ab0400d7fa09fe02ab7b7e8ea443d28069ca557e206916515a7e21d15e5be5eb46235f5"
|
84
|
-
}
|
85
|
-
expected_serialized = "0048000000420481b0d5a665c8a7678398103d4333c684461a71e9ee2a13f6e859fb6cd419ed5f8876fc6c3e12dce4385acc777edf42dcf8d8d844bf6a704e5b2446750559911a4a328d649ddd48000000434705a38470ec2b008bb693426f47f330802f3bd63588ee275e943407649d3bab1898897ab0400d7fa09fe02ab7b7e8ea443d28069ca557e206916515a7e21d15e5be5eb46235f5"
|
86
|
-
expected_serialized_prefix = "00"
|
87
|
-
expected_serialized_length1 = "48000000"
|
88
|
-
expected_serialized_module_bytes = "420481b0d5a665c8a7678398103d4333c684461a71e9ee2a13f6e859fb6cd419ed5f8876fc6c3e12dce4385acc777edf42dcf8d8d844bf6a704e5b2446750559911a4a328d649ddd"
|
89
|
-
|
90
|
-
|
91
|
-
expected_serialized_args_length = "48000000"
|
92
|
-
expected_serialized_args = "434705a38470ec2b008bb693426f47f330802f3bd63588ee275e943407649d3bab1898897ab0400d7fa09fe02ab7b7e8ea443d28069ca557e206916515a7e21d15e5be5eb46235f5"
|
93
|
-
|
94
|
-
# ********************************************************************************************************
|
95
|
-
StoredContractByHash = {
|
96
|
-
hash: "c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa4",
|
97
|
-
entry_point: "pclphXwfYmCmdITj8hnh",
|
98
|
-
args: "d8b59728274edd2334ea328b3292ed15eaf9134f9a00dce31a87d9050570fb0267a4002c85f3a8384d2502733b2e46f44981df85fed5e4854200bbca313e3bca8d888a84a76a1c5b1b3d236a12401a2999d3cad003c9b9d98c92ab1850"
|
99
|
-
}
|
100
|
-
expected_serialized_prefix = "01"
|
101
|
-
expected_serialized_hash = "c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa4"
|
102
|
-
expected_serialized_entry_point = "1400000070636c7068587766596d436d6449546a38686e68"
|
103
|
-
expected_serialized_length_of_args = "5d000000"
|
104
|
-
expected_serialized_args = "d8b59728274edd2334ea328b3292ed15eaf9134f9a00dce31a87d9050570fb0267a4002c85f3a8384d2502733b2e46f44981df85fed5e4854200bbca313e3bca8d888a84a76a1c5b1b3d236a12401a2999d3cad003c9b9d98c92ab1850"
|
105
|
-
expected_serialized = "01c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa41400000070636c7068587766596d436d6449546a38686e685d000000d8b59728274edd2334ea328b3292ed15eaf9134f9a00dce31a87d9050570fb0267a4002c85f3a8384d2502733b2e46f44981df85fed5e4854200bbca313e3bca8d888a84a76a1c5b1b3d236a12401a2999d3cad003c9b9d98c92ab1850"
|
106
|
-
|
107
|
-
serialized_prefix = byte_utils.to_u8(1)
|
108
|
-
serialized_hash = StoredContractByHash[:hash]
|
109
|
-
serialized_entry_point = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredContractByHash[:entry_point])
|
110
|
-
serialized_length_of_args = byte_utils.to_u32(StoredContractByHash[:args].size/2)
|
111
|
-
serialized_args = serialized_length_of_args + StoredContractByHash[:args]
|
112
|
-
answer = serialized_prefix + serialized_hash + serialized_entry_point + serialized_args
|
113
|
-
p answer == expected_serialized
|
114
|
-
|
115
|
-
|
116
|
-
# ********************************************************************************************************
|
117
|
-
StoredContractByName = {
|
118
|
-
name: "U5A74bSZH8abT8HqVaK9",
|
119
|
-
entry_point: "gIetSxltnRDvMhWdxTqQ",
|
120
|
-
args: "07beadc3da884faa17454a"
|
121
|
-
}
|
122
|
-
|
123
|
-
# p CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredContractByName[:entry_point])
|
124
|
-
expected_serialized_prefix = "02"
|
125
|
-
expected_serialized_name = "14000000553541373462535a483861625438487156614b39"
|
126
|
-
expected_serialized_entry_point = "140000006749657453786c746e5244764d68576478547151"
|
127
|
-
expected_serialized_args = "0b00000007beadc3da884faa17454a"
|
128
|
-
expected_serialized = "0214000000553541373462535a483861625438487156614b39140000006749657453786c746e5244764d685764785471510b00000007beadc3da884faa17454a"
|
129
|
-
|
130
|
-
serialized_prefix = "02"
|
131
|
-
serialized_name = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredContractByName[:name])
|
132
|
-
serialized_entry_point = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredContractByName[:entry_point])
|
133
|
-
serialized_length_of_args = byte_utils.to_u32(StoredContractByName[:args].size/2)
|
134
|
-
serialized_args = serialized_length_of_args + StoredContractByName[:args]
|
135
|
-
answer = serialized_prefix + serialized_name + serialized_entry_point + serialized_args
|
136
|
-
p answer == expected_serialized
|
137
|
-
|
138
|
-
# ********************************************************************************************************
|
139
|
-
StoredVersionedContractByHash = {
|
140
|
-
hash: "b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423",
|
141
|
-
version: "None",
|
142
|
-
entry_point: "PsLz5c7JsqT8BK8ll0kF",
|
143
|
-
args: "3d0d7f193f70740386cb78b383e2e30c4f976cf3fa834bafbda4ed9dbfeb52ce1777817e8ed8868cfac6462b7cd31028aa5a7a60066db35371a2f8"
|
144
|
-
}
|
145
|
-
expected_serialized = "03b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423001400000050734c7a3563374a73715438424b386c6c306b463b0000003d0d7f193f70740386cb78b383e2e30c4f976cf3fa834bafbda4ed9dbfeb52ce1777817e8ed8868cfac6462b7cd31028aa5a7a60066db35371a2f8"
|
146
|
-
|
147
|
-
expected_serialized_prefix = "03"
|
148
|
-
expected_serialized_hash = "b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423"
|
149
|
-
expected_serialized_version = "00" # => u8
|
150
|
-
expected_serialized_entry_point = "1400000050734c7a3563374a73715438424b386c6c306b46"
|
151
|
-
expected_serialized_args = "3b0000003d0d7f193f70740386cb78b383e2e30c4f976cf3fa834bafbda4ed9dbfeb52ce1777817e8ed8868cfac6462b7cd31028aa5a7a60066db35371a2f8"
|
152
|
-
|
153
|
-
serialized_prefix = "03"
|
154
|
-
serialized_hash = StoredVersionedContractByHash[:hash]
|
155
|
-
serialized_version = byte_utils.to_u8(0)
|
156
|
-
serialized_entry_point = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredVersionedContractByHash[:entry_point])
|
157
|
-
serialized_length_of_args = byte_utils.to_u32(StoredVersionedContractByHash[:args].size/2)
|
158
|
-
serialized_args = serialized_length_of_args + StoredVersionedContractByHash[:args]
|
159
|
-
|
160
|
-
answer = serialized_prefix + serialized_hash + serialized_version + serialized_entry_point + serialized_args
|
161
|
-
p answer == expected_serialized
|
162
|
-
|
163
|
-
# ********************************************************************************************************
|
164
|
-
StoredVersionedContractByName = {
|
165
|
-
name: "lWJWKdZUEudSakJzw1tn",
|
166
|
-
version: "Some(1632552656)",
|
167
|
-
entry_point: "S1cXRT3E1jyFlWBAIVQ8",
|
168
|
-
args: "9975e6957ea6b07176c7d8471478fb28df9f02a61689ef58234b1a3cffaebf9f303e3ef60ae0d8"
|
169
|
-
}
|
170
|
-
expected_serialized = "04140000006c574a574b645a5545756453616b4a7a7731746e01d0c64e61140000005331635852543345316a79466c57424149565138270000009975e6957ea6b07176c7d8471478fb28df9f02a61689ef58234b1a3cffaebf9f303e3ef60ae0d8"
|
171
|
-
|
172
|
-
serialized_prefix = "04"
|
173
|
-
serialized_name = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredVersionedContractByName[:name])
|
174
|
-
serialized_version = "01d0c64e61"
|
175
|
-
serialized_entry_point = CLValueBytesParsers::CLStringBytesParser.to_bytes(StoredVersionedContractByName[:entry_point])
|
176
|
-
serialized_length_of_args = byte_utils.to_u32(StoredVersionedContractByName[:args].size/2)
|
177
|
-
serialized_args = serialized_length_of_args + StoredVersionedContractByName[:args]
|
178
|
-
|
179
|
-
answer = serialized_prefix + serialized_name + serialized_version + serialized_entry_point + serialized_args
|
180
|
-
p answer
|
181
|
-
p answer == expected_serialized
|
182
|
-
# ********************************************************************************************************
|
183
|
-
|
184
|
-
# Some(1632552656)
|
185
|
-
puts "01" + byte_utils.to_u32(1632552656)
|
186
|
-
# => 01d0c64e61
|
187
|
-
# None
|
188
|
-
puts "00"
|
189
|
-
puts byte_utils.to_u8(0)
|
190
|
-
# => "00"
|
191
|
-
puts CLValueBytesParsers::CLStringBytesParser.to_bytes("PsLz5c7JsqT8BK8ll0kF")
|
192
|
-
|
193
|
-
puts "byte_utils.to_u8(13): " + byte_utils.to_u8(13)
|
194
|
-
puts "byte_utils.to_i32(9): " + byte_utils.to_i32(9)
|
195
|
-
puts "byte_utils.to_i32(1000): " + byte_utils.to_i32(1000)
|
196
|
-
i32_hex_value = byte_utils.to_i32(1000)
|
197
|
-
# puts i32_hex_value
|
198
|
-
puts "byte_utils.hex_to_integer(i32_hex_value): " + byte_utils.hex_to_integer(i32_hex_value).to_s
|
199
|
-
|
200
|
-
puts "casper-test: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("casper-test")
|
201
|
-
puts "Hello World!: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("Hello World!")
|
202
|
-
puts "Hello, Casper!: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("Hello, Casper!")
|
203
|
-
|
204
|
-
|
205
|
-
end
|
206
|
-
describe CLValueSerializer do
|
207
|
-
let (:serializer) { CLValueSerializer.new }
|
208
|
-
|
209
|
-
it "Test serialize ModuleBytes " do
|
210
|
-
puts "payment: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("payment")
|
211
|
-
end
|
212
|
-
|
213
|
-
it "Test serialize storedContractByName " do
|
214
|
-
puts "quantity: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("quantity")
|
215
|
-
puts "casper-example: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("casper-example")
|
216
|
-
puts "example-entry-point: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("example-entry-point")
|
217
|
-
puts "PsLz5c7JsqT8BK8ll0kF: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("PsLz5c7JsqT8BK8ll0kF")
|
218
|
-
puts "pclphXwfYmCmdITj8hnh: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("pclphXwfYmCmdITj8hnh")
|
219
|
-
puts "lWJWKdZUEudSakJzw1tn: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("lWJWKdZUEudSakJzw1tn")
|
220
|
-
puts "S1cXRT3E1jyFlWBAIVQ8: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("S1cXRT3E1jyFlWBAIVQ8")
|
221
|
-
puts "CLi32.new(1000): " + serializer.to_bytes(CLi32.new(1000))
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
data/spec/string_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
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
|
-
|