2018-06-13 15:48:28 +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-06-13 15:48:28 +00:00
|
|
|
|
|
|
|
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 {
|
2018-06-13 16:46:51 +00:00
|
|
|
try (final Repository repository = RepositoryManager.getRepository()) {
|
|
|
|
TransactionRepository transactionRepository = repository.getTransactionRepository();
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-10-04 20:58:04 +00:00
|
|
|
assertTrue(repository.getBlockRepository().getBlockchainHeight() >= 49778,
|
2018-12-03 13:12:52 +00:00
|
|
|
"Migrate from old database to at least block 49778 before running this test");
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-06-13 16:46:51 +00:00
|
|
|
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
|
|
|
byte[] signature = Base58.decode(signature58);
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-06-13 16:46:51 +00:00
|
|
|
System.out.println("Navigating to Block from transaction " + signature58);
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-06-13 16:46:51 +00:00
|
|
|
TransactionData transactionData = transactionRepository.fromSignature(signature);
|
2018-10-04 20:58:04 +00:00
|
|
|
assertNotNull(transactionData, "Transaction data not loaded from repository");
|
|
|
|
assertEquals(TransactionType.PAYMENT, transactionData.getType(), "Transaction data not PAYMENT type");
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-12-03 13:12:52 +00:00
|
|
|
int transactionHeight = transactionRepository.getHeightFromSignature(signature);
|
|
|
|
assertNotEquals(0, transactionHeight, "Transaction not found or transaction's block not found");
|
|
|
|
assertEquals(49778, transactionHeight, "Transaction's block height expected to be 49778");
|
2018-06-13 15:48:28 +00:00
|
|
|
|
2018-12-03 13:12:52 +00:00
|
|
|
BlockData blockData = repository.getBlockRepository().fromHeight(transactionHeight);
|
|
|
|
assertNotNull(blockData, "Block 49778 not loaded from database");
|
2018-06-13 16:46:51 +00:00
|
|
|
System.out.println("Block " + blockData.getHeight() + ", signature: " + Base58.encode(blockData.getSignature()));
|
2018-06-13 15:48:28 +00:00
|
|
|
|
Finally syncs with qora1 chain!
ATData no longer needs deploySignature as a link back to DeployATTransaction,
but does need creator and creation [timestamp].
"creation" is critical for ordering ATs when creating/validating blocks.
Similar changes to ATStateData, adding creation, stateHash (for quicker
comparison with blocks received over the network), and fees incurred
by running AT on that block.
Also added more explicit constructors for different scenarios.
BlockData upgraded from simplistic "atBytes" to use ATStateData (above)
which has details on ATs run for that block, fees incurred, and a hash
of the AT's state. atCount added to keep track of how many ATs ran.
ATTransactions essentially reuse the GenesisAccount's publickey as
creator/sender as they're brought into existence by the Qora code
rather than an end user. ATTransactionData updated to reflect this
and the AT's address used as a "sender" field.
Account tidied up with respect to CIYAM ATs and setConfirmedBalance
ensures there is a corresponding record in Accounts (DB table).
Account, and subclasses, don't need "throws DataException" on
constructor any more.
Fixed bug in Asset Order matching where the matching engine
would give up after first potential match instead of trying others.
Lots more work on CIYAM AT, albeit mainly blind importing of old
v1 ATs from static JSON file as they're all dead and new
v2 implementation is not backwards compatible.
More work on Blocks, mostly AT stuff, but also fork-based corruption
prevention using fix from Qora v1.
Payment-related transactions (multipayment, etc.) always expect/use
non-null (albeit maybe empty) list of PaymentData when validating,
processing or orphaning.
Mainly a change in HSQLDBTransactionRepository.getPayments()
Payment.isValid(byte[], PaymentData, BigDecimal, boolean isZeroAmountValid)
didn't pass on isZeroAmountValid to called method - whoops!
Lots of work on ATTransactions themselves.
MessageTransactions incorrectly assumed the optional payment was always
in Qora. Now fixed to use the transaction's provided assetId.
Mass of fixes/additions to HSQLDBATRepository, especially fixing
incorrect reference to Assets DB table!
In HSQLDBDatabaseUpdates, bump QoraAmount type from DECIMAL(19,8)
to DECIMAL(27,8) to allow for huge asset quantities.
You WILL have to rebuild your database!
2018-10-26 16:47:47 +00:00
|
|
|
assertEquals((Integer) 49778, blockData.getHeight());
|
2018-06-13 16:46:51 +00:00
|
|
|
}
|
2018-06-13 15:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|