16
16
17
17
package com .exonum .binding .blockchain ;
18
18
19
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
20
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
21
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
22
+
23
+ import com .exonum .binding .blockchain .Block .Builder ;
19
24
import com .exonum .binding .common .hash .HashCode ;
25
+ import com .exonum .binding .common .hash .HashFunction ;
26
+ import com .exonum .binding .common .hash .Hashing ;
20
27
import nl .jqno .equalsverifier .EqualsVerifier ;
21
28
import nl .jqno .equalsverifier .Warning ;
22
29
import org .junit .jupiter .api .Test ;
30
+ import org .junit .jupiter .params .ParameterizedTest ;
31
+ import org .junit .jupiter .params .provider .ValueSource ;
23
32
24
33
class BlockTest {
25
34
35
+ @ Test
36
+ void isEmpty () {
37
+ Block emptyBlock = aBlock ()
38
+ .numTransactions (0 )
39
+ .build ();
40
+
41
+ assertTrue (emptyBlock .isEmpty ());
42
+ }
43
+
44
+ @ ParameterizedTest
45
+ @ ValueSource (ints = {1 , 2 , Integer .MAX_VALUE })
46
+ void nonEmptyBlock (int numTransactions ) {
47
+ Block nonEmptyBlock = aBlock ()
48
+ .numTransactions (numTransactions )
49
+ .build ();
50
+
51
+ assertFalse (nonEmptyBlock .isEmpty ());
52
+ }
53
+
26
54
@ Test
27
55
void verifyEquals () {
28
56
EqualsVerifier .forClass (AutoValue_Block .class )
@@ -33,4 +61,17 @@ void verifyEquals() {
33
61
.withPrefabValues (HashCode .class , HashCode .fromInt (1 ), HashCode .fromInt (2 ))
34
62
.verify ();
35
63
}
64
+
65
+ private static Builder aBlock () {
66
+ HashFunction hashFunction = Hashing .sha256 ();
67
+ long blockHeight = 1 ;
68
+ return Block .builder ()
69
+ .proposerId (0 )
70
+ .height (blockHeight )
71
+ .numTransactions (0 )
72
+ .blockHash (hashFunction .hashLong (blockHeight ))
73
+ .previousBlockHash (hashFunction .hashLong (blockHeight - 1 ))
74
+ .txRootHash (hashFunction .hashString ("transactions at" + blockHeight , UTF_8 ))
75
+ .stateHash (hashFunction .hashString ("state hash at " + blockHeight , UTF_8 ));
76
+ }
36
77
}
0 commit comments