File tree Expand file tree Collapse file tree
main/java/com/baeldung/blockchain
test/java/com/baeldung/blockchain Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import java .io .UnsupportedEncodingException ;
44import java .security .MessageDigest ;
55import java .security .NoSuchAlgorithmException ;
6- import java .util .Date ;
76import java .util .logging .Level ;
87import java .util .logging .Logger ;
98
@@ -17,10 +16,10 @@ public class Block {
1716 private long timeStamp ;
1817 private int nonce ;
1918
20- public Block (String data , String previousHash ) {
19+ public Block (String data , String previousHash , long timeStamp ) {
2120 this .data = data ;
2221 this .previousHash = previousHash ;
23- this .timeStamp = new Date (). getTime () ;
22+ this .timeStamp = timeStamp ;
2423 this .hash = calculateBlockHash ();
2524 }
2625
Original file line number Diff line number Diff line change 33import static org .junit .jupiter .api .Assertions .assertTrue ;
44
55import java .util .ArrayList ;
6+ import java .util .Date ;
67import java .util .List ;
78
89import org .junit .AfterClass ;
@@ -17,18 +18,18 @@ public class BlockchainUnitTest {
1718
1819 @ BeforeClass
1920 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 () );
2122 genesisBlock .mineBlock (prefix );
2223 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 () );
2425 firstBlock .mineBlock (prefix );
2526 blockchain .add (firstBlock );
2627 }
2728
2829 @ Test
2930 public void givenBlockchain_whenNewBlockAdded_thenSuccess () {
3031 Block newBlock = new Block ("The is a New Block." , blockchain .get (blockchain .size () - 1 )
31- .getHash ());
32+ .getHash (), new Date (). getTime () );
3233 newBlock .mineBlock (prefix );
3334 assertTrue (newBlock .getHash ()
3435 .substring (0 , prefix )
Original file line number Diff line number Diff line change 579579
580580 <module >spring-boot-nashorn</module >
581581 <module >java-blockchain</module >
582- <!-- <module>Twitter4J</module> --> <!-- Builds locally, but fails in Jenkins, Failed to parse POMs -->
582+
583583 </modules >
584584
585585 </profile >
You can’t perform that action at this time.
0 commit comments