forked from Qortal/qortal
CHANGED: switched to JUnit5
CHANGED: globalization tests
This commit is contained in:
parent
aa7bdaf713
commit
730b5033d1
10
pom.xml
10
pom.xml
@ -118,5 +118,15 @@
|
||||
<version>2.4.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -18,8 +18,8 @@ public class Start {
|
||||
apiService.start();
|
||||
|
||||
//// testing the API client
|
||||
ApiClient client = ApiClient.getInstance();
|
||||
String test = client.executeCommand("GET blocks/height");
|
||||
System.out.println(test);
|
||||
//ApiClient client = ApiClient.getInstance();
|
||||
//String test = client.executeCommand("GET blocks/height");
|
||||
//System.out.println(test);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
package globalization;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
public class ContextPaths {
|
||||
|
||||
public static boolean isValidKey(String value) {
|
||||
return !value.contains("/");
|
||||
return !value.contains("/") && !ContextPaths.containsParentReference(value);
|
||||
}
|
||||
|
||||
public static boolean containsParentReference(String value) {
|
||||
for(String part : value.split("/")) {
|
||||
if(part.equalsIgnoreCase(".."))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String combinePaths(String left, String right) {
|
||||
return Paths.get("/", left, right).normalize().toString();
|
||||
}
|
||||
|
@ -212,10 +212,8 @@ public class TranslationXmlStreamReader {
|
||||
}
|
||||
|
||||
private void assureIsValidPathExtension(String value) throws XMLStreamException {
|
||||
for(String part : value.split("/")) {
|
||||
if(part.equalsIgnoreCase(".."))
|
||||
throw new javax.xml.stream.XMLStreamException("Parent reference .. is not allowed");
|
||||
}
|
||||
if(ContextPaths.containsParentReference(value))
|
||||
throw new javax.xml.stream.XMLStreamException("Parent reference .. is not allowed");
|
||||
}
|
||||
|
||||
private void assureIsValidKey(String value) throws XMLStreamException {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
import data.block.BlockData;
|
||||
|
@ -1,11 +1,10 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import data.block.BlockData;
|
||||
import data.transaction.TransactionData;
|
||||
@ -67,7 +66,7 @@ public class BlockTests extends Common {
|
||||
// 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);
|
||||
assertNotNull(blockData, "Block 754 is required for this test");
|
||||
|
||||
Block block = new Block(repository, blockData);
|
||||
assertTrue(block.isSignatureValid());
|
||||
@ -108,7 +107,7 @@ public class BlockTests extends Common {
|
||||
// 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);
|
||||
assertNotNull(blockData, "Block 754 is required for this test");
|
||||
|
||||
Block block = new Block(repository, blockData);
|
||||
assertTrue(block.isSignatureValid());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package test;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import qora.block.BlockChain;
|
||||
import repository.DataException;
|
||||
|
@ -1,7 +1,9 @@
|
||||
package test;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
import repository.DataException;
|
||||
import repository.RepositoryFactory;
|
||||
@ -13,13 +15,13 @@ 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;sql.pad_space=false";
|
||||
public static final String connectionUrl = "jdbc:hsqldb:file:db/test;create=true";
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setRepository() throws DataException {
|
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(connectionUrl);
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void closeRepository() throws DataException {
|
||||
RepositoryManager.closeRepositoryFactory();
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
@ -16,7 +15,7 @@ public class CryptoTests {
|
||||
byte[] digest = Crypto.digest(input);
|
||||
byte[] expected = HashCode.fromString("6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d").asBytes();
|
||||
|
||||
assertArrayEquals(digest, expected);
|
||||
assertArrayEquals(expected, digest);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -25,7 +24,7 @@ public class CryptoTests {
|
||||
byte[] digest = Crypto.doubleDigest(input);
|
||||
byte[] expected = HashCode.fromString("1406e05881e299367766d313e26c05564ec91bf721d31726bd6e46e60689539a").asBytes();
|
||||
|
||||
assertArrayEquals(digest, expected);
|
||||
assertArrayEquals(expected, digest);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,8 +1,8 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import qora.block.Block;
|
||||
|
||||
public class ExceptionTests {
|
||||
|
@ -1,13 +1,12 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
|
||||
import data.transaction.TransactionData;
|
||||
import qora.account.Account;
|
||||
@ -26,13 +25,13 @@ public class GenesisTests {
|
||||
|
||||
public static final String connectionUrl = "jdbc:hsqldb:mem:db/test;create=true;close_result=true;sql.strict_exec=true;sql.enforce_names=true;sql.syntax_mys=true";
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setRepository() throws DataException {
|
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(connectionUrl);
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void closeRepository() throws DataException {
|
||||
RepositoryManager.closeRepositoryFactory();
|
||||
}
|
||||
@ -40,7 +39,7 @@ public class GenesisTests {
|
||||
@Test
|
||||
public void testGenesisBlockTransactions() throws DataException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
assertEquals("Blockchain should be empty for this test", 0, repository.getBlockRepository().getBlockchainHeight());
|
||||
assertEquals(0, repository.getBlockRepository().getBlockchainHeight(), "Blockchain should be empty for this test");
|
||||
|
||||
GenesisBlock block = new GenesisBlock(repository);
|
||||
|
||||
|
@ -11,11 +11,14 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import org.junit.Assert;
|
||||
import static org.junit.Assert.*;
|
||||
import static test.utils.AssertExtensions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import static test.utils.AssertExtensions.*;
|
||||
import test.utils.EqualityComparer;
|
||||
|
||||
public class GlobalizationTests {
|
||||
@ -54,7 +57,7 @@ public class GlobalizationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTranslationXmlReader() throws XMLStreamException {
|
||||
public void TestTranslationXmlReaderContextPaths() throws XMLStreamException {
|
||||
String xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
@ -64,6 +67,9 @@ public class GlobalizationTests {
|
||||
" <context path=\"./path2//path3\">\n" +
|
||||
" <translation key=\"key2\" template=\"2\" />\n" +
|
||||
" </context>\n" +
|
||||
" <context path=\"/path4\">\n" +
|
||||
" <translation key=\"key3\" template=\"3\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
"</localization>\n";
|
||||
@ -71,12 +77,99 @@ public class GlobalizationTests {
|
||||
List<TranslationEntry> expected = new ArrayList<TranslationEntry>();
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/key1", "1"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path2/path3/key2", "2"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/path4/key3", "3"));
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
TranslationXmlStreamReader reader = new TranslationXmlStreamReader();
|
||||
Iterable<TranslationEntry> actual = reader.ReadFrom(is);
|
||||
|
||||
assertSetEquals(expected, actual, new TranslationEntryEqualityComparer());
|
||||
for(TranslationEntry i:expected)System.out.println(i);for(TranslationEntry i:actual)System.out.println(i);
|
||||
assertItemsEqual(expected, actual, new TranslationEntryEqualityComparer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTranslationXmlReaderLocales() throws XMLStreamException {
|
||||
String xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
" <translation key=\"key1\" template=\"1\" />\n" +
|
||||
" <context locale=\"en-GB\" path=\"path1\">\n" +
|
||||
" <translation key=\"key2\" template=\"2\" />\n" +
|
||||
" <context locale=\"de-DE\" path=\"path2/\">\n" +
|
||||
" <translation key=\"key3\" template=\"3\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
"</localization>\n";
|
||||
|
||||
List<TranslationEntry> expected = new ArrayList<TranslationEntry>();
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("default"), "/key1", "1"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("en-GB"), "/path1/key2", "2"));
|
||||
expected.add(new TranslationEntry(Locale.forLanguageTag("de-DE"), "/path1/path2/key3", "3"));
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
TranslationXmlStreamReader reader = new TranslationXmlStreamReader();
|
||||
Iterable<TranslationEntry> actual = reader.ReadFrom(is);
|
||||
|
||||
assertItemsEqual(expected, actual, new TranslationEntryEqualityComparer());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTranslationXmlReader_BadPath() {
|
||||
String xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
" <context locale=\"en-GB\">\n" +
|
||||
" <context path=\"path1\">\n" +
|
||||
" <context path=\"../path2\">\n" +
|
||||
" <translation key=\"key1\" template=\"1\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
"</localization>\n";
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
TranslationXmlStreamReader reader = new TranslationXmlStreamReader();
|
||||
|
||||
assertThrows(XMLStreamException.class, () -> reader.ReadFrom(is));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTranslationXmlReader_BadKey1() {
|
||||
String xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
" <context locale=\"en-GB\">\n" +
|
||||
" <context path=\"path1\">\n" +
|
||||
" <context path=\"path2\">\n" +
|
||||
" <translation key=\"path3/key1\" template=\"1\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
"</localization>\n";
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
TranslationXmlStreamReader reader = new TranslationXmlStreamReader();
|
||||
|
||||
assertThrows(XMLStreamException.class, () -> reader.ReadFrom(is));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestTranslationXmlReader_BadKey2() {
|
||||
String xml =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<localization>\n" +
|
||||
" <context locale=\"en-GB\">\n" +
|
||||
" <context path=\"path1\">\n" +
|
||||
" <context path=\"path2\">\n" +
|
||||
" <translation key=\"..\" template=\"1\" />\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
" </context>\n" +
|
||||
"</localization>\n";
|
||||
|
||||
InputStream is = new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8")));
|
||||
TranslationXmlStreamReader reader = new TranslationXmlStreamReader();
|
||||
|
||||
assertThrows(XMLStreamException.class, () -> reader.ReadFrom(is));
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import data.transaction.PaymentTransactionData;
|
||||
import data.transaction.TransactionData;
|
||||
@ -21,25 +20,25 @@ public class LoadTests extends Common {
|
||||
try (final 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);
|
||||
assertTrue(repository.getBlockRepository().getBlockchainHeight() >= 49778,
|
||||
"Migrate from old database to at least block 49778 before running this test");
|
||||
|
||||
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());
|
||||
assertEquals(PublicKeyAccount.getAddress(transactionData.getCreatorPublicKey()), "QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E");
|
||||
assertNotNull(transactionData, "Transaction data not loaded from repository");
|
||||
assertEquals(TransactionType.PAYMENT, transactionData.getType(), "Transaction data not PAYMENT type");
|
||||
assertEquals("QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E", PublicKeyAccount.getAddress(transactionData.getCreatorPublicKey()));
|
||||
|
||||
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");
|
||||
assertEquals("QXwu8924WdgPoRmtiWQBUMF6eedmp1Hu2E", PublicKeyAccount.getAddress(paymentTransactionData.getSenderPublicKey()));
|
||||
assertEquals("QZsv8vbJ6QfrBNba4LMp5UtHhAzhrxvVUU", paymentTransactionData.getRecipient());
|
||||
assertEquals(1416209264000L, paymentTransactionData.getTimestamp());
|
||||
assertEquals("31dC6kHHBeG5vYb8LMaZDjLEmhc9kQB2VUApVd8xWncSRiXu7yMejdprjYFMP2rUnzZxWd4KJhkq6LsV7rQvU1kY",
|
||||
Base58.encode(paymentTransactionData.getReference()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,8 +47,8 @@ public class LoadTests extends Common {
|
||||
try (final 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);
|
||||
assertTrue(repository.getBlockRepository().getBlockchainHeight() >= 49778,
|
||||
"Migrate from old database to at least block 49778 before running this test");
|
||||
|
||||
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
||||
byte[] signature = Base58.decode(signature58);
|
||||
|
@ -1,8 +1,7 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import data.block.BlockData;
|
||||
import data.transaction.TransactionData;
|
||||
@ -20,8 +19,8 @@ public class NavigationTests extends Common {
|
||||
try (final 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);
|
||||
assertTrue(repository.getBlockRepository().getBlockchainHeight() >= 49778,
|
||||
"Migrate from old database to at least block 49778 before running this test");
|
||||
|
||||
String signature58 = "1211ZPwG3hk5evWzXCZi9hMDRpwumWmkENjwWkeTCik9xA5uoYnxzF7rwR5hmHH3kG2RXo7ToCAaRc7dvnynByJt";
|
||||
byte[] signature = Base58.decode(signature58);
|
||||
@ -29,11 +28,11 @@ public class NavigationTests extends Common {
|
||||
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());
|
||||
assertNotNull(transactionData, "Transaction data not loaded from repository");
|
||||
assertEquals(TransactionType.PAYMENT, transactionData.getType(), "Transaction data not PAYMENT type");
|
||||
|
||||
BlockData blockData = transactionRepository.getBlockDataFromSignature(signature);
|
||||
assertNotNull("Block 49778 not loaded from database", blockData);
|
||||
assertNotNull(blockData, "Block 49778 not loaded from database");
|
||||
|
||||
System.out.println("Block " + blockData.getHeight() + ", signature: " + Base58.encode(blockData.getSignature()));
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.Test;
|
||||
|
||||
import repository.DataException;
|
||||
import repository.Repository;
|
||||
|
@ -3,7 +3,8 @@ package test;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import data.transaction.PaymentTransactionData;
|
||||
import qora.account.PublicKeyAccount;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import data.block.BlockData;
|
||||
import data.transaction.GenesisTransactionData;
|
||||
import data.transaction.TransactionData;
|
||||
@ -61,15 +60,15 @@ public class SerializationTests extends Common {
|
||||
|
||||
TransactionData parsedTransactionData = TransactionTransformer.fromBytes(bytes);
|
||||
|
||||
assertTrue("Transaction signature mismatch", Arrays.equals(transactionData.getSignature(), parsedTransactionData.getSignature()));
|
||||
assertTrue(Arrays.equals(transactionData.getSignature(), parsedTransactionData.getSignature()), "Transaction signature mismatch");
|
||||
|
||||
assertEquals("Data length mismatch", TransactionTransformer.getDataLength(transactionData), bytes.length);
|
||||
assertEquals(bytes.length, TransactionTransformer.getDataLength(transactionData), "Data length mismatch");
|
||||
}
|
||||
|
||||
private void testSpecificBlockTransactions(int height, TransactionType type) throws DataException, TransformationException {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
BlockData blockData = repository.getBlockRepository().fromHeight(height);
|
||||
assertNotNull("Block " + height + " is required for this test", blockData);
|
||||
assertNotNull(blockData, "Block " + height + " is required for this test");
|
||||
|
||||
Block block = new Block(repository, blockData);
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import data.block.BlockData;
|
||||
import qora.account.PrivateKeyAccount;
|
||||
import qora.block.Block;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
@ -10,8 +12,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.hash.HashCode;
|
||||
|
||||
@ -97,7 +97,7 @@ public class TransactionTests {
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
assertEquals("Blockchain should be empty for this test", 0, repository.getBlockRepository().getBlockchainHeight());
|
||||
assertEquals(0, repository.getBlockRepository().getBlockchainHeight(), "Blockchain should be empty for this test");
|
||||
}
|
||||
|
||||
// [Un]set genesis timestamp as required by test
|
||||
@ -136,7 +136,7 @@ public class TransactionTests {
|
||||
repository.saveChanges();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void closeRepository() throws DataException {
|
||||
RepositoryManager.closeRepositoryFactory();
|
||||
}
|
||||
@ -176,8 +176,8 @@ public class TransactionTests {
|
||||
block.addTransaction(paymentTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -185,21 +185,21 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = initialSenderBalance.subtract(amount).subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Amount should be in recipient's balance
|
||||
expectedBalance = amount;
|
||||
actualBalance = accountRepository.getBalance(recipient.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Recipient's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Recipient's new balance incorrect");
|
||||
|
||||
// Check recipient's reference
|
||||
byte[] recipientsReference = recipient.getLastReference();
|
||||
assertTrue("Recipient's new reference incorrect", Arrays.equals(paymentTransaction.getTransactionData().getSignature(), recipientsReference));
|
||||
assertTrue(Arrays.equals(paymentTransaction.getTransactionData().getSignature(), recipientsReference), "Recipient's new reference incorrect");
|
||||
|
||||
// Orphan block
|
||||
block.orphan();
|
||||
@ -207,11 +207,11 @@ public class TransactionTests {
|
||||
|
||||
// Check sender's balance
|
||||
actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's reverted balance incorrect", initialSenderBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialSenderBalance.compareTo(actualBalance) == 0, "Sender's reverted balance incorrect");
|
||||
|
||||
// Check generator's balance
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", initialGeneratorBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialGeneratorBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -237,8 +237,8 @@ public class TransactionTests {
|
||||
block.addTransaction(registerNameTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -246,19 +246,19 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = initialSenderBalance.subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Check name was registered
|
||||
NameData actualNameData = this.repository.getNameRepository().fromName(name);
|
||||
assertNotNull(actualNameData);
|
||||
|
||||
// Check sender's reference
|
||||
assertTrue("Sender's new reference incorrect", Arrays.equals(registerNameTransactionData.getSignature(), sender.getLastReference()));
|
||||
assertTrue(Arrays.equals(registerNameTransactionData.getSignature(), sender.getLastReference()), "Sender's new reference incorrect");
|
||||
|
||||
// Update variables for use by other tests
|
||||
reference = sender.getLastReference();
|
||||
@ -293,8 +293,8 @@ public class TransactionTests {
|
||||
block.addTransaction(updateNameTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -338,8 +338,8 @@ public class TransactionTests {
|
||||
block.addTransaction(sellNameTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -389,8 +389,8 @@ public class TransactionTests {
|
||||
block.addTransaction(cancelSellNameTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -455,8 +455,8 @@ public class TransactionTests {
|
||||
block.addTransaction(buyNameTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -508,8 +508,8 @@ public class TransactionTests {
|
||||
block.addTransaction(createPollTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -517,19 +517,19 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = initialSenderBalance.subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Check poll was created
|
||||
PollData actualPollData = this.repository.getVotingRepository().fromPollName(pollName);
|
||||
assertNotNull(actualPollData);
|
||||
|
||||
// Check sender's reference
|
||||
assertTrue("Sender's new reference incorrect", Arrays.equals(createPollTransactionData.getSignature(), sender.getLastReference()));
|
||||
assertTrue(Arrays.equals(createPollTransactionData.getSignature(), sender.getLastReference()), "Sender's new reference incorrect");
|
||||
|
||||
// Update variables for use by other tests
|
||||
reference = sender.getLastReference();
|
||||
@ -567,8 +567,8 @@ public class TransactionTests {
|
||||
block.addTransaction(voteOnPollTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -588,10 +588,10 @@ public class TransactionTests {
|
||||
List<VoteOnPollData> votes = repository.getVotingRepository().getVotes(pollName);
|
||||
assertNotNull(votes);
|
||||
|
||||
assertEquals("Only one vote expected", 1, votes.size());
|
||||
assertEquals(1, votes.size(), "Only one vote expected");
|
||||
|
||||
assertEquals("Wrong vote option index", pollOptionsSize - 1, votes.get(0).getOptionIndex());
|
||||
assertTrue("Wrong voter public key", Arrays.equals(sender.getPublicKey(), votes.get(0).getVoterPublicKey()));
|
||||
assertEquals(pollOptionsSize - 1, votes.get(0).getOptionIndex(), "Wrong vote option index");
|
||||
assertTrue(Arrays.equals(sender.getPublicKey(), votes.get(0).getVoterPublicKey()), "Wrong voter public key");
|
||||
|
||||
// Orphan last block
|
||||
BlockData lastBlockData = repository.getBlockRepository().getLastBlock();
|
||||
@ -603,10 +603,10 @@ public class TransactionTests {
|
||||
votes = repository.getVotingRepository().getVotes(pollName);
|
||||
assertNotNull(votes);
|
||||
|
||||
assertEquals("Only one vote expected", 1, votes.size());
|
||||
assertEquals(1, votes.size(), "Only one vote expected");
|
||||
|
||||
assertEquals("Wrong vote option index", pollOptionsSize - 1 - 1, votes.get(0).getOptionIndex());
|
||||
assertTrue("Wrong voter public key", Arrays.equals(sender.getPublicKey(), votes.get(0).getVoterPublicKey()));
|
||||
assertEquals(pollOptionsSize - 1 - 1, votes.get(0).getOptionIndex(), "Wrong vote option index");
|
||||
assertTrue(Arrays.equals(sender.getPublicKey(), votes.get(0).getVoterPublicKey()), "Wrong voter public key");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -634,8 +634,8 @@ public class TransactionTests {
|
||||
block.addTransaction(issueAssetTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -643,12 +643,12 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = initialSenderBalance.subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Check we now have an assetId
|
||||
Long assetId = issueAssetTransactionData.getAssetId();
|
||||
@ -672,11 +672,11 @@ public class TransactionTests {
|
||||
|
||||
// Check sender's balance
|
||||
actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's reverted balance incorrect", initialSenderBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialSenderBalance.compareTo(actualBalance) == 0, "Sender's reverted balance incorrect");
|
||||
|
||||
// Check generator's balance
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's reverted balance incorrect", initialGeneratorBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialGeneratorBalance.compareTo(actualBalance) == 0, "Generator's reverted balance incorrect");
|
||||
|
||||
// Check asset no longer exists
|
||||
assertFalse(assetRepo.assetExists(assetId));
|
||||
@ -724,8 +724,8 @@ public class TransactionTests {
|
||||
block.addTransaction(transferAssetTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -733,12 +733,12 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = originalSenderBalance.subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = originalGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Check asset balances
|
||||
BigDecimal actualSenderAssetBalance = sender.getConfirmedBalance(assetId);
|
||||
@ -756,11 +756,11 @@ public class TransactionTests {
|
||||
|
||||
// Check sender's balance
|
||||
actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's reverted balance incorrect", originalSenderBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(originalSenderBalance.compareTo(actualBalance) == 0, "Sender's reverted balance incorrect");
|
||||
|
||||
// Check generator's balance
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's reverted balance incorrect", originalGeneratorBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(originalGeneratorBalance.compareTo(actualBalance) == 0, "Generator's reverted balance incorrect");
|
||||
|
||||
// Check asset balances
|
||||
actualSenderAssetBalance = sender.getConfirmedBalance(assetId);
|
||||
@ -828,8 +828,8 @@ public class TransactionTests {
|
||||
block.addTransaction(createOrderTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -909,8 +909,8 @@ public class TransactionTests {
|
||||
block.addTransaction(cancelOrderTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -984,8 +984,8 @@ public class TransactionTests {
|
||||
block.addTransaction(createOrderTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -998,7 +998,7 @@ public class TransactionTests {
|
||||
// Check order has trades
|
||||
List<TradeData> trades = assetRepo.getOrdersTrades(orderId);
|
||||
assertNotNull(trades);
|
||||
assertEquals("Trade didn't happen", 1, trades.size());
|
||||
assertEquals(1, trades.size(), "Trade didn't happen");
|
||||
TradeData tradeData = trades.get(0);
|
||||
|
||||
// Check trade has correct values
|
||||
@ -1093,20 +1093,20 @@ public class TransactionTests {
|
||||
block.addTransaction(multiPaymentTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
|
||||
// Check sender's balance
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedSenderBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedSenderBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
BigDecimal expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Check recipients
|
||||
for (int i = 0; i < payments.size(); ++i) {
|
||||
@ -1114,12 +1114,12 @@ public class TransactionTests {
|
||||
Account recipient = new Account(this.repository, paymentData.getRecipient());
|
||||
|
||||
byte[] recipientsReference = recipient.getLastReference();
|
||||
assertTrue("Recipient's new reference incorrect", Arrays.equals(multiPaymentTransaction.getTransactionData().getSignature(), recipientsReference));
|
||||
assertTrue(Arrays.equals(multiPaymentTransaction.getTransactionData().getSignature(), recipientsReference), "Recipient's new reference incorrect");
|
||||
|
||||
// Amount should be in recipient's balance
|
||||
expectedBalance = paymentData.getAmount();
|
||||
actualBalance = accountRepository.getBalance(recipient.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Recipient's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Recipient's new balance incorrect");
|
||||
|
||||
}
|
||||
|
||||
@ -1129,11 +1129,11 @@ public class TransactionTests {
|
||||
|
||||
// Check sender's balance
|
||||
actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's reverted balance incorrect", initialSenderBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialSenderBalance.compareTo(actualBalance) == 0, "Sender's reverted balance incorrect");
|
||||
|
||||
// Check generator's balance
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", initialGeneratorBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(initialGeneratorBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1163,8 +1163,8 @@ public class TransactionTests {
|
||||
block.addTransaction(messageTransactionData);
|
||||
block.sign();
|
||||
|
||||
assertTrue("Block signatures invalid", block.isSignatureValid());
|
||||
assertEquals("Block is invalid", Block.ValidationResult.OK, block.isValid());
|
||||
assertTrue(block.isSignatureValid(), "Block signatures invalid");
|
||||
assertEquals(Block.ValidationResult.OK, block.isValid(), "Block is invalid");
|
||||
|
||||
block.process();
|
||||
repository.saveChanges();
|
||||
@ -1172,17 +1172,17 @@ public class TransactionTests {
|
||||
// Check sender's balance
|
||||
BigDecimal expectedBalance = initialSenderBalance.subtract(amount).subtract(fee);
|
||||
BigDecimal actualBalance = accountRepository.getBalance(sender.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Sender's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Sender's new balance incorrect");
|
||||
|
||||
// Fee should be in generator's balance
|
||||
expectedBalance = initialGeneratorBalance.add(fee);
|
||||
actualBalance = accountRepository.getBalance(generator.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Generator's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Generator's new balance incorrect");
|
||||
|
||||
// Amount should be in recipient's balance
|
||||
expectedBalance = amount;
|
||||
actualBalance = accountRepository.getBalance(recipient.getAddress(), Asset.QORA).getBalance();
|
||||
assertTrue("Recipient's new balance incorrect", expectedBalance.compareTo(actualBalance) == 0);
|
||||
assertTrue(expectedBalance.compareTo(actualBalance) == 0, "Recipient's new balance incorrect");
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,54 @@
|
||||
package test.utils;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.Class;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.Assert;
|
||||
|
||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class AssertExtensions {
|
||||
|
||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, EqualityComparer<T> comparer) {
|
||||
assertItemsEqual(expected, actual, comparer, (String)null);
|
||||
}
|
||||
|
||||
public static <T> void assertSetEquals(Iterable<T> expected, Iterable<T> actual, EqualityComparer<T> comparer) {
|
||||
Set<EquatableWrapper<T>> expectedSet = new HashSet<EquatableWrapper<T>>();
|
||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, EqualityComparer<T> comparer, String message) {
|
||||
List<EquatableWrapper<T>> expectedSet = new ArrayList<EquatableWrapper<T>>();
|
||||
for(T item: expected)
|
||||
expectedSet.add(new EquatableWrapper<T>(item, comparer));
|
||||
|
||||
Set<EquatableWrapper<T>> actualSet = new HashSet<EquatableWrapper<T>>();
|
||||
List<EquatableWrapper<T>> actualSet = new ArrayList<EquatableWrapper<T>>();
|
||||
for(T item: actual)
|
||||
actualSet.add(new EquatableWrapper<T>(item, comparer));
|
||||
|
||||
Assert.assertEquals(expectedSet, actualSet);
|
||||
assertItemsEqual(expectedSet, actualSet, message);
|
||||
}
|
||||
|
||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual) {
|
||||
assertItemsEqual(expected, actual, (String)null);
|
||||
}
|
||||
|
||||
public static <T> void assertItemsEqual(Iterable<T> expected, Iterable<T> actual, String message) {
|
||||
List<T> list = new ArrayList<T>();
|
||||
T[] expectedArray = getArray(expected);
|
||||
assertThat(message, actual, containsInAnyOrder(expectedArray));
|
||||
}
|
||||
|
||||
private static <T> T[] getArray(Iterable<T> iterable) {
|
||||
// XXX: What a horrific way to create an array from an iterable.
|
||||
// Isn't there a better solution?
|
||||
List<T> list = new ArrayList<T>();
|
||||
for(T item : iterable)
|
||||
list.add(item);
|
||||
@SuppressWarnings("unchecked")
|
||||
T[] result = (T[])new Object[list.size()];
|
||||
for(int i = 0; i < list.size(); i++)
|
||||
result[i] = list.get(i);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user