Browse Source

Fix unit tests

pull/67/head
catbref 5 years ago
parent
commit
4b02b7a14f
  1. 6
      src/test/java/org/qora/test/common/AccountUtils.java
  2. 8
      src/test/java/org/qora/test/common/AssetUtils.java
  3. 9
      src/test/java/org/qora/test/common/TransactionUtils.java
  4. 3
      src/test/java/org/qora/test/forging/RewardTests.java

6
src/test/java/org/qora/test/common/AccountUtils.java

@ -24,7 +24,7 @@ public class AccountUtils {
PrivateKeyAccount recipientAccount = Common.getTestAccount(repository, recipient);
byte[] reference = sendingAccount.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
TransactionData transactionData = new PaymentTransactionData(timestamp, txGroupId, reference, sendingAccount.getPublicKey(), recipientAccount.getAddress(), amount, fee);
@ -36,7 +36,7 @@ public class AccountUtils {
PrivateKeyAccount recipientAccount = Common.getTestAccount(repository, recipient);
byte[] reference = forgingAccount.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
byte[] proxyPrivateKey = forgingAccount.getSharedSecret(recipientAccount.getPublicKey());
PrivateKeyAccount proxyAccount = new PrivateKeyAccount(null, proxyPrivateKey);
@ -52,7 +52,7 @@ public class AccountUtils {
PrivateKeyAccount forgingAccount = Common.getTestAccount(repository, forger);
byte[] reference = forgingAccount.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
return new EnableForgingTransactionData(timestamp, txGroupId, reference, forgingAccount.getPublicKey(), Crypto.toAddress(recipientPublicKey), fee);
}

8
src/test/java/org/qora/test/common/AssetUtils.java

@ -31,7 +31,7 @@ public class AssetUtils {
PrivateKeyAccount account = Common.getTestAccount(repository, issuerAccountName);
byte[] reference = account.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
TransactionData transactionData = new IssueAssetTransactionData(timestamp, AssetUtils.txGroupId, reference, account.getPublicKey(), account.getAddress(), assetName, "desc", quantity, isDivisible, "{}", AssetUtils.fee);
@ -45,7 +45,7 @@ public class AssetUtils {
PrivateKeyAccount toAccount = Common.getTestAccount(repository, toAccountName);
byte[] reference = fromAccount.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
TransactionData transactionData = new TransferAssetTransactionData(timestamp, AssetUtils.txGroupId, reference, fromAccount.getPublicKey(), toAccount.getAddress(), amount, assetId, AssetUtils.fee);
@ -56,7 +56,7 @@ public class AssetUtils {
PrivateKeyAccount account = Common.getTestAccount(repository, accountName);
byte[] reference = account.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
TransactionData transactionData = new CreateAssetOrderTransactionData(timestamp, txGroupId, reference, account.getPublicKey(), haveAssetId, wantAssetId, amount, price, fee);
@ -69,7 +69,7 @@ public class AssetUtils {
PrivateKeyAccount account = Common.getTestAccount(repository, accountName);
byte[] reference = account.getLastReference();
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1000;
long timestamp = repository.getTransactionRepository().fromSignature(reference).getTimestamp() + 1;
TransactionData transactionData = new CancelAssetOrderTransactionData(timestamp, txGroupId, reference, account.getPublicKey(), orderId, fee);

9
src/test/java/org/qora/test/common/TransactionUtils.java

@ -20,6 +20,12 @@ public class TransactionUtils {
// Add to unconfirmed
assertTrue("Transaction's signature should be valid", transaction.isSignatureValid());
// We might need to wait until transaction's timestamp is valid for the block we're about to generate
try {
Thread.sleep(1L);
} catch (InterruptedException e) {
}
ValidationResult result = transaction.isValidUnconfirmed();
assertEquals("Transaction invalid", ValidationResult.OK, result);
@ -28,7 +34,8 @@ public class TransactionUtils {
repository.saveChanges();
// Generate block
BlockGenerator.generateTestingBlock(repository, signingAccount);
PrivateKeyAccount generatorAccount = Common.getTestAccount(repository, "alice");
BlockGenerator.generateTestingBlock(repository, generatorAccount);
}
}

3
src/test/java/org/qora/test/forging/RewardTests.java

@ -80,9 +80,6 @@ public class RewardTests extends Common {
final BigDecimal share = new BigDecimal("12.8");
try (final Repository repository = RepositoryManager.getRepository()) {
// Bob needs to make a transaction so his public key is known
AccountUtils.pay(repository, "bob", "chloe", new BigDecimal("1.4444").setScale(8));
byte[] proxyPrivateKey = AccountUtils.proxyForging(repository, "alice", "bob", share);
PrivateKeyAccount proxyAccount = new PrivateKeyAccount(repository, proxyPrivateKey);

Loading…
Cancel
Save