diff --git a/core/src/test/java/com/google/bitcoin/core/AbstractFullPrunedBlockChainTest.java b/core/src/test/java/com/google/bitcoin/core/AbstractFullPrunedBlockChainTest.java index 88a4a1d1..e8e1e97b 100644 --- a/core/src/test/java/com/google/bitcoin/core/AbstractFullPrunedBlockChainTest.java +++ b/core/src/test/java/com/google/bitcoin/core/AbstractFullPrunedBlockChainTest.java @@ -22,7 +22,6 @@ import com.google.bitcoin.params.UnitTestParams; import com.google.bitcoin.script.Script; import com.google.bitcoin.store.BlockStoreException; import com.google.bitcoin.store.FullPrunedBlockStore; -import com.google.bitcoin.store.MemoryFullPrunedBlockStore; import com.google.bitcoin.utils.BlockFileLoader; import com.google.bitcoin.utils.BriefLogFormatter; import org.junit.Before; @@ -58,7 +57,7 @@ public abstract class AbstractFullPrunedBlockChainTest }; } - public abstract FullPrunedBlockStore createStoreFromParamsAndBlockCount(NetworkParameters params, int blockCount) + public abstract FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException; public abstract void resetStore(FullPrunedBlockStore store) throws BlockStoreException; @@ -69,7 +68,7 @@ public abstract class AbstractFullPrunedBlockChainTest FullBlockTestGenerator generator = new FullBlockTestGenerator(params); RuleList blockList = generator.getBlocksToTest(false, false, null); - store = createStoreFromParamsAndBlockCount(params, blockList.maximumReorgBlockCount); + store = createStore(params, blockList.maximumReorgBlockCount); resetStore(store); chain = new FullPrunedBlockChain(params, store); @@ -112,7 +111,7 @@ public abstract class AbstractFullPrunedBlockChainTest @Test public void skipScripts() throws Exception { - store = createStoreFromParamsAndBlockCount(params, 10); + store = createStore(params, 10); resetStore(store); chain = new FullPrunedBlockChain(params, store); @@ -149,7 +148,7 @@ public abstract class AbstractFullPrunedBlockChainTest @Test public void testFinalizedBlocks() throws Exception { final int UNDOABLE_BLOCKS_STORED = 10; - store = createStoreFromParamsAndBlockCount(params, UNDOABLE_BLOCKS_STORED); + store = createStore(params, UNDOABLE_BLOCKS_STORED); resetStore(store); chain = new FullPrunedBlockChain(params, store); @@ -207,7 +206,7 @@ public abstract class AbstractFullPrunedBlockChainTest File blockFile = new File(getClass().getResource("first-100k-blocks.dat").getFile()); BlockFileLoader loader = new BlockFileLoader(params, Arrays.asList(blockFile)); - store = createStoreFromParamsAndBlockCount(params, 10); + store = createStore(params, 10); resetStore(store); chain = new FullPrunedBlockChain(params, store); for (Block block : loader) diff --git a/core/src/test/java/com/google/bitcoin/core/H2FullPrunedBlockChainTest.java b/core/src/test/java/com/google/bitcoin/core/H2FullPrunedBlockChainTest.java index 00ae84b6..4aff3e16 100644 --- a/core/src/test/java/com/google/bitcoin/core/H2FullPrunedBlockChainTest.java +++ b/core/src/test/java/com/google/bitcoin/core/H2FullPrunedBlockChainTest.java @@ -3,21 +3,36 @@ package com.google.bitcoin.core; import com.google.bitcoin.store.BlockStoreException; import com.google.bitcoin.store.FullPrunedBlockStore; import com.google.bitcoin.store.H2FullPrunedBlockStore; +import org.junit.After; + +import java.io.File; /** * An H2 implementation of the FullPrunedBlockStoreTest */ -public class H2FullPrunedBlockChainTest extends AbstractFullPrunedBlockChainTest -{ - @Override - public FullPrunedBlockStore createStoreFromParamsAndBlockCount(NetworkParameters params, int blockCount) throws BlockStoreException - { - return new H2FullPrunedBlockStore(params, "test.h2", blockCount); +public class H2FullPrunedBlockChainTest extends AbstractFullPrunedBlockChainTest { + @After + public void tearDown() throws Exception { + deleteFiles(); } @Override - public void resetStore(FullPrunedBlockStore store) throws BlockStoreException - { + public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException { + deleteFiles(); + return new H2FullPrunedBlockStore(params, "test", blockCount); + } + + private void deleteFiles() { + maybeDelete("test.h2.db"); + maybeDelete("test.trace.db"); + } + + private void maybeDelete(String s) { + new File(s).delete(); + } + + @Override + public void resetStore(FullPrunedBlockStore store) throws BlockStoreException { ((H2FullPrunedBlockStore)store).resetStore(); } } diff --git a/core/src/test/java/com/google/bitcoin/core/MemoryFullPrunedBlockChainTest.java b/core/src/test/java/com/google/bitcoin/core/MemoryFullPrunedBlockChainTest.java index 33d9d812..ae95124b 100644 --- a/core/src/test/java/com/google/bitcoin/core/MemoryFullPrunedBlockChainTest.java +++ b/core/src/test/java/com/google/bitcoin/core/MemoryFullPrunedBlockChainTest.java @@ -10,7 +10,7 @@ import com.google.bitcoin.store.MemoryFullPrunedBlockStore; public class MemoryFullPrunedBlockChainTest extends AbstractFullPrunedBlockChainTest { @Override - public FullPrunedBlockStore createStoreFromParamsAndBlockCount(NetworkParameters params, int blockCount) throws BlockStoreException + public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException { return new MemoryFullPrunedBlockStore(params, blockCount); } diff --git a/core/src/test/java/com/google/bitcoin/core/PostgresFullPrunedBlockChainTest.java b/core/src/test/java/com/google/bitcoin/core/PostgresFullPrunedBlockChainTest.java index f197951f..d5e89a51 100644 --- a/core/src/test/java/com/google/bitcoin/core/PostgresFullPrunedBlockChainTest.java +++ b/core/src/test/java/com/google/bitcoin/core/PostgresFullPrunedBlockChainTest.java @@ -18,7 +18,7 @@ public class PostgresFullPrunedBlockChainTest extends AbstractFullPrunedBlockCha private static final String DB_PASSWORD = "password"; @Override - public FullPrunedBlockStore createStoreFromParamsAndBlockCount(NetworkParameters params, int blockCount) + public FullPrunedBlockStore createStore(NetworkParameters params, int blockCount) throws BlockStoreException { return new PostgresFullPrunedBlockStore(params, blockCount, DB_HOSTNAME, DB_NAME, DB_USERNAME, DB_PASSWORD); }