3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-12 10:15:52 +00:00

More mock clock conversions, to avoid failures when running test cases independently.

Probably we should be injecting a mock Clock class so it goes away at the end of each test, but this would complicate the API somewhat.
This commit is contained in:
Mike Hearn 2014-04-04 15:06:45 +02:00
parent 272ee434c0
commit 150e9fb7df
5 changed files with 12 additions and 9 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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());

View File

@ -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);

View File

@ -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[]{});