Skip to content

Commit

Permalink
Removed unused imports.
Browse files Browse the repository at this point in the history
Removed unnecessary JavaDoc that just said "Created by casatta", since that info is in git anyway.
Fixed consistency about empty lines.
Fixed spaces before catch, between catch/if/for and (.
Also added empty lines around all flow control blocks, i.e. try/for/if, as they are known to often introduce bugs.
Replaced two cases of "byte []" with "byte[] ".
Added IntelliJ *.iml files to .gitignore.
  • Loading branch information
matshenricson committed Mar 8, 2019
1 parent 356c5a7 commit 763f904
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 187 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ key.wif
/.settings/
/.classpath
/.project
*.iml
29 changes: 0 additions & 29 deletions java-opentimestamps.iml

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/java/com/eternitywall/TestBitcoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.eternitywall.ots.BitcoinNode;
import com.eternitywall.ots.BlockHeader;
import com.eternitywall.ots.Timestamp;
import com.eternitywall.ots.Utils;
import org.json.JSONObject;
import org.junit.Test;
Expand All @@ -13,13 +12,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* Created by casatta on 06/03/17.
*/
public class TestBitcoin {
private static Logger log = Utils.getLogger(TestBitcoin.class.getName());


@Test
public void testBitcoin() throws Exception {
try {
Expand All @@ -38,9 +33,5 @@ public void testBitcoin() throws Exception {
} catch (Exception e) {
log.info("no bitcoin node");
}

}



}
62 changes: 30 additions & 32 deletions src/test/java/com/eternitywall/TestCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.bitcoinj.core.NetworkParameters;
import org.junit.Test;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -26,10 +23,8 @@
import static org.junit.Assert.assertTrue;

public class TestCalendar {

private static Logger log = Utils.getLogger(TestCalendar.class.getName());


@Test
public void TestSingle() throws Exception {
String calendarUrl = "https://finney.calendar.eternitywall.com";
Expand All @@ -40,9 +35,6 @@ public void TestSingle() throws Exception {
assertTrue(Arrays.equals(timestamp.getDigest() , digest));
}




@Test
public void TestPrivate() throws Exception {
byte[] digest = Utils.randBytes(32);
Expand All @@ -52,60 +44,67 @@ public void TestPrivate() throws Exception {
// auth.calendar.eternitywall.com = KwT2r9sL........

Path path = Paths.get("key.wif");
if(!Files.exists(path)){

if (!Files.exists(path)){
assertTrue(true);
return;
}

Properties properties = new Properties();
properties.load(new FileInputStream("key.wif"));
HashMap<String,String> privateUrls = new HashMap<>();
for(String key : properties.stringPropertyNames()) {

for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
privateUrls.put(key,value);
}

assertFalse(privateUrls.size() == 0);

for(Map.Entry<String, String> entry : privateUrls.entrySet()) {
for (Map.Entry<String, String> entry : privateUrls.entrySet()) {
String calendarUrl = "https://"+entry.getKey();
String wifKey = entry.getValue();

Calendar calendar = new Calendar(calendarUrl);
ECKey key;

try {
BigInteger privKey = new BigInteger(wifKey);
key = ECKey.fromPrivate(privKey);
}catch (Exception e){
} catch (Exception e){
DumpedPrivateKey dumpedPrivateKey = new DumpedPrivateKey(NetworkParameters.prodNet(), wifKey);
key = dumpedPrivateKey.getKey();
}

calendar.setKey(key);
Timestamp timestamp = calendar.submit(digest);
assertTrue(timestamp != null);
assertTrue(Arrays.equals(timestamp.getDigest() , digest));
}

}

@Test
public void TestPrivateWif() throws Exception {
byte[] digest = Utils.randBytes(32);
Path path = Paths.get("key.wif");
if(!Files.exists(path)){

if (!Files.exists(path)){
assertTrue(true);
return;
}

Properties properties = new Properties();
properties.load(new FileInputStream("key.wif"));
HashMap<String,String> privateUrls = new HashMap<>();
for(String key : properties.stringPropertyNames()) {

for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
privateUrls.put(key,value);
}

assertFalse(privateUrls.size() == 0);

for(Map.Entry<String, String> entry : privateUrls.entrySet()) {
for (Map.Entry<String, String> entry : privateUrls.entrySet()) {
String calendarUrl = "https://"+entry.getKey();
String wifKey = entry.getValue();

Expand All @@ -118,7 +117,6 @@ public void TestPrivateWif() throws Exception {
assertTrue(timestamp != null);
assertTrue(Arrays.equals(timestamp.getDigest() , digest));
}

}

@Test
Expand All @@ -142,21 +140,24 @@ public void TestSingleAsyncPrivate() throws Exception {
ArrayBlockingQueue<Optional<Timestamp>> queue = new ArrayBlockingQueue<>(1);
byte[] digest = Utils.randBytes(32);
Path path = Paths.get("signature.key");
if(!Files.exists(path)){

if (!Files.exists(path)){
assertTrue(true);
return;
}

Properties properties = new Properties();
properties.load(new FileInputStream("signature.key"));
HashMap<String,String> privateUrls = new HashMap<>();
for(String key : properties.stringPropertyNames()) {

for (String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
privateUrls.put(key,value);
}

assertFalse(privateUrls.size() == 0);

for(Map.Entry<String, String> entry : privateUrls.entrySet()) {
for (Map.Entry<String, String> entry : privateUrls.entrySet()) {
String calendarUrl = "https://"+entry.getKey();
String signature = entry.getValue();

Expand All @@ -172,8 +173,6 @@ public void TestSingleAsyncPrivate() throws Exception {
assertTrue(timestamp.get() != null);
assertTrue(Arrays.equals(timestamp.get().getDigest() , digest));
}


}

@Test
Expand All @@ -200,18 +199,19 @@ public void TestMulti() throws Exception {
}

int count = 0;
for (final String calendarUrl : calendarsUrl) {

for (final String calendarUrl : calendarsUrl) {
try {
Optional<Timestamp> stamp = queue.take();
//timestamp.merge(stamp);
if(stamp.isPresent()) {

if (stamp.isPresent()) {
count++;
}

if (count >= m) {
break;
}

} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -220,14 +220,13 @@ public void TestMulti() throws Exception {
if (count < m) {
log.severe("Failed to create timestamp: requested " + String.valueOf(m) + " attestation" + ((m > 1) ? "s" : "") + " but received only " + String.valueOf(count));
}

assertFalse(count < m);

//shut down the executor service now
executor.shutdown();
}



@Test
public void TestMultiWithInvalidCalendar() throws Exception {

Expand All @@ -245,25 +244,25 @@ public void TestMultiWithInvalidCalendar() throws Exception {
CalendarAsyncSubmit task = new CalendarAsyncSubmit(calendarUrl, digest);
task.setQueue(queue);
executor.submit(task);

} catch (Exception e) {
e.printStackTrace();
}
}

int count = 0;
for (final String calendarUrl : calendarsUrl) {

for (final String calendarUrl : calendarsUrl) {
try {
Optional<Timestamp> stamp = queue.take();
//timestamp.merge(stamp);

if(stamp.isPresent()) {
count++;
}

if (count >= m) {
break;
}

} catch (InterruptedException e) {
e.printStackTrace();
}
Expand All @@ -272,13 +271,13 @@ public void TestMultiWithInvalidCalendar() throws Exception {
if (count < m) {
log.severe("Failed to create timestamp: requested " + String.valueOf(m) + " attestation" + ((m > 1) ? "s" : "") + " but received only " + String.valueOf(count));
}

assertFalse(count < m);

//shut down the executor service now
executor.shutdown();
}


@Test
public void rfc6979() {
BigInteger privKey = new BigInteger("235236247357325473457345");
Expand All @@ -287,5 +286,4 @@ public void rfc6979() {
System.out.println(a);
assertTrue(a.equals("IBY7a75Ygps/o1BqTQ0OpFL+a8WHfd9jNO/8820ST0gyQ0SAuIWKm8/M90aG1G40oJvjrlcoiKngKAYYsJS6I0s="));
}

}
3 changes: 2 additions & 1 deletion src/test/java/com/eternitywall/TestLongReceipt.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public void testException() throws Exception {
final byte[] bytes = DatatypeConverter.parseBase64Binary(el);
StreamDeserializationContext ctx = new StreamDeserializationContext(bytes);
Timestamp timestamp = Timestamp.deserialize(ctx, digestByte);

try {
root.merge(timestamp);
} catch (Exception e) {
assertTrue(false);
}
}

StreamSerializationContext streamSerializationContext = new StreamSerializationContext();
root.serialize(streamSerializationContext);
assertTrue(true);
Expand All @@ -48,6 +50,5 @@ public void testException() throws Exception {
Timestamp timestamp = Timestamp.deserialize(ctx2, digestByte);
assertNotNull(timestamp);
//System.out.println(timestamp.strTree(2));

}
}
7 changes: 0 additions & 7 deletions src/test/java/com/eternitywall/TestMultiInsight.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package com.eternitywall;

import com.eternitywall.ots.BlockHeader;
import com.eternitywall.ots.MultiInsight;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
* Created by casatta on 07/03/17.
*/
public class TestMultiInsight {

@Test
Expand Down
Loading

0 comments on commit 763f904

Please sign in to comment.