test_sdk1 1.0.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +478 -89
  3. data/lib/crypto/asymmetric_key.rb +19 -18
  4. data/lib/crypto/ed25519_key.rb +99 -10
  5. data/lib/crypto/keys.rb +1 -2
  6. data/lib/crypto/keys_util.rb +20 -0
  7. data/lib/entity/auction_state.rb +56 -8
  8. data/lib/entity/bid.rb +1 -1
  9. data/lib/entity/bid_info.rb +1 -1
  10. data/lib/entity/block.rb +39 -0
  11. data/lib/entity/block_body.rb +35 -0
  12. data/lib/entity/block_header.rb +81 -0
  13. data/lib/entity/block_info.rb +56 -0
  14. data/lib/entity/block_proof.rb +24 -0
  15. data/lib/entity/deploy.rb +154 -1
  16. data/lib/entity/deploy_executable.rb +108 -6
  17. data/lib/entity/deploy_executable_item_internal.rb +1 -1
  18. data/lib/entity/deploy_header.rb +17 -0
  19. data/lib/entity/deploy_named_argument.rb +69 -2
  20. data/lib/entity/era_summary.rb +13 -12
  21. data/lib/entity/module_bytes.rb +16 -2
  22. data/lib/entity/status.rb +80 -0
  23. data/lib/entity/stored_value.rb +86 -11
  24. data/lib/entity/transfer.rb +7 -7
  25. data/lib/include.rb +2 -0
  26. data/lib/serialization/cl_value_serializer.rb +69 -12
  27. data/lib/serialization/cl_value_serializer1.rb +314 -0
  28. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  29. data/lib/serialization/deploy_header_serializer.rb +1 -0
  30. data/lib/serialization/deploy_named_arg_serializer.rb +1 -0
  31. data/lib/serialization/deploy_serializer.rb +144 -10
  32. data/lib/serialization/deploy_serializer1.rb +392 -0
  33. data/lib/serialization/deploy_serializer_update.rb +397 -0
  34. data/lib/serialization/test.rb +33 -13
  35. data/lib/test_sdk1.rb +29 -10
  36. data/lib/types/cl_option.rb +8 -2
  37. data/lib/types/cl_public_key.rb +2 -0
  38. data/lib/types/cl_value.rb +8 -0
  39. data/lib/utils/byte_utils.rb +28 -0
  40. data/lib/utils/helpers.rb +10 -0
  41. data/lib/version.rb +1 -1
  42. data/spec/cl_value_serializer_spec.rb +16 -1
  43. data/spec/dene_spec.rb +186 -0
  44. data/spec/deploy_executable_spec.rb +90 -0
  45. data/spec/deploy_executable_test_spec.rb +117 -0
  46. data/spec/deploy_serializer_spec.rb +5 -3
  47. data/spec/deploy_serializer_test_spec.rb +7 -1
  48. data/spec/testnet_spec.rb +3 -1
  49. data/spec/time_utils_spec.rb +3 -0
  50. metadata +20 -5
  51. data/lib/crypto/key_pair.rb +0 -40
  52. data/spec/deploy_executable_serializer_spec.rb +0 -0
@@ -0,0 +1,10 @@
1
+ module Utils
2
+ module Helpers
3
+ extend self
4
+ def construct_inner_clvalue(cl_type, value)
5
+ if cl_type == "U64"
6
+ CLu64.new(value)
7
+ end
8
+ end
9
+ end
10
+ end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CasperNetworkSDK
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.4'
3
3
  end
@@ -69,6 +69,16 @@ describe CLValueSerializer do
69
69
  end
70
70
  end
71
71
 
72
+ describe "CLu512 Value Serializer" do
73
+ let(:u512_1) { CLu512.new(1000000000)}
74
+ let(:u512_2) { CLu512.new(23000000000)}
75
+
76
+ it "should serialize CLu512 values" do
77
+ puts serializer.to_bytes(u512_1)
78
+ puts serializer.to_bytes(u512_2)
79
+ end
80
+ end
81
+
72
82
  describe "CLString Value Serializer" do
73
83
  let (:str1) { CLString.new("Hello, Casper!") }
74
84
  it "should serialize CLString values" do
@@ -133,8 +143,13 @@ describe CLValueSerializer do
133
143
  describe "CLUnit Value Serializer" do
134
144
  let(:unit) {CLUnit.new()}
135
145
  it "should serialize CLUnit values" do
136
- puts serializer.to_bytes(unit)
146
+ # puts serializer.to_bytes(unit)
137
147
  expect(serializer.to_bytes(unit)).to eql("0000000009")
148
+ serializer = CLValueSerializer.new
149
+ clvalue = CLOption.new(CLi32.new(-10))
150
+ puts serializer.to_bytes(clvalue)
138
151
  end
139
152
  end
153
+
154
+
140
155
  end
data/spec/dene_spec.rb ADDED
@@ -0,0 +1,186 @@
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_public_key.rb'
15
+ require_relative '../lib/types/constants.rb'
16
+ require_relative '../lib/serialization/cl_value_bytes_parsers.rb'
17
+ require_relative '../lib/serialization/cl_value_serializer.rb'
18
+ require_relative '../lib/entity/deploy_executable.rb'
19
+ require_relative '../lib/entity/stored_contract_by_hash.rb'
20
+ require_relative '../lib/entity/stored_contract_by_name.rb'
21
+ require_relative '../lib/entity/stored_versioned_contract_by_hash.rb'
22
+ require_relative '../lib/entity/stored_versioned_contract_by_name.rb'
23
+ require_relative '../lib/entity/deploy_executable_transfer.rb'
24
+ require_relative '../lib/entity/deploy.rb'
25
+ require_relative '../lib/entity/deploy_hash.rb'
26
+ require_relative '../lib/serialization/deploy_serializer.rb'
27
+ require 'json'
28
+
29
+ RSpec.describe CLValueSerializer do
30
+ it "***************** TEST *************************" do
31
+ serializer = CLValueSerializer.new
32
+
33
+ clvalue = CLString.new("Hello, World!")
34
+ puts "#{clvalue.to_bytes(clvalue.get_value)}"
35
+ puts CLString.to_bytes(clvalue)
36
+ puts CLValueBytesParsers::CLStringBytesParser.to_bytes(clvalue.get_value)
37
+ # puts "#{CLValueBytesParsers::CLStringBytesParser.from_bytes("0e0000006361737065722d6578616d706c65")}: 0e0000006361737065722d6578616d706c65"
38
+ expect(CLString.to_bytes(clvalue)).to eql("0d00000048656c6c6f2c20576f726c6421")
39
+ expect(CLValueBytesParsers::CLStringBytesParser.to_bytes(clvalue.get_value)).to eql("0d00000048656c6c6f2c20576f726c6421")
40
+ expect(clvalue.to_bytes(clvalue.get_value)).to eql("0d00000048656c6c6f2c20576f726c6421")
41
+
42
+ # clvalue = CLu32.new(1024)
43
+ puts serializer.to_bytes(clvalue)
44
+ MIN_U32 = 0
45
+ MAX_U32 = 2.pow(32) - 1
46
+ clvalue = CLu32.new(1024)
47
+ puts serializer.to_bytes(clvalue)
48
+ clvalue = CLu32.new(MIN_U32)
49
+ puts serializer.to_bytes(clvalue)
50
+ clvalue = CLu32.new(MAX_U32)
51
+ puts serializer.to_bytes(clvalue)
52
+
53
+ puts serializer.to_bytes(CLOption.new(CLu32.new(MIN_U32)))
54
+ # => "0500000001000000000d04"
55
+
56
+
57
+ # Important!!!!!!! Need a Fix
58
+ clvalue = CLu512.new(123456789101112131415)
59
+ puts serializer.to_bytes(clvalue)
60
+
61
+ clvalue = CLu512.new(2500000000)
62
+ puts serializer.to_bytes(clvalue)
63
+ # => "050000000400f9029508"
64
+
65
+
66
+ clvalue = CLTuple2.new([CLu32.new(127), CLString.new("ABCDE")])
67
+ puts serializer.to_bytes(clvalue)
68
+ # => 0d0000007f00000005000000414243444513040a
69
+
70
+ # Important!!!!!!! Need a Fix
71
+ clvalue = CLOption.new(CLTuple2.new([CLu32.new(127), CLString.new("ABCDE")]))
72
+ puts serializer.to_bytes(clvalue)
73
+
74
+ # ModuleBytes
75
+ args = []
76
+ arg1 = Casper::Entity::DeployNamedArgument.new("amount", CLu512.new(2500000000))
77
+ args << [arg1]
78
+ module_bytes = Casper::Entity::ModuleBytes.new("", args)
79
+ puts Utils::ByteUtils.byte_array_to_hex(module_bytes.to_bytes)
80
+ expect(Utils::ByteUtils.byte_array_to_hex(module_bytes.to_bytes)).to eql("00000000000100000006000000616d6f756e74050000000400f9029508")
81
+
82
+ args = []
83
+
84
+ # StoredContractByHash
85
+ arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
86
+ args << [arg1]
87
+ stored_contract_by_hash = Casper::Entity::StoredContractByHash.new("c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa4", "pclphXwfYmCmdITj8hnh", args)
88
+ # puts Utils::ByteUtils.byte_array_to_hex(stored_contract_by_hash.to_bytes)
89
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_contract_by_hash.to_bytes)).to eql("01c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa41400000070636c7068587766596d436d6449546a38686e6801000000080000007175616e7469747904000000e803000001")
90
+
91
+ args = []
92
+
93
+ # StoredContractByName
94
+ arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
95
+ args << [arg1]
96
+ stored_contract_by_name = Casper::Entity::StoredContractByName.new("casper-example", "example-entry-point", args)
97
+ puts Utils::ByteUtils.byte_array_to_hex(stored_contract_by_name.to_bytes)
98
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_contract_by_name.to_bytes)).to eql("020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001")
99
+
100
+ args = []
101
+
102
+ # StoredVersionedContractByHash
103
+ arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
104
+ args << [arg1]
105
+ stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByHash.new("b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423", nil, "PsLz5c7JsqT8BK8ll0kF", args)
106
+ puts Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_hash.to_bytes)
107
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_hash.to_bytes)).to eql("03b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423001400000050734c7a3563374a73715438424b386c6c306b46010000000400000074657374110000000d00000048656c6c6f2c20576f726c64210a")
108
+
109
+ args = []
110
+
111
+ # StoredVersionedContractByName
112
+ arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
113
+ args << [arg1]
114
+ stored_versioned_contract_by_name = Casper::Entity::StoredVersionedContractByName.new("test-contract", nil, "PsLz5c7JsqT8BK8ll0kF", args)
115
+ puts Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_name.to_bytes)
116
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_name.to_bytes)).to eql("040d000000746573742d636f6e7472616374001400000050734c7a3563374a73715438424b386c6c306b46010000000400000074657374110000000d00000048656c6c6f2c20576f726c64210a")
117
+
118
+
119
+ # DeployExecutableTransfer
120
+ args = []
121
+ arg1 = Casper::Entity::DeployNamedArgument.new("amount", CLi32.new(1000))
122
+ args << [arg1]
123
+ transfer = Casper::Entity::DeployExecutableTransfer.new(args)
124
+ puts Utils::ByteUtils.byte_array_to_hex(transfer.to_bytes)
125
+ expect(Utils::ByteUtils.byte_array_to_hex(transfer.to_bytes)).to eql("050100000006000000616d6f756e7404000000e803000001")
126
+
127
+ # Serialization of Deploy objects
128
+ serializer = DeploySerializer.new
129
+ serialized_deploy = "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900ca856a4d37501000080ee36000000000001000000000000004811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f0100000001010101010101010101010101010101010101010101010101010101010101010e0000006361737065722d6578616d706c6501da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001050100000006000000616d6f756e7404000000e8030000010100000001d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
130
+ json_deploy = '{
131
+ "hash": "01da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187",
132
+ "header": {
133
+ "account": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
134
+ "timestamp": "2020-11-17T00:39:24.072Z",
135
+ "ttl": "1h",
136
+ "gas_price": 1,
137
+ "body_hash": "4811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f",
138
+ "dependencies": [
139
+ "0101010101010101010101010101010101010101010101010101010101010101"
140
+ ],
141
+ "chain_name": "casper-example"
142
+ },
143
+ "payment": {
144
+ "StoredContractByName": {
145
+ "name": "casper-example",
146
+ "entry_point": "example-entry-point",
147
+ "args": [
148
+ [
149
+ "quantity",
150
+ {
151
+ "cl_type": "I32",
152
+ "bytes": "e8030000",
153
+ "parsed": 1000
154
+ }
155
+ ]
156
+ ]
157
+ }
158
+ },
159
+ "session": {
160
+ "Transfer": {
161
+ "args": [
162
+ [
163
+ "amount",
164
+ {
165
+ "cl_type": "I32",
166
+ "bytes": "e8030000",
167
+ "parsed": 1000
168
+ }
169
+ ]
170
+ ]
171
+ }
172
+ },
173
+ "approvals": [
174
+ {
175
+ "signer": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
176
+ "signature": "012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
177
+ }
178
+ ]
179
+ }'
180
+ h_deploy = JSON.parse(json_deploy)
181
+ h_deploy.deep_symbolize_keys!
182
+ deploy = Casper::Entity::Deploy.new(h_deploy[:hash], h_deploy[:header], h_deploy[:payment], h_deploy[:session], h_deploy[:approvals])
183
+ puts Utils::ByteUtils.byte_array_to_hex(serializer.to_bytes(deploy))
184
+ expect(Utils::ByteUtils.byte_array_to_hex(serializer.to_bytes(deploy))).to eql(serialized_deploy)
185
+ end
186
+ end
@@ -0,0 +1,90 @@
1
+ require_relative '../lib/entity/deploy_named_argument.rb'
2
+ require_relative '../lib/serialization/deploy_named_arg_serializer.rb'
3
+ require_relative '../lib/entity/deploy_executable_item_internal.rb'
4
+ require_relative '../lib/entity/deploy_executable.rb'
5
+ require_relative '../lib/entity/stored_contract_by_hash.rb'
6
+ require_relative '../lib/entity/stored_contract_by_name.rb'
7
+ require_relative '../lib/entity/stored_versioned_contract_by_hash.rb'
8
+ require_relative '../lib/entity/stored_versioned_contract_by_name.rb'
9
+ require_relative '../lib/serialization/deploy_executable_serializer.rb'
10
+ require_relative '../lib/entity/deploy.rb'
11
+ require_relative '../lib/entity/deploy_hash.rb'
12
+ require_relative '../lib/entity/deploy_header.rb'
13
+ require_relative '../lib/entity/deploy_approval.rb'
14
+ require_relative '../lib/entity/deploy_info.rb'
15
+ require_relative '../lib/entity/deploy.rb'
16
+ require_relative '../lib/serialization/deploy_serializer.rb'
17
+
18
+
19
+ RSpec.describe Casper::Entity::DeployExecutable do
20
+ # describe Casper::Entity::DeployExecutable do
21
+ let(:args) {[]}
22
+
23
+
24
+ # ModuleBytes
25
+ describe Casper::Entity::ModuleBytes do
26
+ it "ModuleBytes serialization" do
27
+ args = []
28
+ arg1 = Casper::Entity::DeployNamedArgument.new("amount", CLu512.new(2500000000))
29
+ args << [arg1]
30
+ module_bytes = Casper::Entity::ModuleBytes.new("", args)
31
+ # puts Utils::ByteUtils.byte_array_to_hex(module_bytes.to_bytes)
32
+ expect(Utils::ByteUtils.byte_array_to_hex(module_bytes.to_bytes)).to eql("00000000000100000006000000616d6f756e74050000000400f9029508")
33
+ end
34
+ end
35
+
36
+ # StoredContractByHash
37
+ describe Casper::Entity::StoredContractByHash do
38
+ it "StoredContractByHash serialization" do
39
+ arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
40
+ args << [arg1]
41
+ stored_contract_by_hash = Casper::Entity::StoredContractByHash.new("c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa4", "pclphXwfYmCmdITj8hnh", args)
42
+ # puts Utils::ByteUtils.byte_array_to_hex(stored_contract_by_hash.to_bytes)
43
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_contract_by_hash.to_bytes)).to eql("01c4c411864f7b717c27839e56f6f1ebe5da3f35ec0043f437324325d65a22afa41400000070636c7068587766596d436d6449546a38686e6801000000080000007175616e7469747904000000e803000001")
44
+ end
45
+ end
46
+
47
+ # StoredContractByName
48
+ describe Casper::Entity::StoredContractByName do
49
+ it "StoredContractByName serialization" do
50
+ arg1 = Casper::Entity::DeployNamedArgument.new("quantity", CLi32.new(1000))
51
+ args << [arg1]
52
+ stored_contract_by_name = Casper::Entity::StoredContractByName.new("casper-example", "example-entry-point", args)
53
+ # puts Utils::ByteUtils.byte_array_to_hex(stored_contract_by_name.to_bytes)
54
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_contract_by_name.to_bytes)).to eql("020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001")
55
+ end
56
+ end
57
+
58
+ # StoredVersionedContractByHash
59
+ describe Casper::Entity::StoredVersionedContractByHash do
60
+ it "StoredVersionedContractByHash serialization" do
61
+ arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
62
+ args << [arg1]
63
+ stored_versioned_contract_by_hash = Casper::Entity::StoredVersionedContractByHash.new("b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423", nil, "PsLz5c7JsqT8BK8ll0kF", args)
64
+ # puts Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_hash.to_bytes)
65
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_hash.to_bytes)).to eql("03b348fdd0d0b3f66468687df93141b5924f6bb957d5893c08b60d5a78d0b9a423001400000050734c7a3563374a73715438424b386c6c306b46010000000400000074657374110000000d00000048656c6c6f2c20576f726c64210a")
66
+ end
67
+ end
68
+
69
+ # StoredVersionedContractByName
70
+ describe Casper::Entity::StoredVersionedContractByName do
71
+ it "StoredVersionedContractByName serialization" do
72
+ arg1 = Casper::Entity::DeployNamedArgument.new("test", CLString.new("Hello, World!"))
73
+ args << [arg1]
74
+ stored_versioned_contract_by_name = Casper::Entity::StoredVersionedContractByName.new("test-contract", nil, "PsLz5c7JsqT8BK8ll0kF", args)
75
+ # puts Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_name.to_bytes)
76
+ expect(Utils::ByteUtils.byte_array_to_hex(stored_versioned_contract_by_name.to_bytes)).to eql("040d000000746573742d636f6e7472616374001400000050734c7a3563374a73715438424b386c6c306b46010000000400000074657374110000000d00000048656c6c6f2c20576f726c64210a")
77
+ end
78
+ end
79
+
80
+ # DeployExecutableTransfer
81
+ describe Casper::Entity::DeployExecutableTransfer do
82
+ it "DeployExecutableTransfer serialization" do
83
+ arg1 = Casper::Entity::DeployNamedArgument.new("amount", CLi32.new(1000))
84
+ args << [arg1]
85
+ transfer = Casper::Entity::DeployExecutableTransfer.new(args)
86
+ # puts Utils::ByteUtils.byte_array_to_hex(transfer.to_bytes)
87
+ expect(Utils::ByteUtils.byte_array_to_hex(transfer.to_bytes)).to eql("050100000006000000616d6f756e7404000000e803000001")
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,117 @@
1
+ require_relative '../lib/entity/deploy_named_argument.rb'
2
+ require_relative '../lib/serialization/deploy_named_arg_serializer.rb'
3
+ require_relative '../lib/entity/deploy_executable_item_internal.rb'
4
+ require_relative '../lib/entity/deploy_executable.rb'
5
+ require_relative '../lib/entity/stored_contract_by_hash.rb'
6
+ require_relative '../lib/entity/stored_contract_by_name.rb'
7
+ require_relative '../lib/entity/stored_versioned_contract_by_hash.rb'
8
+ require_relative '../lib/entity/stored_versioned_contract_by_name.rb'
9
+ require_relative '../lib/serialization/deploy_executable_serializer.rb'
10
+ require_relative '../lib/entity/deploy.rb'
11
+ require_relative '../lib/entity/deploy_hash.rb'
12
+ require_relative '../lib/entity/deploy_header.rb'
13
+ require_relative '../lib/entity/deploy_approval.rb'
14
+ require_relative '../lib/entity/deploy_info.rb'
15
+ require_relative '../lib/entity/deploy.rb'
16
+ require_relative '../lib/serialization/deploy_serializer.rb'
17
+
18
+
19
+ RSpec.describe Casper::Entity::DeployExecutable do
20
+ h1 = {
21
+ "hash": "3755a8f1734923b1eb57c71d012d01973d1c85858eb0e0eb56f0f30c591a9bd6",
22
+ "header": {
23
+ "ttl": "30m",
24
+ "account": "01ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1",
25
+ "body_hash": "42751eb696c9ed4d11715f03fe8e053065ce671991d808b6870e2a1e49fe356c",
26
+ "gas_price": 1,
27
+ "timestamp": "2022-10-11T22:50:00.000Z",
28
+ "chain_name": "casper-test",
29
+ "dependencies": []
30
+ },
31
+ "payment": {
32
+ "ModuleBytes": {
33
+ "args": [
34
+ [
35
+ "amount",
36
+ {
37
+ "bytes": "0400f90295",
38
+ "parsed": "2500000000",
39
+ "cl_type": "U512"
40
+ }
41
+ ]
42
+ ],
43
+ "module_bytes": ""
44
+ }
45
+ },
46
+ "session": {
47
+ "Transfer": {
48
+ "args": [
49
+ [
50
+ "amount",
51
+ {
52
+ "bytes": "0400f90295",
53
+ "parsed": "2500000000",
54
+ "cl_type": "U512"
55
+ }
56
+ ],
57
+ [
58
+ "target",
59
+ {
60
+ "bytes": "01fe58ff1043c90607cfcb5f99e33900e8bfab5f3b18c44078eef9c82dab9126f3",
61
+ "parsed": "01fe58ff1043c90607cfcb5f99e33900e8bfab5f3b18c44078eef9c82dab9126f3",
62
+ "cl_type": "PublicKey"
63
+ }
64
+ ],
65
+ [
66
+ "id",
67
+ {
68
+ "bytes": "010100000000000000",
69
+ "parsed": 1,
70
+ "cl_type": {
71
+ "Option": "U64"
72
+ }
73
+ }
74
+ ]
75
+ ]
76
+ }
77
+ },
78
+ "approvals": [
79
+ {
80
+ "signer": "01ccee19366eaf03487cb81197ae8edcb1b47f214cee00d6597380096b9f8463c1",
81
+ "signature": "013945ac2e025344509c1241ca1aa724b95d0830ab15b24ffdafd6b4ebb833456eb72ae6a33af2c87bafec14dafc07373b4aa6d5cbe4152e0d792095fce951870f"
82
+ }
83
+ ]
84
+ }
85
+
86
+ let(:hash) {Casper::Entity::DeployHash.new(h1[:hash])}
87
+ let(:header) {Casper::Entity::DeployHeader.new(h1[:header])}
88
+ let(:session) {h1[:session]}
89
+ let(:payment) {h1[:payment]}
90
+
91
+ it "Serialize Deploy Executable" do
92
+ deploy = Casper::Entity::Deploy.new(h1[:hash], h1[:header], h1[:payment], h1[:session], h1[:approvals])
93
+
94
+ # deploy_serializer = DeploySerializer.new
95
+
96
+ # deploy_serialized_to_bytes = deploy_serializer.to_bytes(deploy)
97
+
98
+
99
+ deploy_executable = Casper::Entity::DeployExecutable.new(payment)
100
+ # puts deploy_executable.module_bytes.get_module_bytes
101
+ # puts deploy_executable.module_bytes.get_args
102
+ puts deploy_executable.get_module_bytes
103
+ puts deploy_executable.to_bytes
104
+
105
+ puts "Session is called...."
106
+ executable_transfer = Casper::Entity::DeployExecutable.new(session)
107
+ puts executable_transfer
108
+ puts executable_transfer.transfer?
109
+ transfer = executable_transfer.transfer
110
+ puts transfer
111
+ # puts transfer.get_args[0][0].get_name
112
+ # puts transfer.get_args[0][0].get_value
113
+ puts transfer.to_bytes
114
+ # puts transfer.to_bytes
115
+ end
116
+
117
+ end
@@ -20,7 +20,7 @@ describe DeploySerializer do
20
20
  let(:serializer) { DeploySerializer.new }
21
21
  it "should serialize Deploy" do
22
22
  serialized_deploy = "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900ca856a4d37501000080ee36000000000001000000000000004811966d37fe5674a8af4001884ea0d9042d1c06668da0c963769c3a01ebd08f0100000001010101010101010101010101010101010101010101010101010101010101010e0000006361737065722d6578616d706c6501da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001050100000006000000616d6f756e7404000000e8030000010100000001d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
23
- json_deploy = {
23
+ json_deploy = '{
24
24
  "hash": "01da3c604f71e0e7df83ff1ab4ef15bb04de64ca02e3d2b78de6950e8b5ee187",
25
25
  "header": {
26
26
  "account": "01d9bf2148748a85c89da5aad8ee0b0fc2d105fd39d41a4c796536354f0ae2900c",
@@ -69,8 +69,10 @@ describe DeploySerializer do
69
69
  "signature": "012dbf03817a51794a8e19e0724884075e6d1fbec326b766ecfa6658b41f81290da85e23b24e88b1c8d9761185c961daee1adab0649912a6477bcd2e69bd91bd08"
70
70
  }
71
71
  ]
72
- }
73
- deploy = Casper::Entity::Deploy.new(json_deploy[:hash], json_deploy[:header], json_deploy[:payment], json_deploy[:session], json_deploy[:approvals])
72
+ }'
73
+ h_deploy = JSON.parse(json_deploy)
74
+ h_deploy.deep_symbolize_keys!
75
+ deploy = Casper::Entity::Deploy.new(h_deploy[:hash], h_deploy[:header], h_deploy[:payment], h_deploy[:session], h_deploy[:approvals])
74
76
  # puts Utils::ByteUtils.hex_to_byte_array(serializer.to_bytes(deploy))
75
77
  expect(Utils::ByteUtils.byte_array_to_hex(serializer.to_bytes(deploy))).to eql(serialized_deploy)
76
78
  end
@@ -12,12 +12,15 @@ RSpec.describe Utils::TimeUtils do
12
12
 
13
13
  it "should serialize Deploy" do
14
14
  ms = time_utils.to_epoc_ms("2020-11-17T00:39:24.072Z")
15
+ puts ms
15
16
  timestamp_serialized = byte_utils.to_u64(ms)
16
17
  puts "timestamp_serialized: #{timestamp_serialized}"
17
18
 
18
19
  ttl_serialized = byte_utils.to_u64(3600000)
19
20
  # ttl_serialized = byte_utils.to_u64(1603994401469)
20
- puts "ttl_serialized: #{ttl_serialized}"
21
+ puts "ttl_serialized 3600000: #{ttl_serialized}"
22
+ ttl_serialized = byte_utils.to_u64(1603994401469)
23
+ puts "ttl_serialized 1603994401469: #{ttl_serialized}"
21
24
 
22
25
  gas_price_serialized = byte_utils.to_u64(1)
23
26
  puts "gas_price_serialized: #{gas_price_serialized}"
@@ -219,7 +222,10 @@ RSpec.describe Utils::TimeUtils do
219
222
  puts "lWJWKdZUEudSakJzw1tn: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("lWJWKdZUEudSakJzw1tn")
220
223
  puts "S1cXRT3E1jyFlWBAIVQ8: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("S1cXRT3E1jyFlWBAIVQ8")
221
224
  puts "CLi32.new(1000): " + serializer.to_bytes(CLi32.new(1000))
225
+ puts "target: " + CLValueBytesParsers::CLStringBytesParser.to_bytes("target")
222
226
  end
223
227
  end
228
+
229
+
224
230
  end
225
231
 
data/spec/testnet_spec.rb CHANGED
@@ -6,7 +6,9 @@ require './lib/rpc/rpc_client.rb'
6
6
  # Ip Address taken from Testnet
7
7
  # client = Casper::RpcClient.new("65.21.227.101") # IP is taken from "TestNet"
8
8
  # client = Casper::RpcClient.new("138.201.54.44") # IP is taken from "TestNet"
9
- client = Casper::RpcClient.new("5.9.23.55") # IP is taken from "TestNet"
9
+ # client = Casper::RpcClient.new("5.9.23.55") # IP is taken from "TestNet"
10
+ client = Casper::RpcClient.new("65.21.235.219") # IP is taken from "TestNet"
11
+
10
12
 
11
13
  # block_Hash taken from Testnet
12
14
  block_hash = "71e19e2e9629c716dc9578066cfeceace559d32fe51b08245ddd4d218f8c18da"
@@ -11,6 +11,8 @@ RSpec.describe Utils::TimeUtils do
11
11
  end
12
12
 
13
13
  it "should convert iso datetime to ms from unix epoch" do
14
+ timestamp = "2022-10-11T21:30:00.000Z"
15
+ puts "timestamp value: #{time_utils.to_epoc_ms(timestamp)}"
14
16
  date = "2020-11-17T00:39:24.072Z"
15
17
  expect(time_utils.to_epoc_ms(date)).to eql(1605573564072)
16
18
  end
@@ -18,6 +20,7 @@ RSpec.describe Utils::TimeUtils do
18
20
  it "should convert miliseconds to iso datetime" do
19
21
  date = "2020-11-17T00:39:24.072Z"
20
22
  milliseconds = 1605573564072
23
+ # puts time_utils.to_iso_string(1640908800555) == "2021-12-31T00:00:00.555Z"
21
24
  expect(time_utils.to_iso_string(milliseconds)).to eql("2020-11-17T00:39:24.072Z")
22
25
  end
23
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_sdk1
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Sait Gülmez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem enables developers to interact with the Casper Network.
14
14
  email: cenggulmez.65@gmail.com
@@ -24,8 +24,8 @@ files:
24
24
  - lib/crypto/01_ed25519.rb
25
25
  - lib/crypto/asymmetric_key.rb
26
26
  - lib/crypto/ed25519_key.rb
27
- - lib/crypto/key_pair.rb
28
27
  - lib/crypto/keys.rb
28
+ - lib/crypto/keys_util.rb
29
29
  - lib/crypto/secp256k1_key.rb
30
30
  - lib/crypto/test_ed25519_key.rb
31
31
  - lib/entity/account.rb
@@ -34,6 +34,11 @@ files:
34
34
  - lib/entity/auction_state.rb
35
35
  - lib/entity/bid.rb
36
36
  - lib/entity/bid_info.rb
37
+ - lib/entity/block.rb
38
+ - lib/entity/block_body.rb
39
+ - lib/entity/block_header.rb
40
+ - lib/entity/block_info.rb
41
+ - lib/entity/block_proof.rb
37
42
  - lib/entity/contract.rb
38
43
  - lib/entity/contract_package.rb
39
44
  - lib/entity/contract_version.rb
@@ -57,6 +62,7 @@ files:
57
62
  - lib/entity/module_bytes.rb
58
63
  - lib/entity/peer.rb
59
64
  - lib/entity/seigniorage_allocation.rb
65
+ - lib/entity/status.rb
60
66
  - lib/entity/stored_contract_by_hash.rb
61
67
  - lib/entity/stored_contract_by_name.rb
62
68
  - lib/entity/stored_value.rb
@@ -72,11 +78,15 @@ files:
72
78
  - lib/serialization/cl_type_serializer.rb
73
79
  - lib/serialization/cl_value_bytes_parsers.rb
74
80
  - lib/serialization/cl_value_serializer.rb
81
+ - lib/serialization/cl_value_serializer1.rb
82
+ - lib/serialization/cl_value_serializer_update.rb
75
83
  - lib/serialization/deploy_approval_serializer.rb
76
84
  - lib/serialization/deploy_executable_serializer.rb
77
85
  - lib/serialization/deploy_header_serializer.rb
78
86
  - lib/serialization/deploy_named_arg_serializer.rb
79
87
  - lib/serialization/deploy_serializer.rb
88
+ - lib/serialization/deploy_serializer1.rb
89
+ - lib/serialization/deploy_serializer_update.rb
80
90
  - lib/serialization/test.rb
81
91
  - lib/test_sdk1.rb
82
92
  - lib/types/cl_account_hash.rb
@@ -132,6 +142,7 @@ files:
132
142
  - lib/utils/byte_utils.rb
133
143
  - lib/utils/find_byte_parser_by_cl_type.rb
134
144
  - lib/utils/hash_utils.rb
145
+ - lib/utils/helpers.rb
135
146
  - lib/utils/hex_utils.rb
136
147
  - lib/utils/time_utils.rb
137
148
  - lib/utils/utils.rb
@@ -143,8 +154,10 @@ files:
143
154
  - spec/cl_value_serializer_spec.rb
144
155
  - spec/client_spec.rb
145
156
  - spec/crypto_spec.rb
157
+ - spec/dene_spec.rb
146
158
  - spec/deploy_approval_serializer_spec.rb
147
- - spec/deploy_executable_serializer_spec.rb
159
+ - spec/deploy_executable_spec.rb
160
+ - spec/deploy_executable_test_spec.rb
148
161
  - spec/deploy_header_serializer_spec.rb
149
162
  - spec/deploy_named_arg_serializer_spec.rb
150
163
  - spec/deploy_serializer_spec.rb
@@ -185,8 +198,10 @@ test_files:
185
198
  - spec/cl_value_serializer_spec.rb
186
199
  - spec/client_spec.rb
187
200
  - spec/crypto_spec.rb
201
+ - spec/dene_spec.rb
188
202
  - spec/deploy_approval_serializer_spec.rb
189
- - spec/deploy_executable_serializer_spec.rb
203
+ - spec/deploy_executable_spec.rb
204
+ - spec/deploy_executable_test_spec.rb
190
205
  - spec/deploy_header_serializer_spec.rb
191
206
  - spec/deploy_named_arg_serializer_spec.rb
192
207
  - spec/deploy_serializer_spec.rb
@@ -1,40 +0,0 @@
1
- require 'ed25519'
2
-
3
-
4
- signing_key = Ed25519::SigningKey.generate
5
- puts "signing_key:\t #{signing_key}"
6
-
7
- message = "hello"
8
- signature = signing_key.sign(message)
9
- puts "signature:\t #{signature}"
10
-
11
- verify_key = signing_key.verify_key
12
- puts "verify_key:\t #{verify_key}"
13
-
14
- check_validity_of_signature = verify_key.verify(signature, message)
15
- puts "check_validity_of_signature:\t #{check_validity_of_signature}"
16
-
17
- # Serializing Keys
18
- signature_key_bytes = signing_key.to_bytes
19
- puts "signature_key_bytes:\t #{signature_key_bytes}"
20
- verify_key_bytes = verify_key.to_bytes
21
- puts "verify_key_bytes:\t #{verify_key_bytes}"
22
-
23
- signing_key = Ed25519::SigningKey.new(signature_key_bytes)
24
- puts "signing_key:\t #{signing_key}"
25
- verify_key = Ed25519::VerifyKey.new(verify_key_bytes)
26
- puts "verify_key:\t #{verify_key}"
27
-
28
-
29
- require "ssh_data"
30
-
31
- # key_data = File.read("/home/mehmet/Desktop/casper-ruby-sdk/lib/crypto/id_ed25519")
32
- # key = SSHData::PrivateKey.parse_openssh(key_data)
33
- #=> <SSHData::PrivateKey::ED25519>
34
-
35
- # SSHData::PrivateKey::ED25519.generate
36
- #=> raises SSHData::AlgorithmError
37
-
38
-
39
- # SSHData::PrivateKey::ED25519.generate
40
- #=> <SSHData::PrivateKey::ED25519>
File without changes