Massive clean-up of DB & conversion to long for timestamps

Collated all development changes to DB so now we build
initial DB structure directly with final layout.
i.e. no ALTER TABLE, etc.

Reordered HSQLDB 'CREATE TYPE' statements into alphabetical order
for easier maintainability.

Replaced TIMESTAMP WITH TIME ZONE with simple BIGINT ("EpochMillis").
Timezone conversion is now a presentation task, rather than having
pretty values in database.

Removed associated conversion methods, like toOffsetDateTime(),
fromOffsetDateTime() and getZonedTimestampMilli().

Renamed some DB columns to make them more obviously timestamps, like:
Names.registered is now Names.registered_when.

Removed IFNULL(balance, 0) from HSQLDBAccountRepository as balances
are never null, or actually never 0 either.

Added more tests to increase API call, and hence repository, coverage.

Removed unused "milestone block" from Transactions.
This commit is contained in:
catbref
2020-05-07 12:16:22 +01:00
parent 359a35931e
commit 3094ec3c26
21 changed files with 904 additions and 1014 deletions

View File

@@ -23,6 +23,11 @@ public class AddressesApiTests extends ApiCommon {
assertNotNull(this.addressesResource.getAccountInfo(aliceAddress));
}
@Test
public void testGetOnlineAccounts() {
assertNotNull(this.addressesResource.getOnlineAccounts());
}
@Test
public void testGetRewardShares() {
assertNotNull(this.addressesResource.getRewardShares(Collections.singletonList(aliceAddress), null, null, null, null, null));

View File

@@ -26,4 +26,9 @@ public class AdminApiTests extends ApiCommon {
assertNotNull(this.adminResource.summary());
}
@Test
public void testGetMintingAccounts() {
assertNotNull(this.adminResource.getMintingAccounts());
}
}

View File

@@ -0,0 +1,43 @@
package org.qortal.test.api;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.qortal.api.resource.ArbitraryResource;
import org.qortal.api.resource.TransactionsResource.ConfirmationStatus;
import org.qortal.test.common.ApiCommon;
public class ArbitraryApiTests extends ApiCommon {
private ArbitraryResource arbitraryResource;
@Before
public void buildResource() {
this.arbitraryResource = (ArbitraryResource) ApiCommon.buildResource(ArbitraryResource.class);
}
@Test
public void testSearch() {
Integer[] startingBlocks = new Integer[] { null, 0, 1, 999999999 };
Integer[] blockLimits = new Integer[] { null, 0, 1, 999999999 };
Integer[] txGroupIds = new Integer[] { null, 0, 1, 999999999 };
Integer[] services = new Integer[] { null, 0, 1, 999999999 };
String[] addresses = new String[] { null, this.aliceAddress };
ConfirmationStatus[] confirmationStatuses = new ConfirmationStatus[] { ConfirmationStatus.UNCONFIRMED, ConfirmationStatus.CONFIRMED, ConfirmationStatus.BOTH };
for (Integer startBlock : startingBlocks)
for (Integer blockLimit : blockLimits)
for (Integer txGroupId : txGroupIds)
for (Integer service : services)
for (String address : addresses)
for (ConfirmationStatus confirmationStatus : confirmationStatuses) {
if (confirmationStatus != ConfirmationStatus.CONFIRMED && (startBlock != null || blockLimit != null))
continue;
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, address, confirmationStatus, 20, null, null));
assertNotNull(this.arbitraryResource.searchTransactions(startBlock, blockLimit, txGroupId, service, address, confirmationStatus, 1, 1, true));
}
}
}

View File

@@ -12,8 +12,12 @@ import org.qortal.api.ApiError;
import org.qortal.api.ApiException;
import org.qortal.api.resource.AssetsResource;
import org.qortal.api.resource.TransactionsResource.ConfirmationStatus;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.repository.AccountRepository.BalanceOrdering;
import org.qortal.repository.DataException;
import org.qortal.test.common.ApiCommon;
import org.qortal.test.common.AssetUtils;
public class AssetsApiTests extends ApiCommon {
@@ -22,12 +26,22 @@ public class AssetsApiTests extends ApiCommon {
private AssetsResource assetsResource;
@Before
public void buildResource() {
public void buildResource() throws DataException {
this.assetsResource = (AssetsResource) ApiCommon.buildResource(AssetsResource.class);
// Create some dummy data
try (final Repository repository = RepositoryManager.getRepository()) {
// Matching orders, to create a trade
AssetUtils.createOrder(repository, "alice", AssetUtils.goldAssetId, AssetUtils.otherAssetId, 1_00000000L, 1_00000000L);
AssetUtils.createOrder(repository, "bob", AssetUtils.otherAssetId, AssetUtils.goldAssetId, 1_00000000L, 1_00000000L);
// Open order
AssetUtils.createOrder(repository, "bob", AssetUtils.otherAssetId, AssetUtils.testAssetId, 1_00000000L, 1_00000000L);
}
}
@Test
public void testGet() {
public void testResource() {
assertNotNull(this.assetsResource);
}
@@ -70,8 +84,8 @@ public class AssetsApiTests extends ApiCommon {
@Test
public void testGetAssetBalances() {
List<String> addresses = Arrays.asList(aliceAddress, aliceAddress);
List<Long> assetIds = Arrays.asList(1L, 2L, 3L);
List<String> addresses = Arrays.asList(aliceAddress, bobAddress);
List<Long> assetIds = Arrays.asList(0L, 1L, 2L, 3L);
for (BalanceOrdering balanceOrdering : BalanceOrdering.values()) {
for (Boolean excludeZero : ALL_BOOLEAN_VALUES) {

View File

@@ -8,8 +8,16 @@ import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.qortal.account.PrivateKeyAccount;
import org.qortal.api.resource.BlocksResource;
import org.qortal.block.GenesisBlock;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.test.common.ApiCommon;
import org.qortal.test.common.BlockUtils;
import org.qortal.test.common.Common;
import org.qortal.utils.Base58;
public class BlockApiTests extends ApiCommon {
@@ -21,24 +29,84 @@ public class BlockApiTests extends ApiCommon {
}
@Test
public void test() {
public void testResource() {
assertNotNull(this.blocksResource);
}
@Test
public void testGetBlockMinters() {
List<String> addresses = Arrays.asList(aliceAddress, aliceAddress);
public void testGetBlock() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
byte[] signatureBytes = GenesisBlock.getInstance(repository).getSignature();
String signature = Base58.encode(signatureBytes);
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(addresses, null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), 1, 1, true));
assertNotNull(this.blocksResource.getBlockMinters(addresses, 1, 1, true));
assertNotNull(this.blocksResource.getBlock(signature));
}
}
@Test
public void testGetBlockSummariesByMinter() {
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, null, null, null));
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, 1, 1, true));
public void testGetBlockTransactions() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
byte[] signatureBytes = GenesisBlock.getInstance(repository).getSignature();
String signature = Base58.encode(signatureBytes);
assertNotNull(this.blocksResource.getBlockTransactions(signature, null, null, null));
assertNotNull(this.blocksResource.getBlockTransactions(signature, 1, 1, true));
}
}
@Test
public void testGetHeight() {
assertNotNull(this.blocksResource.getHeight());
}
@Test
public void testGetBlockHeight() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
byte[] signatureBytes = GenesisBlock.getInstance(repository).getSignature();
String signature = Base58.encode(signatureBytes);
assertNotNull(this.blocksResource.getHeight(signature));
}
}
@Test
public void testGetBlockByHeight() {
assertNotNull(this.blocksResource.getByHeight(1));
}
@Test
public void testGetBlockByTimestamp() {
assertNotNull(this.blocksResource.getByTimestamp(System.currentTimeMillis()));
}
@Test
public void testGetBlockRange() {
assertNotNull(this.blocksResource.getBlockRange(1, 1));
}
@Test
public void testGetBlockMinters() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
PrivateKeyAccount mintingAccount = Common.getTestAccount(repository, "alice-reward-share");
BlockUtils.mintBlock(repository);
List<String> addresses = Arrays.asList(aliceAddress, mintingAccount.getAddress(), bobAddress);
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(addresses, null, null, null));
assertNotNull(this.blocksResource.getBlockMinters(Collections.emptyList(), 1, 1, true));
assertNotNull(this.blocksResource.getBlockMinters(addresses, 1, 1, true));
}
}
@Test
public void testGetBlockSummariesByMinter() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
BlockUtils.mintBlock(repository);
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, null, null, null));
assertNotNull(this.blocksResource.getBlockSummariesByMinter(aliceAddress, 1, 1, true));
}
}
}

View File

@@ -0,0 +1,91 @@
package org.qortal.test.api;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.qortal.account.PrivateKeyAccount;
import org.qortal.api.resource.NamesResource;
import org.qortal.data.transaction.RegisterNameTransactionData;
import org.qortal.data.transaction.SellNameTransactionData;
import org.qortal.data.transaction.TransactionData;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.test.common.ApiCommon;
import org.qortal.test.common.Common;
import org.qortal.test.common.TransactionUtils;
import org.qortal.test.common.transaction.TestTransaction;
public class NamesApiTests extends ApiCommon {
private NamesResource namesResource;
@Before
public void before() throws DataException {
Common.useDefaultSettings();
this.namesResource = (NamesResource) ApiCommon.buildResource(NamesResource.class);
}
@Test
public void testResource() {
assertNotNull(this.namesResource);
}
@Test
public void testGetAllNames() {
assertNotNull(this.namesResource.getAllNames(null, null, null));
assertNotNull(this.namesResource.getAllNames(1, 1, true));
}
@Test
public void testGetNamesByAddress() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
// Register-name
PrivateKeyAccount alice = Common.getTestAccount(repository, "alice");
String name = "test-name";
RegisterNameTransactionData transactionData = new RegisterNameTransactionData(TestTransaction.generateBase(alice), alice.getAddress(), name, "{}");
TransactionUtils.signAndMint(repository, transactionData, alice);
assertNotNull(this.namesResource.getNamesByAddress(alice.getAddress(), null, null, null));
assertNotNull(this.namesResource.getNamesByAddress(alice.getAddress(), 1, 1, true));
}
}
@Test
public void testGetName() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
// Register-name
PrivateKeyAccount alice = Common.getTestAccount(repository, "alice");
String name = "test-name";
RegisterNameTransactionData transactionData = new RegisterNameTransactionData(TestTransaction.generateBase(alice), alice.getAddress(), name, "{}");
TransactionUtils.signAndMint(repository, transactionData, alice);
assertNotNull(this.namesResource.getName(name));
}
}
@Test
public void testGetAllAssets() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
// Register-name
PrivateKeyAccount alice = Common.getTestAccount(repository, "alice");
String name = "test-name";
long price = 1_23456789L;
TransactionData transactionData = new RegisterNameTransactionData(TestTransaction.generateBase(alice), alice.getAddress(), name, "{}");
TransactionUtils.signAndMint(repository, transactionData, alice);
// Sell-name
transactionData = new SellNameTransactionData(TestTransaction.generateBase(alice), name, price);
TransactionUtils.signAndMint(repository, transactionData, alice);
assertNotNull(this.namesResource.getNamesForSale(null, null, null));
assertNotNull(this.namesResource.getNamesForSale(1, 1, true));
}
}
}

View File

@@ -24,12 +24,14 @@ public class ApiCommon extends Common {
private static final FakeRequest FAKE_REQUEST = new FakeRequest();
public String aliceAddress;
public String bobAddress;
@Before
public void beforeTests() throws DataException {
Common.useDefaultSettings();
this.aliceAddress = Common.getTestAccount(null, "alice").getAddress();
this.bobAddress = Common.getTestAccount(null, "bob").getAddress();
}
public static Object buildResource(Class<?> resourceClass) {

View File

@@ -0,0 +1,42 @@
package org.qortal.test.naming;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.qortal.account.PrivateKeyAccount;
import org.qortal.data.transaction.RegisterNameTransactionData;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.test.common.Common;
import org.qortal.test.common.TransactionUtils;
import org.qortal.test.common.transaction.TestTransaction;
public class MiscTests extends Common {
@Before
public void beforeTest() throws DataException {
Common.useDefaultSettings();
}
@Test
public void testGetRecentNames() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
// Register-name
PrivateKeyAccount alice = Common.getTestAccount(repository, "alice");
String name = "test-name";
RegisterNameTransactionData transactionData = new RegisterNameTransactionData(TestTransaction.generateBase(alice), alice.getAddress(), name, "{}");
TransactionUtils.signAndMint(repository, transactionData, alice);
List<String> recentNames = repository.getNameRepository().getRecentNames(0L);
assertNotNull(recentNames);
assertFalse(recentNames.isEmpty());
}
}
}