use of org.ethereum.net.client.Capability in project rskj by rsksmart.
the class HelloMessageTest method test2.
// Instantiate from constructor
@Test
public void test2() {
// Init
byte version = 2;
String clientStr = "Ethereum(++)/v0.7.9/Release/Linux/g++";
List<Capability> capabilities = Arrays.asList(new Capability(Capability.RSK, EthVersion.UPPER), new Capability(Capability.P2P, P2pHandler.VERSION));
int listenPort = 992;
String peerId = "1fbf1e41f08078918c9f7b6734594ee56d7f538614f602c71194db0a1af5a";
HelloMessage helloMessage = new HelloMessage(version, clientStr, capabilities, listenPort, peerId);
logger.info(helloMessage.toString());
assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
assertEquals(version, helloMessage.getP2PVersion());
assertEquals(clientStr, helloMessage.getClientId());
assertEquals(2, helloMessage.getCapabilities().size());
assertEquals(listenPort, helloMessage.getListenPort());
assertEquals(peerId, helloMessage.getPeerId());
}
use of org.ethereum.net.client.Capability in project rskj by rsksmart.
the class HelloMessageTest method test3.
// Fail test
@Test
public void test3() {
// Init
// invalid version
byte version = -1;
// null id
String clientStr = "";
List<Capability> capabilities = Arrays.asList(new Capability(null, (byte) 0), new Capability(null, (byte) 0), // null here causes NullPointerException when using toString
null, // encoding null capabilities
new Capability(null, (byte) 0));
// invalid port
int listenPort = 99999;
// null id
String peerId = "";
HelloMessage helloMessage = new HelloMessage(version, clientStr, capabilities, listenPort, peerId);
assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand());
assertEquals(version, helloMessage.getP2PVersion());
assertEquals(clientStr, helloMessage.getClientId());
assertEquals(4, helloMessage.getCapabilities().size());
assertEquals(listenPort, helloMessage.getListenPort());
assertEquals(peerId, helloMessage.getPeerId());
}
use of org.ethereum.net.client.Capability in project rskj by rsksmart.
the class RlpxConnectionTest method setUp.
@Before
public void setUp() throws Exception {
ECKey remoteKey = new ECKey();
ECKey myKey = new ECKey();
initiator = new EncryptionHandshake(remoteKey.getPubKeyPoint());
responder = new EncryptionHandshake();
AuthInitiateMessage initiate = initiator.createAuthInitiate(null, myKey);
byte[] initiatePacket = initiator.encryptAuthMessage(initiate);
byte[] responsePacket = responder.handleAuthInitiate(initiatePacket, remoteKey);
initiator.handleAuthResponse(myKey, initiatePacket, responsePacket);
to = new PipedInputStream(1024 * 1024);
toOut = new PipedOutputStream(to);
from = new PipedInputStream(1024 * 1024);
fromOut = new PipedOutputStream(from);
iCodec = new FrameCodec(initiator.getSecrets());
rCodec = new FrameCodec(responder.getSecrets());
byte[] nodeId = { 1, 2, 3, 4 };
iMessage = new HandshakeMessage(123, "abcd", Lists.newArrayList(new Capability("zz", (byte) 1), new Capability("yy", (byte) 3)), 3333, nodeId);
}
use of org.ethereum.net.client.Capability in project rskj by rsksmart.
the class AdaptiveMessageIdsTest method test4.
@Test
public void test4() {
List<Capability> capabilities = Arrays.asList(new Capability(Capability.RSK, EthVersion.V62.getCode()));
messageCodesResolver.init(capabilities);
assertEquals(0x10 + 0, messageCodesResolver.withEthOffset(EthMessageCodes.STATUS.asByte()));
assertEquals(0x10 + 1, messageCodesResolver.withEthOffset(EthMessageCodes.NEW_BLOCK_HASHES.asByte()));
assertEquals(0x10 + 2, messageCodesResolver.withEthOffset(EthMessageCodes.TRANSACTIONS.asByte()));
assertEquals(0x10 + 3, messageCodesResolver.withEthOffset(EthMessageCodes.GET_BLOCK_HEADERS.asByte()));
assertEquals(0x10 + 4, messageCodesResolver.withEthOffset(EthMessageCodes.BLOCK_HEADERS.asByte()));
assertEquals(0x10 + 5, messageCodesResolver.withEthOffset(EthMessageCodes.GET_BLOCK_BODIES.asByte()));
assertEquals(0x10 + 6, messageCodesResolver.withEthOffset(EthMessageCodes.BLOCK_BODIES.asByte()));
assertEquals(0x10 + 7, messageCodesResolver.withEthOffset(EthMessageCodes.NEW_BLOCK.asByte()));
}
use of org.ethereum.net.client.Capability in project rskj by rsksmart.
the class AdaptiveMessageIdsTest method test5.
// Capabilities should be read in alphabetical order
@Test
public void test5() {
List<Capability> capabilities = Arrays.asList(new Capability(Capability.RSK, EthVersion.V62.getCode()));
messageCodesResolver.init(capabilities);
assertEquals(0x10 + 0, messageCodesResolver.withEthOffset(EthMessageCodes.STATUS.asByte()));
assertEquals(0x10 + 1, messageCodesResolver.withEthOffset(EthMessageCodes.NEW_BLOCK_HASHES.asByte()));
assertEquals(0x10 + 2, messageCodesResolver.withEthOffset(EthMessageCodes.TRANSACTIONS.asByte()));
assertEquals(0x10 + 3, messageCodesResolver.withEthOffset(EthMessageCodes.GET_BLOCK_HEADERS.asByte()));
assertEquals(0x10 + 4, messageCodesResolver.withEthOffset(EthMessageCodes.BLOCK_HEADERS.asByte()));
assertEquals(0x10 + 5, messageCodesResolver.withEthOffset(EthMessageCodes.GET_BLOCK_BODIES.asByte()));
assertEquals(0x10 + 6, messageCodesResolver.withEthOffset(EthMessageCodes.BLOCK_BODIES.asByte()));
assertEquals(0x10 + 7, messageCodesResolver.withEthOffset(EthMessageCodes.NEW_BLOCK.asByte()));
}
Aggregations