File tree Expand file tree Collapse file tree 3 files changed +7
-7
lines changed
main/java/com/baeldung/blockchain
test/java/com/baeldung/blockchain Expand file tree Collapse file tree 3 files changed +7
-7
lines changed Original file line number Diff line number Diff line change 3
3
import java .io .UnsupportedEncodingException ;
4
4
import java .security .MessageDigest ;
5
5
import java .security .NoSuchAlgorithmException ;
6
- import java .util .Date ;
7
6
import java .util .logging .Level ;
8
7
import java .util .logging .Logger ;
9
8
@@ -17,10 +16,10 @@ public class Block {
17
16
private long timeStamp ;
18
17
private int nonce ;
19
18
20
- public Block (String data , String previousHash ) {
19
+ public Block (String data , String previousHash , long timeStamp ) {
21
20
this .data = data ;
22
21
this .previousHash = previousHash ;
23
- this .timeStamp = new Date (). getTime () ;
22
+ this .timeStamp = timeStamp ;
24
23
this .hash = calculateBlockHash ();
25
24
}
26
25
Original file line number Diff line number Diff line change 3
3
import static org .junit .jupiter .api .Assertions .assertTrue ;
4
4
5
5
import java .util .ArrayList ;
6
+ import java .util .Date ;
6
7
import java .util .List ;
7
8
8
9
import org .junit .AfterClass ;
@@ -17,18 +18,18 @@ public class BlockchainUnitTest {
17
18
18
19
@ BeforeClass
19
20
public static void setUp () {
20
- Block genesisBlock = new Block ("The is the Genesis Block." , "0" );
21
+ Block genesisBlock = new Block ("The is the Genesis Block." , "0" , new Date (). getTime () );
21
22
genesisBlock .mineBlock (prefix );
22
23
blockchain .add (genesisBlock );
23
- Block firstBlock = new Block ("The is the First Block." , genesisBlock .getHash ());
24
+ Block firstBlock = new Block ("The is the First Block." , genesisBlock .getHash (), new Date (). getTime () );
24
25
firstBlock .mineBlock (prefix );
25
26
blockchain .add (firstBlock );
26
27
}
27
28
28
29
@ Test
29
30
public void givenBlockchain_whenNewBlockAdded_thenSuccess () {
30
31
Block newBlock = new Block ("The is a New Block." , blockchain .get (blockchain .size () - 1 )
31
- .getHash ());
32
+ .getHash (), new Date (). getTime () );
32
33
newBlock .mineBlock (prefix );
33
34
assertTrue (newBlock .getHash ()
34
35
.substring (0 , prefix )
Original file line number Diff line number Diff line change 579
579
580
580
<module >spring-boot-nashorn</module >
581
581
<module >java-blockchain</module >
582
- <!-- <module>Twitter4J</module> --> <!-- Builds locally, but fails in Jenkins, Failed to parse POMs -->
582
+
583
583
</modules >
584
584
585
585
</profile >
You can’t perform that action at this time.
0 commit comments