qortal/src/test/navigation.java

55 lines
1.3 KiB
Java
Raw Normal View History

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
package test;
import static org.junit.Assert.*;
import java.sql.Connection;
import java.sql.SQLException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import qora.block.Block;
import qora.transaction.PaymentTransaction;
import utils.Base58;
public class navigation {
private static Connection connection;
@Before
public void connect() throws SQLException {
connection = common.getConnection();
}
@After
public void disconnect() {
try {
connection.createStatement().execute("SHUTDOWN");
} catch (SQLException e) {
fail();
}
}
@Test
public void testNavigateFromTransactionToBlock() throws SQLException {
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
byte[] signature = Base58.decode(signature58);
System.out.println("Navigating to Block from transaction " + signature58);
PaymentTransaction paymentTransaction = PaymentTransaction.fromSignature(connection, signature);
assertNotNull(paymentTransaction);
Block block = paymentTransaction.getBlock(connection);
assertNotNull(block);
System.out.println("Block " + block.getHeight() + ", signature: " + Base58.encode(block.getSignature()));
assertEquals(49778, block.getHeight());
}
}