admin_addPeer should accept only 1 argument

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Chris Mckay 6 years ago committed by GitHub
parent b4e59972e9
commit b221c13c55
  1. 3
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeer.java
  2. 29
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/AdminAddPeerTest.java

@ -44,6 +44,9 @@ public class AdminAddPeer implements JsonRpcMethod {
@Override
public JsonRpcResponse response(final JsonRpcRequest req) {
if (req.getParamLength() != 1) {
return new JsonRpcErrorResponse(req.getId(), JsonRpcError.INVALID_PARAMS);
}
try {
final String enodeString = parameters.required(req.getParams(), 0, String.class);
final Peer peer = DefaultPeer.fromURI(enodeString);

@ -91,6 +91,35 @@ public class AdminAddPeerTest {
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}
@Test
public void requestRefusesListOfNodes() {
final JsonRpcRequest request =
new JsonRpcRequest(
"2.0",
"admin_addPeer",
new String[] {
"enode://"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "@127.0.0.1:30303",
"enode://"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000000"
+ "00000000000000000000000000000001"
+ "@127.0.0.2:30303"
});
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(request.getId(), JsonRpcError.INVALID_PARAMS);
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
}
@Test
public void requestReturnsFalseIfAddFails() {
when(p2pNetwork.addMaintainConnectionPeer(any())).thenReturn(false);

Loading…
Cancel
Save