1919import static com .exonum .binding .common .proofs .list .ListProofUtils .getBranchHashCode ;
2020import static com .exonum .binding .common .proofs .list .ListProofUtils .getNodeHashCode ;
2121import static com .exonum .binding .common .proofs .list .ListProofUtils .getProofListHash ;
22- import static com .exonum .binding .common .proofs .list .ListProofUtils .leafOf ;
2322import static com .google .common .collect .ImmutableMap .of ;
2423import static org .hamcrest .CoreMatchers .equalTo ;
2524import static org .hamcrest .MatcherAssert .assertThat ;
2625import static org .junit .jupiter .api .Assertions .assertEquals ;
2726
2827import com .exonum .binding .common .hash .HashCode ;
29- import com .exonum . binding . common . serialization . StandardSerializers ;
28+ import com .google . protobuf . ByteString ;
3029import org .junit .jupiter .api .Test ;
3130
3231class ListProofHashCalculatorTest {
3332
34- private static final String V1 = "v1" ;
35- private static final String V2 = "v2" ;
36- private static final String V3 = "v3" ;
37- private static final String V4 = "v4" ;
33+ private static final ByteString V1 = ByteString . copyFromUtf8 ( "v1" ) ;
34+ private static final ByteString V2 = ByteString . copyFromUtf8 ( "v2" ) ;
35+ private static final ByteString V3 = ByteString . copyFromUtf8 ( "v3" ) ;
36+ private static final ByteString V4 = ByteString . copyFromUtf8 ( "v4" ) ;
3837
3938 private static final HashCode H1 = HashCode .fromString ("a1" );
4039 private static final HashCode H2 = HashCode .fromString ("a2" );
4140
42- private ListProofHashCalculator < String > calculator ;
41+ private ListProofHashCalculator calculator ;
4342
4443 @ Test
4544 void visit_SingletonListProof () {
46- ListProofNode root = leafOf (V1 );
45+ ListProofNode root = new ListProofElement (V1 );
4746
48- ListProof listProof = new ListProof ( root , 1 ) ;
49- calculator = createListProofCalculator ( listProof );
47+ long length = 1 ;
48+ calculator = new ListProofHashCalculator ( root , length );
5049
51- HashCode expectedProofListHash = getProofListHash (getNodeHashCode (V1 ), listProof . getLength () );
50+ HashCode expectedProofListHash = getProofListHash (getNodeHashCode (V1 ), length );
5251
5352 assertThat (calculator .getElements (), equalTo (of (0L , V1 )));
5453 assertEquals (expectedProofListHash , calculator .getHash ());
5554 }
5655
5756 @ Test
5857 void visit_FullProof2elements () {
59- ListProofElement left = leafOf (V1 );
60- ListProofElement right = leafOf (V2 );
58+ ListProofElement left = new ListProofElement (V1 );
59+ ListProofElement right = new ListProofElement (V2 );
6160 ListProofBranch root = new ListProofBranch (left , right );
6261
63- ListProof listProof = new ListProof ( root , 2 ) ;
64- calculator = createListProofCalculator ( listProof );
62+ long length = 2 ;
63+ calculator = new ListProofHashCalculator ( root , length );
6564
6665 // Calculate expected proof list hash
6766 HashCode expectedRootHash = getBranchHashCode (getNodeHashCode (V1 ), getNodeHashCode (V2 ));
68- HashCode expectedProofListHash = getProofListHash (expectedRootHash , listProof . getLength () );
67+ HashCode expectedProofListHash = getProofListHash (expectedRootHash , length );
6968
7069 assertThat (calculator .getElements (), equalTo (of (0L , V1 ,
7170 1L , V2 )));
@@ -76,23 +75,23 @@ void visit_FullProof2elements() {
7675 void visit_FullProof4elements () {
7776 ListProofBranch root = new ListProofBranch (
7877 new ListProofBranch (
79- leafOf (V1 ),
80- leafOf (V2 )
78+ new ListProofElement (V1 ),
79+ new ListProofElement (V2 )
8180 ),
8281 new ListProofBranch (
83- leafOf (V3 ),
84- leafOf (V4 )
82+ new ListProofElement (V3 ),
83+ new ListProofElement (V4 )
8584 )
8685 );
8786
88- ListProof listProof = new ListProof ( root , 4 ) ;
89- calculator = createListProofCalculator ( listProof );
87+ long length = 4 ;
88+ calculator = new ListProofHashCalculator ( root , length );
9089
9190 // Calculate expected proof list hash
9291 HashCode leftBranchHash = getBranchHashCode (getNodeHashCode (V1 ), getNodeHashCode (V2 ));
9392 HashCode rightBranchHash = getBranchHashCode (getNodeHashCode (V3 ), getNodeHashCode (V4 ));
9493 HashCode expectedRootHash = getBranchHashCode (leftBranchHash , rightBranchHash );
95- HashCode expectedProofListHash = getProofListHash (expectedRootHash , listProof . getLength () );
94+ HashCode expectedProofListHash = getProofListHash (expectedRootHash , length );
9695
9796
9897 assertThat (calculator .getElements (),
@@ -105,15 +104,15 @@ void visit_FullProof4elements() {
105104
106105 @ Test
107106 void visit_ProofLeftValue () {
108- ListProofNode left = leafOf (V1 );
107+ ListProofNode left = new ListProofElement (V1 );
109108 ListProofNode right = new ListProofHashNode (H2 );
110109 ListProofBranch root = new ListProofBranch (left , right );
111110
112- ListProof listProof = new ListProof ( root , 2 ) ;
113- calculator = createListProofCalculator ( listProof );
111+ long length = 2 ;
112+ calculator = new ListProofHashCalculator ( root , length );
114113
115114 HashCode expectedRootHash = getBranchHashCode (getNodeHashCode (V1 ), H2 );
116- HashCode expectedProofListHash = getProofListHash (expectedRootHash , listProof . getLength () );
115+ HashCode expectedProofListHash = getProofListHash (expectedRootHash , length );
117116
118117 assertThat (calculator .getElements (), equalTo (of (0L , V1 )));
119118 assertEquals (expectedProofListHash , calculator .getHash ());
@@ -122,14 +121,14 @@ void visit_ProofLeftValue() {
122121 @ Test
123122 void visit_ProofRightValue () {
124123 ListProofNode left = new ListProofHashNode (H1 );
125- ListProofNode right = leafOf (V2 );
124+ ListProofNode right = new ListProofElement (V2 );
126125 ListProofBranch root = new ListProofBranch (left , right );
127126
128- ListProof listProof = new ListProof ( root , 2 ) ;
129- calculator = createListProofCalculator ( listProof );
127+ long length = 2 ;
128+ calculator = new ListProofHashCalculator ( root , length );
130129
131130 HashCode expectedRootHash = getBranchHashCode (H1 , getNodeHashCode (V2 ));
132- HashCode expectedProofListHash = getProofListHash (expectedRootHash , listProof . getLength () );
131+ HashCode expectedProofListHash = getProofListHash (expectedRootHash , length );
133132
134133 assertThat (calculator .getElements (), equalTo (of (1L , V2 )));
135134 assertEquals (expectedProofListHash , calculator .getHash ());
@@ -139,22 +138,22 @@ void visit_ProofRightValue() {
139138 void visit_FullProof3elements () {
140139 ListProofBranch root = new ListProofBranch (
141140 new ListProofBranch (
142- leafOf (V1 ),
143- leafOf (V2 )
141+ new ListProofElement (V1 ),
142+ new ListProofElement (V2 )
144143 ),
145144 new ListProofBranch (
146- leafOf (V3 ),
145+ new ListProofElement (V3 ),
147146 null
148147 )
149148 );
150149
151- ListProof listProof = new ListProof ( root , 3 ) ;
152- calculator = createListProofCalculator ( listProof );
150+ long length = 3 ;
151+ calculator = new ListProofHashCalculator ( root , length );
153152
154153 HashCode leftBranchHash = getBranchHashCode (getNodeHashCode (V1 ), getNodeHashCode (V2 ));
155154 HashCode rightBranchHash = getBranchHashCode (getNodeHashCode (V3 ), null );
156155 HashCode expectedRootHash = getBranchHashCode (leftBranchHash , rightBranchHash );
157- HashCode expectedProofListHash = getProofListHash (expectedRootHash , listProof . getLength () );
156+ HashCode expectedProofListHash = getProofListHash (expectedRootHash , length );
158157
159158 assertThat (calculator .getElements (),
160159 equalTo (of (
@@ -164,8 +163,4 @@ void visit_FullProof3elements() {
164163 );
165164 assertEquals (expectedProofListHash , calculator .getHash ());
166165 }
167-
168- private ListProofHashCalculator <String > createListProofCalculator (ListProof listProof ) {
169- return new ListProofHashCalculator <>(listProof , StandardSerializers .string ());
170- }
171166}
0 commit comments