Fix a couple of ordering issues with the unit tests.

This commit is contained in:
Mike Hearn 2013-03-01 16:23:07 +01:00
parent 34f3d8b088
commit 018dcd345c
2 changed files with 13 additions and 3 deletions

View File

@ -183,8 +183,7 @@ public class BlockChainTest {
assertTrue(testNetChain.add(getBlock1()));
Block b2 = getBlock2();
assertTrue(testNetChain.add(b2));
NetworkParameters params2 = NetworkParameters.testNet();
Block bad = new Block(params2);
Block bad = new Block(testNet);
// Merkle root can be anything here, doesn't matter.
bad.setMerkleRoot(new Sha256Hash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
// Nonce was just some number that made the hash < difficulty limit set below, it can be anything.
@ -205,7 +204,8 @@ public class BlockChainTest {
}
// Accept any level of difficulty now.
params2.proofOfWorkLimit = new BigInteger
BigInteger oldVal = testNet.proofOfWorkLimit;
testNet.proofOfWorkLimit = new BigInteger
("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
try {
testNetChain.add(bad);
@ -214,6 +214,7 @@ public class BlockChainTest {
} catch (VerificationException e) {
assertTrue(e.getMessage(), e.getCause().getMessage().indexOf("Unexpected change in difficulty") >= 0);
}
testNet.proofOfWorkLimit = oldVal;
// TODO: Test difficulty change is not out of range when a transition period becomes valid.
}

View File

@ -21,6 +21,7 @@ import com.google.bitcoin.core.Transaction.SigHash;
import com.google.bitcoin.store.FullPrunedBlockStore;
import com.google.bitcoin.store.MemoryFullPrunedBlockStore;
import com.google.bitcoin.utils.BriefLogFormatter;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@ -48,15 +49,23 @@ public class FullPrunedBlockChainTest {
private FullPrunedBlockChain chain;
private FullPrunedBlockStore store;
private int oldInterval;
@Before
public void setUp() throws Exception {
BriefLogFormatter.init();
unitTestParams = NetworkParameters.unitTests();
oldInterval = unitTestParams.interval;
unitTestParams.interval = 10000;
store = new MemoryFullPrunedBlockStore(unitTestParams, UNDOABLE_BLOCKS_STORED);
chain = new FullPrunedBlockChain(unitTestParams, store);
}
@After
public void tearDown() {
unitTestParams.interval = oldInterval;
}
@Test
public void testGeneratedChain() throws Exception {