Search in sources :

Example 6 with BtcNode

use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.

the class BtcNodeConverterTest method testConvertWithTor.

@Test
public void testConvertWithTor() throws DnsLookupException {
    InetAddress expected = mock(InetAddress.class);
    Facade facade = mock(Facade.class);
    when(facade.torLookup(any(), anyString())).thenReturn(expected);
    BtcNode node = mock(BtcNode.class);
    when(node.getHostNameOrAddress()).thenReturn("aaa.onion");
    PeerAddress peerAddress = new BtcNodeConverter(facade).convertWithTor(node, mock(Socks5Proxy.class));
    // noinspection ConstantConditions
    assertEquals(expected, peerAddress.getAddr());
}
Also used : Facade(bisq.core.btc.wallet.BtcNodeConverter.Facade) PeerAddress(org.bitcoinj.core.PeerAddress) Socks5Proxy(com.runjva.sourceforge.jsocks.protocol.Socks5Proxy) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 7 with BtcNode

use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.

the class BtcNodeConverterTest method testConvertClearNode.

@Ignore
@Test
public void testConvertClearNode() {
    final String ip = "192.168.0.1";
    BtcNode node = mock(BtcNode.class);
    when(node.getHostNameOrAddress()).thenReturn(ip);
    PeerAddress peerAddress = new BtcNodeConverter().convertClearNode(node);
    // noinspection ConstantConditions
    InetAddress inetAddress = peerAddress.getAddr();
    assertEquals(ip, inetAddress.getHostName());
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InetAddress(java.net.InetAddress) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with BtcNode

use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.

the class PeerAddressesRepositoryTest method testGetPeerAddressesWhenOnionNodesOnly.

@Test
public void testGetPeerAddressesWhenOnionNodesOnly() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);
    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);
    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    PeerAddressesRepository repository = new PeerAddressesRepository(converter, Lists.newArrayList(node, onionNode));
    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), false);
    assertEquals(1, peers.size());
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) Socks5Proxy(com.runjva.sourceforge.jsocks.protocol.Socks5Proxy) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Test(org.junit.Test)

Example 9 with BtcNode

use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.

the class PeerAddressesRepositoryTest method testGetPeerAddressesWhenProxyAndClearNodes.

@Test
public void testGetPeerAddressesWhenProxyAndClearNodes() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);
    BtcNode onionNode = mock(BtcNode.class);
    when(node.hasOnionAddress()).thenReturn(true);
    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    PeerAddressesRepository repository = new PeerAddressesRepository(converter, Lists.newArrayList(node, onionNode));
    List<PeerAddress> peers = repository.getPeerAddresses(mock(Socks5Proxy.class), true);
    assertEquals(2, peers.size());
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) Socks5Proxy(com.runjva.sourceforge.jsocks.protocol.Socks5Proxy) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Test(org.junit.Test)

Example 10 with BtcNode

use of bisq.core.btc.BitcoinNodes.BtcNode in project bisq-core by bisq-network.

the class PeerAddressesRepositoryTest method testGetPeerAddressesWhenClearNodes.

@Test
public void testGetPeerAddressesWhenClearNodes() {
    BtcNode node = mock(BtcNode.class);
    when(node.hasClearNetAddress()).thenReturn(true);
    BtcNodeConverter converter = mock(BtcNodeConverter.class, RETURNS_DEEP_STUBS);
    PeerAddressesRepository repository = new PeerAddressesRepository(converter, Collections.singletonList(node));
    List<PeerAddress> peers = repository.getPeerAddresses(null, false);
    assertFalse(peers.isEmpty());
}
Also used : PeerAddress(org.bitcoinj.core.PeerAddress) BtcNode(bisq.core.btc.BitcoinNodes.BtcNode) Test(org.junit.Test)

Aggregations

BtcNode (bisq.core.btc.BitcoinNodes.BtcNode)11 Test (org.junit.Test)10 PeerAddress (org.bitcoinj.core.PeerAddress)8 Facade (bisq.core.btc.wallet.BtcNodeConverter.Facade)3 Socks5Proxy (com.runjva.sourceforge.jsocks.protocol.Socks5Proxy)3 InetAddress (java.net.InetAddress)3 BitcoinNodes (bisq.core.btc.BitcoinNodes)2 Preferences (bisq.core.user.Preferences)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 BitcoinNodesOption (bisq.core.btc.BitcoinNodes.BitcoinNodesOption)1 Ignore (org.junit.Ignore)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1