mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-11 17:55:50 +00:00
Renamed and converted unit tests **COMPILES OK BUT UNTESTED**
Let the debugging begin!
This commit is contained in:
parent
f2d7a3d0cd
commit
fc3e951e8e
@ -1,5 +1,3 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@ -24,24 +22,25 @@ import org.json.simple.JSONArray;
|
|||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.google.common.hash.HashCode;
|
import com.google.common.hash.HashCode;
|
||||||
import com.google.common.io.CharStreams;
|
import com.google.common.io.CharStreams;
|
||||||
|
|
||||||
import database.DB;
|
import qora.transaction.Transaction;
|
||||||
import qora.block.BlockChain;
|
import repository.BlockRepository;
|
||||||
import qora.transaction.TransactionHandler;
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
import utils.Base58;
|
import utils.Base58;
|
||||||
|
|
||||||
public class migrate extends common {
|
public class migrate {
|
||||||
|
|
||||||
private static final String GENESIS_ADDRESS = "QfGMeDQQUQePMpAmfLBJzgqyrM35RWxHGD";
|
private static final String GENESIS_ADDRESS = "QfGMeDQQUQePMpAmfLBJzgqyrM35RWxHGD";
|
||||||
private static final byte[] GENESIS_PUBLICKEY = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1 };
|
private static final byte[] GENESIS_PUBLICKEY = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||||
|
|
||||||
private static Map<String, byte[]> publicKeyByAddress = new HashMap<String, byte[]>();
|
private static Map<String, byte[]> publicKeyByAddress = new HashMap<String, byte[]>();
|
||||||
|
|
||||||
public Object fetchBlockJSON(int height) throws IOException {
|
public static Object fetchBlockJSON(int height) throws IOException {
|
||||||
InputStream is;
|
InputStream is;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -60,7 +59,7 @@ public class migrate extends common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] addressToPublicKey(String address) throws IOException {
|
public static byte[] addressToPublicKey(String address) throws IOException {
|
||||||
byte[] cachedPublicKey = publicKeyByAddress.get(address);
|
byte[] cachedPublicKey = publicKeyByAddress.get(address);
|
||||||
if (cachedPublicKey != null)
|
if (cachedPublicKey != null)
|
||||||
return cachedPublicKey;
|
return cachedPublicKey;
|
||||||
@ -78,7 +77,7 @@ public class migrate extends common {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String formatWithPlaceholders(String... columns) {
|
public static String formatWithPlaceholders(String... columns) {
|
||||||
String[] placeholders = new String[columns.length];
|
String[] placeholders = new String[columns.length];
|
||||||
Arrays.setAll(placeholders, (int i) -> "?");
|
Arrays.setAll(placeholders, (int i) -> "?");
|
||||||
|
|
||||||
@ -91,14 +90,18 @@ public class migrate extends common {
|
|||||||
return output.toString();
|
return output.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
public static void main(String args[]) throws SQLException, DataException, IOException {
|
||||||
public void testMigration() throws SQLException, IOException {
|
|
||||||
// Genesis public key
|
// Genesis public key
|
||||||
publicKeyByAddress.put(GENESIS_ADDRESS, GENESIS_PUBLICKEY);
|
publicKeyByAddress.put(GENESIS_ADDRESS, GENESIS_PUBLICKEY);
|
||||||
// Some other public keys for addresses that have never created a transaction
|
// Some other public keys for addresses that have never created a transaction
|
||||||
publicKeyByAddress.put("QcDLhirHkSbR4TLYeShLzHw61B8UGTFusk", Base58.decode("HP58uWRBae654ze6ysmdyGv3qaDrr9BEk6cHv4WuiF7d"));
|
publicKeyByAddress.put("QcDLhirHkSbR4TLYeShLzHw61B8UGTFusk", Base58.decode("HP58uWRBae654ze6ysmdyGv3qaDrr9BEk6cHv4WuiF7d"));
|
||||||
|
|
||||||
Connection c = DB.getConnection();
|
// TODO convert to repository
|
||||||
|
Connection c = null;
|
||||||
|
|
||||||
|
test.Common.setRepository();
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
BlockRepository blockRepository = repository.getBlockRepository();
|
||||||
|
|
||||||
PreparedStatement blocksPStmt = c
|
PreparedStatement blocksPStmt = c
|
||||||
.prepareStatement("INSERT INTO Blocks " + formatWithPlaceholders("signature", "version", "reference", "transaction_count", "total_fees",
|
.prepareStatement("INSERT INTO Blocks " + formatWithPlaceholders("signature", "version", "reference", "transaction_count", "total_fees",
|
||||||
@ -150,7 +153,7 @@ public class migrate extends common {
|
|||||||
PreparedStatement blockTxPStmt = c
|
PreparedStatement blockTxPStmt = c
|
||||||
.prepareStatement("INSERT INTO BlockTransactions " + formatWithPlaceholders("block_signature", "sequence", "transaction_signature"));
|
.prepareStatement("INSERT INTO BlockTransactions " + formatWithPlaceholders("block_signature", "sequence", "transaction_signature"));
|
||||||
|
|
||||||
int height = BlockChain.getHeight() + 1;
|
int height = blockRepository.getBlockchainHeight() + 1;
|
||||||
byte[] milestone_block = null;
|
byte[] milestone_block = null;
|
||||||
System.out.println("Starting migration from block height " + height);
|
System.out.println("Starting migration from block height " + height);
|
||||||
|
|
||||||
@ -164,8 +167,6 @@ public class migrate extends common {
|
|||||||
|
|
||||||
JSONArray transactions = (JSONArray) json.get("transactions");
|
JSONArray transactions = (JSONArray) json.get("transactions");
|
||||||
|
|
||||||
DB.startTransaction();
|
|
||||||
|
|
||||||
// Blocks:
|
// Blocks:
|
||||||
// signature, version, reference, transaction_count, total_fees, transactions_signature, height, generation, generating_balance, generator,
|
// signature, version, reference, transaction_count, total_fees, transactions_signature, height, generation, generating_balance, generator,
|
||||||
// generator_signature
|
// generator_signature
|
||||||
@ -561,7 +562,7 @@ public class migrate extends common {
|
|||||||
}
|
}
|
||||||
|
|
||||||
messagePStmt.setBinaryStream(1, new ByteArrayInputStream(txSignature));
|
messagePStmt.setBinaryStream(1, new ByteArrayInputStream(txSignature));
|
||||||
messagePStmt.setInt(2, TransactionHandler.getVersionByTimestamp(transactionTimestamp));
|
messagePStmt.setInt(2, Transaction.getVersionByTimestamp(transactionTimestamp));
|
||||||
messagePStmt.setBinaryStream(3, new ByteArrayInputStream(addressToPublicKey((String) transaction.get("creator"))));
|
messagePStmt.setBinaryStream(3, new ByteArrayInputStream(addressToPublicKey((String) transaction.get("creator"))));
|
||||||
messagePStmt.setString(4, (String) transaction.get("recipient"));
|
messagePStmt.setString(4, (String) transaction.get("recipient"));
|
||||||
messagePStmt.setBoolean(5, isText);
|
messagePStmt.setBoolean(5, isText);
|
||||||
@ -590,7 +591,7 @@ public class migrate extends common {
|
|||||||
blockTxPStmt.execute();
|
blockTxPStmt.execute();
|
||||||
blockTxPStmt.clearParameters();
|
blockTxPStmt.clearParameters();
|
||||||
|
|
||||||
DB.commit();
|
repository.saveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
// new milestone block every 500 blocks?
|
// new milestone block every 500 blocks?
|
||||||
@ -600,7 +601,7 @@ public class migrate extends common {
|
|||||||
++height;
|
++height;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Migration finished with new blockchain height " + BlockChain.getHeight());
|
System.out.println("Migration finished with new blockchain height " + blockRepository.getBlockchainHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -82,6 +82,15 @@ public class Block {
|
|||||||
this.generator = new PublicKeyAccount(repository, blockData.getGeneratorPublicKey());
|
this.generator = new PublicKeyAccount(repository, blockData.getGeneratorPublicKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For creating a new block
|
||||||
|
public Block(Repository repository, int version, byte[] reference, long timestamp, BigDecimal generatingBalance, PrivateKeyAccount generator,
|
||||||
|
byte[] atBytes, BigDecimal atFees) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.generator = generator;
|
||||||
|
this.blockData = new BlockData(version, reference, 0, BigDecimal.ZERO.setScale(8), null, 0, timestamp, generatingBalance, generator.getPublicKey(),
|
||||||
|
null, atBytes, atFees);
|
||||||
|
}
|
||||||
|
|
||||||
// Getters/setters
|
// Getters/setters
|
||||||
|
|
||||||
public BlockData getBlockData() {
|
public BlockData getBlockData() {
|
||||||
|
121
src/test/BlockTests.java
Normal file
121
src/test/BlockTests.java
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.block.BlockData;
|
||||||
|
import data.transaction.TransactionData;
|
||||||
|
import qora.block.Block;
|
||||||
|
import qora.block.GenesisBlock;
|
||||||
|
import qora.transaction.Transaction;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import transform.TransformationException;
|
||||||
|
import transform.block.BlockTransformer;
|
||||||
|
|
||||||
|
public class BlockTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenesisBlockTransactions() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
GenesisBlock block = new GenesisBlock(repository);
|
||||||
|
|
||||||
|
assertNotNull(block);
|
||||||
|
assertTrue(block.isSignatureValid());
|
||||||
|
// only true if blockchain is empty
|
||||||
|
// assertTrue(block.isValid(connection));
|
||||||
|
|
||||||
|
List<Transaction> transactions = block.getTransactions();
|
||||||
|
assertNotNull(transactions);
|
||||||
|
|
||||||
|
for (Transaction transaction : transactions) {
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
TransactionData transactionData = transaction.getTransactionData();
|
||||||
|
|
||||||
|
assertEquals(Transaction.TransactionType.GENESIS, transactionData.getType());
|
||||||
|
assertTrue(transactionData.getFee().compareTo(BigDecimal.ZERO) == 0);
|
||||||
|
assertNull(transactionData.getReference());
|
||||||
|
assertTrue(transaction.isSignatureValid());
|
||||||
|
assertEquals(Transaction.ValidationResult.OK, transaction.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to load first transaction directly from database
|
||||||
|
TransactionData transactionData = repository.getTransactionRepository().fromSignature(transactions.get(0).getTransactionData().getSignature());
|
||||||
|
assertNotNull(transactionData);
|
||||||
|
|
||||||
|
assertEquals(Transaction.TransactionType.GENESIS, transactionData.getType());
|
||||||
|
assertTrue(transactionData.getFee().compareTo(BigDecimal.ZERO) == 0);
|
||||||
|
assertNull(transactionData.getReference());
|
||||||
|
|
||||||
|
Transaction transaction = Transaction.fromData(repository, transactionData);
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
assertTrue(transaction.isSignatureValid());
|
||||||
|
assertEquals(Transaction.ValidationResult.OK, transaction.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlockPaymentTransactions() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
|
||||||
|
// Block 949 has lots of varied transactions
|
||||||
|
// Blocks 390 & 754 have only payment transactions
|
||||||
|
BlockData blockData = repository.getBlockRepository().fromHeight(754);
|
||||||
|
assertNotNull("Block 754 is required for this test", blockData);
|
||||||
|
|
||||||
|
Block block = new Block(repository, blockData);
|
||||||
|
assertTrue(block.isSignatureValid());
|
||||||
|
|
||||||
|
List<Transaction> transactions = block.getTransactions();
|
||||||
|
assertNotNull(transactions);
|
||||||
|
|
||||||
|
for (Transaction transaction : transactions) {
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
TransactionData transactionData = transaction.getTransactionData();
|
||||||
|
|
||||||
|
assertEquals(Transaction.TransactionType.PAYMENT, transactionData.getType());
|
||||||
|
assertFalse(transactionData.getFee().compareTo(BigDecimal.ZERO) == 0);
|
||||||
|
assertNotNull(transactionData.getReference());
|
||||||
|
|
||||||
|
assertTrue(transaction.isSignatureValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to load first transaction directly from database
|
||||||
|
TransactionData transactionData = repository.getTransactionRepository().fromSignature(transactions.get(0).getTransactionData().getSignature());
|
||||||
|
assertNotNull(transactionData);
|
||||||
|
|
||||||
|
assertEquals(Transaction.TransactionType.GENESIS, transactionData.getType());
|
||||||
|
assertTrue(transactionData.getFee().compareTo(BigDecimal.ZERO) == 0);
|
||||||
|
assertNull(transactionData.getReference());
|
||||||
|
|
||||||
|
Transaction transaction = Transaction.fromData(repository, transactionData);
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
assertTrue(transaction.isSignatureValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBlockSerialization() throws DataException, TransformationException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
|
||||||
|
// Block 949 has lots of varied transactions
|
||||||
|
// Blocks 390 & 754 have only payment transactions
|
||||||
|
BlockData blockData = repository.getBlockRepository().fromHeight(754);
|
||||||
|
assertNotNull("Block 754 is required for this test", blockData);
|
||||||
|
|
||||||
|
Block block = new Block(repository, blockData);
|
||||||
|
assertTrue(block.isSignatureValid());
|
||||||
|
|
||||||
|
byte[] bytes = BlockTransformer.toBytes(block);
|
||||||
|
|
||||||
|
assertEquals(BlockTransformer.getDataLength(block), bytes.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
src/test/BlockchainTests.java
Normal file
15
src/test/BlockchainTests.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import qora.block.BlockChain;
|
||||||
|
import repository.DataException;
|
||||||
|
|
||||||
|
public class BlockchainTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidateOrRebuild() throws DataException {
|
||||||
|
BlockChain.validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
27
src/test/Common.java
Normal file
27
src/test/Common.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.RepositoryFactory;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import repository.hsqldb.HSQLDBRepositoryFactory;
|
||||||
|
|
||||||
|
public class Common {
|
||||||
|
|
||||||
|
public static final String connectionUrl = "jdbc:hsqldb:file:db/test;create=true;close_result=true;sql.strict_exec=true;sql.enforce_names=true;sql.syntax_mys=true";
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setRepository() throws DataException {
|
||||||
|
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(connectionUrl);
|
||||||
|
|
||||||
|
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void closeRepository() throws DataException {
|
||||||
|
// Currently a no-op?
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -8,7 +8,7 @@ import com.google.common.hash.HashCode;
|
|||||||
|
|
||||||
import qora.crypto.Crypto;
|
import qora.crypto.Crypto;
|
||||||
|
|
||||||
public class crypto {
|
public class CryptoTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCryptoDigest() {
|
public void testCryptoDigest() {
|
@ -5,7 +5,7 @@ import static org.junit.Assert.*;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import qora.block.Block;
|
import qora.block.Block;
|
||||||
|
|
||||||
public class exceptions {
|
public class ExceptionTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proof of concept for block processing throwing transaction-related SQLException rather than savepoint-rollback-related SQLException.
|
* Proof of concept for block processing throwing transaction-related SQLException rather than savepoint-rollback-related SQLException.
|
89
src/test/LoadTests.java
Normal file
89
src/test/LoadTests.java
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.transaction.PaymentTransactionData;
|
||||||
|
import data.transaction.TransactionData;
|
||||||
|
import qora.account.PublicKeyAccount;
|
||||||
|
import qora.transaction.Transaction.TransactionType;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import repository.TransactionRepository;
|
||||||
|
import utils.Base58;
|
||||||
|
|
||||||
|
public class LoadTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadPaymentTransaction() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
TransactionRepository transactionRepository = repository.getTransactionRepository();
|
||||||
|
|
||||||
|
assertTrue("Migrate from old database to at least block 49778 before running this test",
|
||||||
|
repository.getBlockRepository().getBlockchainHeight() >= 49778);
|
||||||
|
|
||||||
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
||||||
|
byte[] signature = Base58.decode(signature58);
|
||||||
|
|
||||||
|
TransactionData transactionData = transactionRepository.fromSignature(signature);
|
||||||
|
assertNotNull("Transaction data not loaded from repository", transactionData);
|
||||||
|
assertEquals("Transaction data not PAYMENT type", TransactionType.PAYMENT, transactionData.getType().value);
|
||||||
|
assertEquals(PublicKeyAccount.getAddress(transactionData.getCreatorPublicKey()), "QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E");
|
||||||
|
|
||||||
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) transactionData;
|
||||||
|
|
||||||
|
assertNotNull(paymentTransactionData);
|
||||||
|
assertEquals(PublicKeyAccount.getAddress(paymentTransactionData.getSenderPublicKey()), "QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E");
|
||||||
|
assertEquals(paymentTransactionData.getRecipient(), "QZsv8vbJ6QfrBNba4LMp5UtHhAzhrxvVUU");
|
||||||
|
assertEquals(paymentTransactionData.getTimestamp(), 1416209264000L);
|
||||||
|
assertEquals(Base58.encode(paymentTransactionData.getReference()),
|
||||||
|
"31dC6kHHBeG5vYb8LMaZDjLEmhc9kQB2VUApVd8xWncSRiXu7yMejdprjYFMP2rUnzZxWd4KJhkq6LsV7rQvU1kY");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadFactory() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
TransactionRepository transactionRepository = repository.getTransactionRepository();
|
||||||
|
|
||||||
|
assertTrue("Migrate from old database to at least block 49778 before running this test",
|
||||||
|
repository.getBlockRepository().getBlockchainHeight() >= 49778);
|
||||||
|
|
||||||
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
||||||
|
byte[] signature = Base58.decode(signature58);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
TransactionData transactionData = transactionRepository.fromSignature(signature);
|
||||||
|
if (transactionData == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) transactionData;
|
||||||
|
System.out.println(PublicKeyAccount.getAddress(paymentTransactionData.getSenderPublicKey()) + " sent " + paymentTransactionData.getAmount()
|
||||||
|
+ " QORA to " + paymentTransactionData.getRecipient());
|
||||||
|
|
||||||
|
signature = paymentTransactionData.getReference();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadNonexistentTransaction() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
TransactionRepository transactionRepository = repository.getTransactionRepository();
|
||||||
|
|
||||||
|
String signature58 = "1111222233334444";
|
||||||
|
byte[] signature = Base58.decode(signature58);
|
||||||
|
|
||||||
|
TransactionData transactionData = transactionRepository.fromSignature(signature);
|
||||||
|
|
||||||
|
if (transactionData != null) {
|
||||||
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) transactionData;
|
||||||
|
|
||||||
|
System.out.println(PublicKeyAccount.getAddress(paymentTransactionData.getSenderPublicKey()) + " sent " + paymentTransactionData.getAmount()
|
||||||
|
+ " QORA to " + paymentTransactionData.getRecipient());
|
||||||
|
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
src/test/NavigationTests.java
Normal file
43
src/test/NavigationTests.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.block.BlockData;
|
||||||
|
import data.transaction.TransactionData;
|
||||||
|
import qora.transaction.Transaction.TransactionType;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import repository.TransactionRepository;
|
||||||
|
import utils.Base58;
|
||||||
|
|
||||||
|
public class NavigationTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNavigateFromTransactionToBlock() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
TransactionRepository transactionRepository = repository.getTransactionRepository();
|
||||||
|
|
||||||
|
assertTrue("Migrate from old database to at least block 49778 before running this test",
|
||||||
|
repository.getBlockRepository().getBlockchainHeight() >= 49778);
|
||||||
|
|
||||||
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
||||||
|
byte[] signature = Base58.decode(signature58);
|
||||||
|
|
||||||
|
System.out.println("Navigating to Block from transaction " + signature58);
|
||||||
|
|
||||||
|
TransactionData transactionData = transactionRepository.fromSignature(signature);
|
||||||
|
assertNotNull("Transaction data not loaded from repository", transactionData);
|
||||||
|
assertEquals("Transaction data not PAYMENT type", TransactionType.PAYMENT, transactionData.getType().value);
|
||||||
|
|
||||||
|
BlockData blockData = transactionRepository.toBlock(transactionData);
|
||||||
|
assertNotNull("Block 49778 not loaded from database", blockData);
|
||||||
|
|
||||||
|
System.out.println("Block " + blockData.getHeight() + ", signature: " + Base58.encode(blockData.getSignature()));
|
||||||
|
|
||||||
|
assertEquals(49778, blockData.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
src/test/RepositoryTests.java
Normal file
44
src/test/RepositoryTests.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
|
||||||
|
public class RepositoryTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRepository() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
assertNotNull(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMultipleInstances() throws DataException {
|
||||||
|
int n_instances = 5;
|
||||||
|
Repository[] repositories = new Repository[n_instances];
|
||||||
|
|
||||||
|
for (int i = 0; i < n_instances; ++i) {
|
||||||
|
repositories[i] = RepositoryManager.getRepository();
|
||||||
|
assertNotNull(repositories[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAccessAfterCommit() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
assertNotNull(repository);
|
||||||
|
|
||||||
|
repository.saveChanges();
|
||||||
|
|
||||||
|
try {
|
||||||
|
repository.discardChanges();
|
||||||
|
fail();
|
||||||
|
} catch (DataException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
33
src/test/SaveTests.java
Normal file
33
src/test/SaveTests.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.transaction.PaymentTransactionData;
|
||||||
|
import qora.account.PublicKeyAccount;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import utils.Base58;
|
||||||
|
|
||||||
|
public class SaveTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSavePaymentTransaction() throws DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
|
||||||
|
String reference58 = "rrrr";
|
||||||
|
byte[] reference = Base58.decode(reference58);
|
||||||
|
String signature58 = "ssss";
|
||||||
|
byte[] signature = Base58.decode(signature58);
|
||||||
|
PublicKeyAccount sender = new PublicKeyAccount(repository, "Qsender".getBytes());
|
||||||
|
|
||||||
|
PaymentTransactionData paymentTransactionData = new PaymentTransactionData(sender.getPublicKey(), "Qrecipient", BigDecimal.valueOf(12345L),
|
||||||
|
BigDecimal.ONE, Instant.now().getEpochSecond(), reference, signature);
|
||||||
|
|
||||||
|
repository.getTransactionRepository().save(paymentTransactionData);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,42 +3,54 @@ package test;
|
|||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.block.BlockData;
|
||||||
import qora.account.PrivateKeyAccount;
|
import qora.account.PrivateKeyAccount;
|
||||||
import qora.block.Block;
|
import qora.block.Block;
|
||||||
import qora.block.GenesisBlock;
|
import qora.block.GenesisBlock;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
import utils.Base58;
|
import utils.Base58;
|
||||||
import utils.NTP;
|
import utils.NTP;
|
||||||
|
|
||||||
public class signatures extends common {
|
public class SignatureTests extends Common {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenesisBlockSignature() throws SQLException {
|
public void testGenesisBlockSignature() throws DataException {
|
||||||
String expected58 = "6pHMBFif7jXFG654joT8GPaymau1fMtaxacRyqSrnAwQMQDvqRuLpHpfFyqX4gWVvj4pF1mwQhFgqWAvjVvPJUjmBZQvL751dM9cEcQBTaUcxtNLuWZCVUAtbnWN9f7FsLppHhkPbxwpoodL3UJYRGt3EZrG17mhv1RJbmq8j6rr7Mk";
|
String expected58 = "6pHMBFif7jXFG654joT8GPaymau1fMtaxacRyqSrnAwQMQDvqRuLpHpfFyqX4gWVvj4pF1mwQhFgqWAvjVvPJUjmBZQvL751dM9cEcQBTaUcxtNLuWZCVUAtbnWN9f7FsLppHhkPbxwpoodL3UJYRGt3EZrG17mhv1RJbmq8j6rr7Mk";
|
||||||
|
|
||||||
GenesisBlock block = GenesisBlock.getInstance();
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
GenesisBlock block = new GenesisBlock(repository);
|
||||||
|
BlockData blockData = block.getBlockData();
|
||||||
|
|
||||||
System.out.println("Generator: " + block.getGenerator().getAddress() + ", generator signature: " + Base58.encode(block.getGeneratorSignature()));
|
System.out.println("Generator: " + block.getGenerator().getAddress() + ", generator signature: " + Base58.encode(blockData.getGeneratorSignature()));
|
||||||
|
|
||||||
assertEquals(expected58, Base58.encode(block.getSignature()));
|
assertEquals(expected58, Base58.encode(block.getSignature()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBlockSignature() throws SQLException {
|
public void testBlockSignature() throws DataException {
|
||||||
int version = 3;
|
int version = 3;
|
||||||
|
|
||||||
byte[] reference = Base58.decode(
|
byte[] reference = Base58.decode(
|
||||||
"BSfgEr6r1rXGGJCv8criR5NcBWfpHdJnm9x5unPwxvojEKCESv1wH1zJm7yvCeC48wshymYtARbHdUojbqWCCWW7h2UTc8g5oEx59C9M41dM7H48My8gVkcEZdxR1of3VgpE5UcowFp3kFC12hVcD9hUttJ2i2nZWMwprbFtUGyVv1U");
|
"BSfgEr6r1rXGGJCv8criR5NcBWfpHdJnm9x5unPwxvojEKCESv1wH1zJm7yvCeC48wshymYtARbHdUojbqWCCWW7h2UTc8g5oEx59C9M41dM7H48My8gVkcEZdxR1of3VgpE5UcowFp3kFC12hVcD9hUttJ2i2nZWMwprbFtUGyVv1U");
|
||||||
|
|
||||||
long timestamp = NTP.getTime() - 5000;
|
long timestamp = NTP.getTime() - 5000;
|
||||||
|
|
||||||
BigDecimal generatingBalance = BigDecimal.valueOf(10_000_000L).setScale(8);
|
BigDecimal generatingBalance = BigDecimal.valueOf(10_000_000L).setScale(8);
|
||||||
PrivateKeyAccount generator = new PrivateKeyAccount(
|
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
PrivateKeyAccount generator = new PrivateKeyAccount(repository,
|
||||||
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
|
new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 });
|
||||||
|
|
||||||
byte[] atBytes = null;
|
byte[] atBytes = null;
|
||||||
|
|
||||||
BigDecimal atFees = null;
|
BigDecimal atFees = null;
|
||||||
|
|
||||||
Block block = new Block(version, reference, timestamp, generatingBalance, generator, atBytes, atFees);
|
Block block = new Block(repository, version, reference, timestamp, generatingBalance, generator, atBytes, atFees);
|
||||||
|
|
||||||
block.calcGeneratorSignature();
|
block.calcGeneratorSignature();
|
||||||
block.calcTransactionsSignature();
|
block.calcTransactionsSignature();
|
86
src/test/TransactionTests.java
Normal file
86
src/test/TransactionTests.java
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import data.block.BlockData;
|
||||||
|
import data.transaction.GenesisTransactionData;
|
||||||
|
import data.transaction.TransactionData;
|
||||||
|
import qora.block.Block;
|
||||||
|
import qora.block.GenesisBlock;
|
||||||
|
import qora.transaction.GenesisTransaction;
|
||||||
|
import qora.transaction.Transaction;
|
||||||
|
import repository.DataException;
|
||||||
|
import repository.Repository;
|
||||||
|
import repository.RepositoryManager;
|
||||||
|
import transform.TransformationException;
|
||||||
|
import transform.transaction.TransactionTransformer;
|
||||||
|
|
||||||
|
public class TransactionTests extends Common {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenesisSerialization() throws TransformationException, DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
GenesisBlock block = new GenesisBlock(repository);
|
||||||
|
|
||||||
|
GenesisTransaction transaction = (GenesisTransaction) block.getTransactions().get(1);
|
||||||
|
assertNotNull(transaction);
|
||||||
|
|
||||||
|
GenesisTransactionData genesisTransactionData = (GenesisTransactionData) transaction.getTransactionData();
|
||||||
|
|
||||||
|
System.out.println(genesisTransactionData.getTimestamp() + ": " + genesisTransactionData.getRecipient() + " received "
|
||||||
|
+ genesisTransactionData.getAmount().toPlainString());
|
||||||
|
|
||||||
|
byte[] bytes = TransactionTransformer.toBytes(genesisTransactionData);
|
||||||
|
|
||||||
|
GenesisTransactionData parsedTransactionData = (GenesisTransactionData) TransactionTransformer.fromBytes(bytes);
|
||||||
|
|
||||||
|
System.out.println(parsedTransactionData.getTimestamp() + ": " + parsedTransactionData.getRecipient() + " received "
|
||||||
|
+ parsedTransactionData.getAmount().toPlainString());
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(genesisTransactionData.getSignature(), parsedTransactionData.getSignature()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testGenericSerialization(TransactionData transactionData) throws TransformationException {
|
||||||
|
assertNotNull(transactionData);
|
||||||
|
|
||||||
|
byte[] bytes = TransactionTransformer.toBytes(transactionData);
|
||||||
|
|
||||||
|
TransactionData parsedTransactionData = TransactionTransformer.fromBytes(bytes);
|
||||||
|
|
||||||
|
assertTrue(Arrays.equals(transactionData.getSignature(), parsedTransactionData.getSignature()));
|
||||||
|
|
||||||
|
assertEquals(TransactionTransformer.getDataLength(transactionData), bytes.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPaymentSerialization() throws TransformationException, DataException {
|
||||||
|
Repository repository = RepositoryManager.getRepository();
|
||||||
|
|
||||||
|
// Block 949 has lots of varied transactions
|
||||||
|
// Blocks 390 & 754 have only payment transactions
|
||||||
|
BlockData blockData = repository.getBlockRepository().fromHeight(754);
|
||||||
|
assertNotNull("Block 754 is required for this test", blockData);
|
||||||
|
|
||||||
|
Block block = new Block(repository, blockData);
|
||||||
|
assertTrue(block.isSignatureValid());
|
||||||
|
|
||||||
|
List<Transaction> transactions = block.getTransactions();
|
||||||
|
assertNotNull(transactions);
|
||||||
|
|
||||||
|
for (Transaction transaction : transactions)
|
||||||
|
testGenericSerialization(transaction.getTransactionData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMessageSerialization() throws SQLException, TransformationException {
|
||||||
|
// Message transactions went live block 99000
|
||||||
|
// Some transactions to be found in block 99001/2/5/6
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import qora.block.BlockChain;
|
|
||||||
|
|
||||||
public class blockchain extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRebuild() throws SQLException {
|
|
||||||
BlockChain.validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,89 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import qora.block.Block;
|
|
||||||
import qora.block.GenesisBlock;
|
|
||||||
import qora.transaction.TransactionHandler;
|
|
||||||
import qora.transaction.TransactionHandler;
|
|
||||||
|
|
||||||
public class blocks extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGenesisBlockTransactions() throws SQLException {
|
|
||||||
GenesisBlock block = GenesisBlock.getInstance();
|
|
||||||
assertNotNull(block);
|
|
||||||
assertTrue(block.isSignatureValid());
|
|
||||||
// only true if blockchain is empty
|
|
||||||
// assertTrue(block.isValid(connection));
|
|
||||||
|
|
||||||
List<TransactionHandler> transactions = block.getTransactions();
|
|
||||||
assertNotNull(transactions);
|
|
||||||
|
|
||||||
for (TransactionHandler transaction : transactions) {
|
|
||||||
assertNotNull(transaction);
|
|
||||||
assertEquals(Transaction.TransactionHandler.GENESIS, transaction.getType());
|
|
||||||
assertTrue(transaction.getFee().compareTo(BigDecimal.ZERO) == 0);
|
|
||||||
assertNull(transaction.getReference());
|
|
||||||
assertTrue(transaction.isSignatureValid());
|
|
||||||
assertEquals(TransactionHandler.ValidationResult.OK, transaction.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to load first transaction directly from database
|
|
||||||
TransactionHandler transaction = TransactionFactory.fromSignature(transactions.get(0).getSignature());
|
|
||||||
assertNotNull(transaction);
|
|
||||||
assertEquals(Transaction.TransactionHandler.GENESIS, transaction.getType());
|
|
||||||
assertTrue(transaction.getFee().compareTo(BigDecimal.ZERO) == 0);
|
|
||||||
assertNull(transaction.getReference());
|
|
||||||
assertTrue(transaction.isSignatureValid());
|
|
||||||
assertEquals(TransactionHandler.ValidationResult.OK, transaction.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBlockPaymentTransactions() throws SQLException {
|
|
||||||
// Block 949 has lots of varied transactions
|
|
||||||
// Blocks 390 & 754 have only payment transactions
|
|
||||||
Block block = Block.fromHeight(754);
|
|
||||||
assertNotNull("Block 754 is required for this test", block);
|
|
||||||
assertTrue(block.isSignatureValid());
|
|
||||||
|
|
||||||
List<TransactionHandler> transactions = block.getTransactions();
|
|
||||||
assertNotNull(transactions);
|
|
||||||
|
|
||||||
for (TransactionHandler transaction : transactions) {
|
|
||||||
assertNotNull(transaction);
|
|
||||||
assertEquals(Transaction.TransactionHandler.PAYMENT, transaction.getType());
|
|
||||||
assertFalse(transaction.getFee().compareTo(BigDecimal.ZERO) == 0);
|
|
||||||
assertNotNull(transaction.getReference());
|
|
||||||
assertTrue(transaction.isSignatureValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to load first transaction directly from database
|
|
||||||
TransactionHandler transaction = TransactionFactory.fromSignature(transactions.get(0).getSignature());
|
|
||||||
assertNotNull(transaction);
|
|
||||||
assertEquals(Transaction.TransactionHandler.PAYMENT, transaction.getType());
|
|
||||||
assertFalse(transaction.getFee().compareTo(BigDecimal.ZERO) == 0);
|
|
||||||
assertNotNull(transaction.getReference());
|
|
||||||
assertTrue(transaction.isSignatureValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBlockSerialization() throws SQLException {
|
|
||||||
// Block 949 has lots of varied transactions
|
|
||||||
// Blocks 390 & 754 have only payment transactions
|
|
||||||
Block block = Block.fromHeight(754);
|
|
||||||
assertNotNull("Block 754 is required for this test", block);
|
|
||||||
assertTrue(block.isSignatureValid());
|
|
||||||
|
|
||||||
byte[] bytes = block.toBytes();
|
|
||||||
|
|
||||||
assertEquals(block.getDataLength(), bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
|
|
||||||
import database.DB;
|
|
||||||
import database.DatabaseUpdates;
|
|
||||||
|
|
||||||
public class common {
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setConnection() throws SQLException {
|
|
||||||
DB.setUrl("jdbc:hsqldb:file:db/test;create=true;close_result=true;sql.strict_exec=true;sql.enforce_names=true;sql.syntax_mys=true");
|
|
||||||
DB.open();
|
|
||||||
|
|
||||||
// Create/update database schema
|
|
||||||
DatabaseUpdates.updateDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void closeDatabase() throws SQLException {
|
|
||||||
DB.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,54 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import database.DB;
|
|
||||||
|
|
||||||
public class connections extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testConnection() {
|
|
||||||
Connection connection = DB.getConnection();
|
|
||||||
assertNotNull(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSimultaneousConnections() {
|
|
||||||
// First connection is the thread-local one
|
|
||||||
Connection connection = DB.getConnection();
|
|
||||||
assertNotNull(connection);
|
|
||||||
|
|
||||||
int n_connections = 5;
|
|
||||||
Connection[] connections = new Connection[n_connections];
|
|
||||||
|
|
||||||
for (int i = 0; i < n_connections; ++i) {
|
|
||||||
connections[i] = DB.getConnection();
|
|
||||||
assertEquals(connection, connections[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testConnectionAfterShutdown() {
|
|
||||||
try {
|
|
||||||
DB.shutdown();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
DB.open();
|
|
||||||
Connection connection = DB.getConnection();
|
|
||||||
assertNotNull(connection);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
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.TransactionHandler;
|
|
||||||
import qora.transaction.TransactionHandler;
|
|
||||||
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) {
|
|
||||||
TransactionHandler 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import qora.block.Block;
|
|
||||||
import qora.block.BlockChain;
|
|
||||||
import qora.transaction.PaymentTransaction;
|
|
||||||
import utils.Base58;
|
|
||||||
|
|
||||||
public class navigation extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNavigateFromTransactionToBlock() 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);
|
|
||||||
|
|
||||||
System.out.println("Navigating to Block from transaction " + signature58);
|
|
||||||
|
|
||||||
PaymentTransaction paymentTransaction = PaymentTransaction.fromSignature(signature);
|
|
||||||
assertNotNull("Payment transaction not loaded from database", paymentTransaction);
|
|
||||||
|
|
||||||
Block block = paymentTransaction.getBlock();
|
|
||||||
assertNotNull("Block 49778 not loaded from database", block);
|
|
||||||
|
|
||||||
System.out.println("Block " + block.getHeight() + ", signature: " + Base58.encode(block.getSignature()));
|
|
||||||
|
|
||||||
assertEquals(49778, block.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import qora.account.PublicKeyAccount;
|
|
||||||
import qora.transaction.PaymentTransaction;
|
|
||||||
import utils.Base58;
|
|
||||||
|
|
||||||
public class save extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSavePaymentTransaction() throws SQLException {
|
|
||||||
String reference58 = "rrrr";
|
|
||||||
byte[] reference = Base58.decode(reference58);
|
|
||||||
String signature58 = "ssss";
|
|
||||||
byte[] signature = Base58.decode(signature58);
|
|
||||||
PublicKeyAccount sender = new PublicKeyAccount("Qsender".getBytes());
|
|
||||||
|
|
||||||
PaymentTransaction paymentTransaction = new PaymentTransaction(sender, "Qrecipient", BigDecimal.valueOf(12345L), BigDecimal.ONE,
|
|
||||||
Instant.now().getEpochSecond(), reference, signature);
|
|
||||||
|
|
||||||
paymentTransaction.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import qora.block.Block;
|
|
||||||
import qora.block.GenesisBlock;
|
|
||||||
import qora.transaction.GenesisTransaction;
|
|
||||||
import qora.transaction.TransactionHandler;
|
|
||||||
import transform.TransformationException;
|
|
||||||
|
|
||||||
public class transactions extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGenesisSerialization() throws SQLException, TransformationException {
|
|
||||||
GenesisBlock block = GenesisBlock.getInstance();
|
|
||||||
|
|
||||||
GenesisTransaction transaction = (GenesisTransaction) block.getTransactions().get(1);
|
|
||||||
assertNotNull(transaction);
|
|
||||||
System.out
|
|
||||||
.println(transaction.getTimestamp() + ": " + transaction.getRecipient().getAddress() + " received " + transaction.getAmount().toPlainString());
|
|
||||||
|
|
||||||
byte[] bytes = transaction.toBytes();
|
|
||||||
|
|
||||||
GenesisTransaction parsedTransaction = (GenesisTransaction) TransactionHandler.parse(bytes);
|
|
||||||
System.out.println(parsedTransaction.getTimestamp() + ": " + parsedTransaction.getRecipient().getAddress() + " received "
|
|
||||||
+ parsedTransaction.getAmount().toPlainString());
|
|
||||||
|
|
||||||
assertTrue(Arrays.equals(transaction.getSignature(), parsedTransaction.getSignature()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGenericSerialization(TransactionHandler transaction) throws SQLException, TransformationException {
|
|
||||||
assertNotNull(transaction);
|
|
||||||
|
|
||||||
byte[] bytes = transaction.toBytes();
|
|
||||||
|
|
||||||
TransactionHandler parsedTransaction = TransactionHandler.parse(bytes);
|
|
||||||
|
|
||||||
assertTrue(Arrays.equals(transaction.getSignature(), parsedTransaction.getSignature()));
|
|
||||||
|
|
||||||
assertEquals(transaction.getDataLength(), bytes.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testPaymentSerialization() throws SQLException, TransformationException {
|
|
||||||
// Block 949 has lots of varied transactions
|
|
||||||
// Blocks 390 & 754 have only payment transactions
|
|
||||||
Block block = Block.fromHeight(754);
|
|
||||||
assertNotNull("Block 754 is required for this test", block);
|
|
||||||
assertTrue(block.isSignatureValid());
|
|
||||||
|
|
||||||
List<TransactionHandler> transactions = block.getTransactions();
|
|
||||||
assertNotNull(transactions);
|
|
||||||
|
|
||||||
for (TransactionHandler transaction : transactions)
|
|
||||||
testGenericSerialization(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMessageSerialization() throws SQLException, TransformationException {
|
|
||||||
// Message transactions went live block 99000
|
|
||||||
// Some transactions to be found in block 99001/2/5/6
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package test;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import database.DatabaseUpdates;
|
|
||||||
|
|
||||||
public class updates extends common {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testUpdates() throws SQLException {
|
|
||||||
DatabaseUpdates.updateDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user