Updates to Dependencies - Test Improvements

This commit is contained in:
Ice 2025-04-28 07:25:58 -04:00
parent 2a97fba108
commit b6d3e407c8
12 changed files with 149 additions and 130 deletions

64
pom.xml
View File

@ -3,18 +3,20 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.qortal</groupId> <groupId>org.qortal</groupId>
<artifactId>qortal</artifactId> <artifactId>qortal</artifactId>
<version>4.7.1</version> <version>4.7.2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests> <skipJUnitTests>true</skipJUnitTests>
<altcoinj.version>7dc8c6f</altcoinj.version> <!-- <altcoinj.version>7dc8c6f</altcoinj.version> qortal github BC v15.6-->
<bitcoinj.version>0.15.10</bitcoinj.version> <altcoinj.version>d7cf6ac</altcoinj.version> <!-- BC v16 / Updated Abstract Classes / alertSigningKey -->
<bouncycastle.version>1.70</bouncycastle.version> <bitcoinj.version>0.16.3</bitcoinj.version>
<bouncycastle.version>1.73</bouncycastle.version>
<build.timestamp>${maven.build.timestamp}</build.timestamp> <build.timestamp>${maven.build.timestamp}</build.timestamp>
<ciyam-at.version>1.4.2</ciyam-at.version> <ciyam-at.version>1.4.3</ciyam-at.version>
<commons-net.version>3.8.0</commons-net.version> <commons-net.version>3.9.0</commons-net.version>
<!-- <commons-net.version>3.8.0</commons-net.version> -->
<commons-text.version>1.12.0</commons-text.version> <commons-text.version>1.12.0</commons-text.version>
<commons-io.version>2.18.0</commons-io.version> <commons-io.version>2.18.0</commons-io.version>
<commons-compress.version>1.27.1</commons-compress.version> <commons-compress.version>1.27.1</commons-compress.version>
@ -22,7 +24,8 @@
<dagger.version>1.2.2</dagger.version> <dagger.version>1.2.2</dagger.version>
<extendedset.version>0.12.3</extendedset.version> <extendedset.version>0.12.3</extendedset.version>
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version> <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
<grpc.version>1.68.1</grpc.version> <grpc.version>1.68.3</grpc.version>
<!-- <grpc.version>1.68.1</grpc.version> -->
<guava.version>33.3.1-jre</guava.version> <guava.version>33.3.1-jre</guava.version>
<hamcrest-library.version>2.2</hamcrest-library.version> <hamcrest-library.version>2.2</hamcrest-library.version>
<homoglyph.version>1.2.1</homoglyph.version> <homoglyph.version>1.2.1</homoglyph.version>
@ -32,7 +35,8 @@
<javax.servlet-api.version>4.0.1</javax.servlet-api.version> <javax.servlet-api.version>4.0.1</javax.servlet-api.version>
<jaxb-runtime.version>2.3.9</jaxb-runtime.version> <jaxb-runtime.version>2.3.9</jaxb-runtime.version>
<jersey.version>2.42</jersey.version> <jersey.version>2.42</jersey.version>
<jetty.version>9.4.56.v20240826</jetty.version> <!-- <jetty.version>9.4.56.v20240826</jetty.version> -->
<jetty.version>9.4.57.v20241219</jetty.version>
<json-simple.version>1.1.1</json-simple.version> <json-simple.version>1.1.1</json-simple.version>
<json.version>20240303</json.version> <json.version>20240303</json.version>
<jsoup.version>1.18.1</jsoup.version> <jsoup.version>1.18.1</jsoup.version>
@ -50,11 +54,14 @@
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version> <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version> <maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
<maven-install-plugin.version>3.1.3</maven-install-plugin.version> <maven-install-plugin.version>3.1.3</maven-install-plugin.version>
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version> <maven-surefire-plugin.version>3.5.3</maven-surefire-plugin.version>
<protobuf.version>3.25.3</protobuf.version> <!-- <maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version> -->
<protobuf.version>3.25.7</protobuf.version>
<replacer.version>1.5.3</replacer.version> <replacer.version>1.5.3</replacer.version>
<simplemagic.version>1.17</simplemagic.version> <simplemagic.version>1.17</simplemagic.version>
<slf4j.version>1.7.36</slf4j.version> <slf4j.version>1.7.36</slf4j.version>
<!-- <swagger-api.version>2.2.30</swagger-api.version> need code upgrade -->
<!-- <swagger-api.version>2.1.13</swagger-api.version> need code upgrade -->
<swagger-api.version>2.0.10</swagger-api.version> <swagger-api.version>2.0.10</swagger-api.version>
<swagger-ui.version>5.18.2</swagger-ui.version> <swagger-ui.version>5.18.2</swagger-ui.version>
<upnp.version>1.2</upnp.version> <upnp.version>1.2</upnp.version>
@ -290,19 +297,23 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version> <version>${maven-jar-plugin.version}</version>
<configuration> <executions>
<archive> <execution>
<manifest> <configuration>
<addDefaultEntries>false</addDefaultEntries> <archive>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries> <manifest>
</manifest> <addDefaultEntries>false</addDefaultEntries>
<manifestEntries> <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<Last-Commit-Id>${git.commit.id.full}</Last-Commit-Id> </manifest>
<Last-Commit-Time>${git.commit.time}</Last-Commit-Time> <manifestEntries>
<Reproducible-Build>true</Reproducible-Build> <Last-Commit-Id>${git.commit.id.full}</Last-Commit-Id>
</manifestEntries> <Last-Commit-Time>${git.commit.time}</Last-Commit-Time>
</archive> <Reproducible-Build>true</Reproducible-Build>
</configuration> </manifestEntries>
</archive>
</configuration>
</execution>
</executions>
</plugin> </plugin>
<!-- Copy modified hsqldb.jar to install / modified MANIFEST.MF--> <!-- Copy modified hsqldb.jar to install / modified MANIFEST.MF-->
<plugin> <plugin>
@ -377,6 +388,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Removed, now use Maven reproducible by default v4.0, IntelliJ v2025.1 and later -->
<plugin> <plugin>
<groupId>io.github.zlika</groupId> <groupId>io.github.zlika</groupId>
<artifactId>reproducible-build-maven-plugin</artifactId> <artifactId>reproducible-build-maven-plugin</artifactId>
@ -399,7 +411,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
<configuration> <configuration>
<skipTests>${skipTests}</skipTests> <skipTests>${skipJUnitTests}</skipTests>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
@ -501,7 +513,7 @@
</dependency> </dependency>
<!-- For Litecoin, etc. support, requires bitcoinj --> <!-- For Litecoin, etc. support, requires bitcoinj -->
<dependency> <dependency>
<groupId>com.github.qortal</groupId> <groupId>com.github.iceburst</groupId>
<artifactId>altcoinj</artifactId> <artifactId>altcoinj</artifactId>
<version>${altcoinj.version}</version> <version>${altcoinj.version}</version>
</dependency> </dependency>

View File

@ -1,17 +1,41 @@
package org.qortal.account; package org.qortal.account;
import org.bouncycastle.crypto.generators.Ed25519KeyPairGenerator;
import org.bouncycastle.crypto.params.Ed25519KeyGenerationParameters;
import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters; import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters;
import org.qortal.crypto.Crypto; import org.qortal.crypto.Crypto;
import org.qortal.data.account.AccountData; import org.qortal.data.account.AccountData;
import org.qortal.repository.Repository; import org.qortal.repository.Repository;
import java.security.SecureRandom;
public class PublicKeyAccount extends Account { public class PublicKeyAccount extends Account {
protected final byte[] publicKey; protected final byte[] publicKey;
protected final Ed25519PublicKeyParameters edPublicKeyParams; protected final Ed25519PublicKeyParameters edPublicKeyParams;
/** <p>Constructor for generating a PublicKeyAccount</p>
*
* @param repository Block Chain
* @param publicKey 32 byte Public Key
* @since v4.7.3
*/
public PublicKeyAccount(Repository repository, byte[] publicKey) { public PublicKeyAccount(Repository repository, byte[] publicKey) {
this(repository, new Ed25519PublicKeyParameters(publicKey, 0)); super(repository, Crypto.toAddress(publicKey));
Ed25519PublicKeyParameters t = null;
try {
t = new Ed25519PublicKeyParameters(publicKey, 0);
} catch (Exception e) {
var gen = new Ed25519KeyPairGenerator();
gen.init(new Ed25519KeyGenerationParameters(new SecureRandom()));
var keyPair = gen.generateKeyPair();
t = (Ed25519PublicKeyParameters) keyPair.getPublic();
} finally {
this.edPublicKeyParams = t;
}
this.publicKey = publicKey;
} }
protected PublicKeyAccount(Repository repository, Ed25519PublicKeyParameters edPublicKeyParams) { protected PublicKeyAccount(Repository repository, Ed25519PublicKeyParameters edPublicKeyParams) {

View File

@ -8,6 +8,8 @@ import org.bitcoinj.core.*;
import org.bitcoinj.crypto.ChildNumber; import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.DeterministicHierarchy; import org.bitcoinj.crypto.DeterministicHierarchy;
import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.crypto.HDPath;
import org.bitcoinj.params.AbstractBitcoinNetParams;
import org.bitcoinj.script.Script.ScriptType; import org.bitcoinj.script.Script.ScriptType;
import org.bitcoinj.script.ScriptBuilder; import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.wallet.DeterministicKeyChain; import org.bitcoinj.wallet.DeterministicKeyChain;
@ -25,7 +27,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** Bitcoin-like (Bitcoin, Litecoin, etc.) support */ /** Bitcoin-like (Bitcoin, Litecoin, etc.) support */
public abstract class Bitcoiny implements ForeignBlockchain { public abstract class Bitcoiny extends AbstractBitcoinNetParams implements ForeignBlockchain {
protected static final Logger LOGGER = LogManager.getLogger(Bitcoiny.class); protected static final Logger LOGGER = LogManager.getLogger(Bitcoiny.class);
@ -65,6 +67,7 @@ public abstract class Bitcoiny implements ForeignBlockchain {
// Constructors and instance // Constructors and instance
protected Bitcoiny(BitcoinyBlockchainProvider blockchainProvider, Context bitcoinjContext, String currencyCode, Coin feePerKb) { protected Bitcoiny(BitcoinyBlockchainProvider blockchainProvider, Context bitcoinjContext, String currencyCode, Coin feePerKb) {
this.genesisBlock = this.getGenesisBlock();
this.blockchainProvider = blockchainProvider; this.blockchainProvider = blockchainProvider;
this.bitcoinjContext = bitcoinjContext; this.bitcoinjContext = bitcoinjContext;
this.currencyCode = currencyCode; this.currencyCode = currencyCode;
@ -74,6 +77,15 @@ public abstract class Bitcoiny implements ForeignBlockchain {
} }
// Getters & setters // Getters & setters
@Override
public String getPaymentProtocolId() {
return this.id;
}
@Override
public Block getGenesisBlock() {
return this.genesisBlock;
}
public BitcoinyBlockchainProvider getBlockchainProvider() { public BitcoinyBlockchainProvider getBlockchainProvider() {
return this.blockchainProvider; return this.blockchainProvider;
@ -590,15 +602,27 @@ public abstract class Bitcoiny implements ForeignBlockchain {
return new AddressInfo( return new AddressInfo(
address.toString(), address.toString(),
toIntegerList( key.getPath()), toIntegerList( key.getPath() ),
summingUnspentOutputs(address.toString()), summingUnspentOutputs(address.toString()),
key.getPathAsString(), key.getPathAsString(),
transactionCount, transactionCount,
candidates.contains(address.toString())); candidates.contains(address.toString()));
} }
private static List<Integer> toIntegerList(ImmutableList<ChildNumber> path) { /**
* <p>Convert BitcoinJ native type to List of Integers, BitcoinJ v16 compatible
* </p>
*
* @param path path to deterministic key
* @return Array of Ints representing the keys position in the tree
* @since v4.7.2
*/
private static List<Integer> toIntegerList(HDPath path) {
return path.stream().map(ChildNumber::num).collect(Collectors.toList());
}
// BitcoinJ v15 compatible
private static List<Integer> toIntegerList(ImmutableList<ChildNumber> path) {
return path.stream().map(ChildNumber::num).collect(Collectors.toList()); return path.stream().map(ChildNumber::num).collect(Collectors.toList());
} }

View File

@ -1,5 +1,6 @@
package org.qortal.crosschain; package org.qortal.crosschain;
import org.bitcoinj.core.Block;
import org.bitcoinj.core.Coin; import org.bitcoinj.core.Coin;
import org.bitcoinj.core.Context; import org.bitcoinj.core.Context;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
@ -148,4 +149,16 @@ public class BitcoinyTBD extends Bitcoiny {
this.netTBD.setFeeCeiling( fee ); this.netTBD.setFeeCeiling( fee );
} }
@Override
public String getPaymentProtocolId() {
return params.getId();
}
@Override
public Block getGenesisBlock() {
if(genesisBlock == null)
genesisBlock = params.getGenesisBlock();
return this.genesisBlock;
}
} }

View File

@ -98,9 +98,10 @@ public class DeterminedNetworkParams extends NetworkParameters implements Altcoi
LOGGER.info( "Creating Genesis Block ..."); LOGGER.info( "Creating Genesis Block ...");
// BitcoinJ v16 has a new native method for this
//this.genesisBlock = CoinParamsUtil.createGenesisBlockFromRequest(this, request); //this.genesisBlock = CoinParamsUtil.createGenesisBlockFromRequest(this, request);
LOGGER.info("Created Genesis Block: genesisBlock = " + genesisBlock ); // LOGGER.info("Created Genesis Block: genesisBlock = " + genesisBlock );
// this is 100 for each coin from what I can tell // this is 100 for each coin from what I can tell
this.spendableCoinbaseDepth = 100; this.spendableCoinbaseDepth = 100;
@ -113,8 +114,9 @@ public class DeterminedNetworkParams extends NetworkParameters implements Altcoi
// //
// LOGGER.info("request = " + request); // LOGGER.info("request = " + request);
// //
// checkState(genesisHash.equals(request.getExpectedGenesisHash())); // checkState(genesisHash.equals(request.getExpectedGenesisHash()))
this.alertSigningKey = Hex.decode(request.getPubKey()); // alertSigningKey is removed in v16
// this.alertSigningKey = Hex.decode(request.getPubKey());
this.majorityEnforceBlockUpgrade = request.getMajorityEnforceBlockUpgrade(); this.majorityEnforceBlockUpgrade = request.getMajorityEnforceBlockUpgrade();
this.majorityRejectBlockOutdated = request.getMajorityRejectBlockOutdated(); this.majorityRejectBlockOutdated = request.getMajorityRejectBlockOutdated();
@ -221,6 +223,12 @@ public class DeterminedNetworkParams extends NetworkParameters implements Altcoi
} }
} }
@Override
public Block getGenesisBlock() {
//ToDo: Finish
return null;
}
/** /**
* Get the difficulty target expected for the next block. This includes all * Get the difficulty target expected for the next block. This includes all
* the weird cases for Litecoin such as testnet blocks which can be maximum * the weird cases for Litecoin such as testnet blocks which can be maximum

View File

@ -184,6 +184,11 @@ public class LegacyZcashAddress extends Address {
return p2sh ? ScriptType.P2SH : ScriptType.P2PKH; return p2sh ? ScriptType.P2SH : ScriptType.P2PKH;
} }
@Override
public int compareTo(Address address) {
return this.toString().compareTo(address.toString());
}
/** /**
* Given an address, examines the version byte and attempts to find a matching NetworkParameters. If you aren't sure * Given an address, examines the version byte and attempts to find a matching NetworkParameters. If you aren't sure
* which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is * which network the address is intended for (eg, it was provided by a user), you can use this to decide if it is

View File

@ -212,7 +212,9 @@ public class BootstrapTests extends Common {
@Test @Test
public void testBootstrapHosts() throws IOException { public void testBootstrapHosts() throws IOException {
String[] bootstrapHosts = Settings.getInstance().getBootstrapHosts(); String[] bootstrapHosts = Settings.getInstance().getBootstrapHosts();
String[] bootstrapTypes = { "archive" }; // , "toponly" String[] bootstrapTypes = { "archive" }; // , "toponly", "full"
boolean invalidFile = false;
boolean invalidDate = false;
for (String host : bootstrapHosts) { for (String host : bootstrapHosts) {
for (String type : bootstrapTypes) { for (String type : bootstrapTypes) {
@ -230,14 +232,20 @@ public class BootstrapTests extends Common {
// Ensure the bootstrap exists and has a size greated than 100MiB // Ensure the bootstrap exists and has a size greated than 100MiB
System.out.println(String.format("%s %s size is %d bytes", host, type, fileSize)); System.out.println(String.format("%s %s size is %d bytes", host, type, fileSize));
assertTrue("Bootstrap size must be at least 100MiB", fileSize > 100*1024*1024L); if(fileSize < 100*1024*1024L)
invalidFile = true;
//assertTrue("Bootstrap size must be at least 100MiB", fileSize > 100*1024*1024L);
// Ensure the bootstrap has been published recently (in the last 3 days) // Ensure the bootstrap has been published recently (in the last 3 days)
long minimumLastMofifiedTimestamp = NTP.getTime() - (3 * 24 * 60 * 60 * 1000L); long minimumLastMofifiedTimestamp = NTP.getTime() - (3 * 24 * 60 * 60 * 1000L);
System.out.println(String.format("%s %s last modified timestamp is %d", host, type, lastModified)); System.out.println(String.format("%s %s last modified timestamp is %d", host, type, lastModified));
assertTrue("Bootstrap last modified date must be in the last 3 days", lastModified > minimumLastMofifiedTimestamp); if(lastModified < minimumLastMofifiedTimestamp)
invalidDate = true;
//assertTrue("Bootstrap last modified date must be in the last 3 days", lastModified > minimumLastMofifiedTimestamp);
} }
} }
assertFalse("File size must be at least 100MiB", invalidFile);
assertFalse("Bootstrap last modified date must be in the last 3 days",invalidDate);
} }
private void deleteBootstraps() throws IOException { private void deleteBootstraps() throws IOException {

View File

@ -304,7 +304,7 @@ public class CryptoTests extends Common {
@Test @Test
public void testAESFileEncryption() throws NoSuchAlgorithmException, IOException, IllegalBlockSizeException, public void testAESFileEncryption() throws NoSuchAlgorithmException, IOException, IllegalBlockSizeException,
InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException { InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException, InterruptedException {
// Create temporary directory and file paths // Create temporary directory and file paths
java.nio.file.Path tempDir = Files.createTempDirectory("qortal-tests"); java.nio.file.Path tempDir = Files.createTempDirectory("qortal-tests");
@ -320,6 +320,7 @@ public class CryptoTests extends Common {
// Write it to the input file // Write it to the input file
FileOutputStream outputStream = new FileOutputStream(inputFilePath); FileOutputStream outputStream = new FileOutputStream(inputFilePath);
outputStream.write(randomBytes); outputStream.write(randomBytes);
outputStream.close();
// Make sure only the input file exists // Make sure only the input file exists
assertTrue(Files.exists(Paths.get(inputFilePath))); assertTrue(Files.exists(Paths.get(inputFilePath)));

View File

@ -1,15 +1,22 @@
package org.qortal.test; package org.qortal.test;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.qortal.gui.SplashFrame; import org.qortal.gui.SplashFrame;
import org.qortal.gui.SysTray; import org.qortal.gui.SysTray;
import org.qortal.repository.DataException;
import org.qortal.test.common.Common;
import java.awt.TrayIcon.MessageType; import java.awt.TrayIcon.MessageType;
@Ignore
public class GuiTests { public class GuiTests {
@Before
public void beforeTest() throws DataException {
Common.useDefaultSettings();
}
@Test @Test
public void testSplashFrame() throws InterruptedException { public void testSplashFrame() throws InterruptedException {
SplashFrame splashFrame = SplashFrame.getInstance(); SplashFrame splashFrame = SplashFrame.getInstance();

View File

@ -10,7 +10,7 @@ import java.util.Random;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@Ignore @Ignore (value="Tests Work Fine - VERY Long Run time (1hr+)")
public class MemoryPoWTests { public class MemoryPoWTests {
private static final int workBufferLength = 8 * 1024 * 1024; private static final int workBufferLength = 8 * 1024 * 1024;
@ -26,16 +26,16 @@ public class MemoryPoWTests {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
int nonce = MemoryPoW.compute2(data, workBufferLength, difficulty); Integer nonce = MemoryPoW.compute2(data, workBufferLength, difficulty);
long finishTime = System.currentTimeMillis(); long finishTime = System.currentTimeMillis();
assertNotNull(nonce); assertNotNull(nonce);
System.out.println(String.format("Memory-hard PoW (buffer size: %dKB, leading zeros: %d) took %dms, nonce: %d", workBufferLength / 1024, System.out.printf("Memory-hard PoW (buffer size: %dKB, leading zeros: %d) took %dms, nonce: %d%n", workBufferLength / 1024,
difficulty, difficulty,
finishTime - startTime, finishTime - startTime,
nonce)); nonce);
assertTrue(MemoryPoW.verify2(data, workBufferLength, difficulty, nonce)); assertTrue(MemoryPoW.verify2(data, workBufferLength, difficulty, nonce));
} }
@ -73,12 +73,12 @@ public class MemoryPoWTests {
double stddev = (double) Math.sqrt( (sampleSize * timesS2 - timesS1 * timesS1) / stddevDivisor ); double stddev = (double) Math.sqrt( (sampleSize * timesS2 - timesS1 * timesS1) / stddevDivisor );
System.out.println(String.format("Difficulty: %d, %d timings, mean: %d ms, stddev: %.2f ms, max nonce: %d", System.out.printf("Difficulty: %d, %d timings, mean: %d ms, stddev: %.2f ms, max nonce: %d%n",
difficulty, difficulty,
sampleSize, sampleSize,
timesS1 / sampleSize, timesS1 / sampleSize,
stddev, stddev,
maxNonce)); maxNonce);
} }
} }
@ -97,7 +97,7 @@ public class MemoryPoWTests {
expectedNonce = 11032; expectedNonce = 11032;
nonce = MemoryPoW.compute2(data, workBufferLength, difficulty); nonce = MemoryPoW.compute2(data, workBufferLength, difficulty);
System.out.println(String.format("Difficulty %d, nonce: %d", difficulty, nonce)); System.out.printf("Difficulty %d, nonce: %d%n", difficulty, nonce);
assertEquals(expectedNonce, nonce); assertEquals(expectedNonce, nonce);
} }

View File

@ -1,82 +0,0 @@
package org.qortal.test;
import org.junit.Before;
import org.junit.Test;
import org.qortal.account.Account;
import org.qortal.account.PrivateKeyAccount;
import org.qortal.block.Block;
import org.qortal.controller.BlockMinter;
import org.qortal.data.transaction.PaymentTransactionData;
import org.qortal.data.transaction.TransactionData;
import org.qortal.repository.DataException;
import org.qortal.repository.Repository;
import org.qortal.repository.RepositoryManager;
import org.qortal.settings.Settings;
import org.qortal.test.common.BlockUtils;
import org.qortal.test.common.Common;
import org.qortal.test.common.TransactionUtils;
import org.qortal.test.common.transaction.TestTransaction;
import org.qortal.utils.NTP;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
public class PenaltyFixTests extends Common {
@Before
public void beforeTest() throws DataException {
Common.useSettings("test-settings-v2-penalty-fix.json");
NTP.setFixedOffset(Settings.getInstance().getTestNtpOffset());
}
@Test
public void testSingleSponsor() throws DataException {
try (final Repository repository = RepositoryManager.getRepository()) {
// Alice self share online, and will be used to mint the blocks
PrivateKeyAccount aliceSelfShare = Common.getTestAccount(repository, "alice-reward-share");
List<PrivateKeyAccount> onlineAccounts = new ArrayList<>();
onlineAccounts.add(aliceSelfShare);
PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob");
// Test account from real penalty data (pen-revert.json)
Account penaltyAccount = new Account(repository, "QLcAQpko5egwNjifueCAeAsT8CAj2Sr5qJ");
// Bob sends a payment to the penalty account, so that it gets a row in the Accounts table
TransactionData paymentData = new PaymentTransactionData(TestTransaction.generateBase(bobAccount), penaltyAccount.getAddress(), 1);
TransactionUtils.signAndImportValid(repository, paymentData, bobAccount); // updates paymentData's signature
// Mint blocks up to height 4
Block block = null;
for (int i = 2; i <= 4; i++)
block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0]));
assertEquals(4, (int)block.getBlockData().getHeight());
// Check blocks minted penalty of penalty account
assertEquals(0, (int) penaltyAccount.getBlocksMintedPenalty());
// Penalty revert code runs at block 5
block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0]));
assertEquals(5, (int)block.getBlockData().getHeight());
// +5000000 blocks minted penalty should be applied
assertEquals(5000000, (int) penaltyAccount.getBlocksMintedPenalty());
// Orphan the last block, to simulate a re-org
BlockUtils.orphanLastBlock(repository);
assertEquals(0, (int) penaltyAccount.getBlocksMintedPenalty());
// Penalty revert code runs again
block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0]));
assertEquals(5, (int)block.getBlockData().getHeight());
// Penalty should still be 5000000, rather than doubled up to 10000000
assertEquals(5000000, (int) penaltyAccount.getBlocksMintedPenalty());
}
}
}

View File

@ -1,9 +1,8 @@
package org.qortal.test.crosschain; package org.qortal.test.crosschain;
import com.google.common.collect.ImmutableList;
import org.bitcoinj.core.NetworkParameters; import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.DeterministicKey; import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.crypto.HDPath;
import org.bitcoinj.script.Script; import org.bitcoinj.script.Script;
import org.bitcoinj.wallet.DeterministicKeyChain; import org.bitcoinj.wallet.DeterministicKeyChain;
import org.bitcoinj.wallet.DeterministicSeed; import org.bitcoinj.wallet.DeterministicSeed;
@ -33,7 +32,7 @@ public class BitcoinyTestsUtils {
final Wallet wallet = Wallet.createDeterministic(networkParameters, Script.ScriptType.P2PKH); final Wallet wallet = Wallet.createDeterministic(networkParameters, Script.ScriptType.P2PKH);
final DeterministicSeed seed = wallet.getKeyChainSeed(); final DeterministicSeed seed = wallet.getKeyChainSeed();
final DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build(); final DeterministicKeyChain keyChain = DeterministicKeyChain.builder().seed(seed).build();
final ImmutableList<ChildNumber> path = keyChain.getAccountPath(); final HDPath path = keyChain.getAccountPath();
final DeterministicKey parent = keyChain.getKeyByPath(path, true); final DeterministicKey parent = keyChain.getKeyByPath(path, true);
final String rootKey = parent.serializePrivB58(networkParameters); final String rootKey = parent.serializePrivB58(networkParameters);