forked from Qortal-Forker/qortal
DB.rebuild() to shutdown and delete database, then rebuild it (schema only). DB.callIdentity() to fetch value of IDENTITY column after an INSERT. Added basic Asset class. Added TODOs to Account. BULK REFACTOR to rename "generation target" back to "generating balance" and "generation signature" back to "generator signature" to ease compatibility with old QORA for now. (Maybe change again in the future if we change from PoS). Added support for Block's totalFees which is either loaded from DB or recalculated as transactions are added to the block. Also in Block: * We can't assume generator's public key is the correct length in case we encounter the GenesisAccount's special 8-byte public key. Fix applied to Block's ResultSet-based constructor. * Forgot to save "signature" column! * Initial version of Block.process() * Block constructor takes transactionsSignature too now Added BlockChain startup/init/validation method to determine whether to (re)build blockchain. Rebuilding blockchain involves rebuilding DB schema, processing GenesisBlock and adding QORA asset. Added some initial GenesisTranaction.process() code: GenesisTransactions are saved but recipient's balance/reference not yet updated. Fix incorrect placeholder bind value for "creation" timestamp in Transaction.save(). Moved incremental database schema updates out from "updates" unit test into DatabaseUpdates class. All unit tests work at this point!
70 lines
2.5 KiB
Java
70 lines
2.5 KiB
Java
package test;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import org.junit.Test;
|
|
|
|
import qora.block.BlockChain;
|
|
import qora.transaction.PaymentTransaction;
|
|
import qora.transaction.Transaction;
|
|
import qora.transaction.TransactionFactory;
|
|
import utils.Base58;
|
|
|
|
public class load extends common {
|
|
|
|
@Test
|
|
public void testLoadPaymentTransaction() throws SQLException {
|
|
assertTrue("Migrate old database to at least block 49778 before running this test", BlockChain.getHeight() >= 49778);
|
|
|
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
|
byte[] signature = Base58.decode(signature58);
|
|
|
|
PaymentTransaction paymentTransaction = PaymentTransaction.fromSignature(signature);
|
|
|
|
assertNotNull(paymentTransaction);
|
|
assertEquals(paymentTransaction.getSender().getAddress(), "QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E");
|
|
assertEquals(paymentTransaction.getCreator().getAddress(), "QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E");
|
|
assertEquals(paymentTransaction.getRecipient().getAddress(), "QZsv8vbJ6QfrBNba4LMp5UtHhAzhrxvVUU");
|
|
assertEquals(paymentTransaction.getTimestamp(), 1416209264000L);
|
|
assertEquals(Base58.encode(paymentTransaction.getReference()),
|
|
"31dC6kHHBeG5vYb8LMaZDjLEmhc9kQB2VUApVd8xWncSRiXu7yMejdprjYFMP2rUnzZxWd4KJhkq6LsV7rQvU1kY");
|
|
}
|
|
|
|
@Test
|
|
public void testLoadFactory() throws SQLException {
|
|
assertTrue("Migrate old database to at least block 49778 before running this test", BlockChain.getHeight() >= 49778);
|
|
|
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
|
byte[] signature = Base58.decode(signature58);
|
|
|
|
while (true) {
|
|
Transaction transaction = TransactionFactory.fromSignature(signature);
|
|
if (transaction == null)
|
|
break;
|
|
|
|
PaymentTransaction payment = (PaymentTransaction) transaction;
|
|
System.out
|
|
.println(payment.getSender().getAddress() + " sent " + payment.getAmount().toString() + " QORA to " + payment.getRecipient().getAddress());
|
|
|
|
signature = payment.getReference();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testLoadNonexistentTransaction() throws SQLException {
|
|
String signature58 = "1111222233334444";
|
|
byte[] signature = Base58.decode(signature58);
|
|
|
|
PaymentTransaction payment = PaymentTransaction.fromSignature(signature);
|
|
|
|
if (payment != null) {
|
|
System.out
|
|
.println(payment.getSender().getAddress() + " sent " + payment.getAmount().toString() + " QORA to " + payment.getRecipient().getAddress());
|
|
fail();
|
|
}
|
|
}
|
|
|
|
}
|