diff --git a/core/src/test/java/com/google/bitcoin/core/ECKeyTest.java b/core/src/test/java/com/google/bitcoin/core/ECKeyTest.java index 99f9fd61..c8edd189 100644 --- a/core/src/test/java/com/google/bitcoin/core/ECKeyTest.java +++ b/core/src/test/java/com/google/bitcoin/core/ECKeyTest.java @@ -254,7 +254,7 @@ public class ECKeyTest { @Test public void testUnencryptedCreate() throws Exception { - Utils.rollMockClock(0); + Utils.setMockClock(); ECKey key = new ECKey(); long time = key.getCreationTimeSeconds(); assertNotEquals(0, time); diff --git a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java index 44e0adc5..7c025373 100644 --- a/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java +++ b/core/src/test/java/com/google/bitcoin/core/FullBlockTestGenerator.java @@ -96,7 +96,7 @@ public class FullBlockTestGenerator { this.params = params; coinbaseOutKey = new ECKey(); coinbaseOutKeyPubKey = coinbaseOutKey.getPubKey(); - Utils.rollMockClock(0); // Set a mock clock for timestamp tests + Utils.setMockClock(); } public RuleList getBlocksToTest(boolean addSigExpensiveBlocks, boolean runLargeReorgs, File blockStorageFile) throws ScriptException, ProtocolException, IOException { diff --git a/core/src/test/java/com/google/bitcoin/core/PeerTest.java b/core/src/test/java/com/google/bitcoin/core/PeerTest.java index d8d93b13..5caa15d9 100644 --- a/core/src/test/java/com/google/bitcoin/core/PeerTest.java +++ b/core/src/test/java/com/google/bitcoin/core/PeerTest.java @@ -36,7 +36,6 @@ import java.math.BigInteger; import java.net.InetSocketAddress; import java.net.SocketException; import java.nio.channels.CancelledKeyException; -import java.nio.channels.ClosedChannelException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; @@ -436,7 +435,7 @@ public class PeerTest extends TestWithNetworkConnections { @Test public void fastCatchup() throws Exception { connect(); - + Utils.setMockClock(); // Check that blocks before the fast catchup point are retrieved using getheaders, and after using getblocks. // This test is INCOMPLETE because it does not check we handle >2000 blocks correctly. Block b1 = createFakeBlock(blockStore).block; @@ -484,7 +483,7 @@ public class PeerTest extends TestWithNetworkConnections { @Test public void pingPong() throws Exception { connect(); - Utils.rollMockClock(0); + Utils.setMockClock(); // No ping pong happened yet. assertEquals(Long.MAX_VALUE, peer.getLastPingTime()); assertEquals(Long.MAX_VALUE, peer.getPingTime()); diff --git a/core/src/test/java/com/google/bitcoin/core/WalletTest.java b/core/src/test/java/com/google/bitcoin/core/WalletTest.java index 2bea4cc7..ac276e7c 100644 --- a/core/src/test/java/com/google/bitcoin/core/WalletTest.java +++ b/core/src/test/java/com/google/bitcoin/core/WalletTest.java @@ -948,7 +948,7 @@ public class WalletTest extends TestWithWallet { @Test public void transactionsList() throws Exception { // Check the wallet can give us an ordered list of all received transactions. - Utils.rollMockClock(0); + Utils.setMockClock(); Transaction tx1 = sendMoneyToWallet(Utils.toNanoCoins(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN); Utils.rollMockClock(60 * 10); Transaction tx2 = sendMoneyToWallet(Utils.toNanoCoins(0, 5), AbstractBlockChain.NewBlockType.BEST_CHAIN); @@ -986,7 +986,8 @@ public class WalletTest extends TestWithWallet { @Test public void keyCreationTime() throws Exception { wallet = new Wallet(params); - long now = Utils.rollMockClock(0).getTime() / 1000; // Fix the mock clock. + Utils.setMockClock(); + long now = Utils.currentTimeSeconds(); // No keys returns current time. assertEquals(now, wallet.getEarliestKeyCreationTime()); Utils.rollMockClock(60); @@ -1000,7 +1001,8 @@ public class WalletTest extends TestWithWallet { @Test public void scriptCreationTime() throws Exception { wallet = new Wallet(params); - long now = Utils.rollMockClock(0).getTime() / 1000; // Fix the mock clock. + Utils.setMockClock(); + long now = Utils.currentTimeSeconds(); // No keys returns current time. assertEquals(now, wallet.getEarliestKeyCreationTime()); Utils.rollMockClock(60); @@ -2186,6 +2188,7 @@ public class WalletTest extends TestWithWallet { @Test public void keyRotation() throws Exception { + Utils.setMockClock(); // Watch out for wallet-initiated broadcasts. MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet); wallet.setTransactionBroadcaster(broadcaster); @@ -2258,6 +2261,7 @@ public class WalletTest extends TestWithWallet { ECKey key = new ECKey(); wallet.addKey(key); Address address = key.toAddress(params); + Utils.setMockClock(); Utils.rollMockClock(86400); for (int i = 0; i < 800; i++) { sendMoneyToWallet(wallet, Utils.CENT, address, AbstractBlockChain.NewBlockType.BEST_CHAIN); diff --git a/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java b/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java index e0ed05ca..0bd9b863 100644 --- a/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java +++ b/core/src/test/java/com/google/bitcoin/protocols/channels/ChannelConnectionTest.java @@ -268,7 +268,7 @@ public class ChannelConnectionTest extends TestWithWallet { @Test public void testChannelResume() throws Exception { // Tests various aspects of channel resuming. - Utils.rollMockClock(0); + Utils.setMockClock(); final Sha256Hash someServerId = Sha256Hash.create(new byte[]{});