test_sdk1 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,72 @@
|
|
1
|
+
require_relative '../lib/utils/byte_utils.rb'
|
2
|
+
|
3
|
+
|
4
|
+
RSpec.describe Utils::ByteUtils do
|
5
|
+
let(:byte_utils) { Utils::ByteUtils }
|
6
|
+
|
7
|
+
describe '.string_to_hex' do
|
8
|
+
it "convert string to hex" do
|
9
|
+
str = "abc"
|
10
|
+
expect(byte_utils.string_to_hex(str)).to eql("616263")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '.hex_to_string' do
|
15
|
+
it "convert hex to string" do
|
16
|
+
hex_str = "616263"
|
17
|
+
expect(byte_utils.hex_to_string(hex_str)).to eql( "abc")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.hex_to_byte_array' do
|
22
|
+
it "convert hex to byte_array" do
|
23
|
+
hex_str = "616263"
|
24
|
+
expect(byte_utils.hex_to_byte_array(hex_str)).to eql([97, 98, 99])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.byte_array_to_hex' do
|
29
|
+
it "convert byte_array to hex" do
|
30
|
+
str = "deposit"
|
31
|
+
str_hex = "6465706f736974"
|
32
|
+
bytes = [100, 101, 112, 111, 115, 105, 116]
|
33
|
+
expect(byte_utils.byte_array_to_hex(bytes)).to eql("6465706f736974")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
describe '.byte_array_to_string' do
|
37
|
+
it "convert byte_array to string" do
|
38
|
+
bytes = [100, 101, 112, 111, 115, 105, 116]
|
39
|
+
expected_str = "deposit"
|
40
|
+
expect(byte_utils.byte_array_to_string(bytes)).to eql(expected_str)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '.integer_to_hex' do
|
45
|
+
it "convert integer to hex value" do
|
46
|
+
n = 13
|
47
|
+
# Expected little endian hex
|
48
|
+
expected_hex = "0d000000"
|
49
|
+
expect(byte_utils.integer_to_hex(n)).to eql(expected_hex)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.hex_to_integer' do
|
54
|
+
it "convert hex to integer value" do
|
55
|
+
# Little endian hex
|
56
|
+
hex = "0d000000"
|
57
|
+
expected_value = 13
|
58
|
+
expect(byte_utils.hex_to_integer(hex)).to eql(expected_value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.hex_from_little_endian_to_big_endian' do
|
63
|
+
it "convert hex little endian to hex big endian format" do
|
64
|
+
# Little endian hex
|
65
|
+
hex = "0d000000"
|
66
|
+
# Big endian hex
|
67
|
+
expected_hex = "0000000d"
|
68
|
+
expect(byte_utils.hex_from_little_endian_to_big_endian(hex)).to eql(expected_hex)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1,169 @@
|
|
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
|