2018-05-16 10:46:44 +00:00
|
|
|
package test;
|
|
|
|
|
2018-10-04 20:58:04 +00:00
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
2018-05-16 10:46:44 +00:00
|
|
|
|
|
|
|
import com.google.common.hash.HashCode;
|
|
|
|
|
|
|
|
import qora.crypto.Crypto;
|
|
|
|
|
2018-06-13 15:48:28 +00:00
|
|
|
public class CryptoTests {
|
2018-05-16 10:46:44 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCryptoDigest() {
|
|
|
|
byte[] input = HashCode.fromString("00").asBytes();
|
|
|
|
byte[] digest = Crypto.digest(input);
|
|
|
|
byte[] expected = HashCode.fromString("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d").asBytes();
|
2018-05-24 10:26:59 +00:00
|
|
|
|
2018-10-04 20:58:04 +00:00
|
|
|
assertArrayEquals(expected, digest);
|
2018-05-16 10:46:44 +00:00
|
|
|
}
|
2018-05-24 10:26:59 +00:00
|
|
|
|
2018-05-16 10:46:44 +00:00
|
|
|
@Test
|
|
|
|
public void testCryptoDoubleDigest() {
|
|
|
|
byte[] input = HashCode.fromString("00").asBytes();
|
|
|
|
byte[] digest = Crypto.doubleDigest(input);
|
|
|
|
byte[] expected = HashCode.fromString("1406e05881e299367766d313e26c05564ec91bf721d31726bd6e46e60689539a").asBytes();
|
2018-05-24 10:26:59 +00:00
|
|
|
|
2018-10-04 20:58:04 +00:00
|
|
|
assertArrayEquals(expected, digest);
|
2018-05-16 10:46:44 +00:00
|
|
|
}
|
2018-05-24 10:26:59 +00:00
|
|
|
|
2018-05-16 10:46:44 +00:00
|
|
|
@Test
|
|
|
|
public void testCryptoQoraAddress() {
|
|
|
|
byte[] publicKey = HashCode.fromString("775ada64a48a30b3bfc4f1db16bca512d4088704975a62bde78781ce0cba90d6").asBytes();
|
|
|
|
String expected = "QUD9y7NZqTtNwvSAUfewd7zKUGoVivVnTW";
|
2018-05-24 10:26:59 +00:00
|
|
|
|
2018-05-16 10:46:44 +00:00
|
|
|
assertEquals(expected, Crypto.toAddress(publicKey));
|
|
|
|
}
|
More work on Blocks, refactor to using public key in DB, etc.
Added brokenmd160.java as command-line support for producing broken MD160 digests.
Transactions, and sub-classes, now use/store public key instead of Qora address.
(Qora address can be derived from public key and they take up about the same space in DB).
Loads more JavaDoc for lovely mouseover help in Eclipse IDE.
Crypto.verify() and Crypto.sign() moved into PublicKeyAccount and PrivateKeyAccount
as appropriate.
Fleshed out Block, added BlockTransactions support.
Added TODO comments as Eclipse helpfully lists these for later implementation.
Made loading-from-DB-constructors protected/private and also throw NoDataFoundException
if unable to load from DB. Public methods can call respective constructors, catch the above
exception and return null if they like. Load-from-DB-constructors are to allow sub-classes
to load some data from sub-tables and super-class to load from another table.
(See PaymentTransaction/Transaction for example). Using public methods allows similar argument
lists but with different names,
e.g. DBObject.fromSignature(Connection, byte[]) and DBObject.fromReference(Connection, byte[])
Saving into DB maybe still a bit untidy. Looking for a way to close-couple column names with
place-holder bind Objects.
Less of:
connection.prepareStatement("INSERT INTO table (column) VALUES (?)")
DB.bindInsertPlaceholders(PreparedStatement, Object...);
More like:
DB.insertUpdate(String tableName, SomeMagicCloseCoupledPairs...)
called like:
DB.insertUpdate("Cats", {"name", "Tiddles"}, {"age", 3});
2018-05-17 16:39:55 +00:00
|
|
|
|
2018-05-16 10:46:44 +00:00
|
|
|
}
|