@Test
public void timeLockedTransactionNew() throws Exception {

    connectWithVersion(NetworkParameters.ProtocolVersion.MINIMUM.getBitcoinProtocolVersion(), VersionMessage.NODE_NETWORK);
    // Test that if we receive a relevant transaction that has a lock time, it doesn't result in a notification
    // until we explicitly opt in to seeing those.
    Wallet wallet = new Wallet(PARAMS);
    ECKey key = wallet.freshReceiveKey();
    peer.addWallet(wallet);
    final Transaction[] vtx = new Transaction[1];
    wallet.addCoinsReceivedEventListener(new WalletCoinsReceivedEventListener() {
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            vtx[0] = tx;
        }
    });
    // Send a normal relevant transaction, it's received correctly.
    Transaction t1 = FakeTxBuilder.createFakeTx(PARAMS, COIN, key);
    inbound(writeTarget, t1);
    GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
    inbound(writeTarget, new NotFoundMessage(PARAMS, getdata.getItems()));
    pingAndWait(writeTarget);
    Threading.waitForUserCode();
    assertNotNull(vtx[0]);
    vtx[0] = null;
    // Send a timelocked transaction, nothing happens.
    Transaction t2 = FakeTxBuilder.createFakeTx(PARAMS, valueOf(2, 0), key);
    t2.setLockTime(999999);
    inbound(writeTarget, t2);
    Threading.waitForUserCode();
    assertNull(vtx[0]);
    // Now we want to hear about them. Send another, we are told about it.
    wallet.setAcceptRiskyTransactions(true);
    inbound(writeTarget, t2);
    getdata = (GetDataMessage) outbound(writeTarget);
    inbound(writeTarget, new NotFoundMessage(PARAMS, getdata.getItems()));
    pingAndWait(writeTarget);
    Threading.waitForUserCode();
    assertEquals(t2, vtx[0]);
}