test_sdk1 1.0.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +495 -76
  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/group.rb +1 -1
  22. data/lib/entity/module_bytes.rb +16 -2
  23. data/lib/entity/status.rb +80 -0
  24. data/lib/entity/stored_contract_by_name.rb +2 -1
  25. data/lib/entity/stored_value.rb +86 -11
  26. data/lib/entity/stored_versioned_contract_by_hash.rb +2 -1
  27. data/lib/entity/stored_versioned_contract_by_name.rb +1 -1
  28. data/lib/entity/transfer.rb +7 -7
  29. data/lib/include.rb +2 -0
  30. data/lib/rpc/rpc_client.rb +1 -2
  31. data/lib/serialization/cl_type_serializer.rb +1 -0
  32. data/lib/serialization/cl_value_serializer.rb +70 -12
  33. data/lib/serialization/cl_value_serializer1.rb +314 -0
  34. data/lib/serialization/cl_value_serializer_update.rb +320 -0
  35. data/lib/serialization/deploy_approval_serializer.rb +1 -0
  36. data/lib/serialization/deploy_executable_serializer.rb +1 -1
  37. data/lib/serialization/deploy_header_serializer.rb +2 -1
  38. data/lib/serialization/deploy_named_arg_serializer.rb +2 -0
  39. data/lib/serialization/deploy_serializer.rb +145 -10
  40. data/lib/serialization/deploy_serializer1.rb +392 -0
  41. data/lib/serialization/deploy_serializer_update.rb +397 -0
  42. data/lib/serialization/test.rb +33 -13
  43. data/lib/test_sdk1.rb +30 -13
  44. data/lib/types/cl_option.rb +8 -2
  45. data/lib/types/cl_public_key.rb +2 -0
  46. data/lib/types/cl_type.rb +1 -0
  47. data/lib/types/cl_value.rb +8 -0
  48. data/lib/utils/byte_utils.rb +28 -0
  49. data/lib/utils/helpers.rb +10 -0
  50. data/lib/version.rb +1 -1
  51. data/spec/cl_value_serializer_spec.rb +16 -1
  52. data/spec/client_spec.rb +20 -20
  53. data/spec/dene_spec.rb +186 -0
  54. data/spec/deploy_executable_spec.rb +90 -0
  55. data/spec/deploy_executable_test_spec.rb +117 -0
  56. data/spec/deploy_serializer_spec.rb +5 -3
  57. data/spec/deploy_serializer_test_spec.rb +7 -1
  58. data/spec/testnet_spec.rb +3 -1
  59. data/spec/time_utils_spec.rb +3 -0
  60. metadata +20 -5
  61. data/lib/crypto/key_pair.rb +0 -40
  62. data/spec/deploy_executable_serializer_spec.rb +0 -0
@@ -27,6 +27,11 @@ module Utils
27
27
  # byte_array.pack("C*").unpack1("H*")
28
28
  byte_array.pack("C*").unpack("H*").first
29
29
  end
30
+
31
+ def byte_array_to_hex_64(byte_array)
32
+ # byte_array.pack("C*").unpack1("H*")
33
+ byte_array.pack("C*").unpack("H*").first
34
+ end
30
35
 
31
36
  # @param [String] str
32
37
  # @return [Array]
@@ -74,6 +79,15 @@ module Utils
74
79
  # @param [Integer] n
75
80
  # @return [String]
76
81
  def to_u64(n)
82
+ # bytes = Utils::ByteUtils.byte_array_to_hex(to_byte_array(n)) + "0000"
83
+ # puts "bytes: #{bytes}"
84
+ # puts "bytes_conversion: #{[bytes].pack("H*").unpack("C*")}"
85
+ [n].pack("Q<*").unpack("H*").first
86
+ end
87
+
88
+ # @param [Integer] n
89
+ # @return [String]
90
+ def to_u512(n)
77
91
  [n].pack("Q<*").unpack("H*").first
78
92
  end
79
93
 
@@ -103,5 +117,19 @@ module Utils
103
117
  def hex_to_u64_value(hex_str)
104
118
  [hex_str].pack("H*").unpack("Q*").first
105
119
  end
120
+ def hex_to_u512_value(hex_str)
121
+ [hex_str].pack("H*").unpack("Q*").first
122
+ end
123
+
124
+ # @return byte array containing two's complement representation of Bignum/Fixnum
125
+ def to_byte_array(num)
126
+ result = []
127
+ begin
128
+ result << (num & 0xff)
129
+ num >>= 8
130
+ end until (num == 0 || num == -1) && (result.last[7] == num[7])
131
+ # result.reverse
132
+ result
133
+ end
106
134
  end
107
135
  end
@@ -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.2'
2
+ VERSION = '1.1.3'
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/client_spec.rb CHANGED
@@ -1,25 +1,25 @@
1
1
  # client_spec.rb
2
- # require './lib/casper_network.rb'
2
+ require './lib/rpc/rpc_client.rb'
3
3
 
4
- # describe CasperClient do
5
- # client1 = CasperClient.new("185.246.84.43")
6
- # # Test info_get_peers()
7
- # describe "#info_get_peers" do
8
- # it "returns peers array." do
9
- # # Check whether ıt is an array or not
10
- # expect(client1.info_get_peers).to be_an(Array)
11
- # # Check the length of the peers array
12
- # expect(client1.info_get_peers.length).to be > 0
4
+ describe Casper::RpcClient do
5
+ client1 = Casper::RpcClient.new("185.246.84.43")
6
+ # Test info_get_peers()
7
+ describe "#info_get_peers" do
8
+ it "returns peers array." do
9
+ # Check whether ıt is an array or not
10
+ expect(client1.info_get_peers).to be_an(Array)
11
+ # Check the length of the peers array
12
+ expect(client1.info_get_peers.length).to be > 0
13
13
 
14
- # end
15
- # end
16
- # # Test chain_get_StateRootHash()
17
- # describe "#chain_get_StateRootHash" do
18
- # it "returns current state_root_hash." do
19
- # # Check whether its type is string or not
20
- # expect(client1.chain_get_StateRootHash).to be_an(String)
21
- # end
22
- # end
14
+ end
15
+ end
16
+ # Test chain_get_StateRootHash()
17
+ describe "#chain_get_StateRootHash" do
18
+ it "returns current state_root_hash." do
19
+ # Check whether its type is string or not
20
+ expect(client1.chain_get_StateRootHash).to be_an(String)
21
+ end
22
+ end
23
23
 
24
24
 
25
- # end
25
+ 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