mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
BlockChainTest: remove TWEAKABLE_TESTNET
from badDifficulty()
The max target aspect is tested by the `difficultyTransitions*()` tests already.
This commit is contained in:
parent
ce10061510
commit
fccb164c90
@ -39,7 +39,6 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
import org.junit.rules.ExpectedException;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@ -213,20 +212,12 @@ public class BlockChainTest {
|
|||||||
assertTrue(chain.add(newBlock));
|
assertTrue(chain.add(newBlock));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TweakableTestNet3Params extends TestNet3Params {
|
|
||||||
public void setMaxTarget(BigInteger limit) {
|
|
||||||
maxTarget = limit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void badDifficulty() throws Exception {
|
public void badDifficultyTarget() throws Exception {
|
||||||
TweakableTestNet3Params TWEAKABLE_TESTNET = new TweakableTestNet3Params();
|
|
||||||
|
|
||||||
assertTrue(testNetChain.add(getBlock1()));
|
assertTrue(testNetChain.add(getBlock1()));
|
||||||
Block b2 = getBlock2();
|
Block b2 = getBlock2();
|
||||||
assertTrue(testNetChain.add(b2));
|
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.
|
// Merkle root can be anything here, doesn't matter.
|
||||||
bad.setMerkleRoot(Sha256Hash.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
bad.setMerkleRoot(Sha256Hash.wrap("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
|
||||||
// Nonce was just some number that made the hash < difficulty limit set below, it can be anything.
|
// 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) {
|
} catch (VerificationException e) {
|
||||||
assertTrue(e.getMessage(), e.getCause().getMessage().contains("Difficulty target is bad"));
|
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.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user