BlockChainTest: remove TWEAKABLE_TESTNET from badDifficulty()

The max target aspect is tested by the `difficultyTransitions*()` tests
already.
This commit is contained in:
Andreas Schildbach 2023-04-02 14:02:02 +02:00
parent ce10061510
commit fccb164c90

View File

@ -39,7 +39,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.math.BigInteger;
import java.time.Duration;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
@ -213,20 +212,12 @@ public class BlockChainTest {
assertTrue(chain.add(newBlock));
}
private static class TweakableTestNet3Params extends TestNet3Params {
public void setMaxTarget(BigInteger limit) {
maxTarget = limit;
}
}
@Test
public void badDifficulty() throws Exception {
TweakableTestNet3Params TWEAKABLE_TESTNET = new TweakableTestNet3Params();
public void badDifficultyTarget() throws Exception {
assertTrue(testNetChain.add(getBlock1()));
Block b2 = getBlock2();
assertTrue(testNetChain.add(b2));
Block bad = new Block(TWEAKABLE_TESTNET, Block.BLOCK_VERSION_GENESIS);
Block bad = new Block(TESTNET, Block.BLOCK_VERSION_GENESIS);
// Merkle root can be anything here, doesn't matter.
bad.setMerkleRoot(Sha256Hash.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
// Nonce was just some number that made the hash < difficulty limit set below, it can be anything.
@ -245,20 +236,6 @@ public class BlockChainTest {
} catch (VerificationException e) {
assertTrue(e.getMessage(), e.getCause().getMessage().contains("Difficulty target is bad"));
}
// Accept any level of difficulty now.
BigInteger oldVal = TWEAKABLE_TESTNET.getMaxTarget();
TWEAKABLE_TESTNET.setMaxTarget(new BigInteger("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16));
try {
testNetChain.add(bad);
// We should not get here as the difficulty target should not be changing at this point.
fail();
} catch (VerificationException e) {
assertTrue(e.getMessage(), e.getCause().getMessage().contains("Unexpected change in difficulty"));
}
TWEAKABLE_TESTNET.setMaxTarget(oldVal);
// TODO: Test difficulty change is not out of range when a transition period becomes valid.
}
/**