4
4
5
5
namespace spec \drupol \phptree \Node ;
6
6
7
- use drupol \phpmerkle \Hasher \DoubleSha256 ;
8
- use drupol \phptree \Node \MerkleNode ;
9
7
use drupol \phpmerkle \Hasher \DummyHasher ;
8
+ use drupol \phptree \Node \MerkleNode ;
10
9
use PhpSpec \ObjectBehavior ;
11
10
12
11
class MerkleNodeSpec extends ObjectBehavior
13
12
{
14
13
public function it_can_get_a_hash ()
15
14
{
16
15
$ this
17
- ->beConstructedWith ('root ' , 2 , new DoubleSha256 () );
16
+ ->beConstructedWith ('root ' );
18
17
19
18
$ input = [
20
19
null ,
@@ -50,7 +49,7 @@ public function it_can_get_a_hash()
50
49
];
51
50
52
51
foreach ($ input as $ word ) {
53
- $ nodes [] = new MerkleNode ($ word, 2 , new DoubleSha256 () );
52
+ $ nodes [] = new MerkleNode ($ word );
54
53
}
55
54
56
55
$ this
@@ -77,9 +76,19 @@ public function it_can_get_the_value_of_a_tree_with_four_nodes()
77
76
];
78
77
79
78
$ this
80
- ->add (...$ nodes )
79
+ ->add (...$ nodes );
80
+
81
+ $ this
82
+ ->count ()
83
+ ->shouldReturn (5 );
84
+
85
+ $ this
81
86
->getValue ()
82
87
->shouldReturn ('abcc ' );
88
+
89
+ $ this
90
+ ->count ()
91
+ ->shouldReturn (5 );
83
92
}
84
93
85
94
public function it_can_get_the_value_of_a_tree_with_three_nodes ()
@@ -105,6 +114,33 @@ public function it_can_get_the_value_of_a_tree_with_two_nodes()
105
114
->shouldReturn ('aa ' );
106
115
}
107
116
117
+ public function it_can_handle_null_values ()
118
+ {
119
+ $ nodes = [
120
+ new MerkleNode (null , 2 , new DummyHasher ()),
121
+ new MerkleNode (null , 2 , new DummyHasher ()),
122
+ new MerkleNode ('a ' , 2 , new DummyHasher ()),
123
+ new MerkleNode ('b ' , 2 , new DummyHasher ()),
124
+ new MerkleNode (null , 2 , new DummyHasher ()),
125
+ new MerkleNode ('c ' , 2 , new DummyHasher ()),
126
+ ];
127
+
128
+ $ this
129
+ ->add (...$ nodes );
130
+
131
+ $ this
132
+ ->count ()
133
+ ->shouldReturn (6 );
134
+
135
+ $ this
136
+ ->getValue ()
137
+ ->shouldReturn ('abcc ' );
138
+
139
+ $ this
140
+ ->count ()
141
+ ->shouldReturn (6 );
142
+ }
143
+
108
144
public function it_is_initializable ()
109
145
{
110
146
$ this ->shouldHaveType (MerkleNode::class);
0 commit comments