mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-07-29 11:01:22 +00:00
Implement support for IRC peer discovery. Patch contributed by John Sample.
This commit is contained in:
49
tests/com/google/bitcoin/core/IrcDiscoveryTest.java
Normal file
49
tests/com/google/bitcoin/core/IrcDiscoveryTest.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright John Sample
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IrcDiscoveryTest {
|
||||
// TODO: Inject a mock IRC server and more thoroughly exercise this class.
|
||||
|
||||
@Test
|
||||
public void testParseUserList() throws UnknownHostException {
|
||||
// Test some random addresses grabbed from the channel.
|
||||
String[] userList = new String[]{ "x201500200","u4stwEBjT6FYyVV", "u5BKEqDApa8SbA7"};
|
||||
|
||||
ArrayList<InetSocketAddress> addresses = IrcDiscovery.parseUserList(userList);
|
||||
|
||||
// Make sure the "x" address is excluded.
|
||||
assertEquals("Too many addresses.", 2, addresses.size());
|
||||
|
||||
String[] ips = new String[]{"69.4.98.82:8333","74.92.222.129:8333"};
|
||||
InetSocketAddress[] decoded = addresses.toArray(new InetSocketAddress[]{});
|
||||
|
||||
for (int i = 0; i < decoded.length; i++) {
|
||||
String formattedIP = decoded[0].getAddress().getHostAddress() + ":" + ((Integer)decoded[i].getPort()).toString();
|
||||
assertEquals("IPs decoded improperly", ips[0], formattedIP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user