ciri 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +8 -3
- data/README.md +5 -0
- data/Rakefile +24 -2
- data/ciri-rlp/.gitignore +11 -0
- data/ciri-rlp/.rspec +3 -0
- data/ciri-rlp/.travis.yml +5 -0
- data/ciri-rlp/CODE_OF_CONDUCT.md +74 -0
- data/ciri-rlp/Gemfile +6 -0
- data/ciri-rlp/Gemfile.lock +39 -0
- data/ciri-rlp/LICENSE.txt +21 -0
- data/ciri-rlp/README.md +98 -0
- data/ciri-rlp/Rakefile +6 -0
- data/ciri-rlp/bin/console +14 -0
- data/ciri-rlp/bin/setup +8 -0
- data/ciri-rlp/ciri-rlp.gemspec +28 -0
- data/{lib → ciri-rlp/lib}/ciri/rlp.rb +2 -2
- data/ciri-rlp/lib/ciri/rlp/decode.rb +144 -0
- data/ciri-rlp/lib/ciri/rlp/encode.rb +140 -0
- data/ciri-rlp/lib/ciri/rlp/serializable.rb +241 -0
- data/ciri-rlp/lib/ciri/rlp/version.rb +5 -0
- data/ciri-rlp/spec/ciri/fixture_spec.rb +95 -0
- data/ciri-rlp/spec/ciri/rlp/decode_spec.rb +68 -0
- data/ciri-rlp/spec/ciri/rlp/encode_spec.rb +72 -0
- data/ciri-rlp/spec/ciri/rlp/serializable_spec.rb +147 -0
- data/ciri-rlp/spec/ciri/rlp_spec.rb +5 -0
- data/ciri-rlp/spec/spec_helper.rb +14 -0
- data/ciri-utils/.gitignore +11 -0
- data/ciri-utils/.rspec +3 -0
- data/ciri-utils/.travis.yml +5 -0
- data/ciri-utils/CODE_OF_CONDUCT.md +74 -0
- data/ciri-utils/Gemfile +6 -0
- data/ciri-utils/Gemfile.lock +37 -0
- data/ciri-utils/LICENSE.txt +21 -0
- data/ciri-utils/README.md +61 -0
- data/ciri-utils/Rakefile +6 -0
- data/ciri-utils/bin/console +14 -0
- data/ciri-utils/bin/setup +8 -0
- data/ciri-utils/ciri-utils.gemspec +28 -0
- data/{lib → ciri-utils/lib}/ciri/utils.rb +9 -33
- data/{lib → ciri-utils/lib}/ciri/utils/logger.rb +0 -0
- data/{lib → ciri-utils/lib}/ciri/utils/number.rb +15 -12
- data/ciri-utils/lib/ciri/utils/version.rb +5 -0
- data/ciri-utils/spec/ciri/utils_spec.rb +5 -0
- data/ciri-utils/spec/spec_helper.rb +14 -0
- data/ciri.gemspec +6 -3
- data/lib/ciri/bloom_filter.rb +83 -0
- data/lib/ciri/chain.rb +67 -130
- data/lib/ciri/chain/header.rb +2 -2
- data/lib/ciri/chain/header_chain.rb +136 -0
- data/lib/ciri/chain/transaction.rb +1 -1
- data/lib/ciri/crypto.rb +2 -2
- data/lib/ciri/db/account_db.rb +145 -0
- data/lib/ciri/db/backend/memory.rb +24 -1
- data/lib/ciri/devp2p/peer.rb +1 -1
- data/lib/ciri/devp2p/rlpx/connection.rb +5 -5
- data/lib/ciri/eth/peer.rb +3 -3
- data/lib/ciri/eth/protocol_manage.rb +3 -3
- data/lib/ciri/eth/protocol_messages.rb +27 -26
- data/lib/ciri/ethash.rb +18 -3
- data/lib/ciri/evm.rb +101 -56
- data/lib/ciri/{utils/lib_c.rb → evm/errors.rb} +28 -18
- data/lib/ciri/evm/instruction.rb +3 -1
- data/lib/ciri/evm/{serialize.rb → log_entry.rb} +9 -27
- data/lib/ciri/evm/machine_state.rb +21 -2
- data/lib/ciri/evm/op.rb +19 -16
- data/lib/ciri/evm/state.rb +61 -0
- data/lib/ciri/evm/vm.rb +78 -102
- data/lib/ciri/forks.rb +1 -4
- data/lib/ciri/forks/base.rb +55 -0
- data/lib/ciri/forks/frontier.rb +37 -10
- data/lib/ciri/forks/frontier/cost.rb +186 -0
- data/lib/ciri/key.rb +1 -1
- data/lib/ciri/pow.rb +1 -1
- data/lib/ciri/rlp/decode.rb +6 -3
- data/lib/ciri/rlp/encode.rb +10 -10
- data/lib/ciri/rlp/serializable.rb +12 -9
- data/lib/ciri/serialize.rb +58 -0
- data/lib/ciri/trie.rb +362 -0
- data/lib/ciri/trie/nibbles.rb +97 -0
- data/lib/ciri/trie/nodes.rb +187 -0
- data/lib/ciri/{evm → types}/account.rb +20 -13
- data/lib/ciri/types/address.rb +16 -11
- data/lib/ciri/types/number.rb +73 -0
- data/lib/ciri/types/receipt.rb +57 -0
- data/lib/ciri/version.rb +1 -1
- metadata +82 -19
- data/lib/ciri/evm/forks/frontier.rb +0 -183
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
|
24
|
+
require 'spec_helper'
|
25
|
+
require 'json'
|
26
|
+
require 'ciri/rlp'
|
27
|
+
require 'ciri/utils'
|
28
|
+
|
29
|
+
RSpec.describe Ciri::RLP do
|
30
|
+
|
31
|
+
fixture_path = File.join(File.dirname(__FILE__), "..", "..", "..", "fixtures")
|
32
|
+
|
33
|
+
before(:all) do
|
34
|
+
`git submodule init #{fixture_path}`
|
35
|
+
`git submodule update #{fixture_path}`
|
36
|
+
end
|
37
|
+
|
38
|
+
decode_types = proc do |value|
|
39
|
+
if value.is_a?(Array)
|
40
|
+
value.map {|i| decode_types[i]}
|
41
|
+
elsif value.is_a?(String)
|
42
|
+
Ciri::RLP::Raw
|
43
|
+
else
|
44
|
+
value.class
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
skip_tests = %w{
|
49
|
+
}.map {|f| [f, true]}.to_h
|
50
|
+
|
51
|
+
run_test_case = proc do |test_case, prefix: nil, tags: {}|
|
52
|
+
test_case.each do |name, t|
|
53
|
+
tags2 = tags.dup
|
54
|
+
|
55
|
+
if skip_tests.include?(name)
|
56
|
+
tags2[:skip] = true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "#{prefix} #{name}", **tags2 do
|
60
|
+
# in
|
61
|
+
in_value = t['in']
|
62
|
+
if in_value.is_a?(String) && in_value.start_with?('#')
|
63
|
+
in_value = in_value[1..-1].to_i
|
64
|
+
end
|
65
|
+
out_value = t['out']
|
66
|
+
|
67
|
+
if in_value == 'INVALID'
|
68
|
+
expect {
|
69
|
+
rlp_decoded = Ciri::RLP.decode(Ciri::Utils.to_bytes out_value)
|
70
|
+
if Ciri::Utils.to_hex(Ciri::RLP.encode(rlp_decoded)) != out_value
|
71
|
+
raise Ciri::RLP::InvalidValueError, "not invalid encoding"
|
72
|
+
end
|
73
|
+
}.to raise_error(Ciri::RLP::InvalidValueError)
|
74
|
+
elsif in_value == 'VALID'
|
75
|
+
expect {Ciri::RLP.decode(Ciri::Utils.to_bytes out_value)}.to_not raise_error
|
76
|
+
else
|
77
|
+
rlp_encoded = Ciri::RLP.encode(in_value)
|
78
|
+
expect(Ciri::Utils.to_hex(rlp_encoded)[2..-1]).to eq out_value
|
79
|
+
|
80
|
+
rlp_decoded = Ciri::RLP.decode(Ciri::Utils.to_bytes(out_value), decode_types[in_value])
|
81
|
+
expect(rlp_decoded).to eq in_value
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
Dir.glob("#{fixture_path}/RLPTests/**/*.json").each do |topic|
|
90
|
+
tags = {}
|
91
|
+
|
92
|
+
run_test_case[JSON.load(open topic), prefix: 'fixtures/RLPTests', tags: tags]
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'ciri/rlp'
|
2
|
+
|
3
|
+
RSpec.describe Ciri::RLP::Decode do
|
4
|
+
|
5
|
+
context 'numbers' do
|
6
|
+
it '0x00' do
|
7
|
+
expect(Ciri::RLP.decode("\x00".b)).to eq "\x00"
|
8
|
+
end
|
9
|
+
|
10
|
+
it '0x0f' do
|
11
|
+
expect(Ciri::RLP.decode("\x0f".b)).to eq "\x0f"
|
12
|
+
end
|
13
|
+
|
14
|
+
it '1024' do
|
15
|
+
expect(Ciri::RLP.decode("\x82\x04\x00".b)).to eq "\x04\x00"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'decode strings' do
|
20
|
+
it 'single byte' do
|
21
|
+
expect(Ciri::RLP.decode('a'.b)).to eq 'a'
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'simple string' do
|
25
|
+
expect(Ciri::RLP.decode("\x83dog")).to eq 'dog'.b
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'empty' do
|
29
|
+
expect(Ciri::RLP.decode("\x80")).to eq ''
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'long string' do
|
33
|
+
expect(Ciri::RLP.decode("\xb8\x38Lorem ipsum dolor sit amet, consectetur adipisicing elit".b)).to eq 'Lorem ipsum dolor sit amet, consectetur adipisicing elit'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'decode lists' do
|
38
|
+
it 'list of strings' do
|
39
|
+
expect(Ciri::RLP.decode("\xc8\x83cat\x83dog".b)).to eq ["cat", "dog"]
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'empty list' do
|
43
|
+
expect(Ciri::RLP.decode("\xc0")).to eq []
|
44
|
+
end
|
45
|
+
|
46
|
+
it "empty lists" do
|
47
|
+
expect(Ciri::RLP.decode("\xc7\xc0\xc1\xc0\xc3\xc0\xc1\xc0")).to eq [[], [[]], [[], [[]]]]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'decode int' do
|
52
|
+
it '0' do
|
53
|
+
expect(Ciri::RLP.decode_with_type("\x80".b, Integer)).to eq 0
|
54
|
+
end
|
55
|
+
|
56
|
+
it '127' do
|
57
|
+
expect(Ciri::RLP.decode_with_type("\x7f".b, Integer)).to eq 127
|
58
|
+
end
|
59
|
+
|
60
|
+
it '128' do
|
61
|
+
expect(Ciri::RLP.decode_with_type("\x81\x80".b, Integer)).to eq 128
|
62
|
+
end
|
63
|
+
|
64
|
+
it '1024' do
|
65
|
+
expect(Ciri::RLP.decode_with_type("\x82\x04\x00".b, Integer)).to eq 1024
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'ciri/rlp'
|
2
|
+
|
3
|
+
RSpec.describe Ciri::RLP::Encode do
|
4
|
+
|
5
|
+
context 'numbers' do
|
6
|
+
it '0x00' do
|
7
|
+
expect(Ciri::RLP.encode("\x00")).to eq "\x00"
|
8
|
+
end
|
9
|
+
|
10
|
+
it '0x0f' do
|
11
|
+
expect(Ciri::RLP.encode("\x0f")).to eq "\x0f"
|
12
|
+
end
|
13
|
+
|
14
|
+
it '1024' do
|
15
|
+
expect(Ciri::RLP.encode("\x04\x00")).to eq "\x82\x04\x00".b
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'encode strings' do
|
20
|
+
it 'single byte' do
|
21
|
+
expect(Ciri::RLP.encode('a')).to eq 'a'.b
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'simple string' do
|
25
|
+
expect(Ciri::RLP.encode('dog')).to eq "\x83dog".b
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'empty' do
|
29
|
+
expect(Ciri::RLP.encode('')).to eq "\x80".b
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'long string' do
|
33
|
+
expect(Ciri::RLP.encode('Lorem ipsum dolor sit amet, consectetur adipisicing elit')).to eq "\xb8\x38Lorem ipsum dolor sit amet, consectetur adipisicing elit".b
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'encode lists' do
|
38
|
+
it 'list of strings' do
|
39
|
+
expect(Ciri::RLP.encode(["cat", "dog"])).to eq "\xc8\x83cat\x83dog".b
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'empty list' do
|
43
|
+
expect(Ciri::RLP.encode([])).to eq "\xc0".b
|
44
|
+
end
|
45
|
+
|
46
|
+
it "empty lists" do
|
47
|
+
expect(Ciri::RLP.encode([[], [[]], [[], [[]]]])).to eq "\xc7\xc0\xc1\xc0\xc3\xc0\xc1\xc0".b
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'encode int' do
|
52
|
+
it '0' do
|
53
|
+
expect(Ciri::RLP.encode_with_type(0, Integer)).to eq "\x80".b
|
54
|
+
end
|
55
|
+
|
56
|
+
it '127' do
|
57
|
+
expect(Ciri::RLP.encode_with_type(127, Integer)).to eq "\x7f".b
|
58
|
+
end
|
59
|
+
|
60
|
+
it '128' do
|
61
|
+
expect(Ciri::RLP.encode_with_type(128, Integer)).to eq "\x81\x80".b
|
62
|
+
end
|
63
|
+
|
64
|
+
it '1024' do
|
65
|
+
expect(Ciri::RLP.encode_with_type(1024, Integer)).to eq "\x82\x04\x00".b
|
66
|
+
end
|
67
|
+
|
68
|
+
it '1833967303248889' do
|
69
|
+
expect(Ciri::RLP.encode_with_type(1833967303248889, Integer)).to eq Ciri::Utils.to_bytes("870683FBC9A3CBF9")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# Copyright (c) 2018, by Jiang Jinyang. <https://justjjy.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
|
22
|
+
require 'ciri/rlp'
|
23
|
+
require 'ciri/rlp/serializable'
|
24
|
+
|
25
|
+
RSpec.describe Ciri::RLP::Serializable do
|
26
|
+
|
27
|
+
let(:my_class) {
|
28
|
+
Class.new do
|
29
|
+
include Ciri::RLP::Serializable
|
30
|
+
|
31
|
+
schema [
|
32
|
+
:signature,
|
33
|
+
{nonce: [Integer]},
|
34
|
+
{version: Integer}
|
35
|
+
]
|
36
|
+
default_data(version: 1)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
|
40
|
+
it 'apply default value' do
|
41
|
+
msg = my_class.new(signature: '123', nonce: [1, 2, 3], version: 4)
|
42
|
+
expect(msg.version).to eq 4
|
43
|
+
msg = my_class.new(signature: '123', nonce: [1, 2, 3])
|
44
|
+
expect(msg.version).to eq 1
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raise invalid if missing key' do
|
48
|
+
expect do
|
49
|
+
my_class.new(signature: '123')
|
50
|
+
end.to raise_error(Ciri::RLP::Serializable::Schema::InvalidSchemaError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'rlp encoding/decoding' do
|
54
|
+
msg = my_class.new(signature: '123', nonce: [1, 2, 3], version: 4)
|
55
|
+
binary = msg.rlp_encode
|
56
|
+
# is valid RLP encoding format
|
57
|
+
expect {Ciri::RLP.decode(binary)}.to_not raise_error
|
58
|
+
|
59
|
+
decoded_msg = my_class.rlp_decode(binary)
|
60
|
+
expect(decoded_msg).to eq msg
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'deserialize real world geth handshake' do
|
64
|
+
it 'decode handshake' do
|
65
|
+
my_cap = Class.new do
|
66
|
+
include Ciri::RLP::Serializable
|
67
|
+
|
68
|
+
schema [
|
69
|
+
:name,
|
70
|
+
{version: Integer}
|
71
|
+
]
|
72
|
+
end
|
73
|
+
|
74
|
+
my_protocol_handshake = Class.new do
|
75
|
+
include Ciri::RLP::Serializable
|
76
|
+
|
77
|
+
schema [
|
78
|
+
{version: Integer},
|
79
|
+
:name,
|
80
|
+
{caps: [my_cap]},
|
81
|
+
{listen_port: Integer},
|
82
|
+
:id
|
83
|
+
]
|
84
|
+
end
|
85
|
+
|
86
|
+
encoded_handshake = ['f87d05b1476574682f76312e382e372d756e737461626c652d38366265393162332f64617277696e2d616d6436342f676f312e3130c6c5836574683f80b840da982df3c882252c126ac3ee8fa008ade932c4166dfdc7c117c9852b5df0c6ddcf34bf2555a38596268b3b6bcbdaf48bba57b84a1abc400b4ba65c59ee5342c3'].pack("H*")
|
87
|
+
hs = my_protocol_handshake.rlp_decode(encoded_handshake)
|
88
|
+
expect(hs.version).to eq 5
|
89
|
+
expect(hs.listen_port).to eq 0
|
90
|
+
expect(hs.caps[0].name).to eq 'eth'
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'decode eth getBlockHashes' do
|
94
|
+
get_block_hashes = Class.new do
|
95
|
+
include Ciri::RLP::Serializable
|
96
|
+
CODE = 0x03
|
97
|
+
schema [
|
98
|
+
{hash_or_number: Integer},
|
99
|
+
{amount: Integer},
|
100
|
+
{skip: Integer},
|
101
|
+
{reverse: Ciri::RLP::Bool},
|
102
|
+
]
|
103
|
+
end
|
104
|
+
|
105
|
+
encoded_handshake = ['c7831d4c00018080'].pack("H*")
|
106
|
+
msg = get_block_hashes.rlp_decode(encoded_handshake)
|
107
|
+
expect(msg.hash_or_number).to eq 1920000
|
108
|
+
expect(msg.amount).to eq 1
|
109
|
+
expect(msg.skip).to eq 0
|
110
|
+
expect(msg.reverse).to be_falsey
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'self consistent' do
|
115
|
+
let(:raw_headers) {'f90213f90210a0e48ecfcb38189b103f389a719b782325bdf0f5c005871ea91cd11a52c30ac37ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794829bd824b016326a401d083b33d092293333a830a07007e575a80584487653324053b8ef65cd843fd09d7805eec9d8b840ba60e202a0abf18050f443bdc29bff9a959cb48bdf060861b89662484010ecbb0fdd8d3d9da07129bfc1aefeff683decb5060a00e2d002a2e2934516092aa34d6d62bdb3406fb901000000000000000010000200000000020200002000000000000d100000000000000000000000000000000000000040000200000100000040d00000000000000400000000000802040000000008000000100000000000200000000002000000000000000004020000000000084000000800002000000080000000000114001800000000020000000000800002000000000000000000008008000002000000000100008000000000000000000000400000000000000000400000000000000000000000000002000000000000000000000000008000000012000420000000800020000100000080000000000000000000000000000000000000000000000001000000870683fbc9a3cbf9833ffa818366251183173f8284599d077c8fe4b883e5bda9e7a59ee4bb99e9b1bca0b9566fe1fe4ae4b237a54955b88cc990e64013d1bed4761b32fbd45742825d4488d50741500da57701'}
|
116
|
+
let(:my_header) {
|
117
|
+
Class.new do
|
118
|
+
include Ciri::RLP::Serializable
|
119
|
+
|
120
|
+
schema [
|
121
|
+
:parent_hash,
|
122
|
+
:ommers_hash,
|
123
|
+
:beneficiary,
|
124
|
+
:state_root,
|
125
|
+
:transactions_root,
|
126
|
+
:receipts_root,
|
127
|
+
:logs_bloom,
|
128
|
+
{difficulty: Integer},
|
129
|
+
{number: Integer},
|
130
|
+
{gas_limit: Integer},
|
131
|
+
{gas_used: Integer},
|
132
|
+
{timestamp: Integer},
|
133
|
+
:extra_data,
|
134
|
+
:mix_hash,
|
135
|
+
:nonce,
|
136
|
+
]
|
137
|
+
end
|
138
|
+
}
|
139
|
+
|
140
|
+
it 'decode then encode again' do
|
141
|
+
raw_headers_b = [raw_headers].pack("H*")
|
142
|
+
headers = Ciri::RLP.decode(raw_headers_b, [my_header])
|
143
|
+
expect(Ciri::RLP.encode(headers, [my_header]).unpack("H*")[0]).to eq raw_headers
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "ciri/rlp"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
data/ciri-utils/.rspec
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jjyruby@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|