mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-12 18:25:51 +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:
parent
272ee434c0
commit
150e9fb7df
@ -254,7 +254,7 @@ public class ECKeyTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUnencryptedCreate() throws Exception {
|
public void testUnencryptedCreate() throws Exception {
|
||||||
Utils.rollMockClock(0);
|
Utils.setMockClock();
|
||||||
ECKey key = new ECKey();
|
ECKey key = new ECKey();
|
||||||
long time = key.getCreationTimeSeconds();
|
long time = key.getCreationTimeSeconds();
|
||||||
assertNotEquals(0, time);
|
assertNotEquals(0, time);
|
||||||
|
@ -96,7 +96,7 @@ public class FullBlockTestGenerator {
|
|||||||
this.params = params;
|
this.params = params;
|
||||||
coinbaseOutKey = new ECKey();
|
coinbaseOutKey = new ECKey();
|
||||||
coinbaseOutKeyPubKey = coinbaseOutKey.getPubKey();
|
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 {
|
public RuleList getBlocksToTest(boolean addSigExpensiveBlocks, boolean runLargeReorgs, File blockStorageFile) throws ScriptException, ProtocolException, IOException {
|
||||||
|
@ -36,7 +36,6 @@ import java.math.BigInteger;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.nio.channels.CancelledKeyException;
|
import java.nio.channels.CancelledKeyException;
|
||||||
import java.nio.channels.ClosedChannelException;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -436,7 +435,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
@Test
|
@Test
|
||||||
public void fastCatchup() throws Exception {
|
public void fastCatchup() throws Exception {
|
||||||
connect();
|
connect();
|
||||||
|
Utils.setMockClock();
|
||||||
// Check that blocks before the fast catchup point are retrieved using getheaders, and after using getblocks.
|
// 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.
|
// This test is INCOMPLETE because it does not check we handle >2000 blocks correctly.
|
||||||
Block b1 = createFakeBlock(blockStore).block;
|
Block b1 = createFakeBlock(blockStore).block;
|
||||||
@ -484,7 +483,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||||||
@Test
|
@Test
|
||||||
public void pingPong() throws Exception {
|
public void pingPong() throws Exception {
|
||||||
connect();
|
connect();
|
||||||
Utils.rollMockClock(0);
|
Utils.setMockClock();
|
||||||
// No ping pong happened yet.
|
// No ping pong happened yet.
|
||||||
assertEquals(Long.MAX_VALUE, peer.getLastPingTime());
|
assertEquals(Long.MAX_VALUE, peer.getLastPingTime());
|
||||||
assertEquals(Long.MAX_VALUE, peer.getPingTime());
|
assertEquals(Long.MAX_VALUE, peer.getPingTime());
|
||||||
|
@ -948,7 +948,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
@Test
|
@Test
|
||||||
public void transactionsList() throws Exception {
|
public void transactionsList() throws Exception {
|
||||||
// Check the wallet can give us an ordered list of all received transactions.
|
// 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);
|
Transaction tx1 = sendMoneyToWallet(Utils.toNanoCoins(1, 0), AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
Utils.rollMockClock(60 * 10);
|
Utils.rollMockClock(60 * 10);
|
||||||
Transaction tx2 = sendMoneyToWallet(Utils.toNanoCoins(0, 5), AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
Transaction tx2 = sendMoneyToWallet(Utils.toNanoCoins(0, 5), AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
@ -986,7 +986,8 @@ public class WalletTest extends TestWithWallet {
|
|||||||
@Test
|
@Test
|
||||||
public void keyCreationTime() throws Exception {
|
public void keyCreationTime() throws Exception {
|
||||||
wallet = new Wallet(params);
|
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.
|
// No keys returns current time.
|
||||||
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
||||||
Utils.rollMockClock(60);
|
Utils.rollMockClock(60);
|
||||||
@ -1000,7 +1001,8 @@ public class WalletTest extends TestWithWallet {
|
|||||||
@Test
|
@Test
|
||||||
public void scriptCreationTime() throws Exception {
|
public void scriptCreationTime() throws Exception {
|
||||||
wallet = new Wallet(params);
|
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.
|
// No keys returns current time.
|
||||||
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
assertEquals(now, wallet.getEarliestKeyCreationTime());
|
||||||
Utils.rollMockClock(60);
|
Utils.rollMockClock(60);
|
||||||
@ -2186,6 +2188,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void keyRotation() throws Exception {
|
public void keyRotation() throws Exception {
|
||||||
|
Utils.setMockClock();
|
||||||
// Watch out for wallet-initiated broadcasts.
|
// Watch out for wallet-initiated broadcasts.
|
||||||
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
|
MockTransactionBroadcaster broadcaster = new MockTransactionBroadcaster(wallet);
|
||||||
wallet.setTransactionBroadcaster(broadcaster);
|
wallet.setTransactionBroadcaster(broadcaster);
|
||||||
@ -2258,6 +2261,7 @@ public class WalletTest extends TestWithWallet {
|
|||||||
ECKey key = new ECKey();
|
ECKey key = new ECKey();
|
||||||
wallet.addKey(key);
|
wallet.addKey(key);
|
||||||
Address address = key.toAddress(params);
|
Address address = key.toAddress(params);
|
||||||
|
Utils.setMockClock();
|
||||||
Utils.rollMockClock(86400);
|
Utils.rollMockClock(86400);
|
||||||
for (int i = 0; i < 800; i++) {
|
for (int i = 0; i < 800; i++) {
|
||||||
sendMoneyToWallet(wallet, Utils.CENT, address, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(wallet, Utils.CENT, address, AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
|
@ -268,7 +268,7 @@ public class ChannelConnectionTest extends TestWithWallet {
|
|||||||
@Test
|
@Test
|
||||||
public void testChannelResume() throws Exception {
|
public void testChannelResume() throws Exception {
|
||||||
// Tests various aspects of channel resuming.
|
// Tests various aspects of channel resuming.
|
||||||
Utils.rollMockClock(0);
|
Utils.setMockClock();
|
||||||
|
|
||||||
final Sha256Hash someServerId = Sha256Hash.create(new byte[]{});
|
final Sha256Hash someServerId = Sha256Hash.create(new byte[]{});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user