Commit 2ad8622f authored by luxq's avatar luxq

fix error

parent 576d9934
......@@ -14,7 +14,11 @@ public class AttackService {
this.jsonRpcClient = JsonRpcClientUtil.getJsonRpcClient();
}
private SafeFuture<AttackerResponse> invokeRpc(String method, Object[] params) {
public AttackService(final String url) {
this.jsonRpcClient = JsonRpcClientUtil.getJsonRpcClientByUrl(url);
}
private SafeFuture<AttackerResponse> invokeRpc(final String method, final Object[] params) {
try {
AttackerResponse response = jsonRpcClient.invoke(method, params, AttackerResponse.class);
return SafeFuture.completedFuture(response);
......@@ -25,59 +29,59 @@ public class AttackService {
}
}
public SafeFuture<AttackerResponse> blockGetNewParentRoot(long slot, String pubkey, String parentRoot) {
public SafeFuture<AttackerResponse> blockGetNewParentRoot(final long slot, final String pubkey, final String parentRoot) {
return invokeRpc(BLOCK_MODULE + "_getNewParentRoot", new Object[]{slot, pubkey, parentRoot});
}
public SafeFuture<AttackerResponse> delayForReceiveBlock(long slot) {
public SafeFuture<AttackerResponse> delayForReceiveBlock(final long slot) {
return invokeRpc(BLOCK_MODULE + "_delayForReceiveBlock", new Object[]{slot});
}
public SafeFuture<AttackerResponse> blockBeforeBroadcast(long slot) {
public SafeFuture<AttackerResponse> blockBeforeBroadcast(final long slot) {
return invokeRpc(BLOCK_MODULE + "_beforeBroadCast", new Object[]{slot});
}
public SafeFuture<AttackerResponse> blockAfterBroadcast(long slot) {
public SafeFuture<AttackerResponse> blockAfterBroadcast(final long slot) {
return invokeRpc(BLOCK_MODULE + "_afterBroadCast", new Object[]{slot});
}
public SafeFuture<AttackerResponse> blockBeforeSign(long slot, String pubkey, String blockDataBase64) {
public SafeFuture<AttackerResponse> blockBeforeSign(final long slot, final String pubkey, final String blockDataBase64) {
return invokeRpc(BLOCK_MODULE + "_beforeSign", new Object[]{slot, pubkey, blockDataBase64});
}
public SafeFuture<AttackerResponse> blockAfterSign(long slot, String pubkey, String signedBlockDataBase64) {
public SafeFuture<AttackerResponse> blockAfterSign(final long slot, final String pubkey, final String signedBlockDataBase64) {
return invokeRpc(BLOCK_MODULE + "_afterSign", new Object[]{slot, pubkey, signedBlockDataBase64});
}
public SafeFuture<AttackerResponse> blockBeforePropose(long slot, String pubkey, String signedBlockDataBase64) {
public SafeFuture<AttackerResponse> blockBeforePropose(final long slot, final String pubkey, final String signedBlockDataBase64) {
return invokeRpc(BLOCK_MODULE + "_beforePropose", new Object[]{slot, pubkey, signedBlockDataBase64});
}
public SafeFuture<AttackerResponse> blockAfterPropose(long slot, String pubkey, String signedBlockDataBase64) {
public SafeFuture<AttackerResponse> blockAfterPropose(final long slot, final String pubkey, final String signedBlockDataBase64) {
return invokeRpc(BLOCK_MODULE + "_afterPropose", new Object[]{slot, pubkey, signedBlockDataBase64});
}
public SafeFuture<AttackerResponse> attestBeforeBroadcast(long slot) {
public SafeFuture<AttackerResponse> attestBeforeBroadcast(final long slot) {
return invokeRpc(ATTEST_MODULE + "_beforeBroadCast", new Object[]{slot});
}
public SafeFuture<AttackerResponse> attestAfterBroadcast(long slot) {
public SafeFuture<AttackerResponse> attestAfterBroadcast(final long slot) {
return invokeRpc(ATTEST_MODULE + "_afterBroadCast", new Object[]{slot});
}
public SafeFuture<AttackerResponse> attestBeforeSign(long slot, String pubkey, String attestDataBase64) {
public SafeFuture<AttackerResponse> attestBeforeSign(final long slot, final String pubkey, final String attestDataBase64) {
return invokeRpc(ATTEST_MODULE + "_beforeSign", new Object[]{slot, pubkey, attestDataBase64});
}
public SafeFuture<AttackerResponse> attestAfterSign(long slot, String pubkey, String signedAttestDataBase64) {
public SafeFuture<AttackerResponse> attestAfterSign(final long slot, final String pubkey, final String signedAttestDataBase64) {
return invokeRpc(ATTEST_MODULE + "_afterSign", new Object[]{slot, pubkey, signedAttestDataBase64});
}
public SafeFuture<AttackerResponse> attestBeforePropose(long slot, String pubkey, String signedAttestDataBase64) {
public SafeFuture<AttackerResponse> attestBeforePropose(final long slot, final String pubkey, final String signedAttestDataBase64) {
return invokeRpc(ATTEST_MODULE + "_beforePropose", new Object[]{slot, pubkey, signedAttestDataBase64});
}
public SafeFuture<AttackerResponse> attestAfterPropose(long slot, String pubkey, String signedAttestDataBase64) {
public SafeFuture<AttackerResponse> attestAfterPropose(final long slot, final String pubkey, final String signedAttestDataBase64) {
return invokeRpc(ATTEST_MODULE + "_afterPropose", new Object[]{slot, pubkey, signedAttestDataBase64});
}
}
\ No newline at end of file
......@@ -34,7 +34,7 @@ public enum AttackerCommand {
private final int value;
AttackerCommand(int value) {
AttackerCommand(final int value) {
this.value = value;
}
......@@ -44,7 +44,7 @@ public enum AttackerCommand {
}
@JsonCreator
public static AttackerCommand fromValue(int value) {
public static AttackerCommand fromValue(final int value) {
for (AttackerCommand command : AttackerCommand.values()) {
if (command.value == value) {
return command;
......
......@@ -30,7 +30,7 @@ public class AttackerResponse {
// Default constructor for Jackson deserialization
}
public AttackerResponse(AttackerCommand cmd, String result) {
public AttackerResponse(final AttackerCommand cmd, final String result) {
this.cmd = cmd;
this.result = result;
}
......
......@@ -2,6 +2,7 @@ package tech.pegasys.teku.attacker;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import java.net.MalformedURLException;
import java.net.URI;
public class JsonRpcClientUtil {
......@@ -10,15 +11,22 @@ public class JsonRpcClientUtil {
}
public static JsonRpcHttpClient getJsonRpcClient(){
return JsonRpcHttpClientSingleton.singleton();
return JsonRpcHttpClientSingleton.singleton("");
}
public static JsonRpcHttpClient getJsonRpcClientByUrl(final String url){
return JsonRpcHttpClientSingleton.singleton(url);
}
private static class JsonRpcHttpClientSingleton{
private static JsonRpcHttpClient singleton(){
private static JsonRpcHttpClient singleton(final String url){
JsonRpcHttpClient client = null;
try {
client = new JsonRpcHttpClient(URI.create(System.getenv("ATTACKER_SERVICE_URL")).toURL());
} catch (Exception e) {
e.printStackTrace();
String real = url;
if (url.isEmpty()) {
real = System.getenv("ATTACKER_SERVICE_URL");
}
client = new JsonRpcHttpClient(URI.create(real).toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
return client;
}
......
......@@ -2,16 +2,23 @@ package tech.pegasys.teku.attacker;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
import java.util.concurrent.ExecutionException;
public class AttackServiceTest {
private AttackService attackService;
@Test
public void blockGetNewParentRoot() {
public void blockGetNewParentRoot() throws ExecutionException, InterruptedException {
attackService = new AttackService("http://127.0.0.1:12000");
long slot = 1L;
String pub = "";
String parentRoot = "";
SafeFuture<AttackerResponse> attackerResponse = attackService.blockGetNewParentRoot(slot, pub, parentRoot);
assertThat(attackerResponse.get().getCommond().getValue).(AttackerCommand.CMD_CONTINUE.getValue()s);
SafeFuture<AttackerResponse> attackerResponse = attackService.blockGetNewParentRoot(slot, pub, parentRoot);
assertThat(attackerResponse.get().getCmd().getValue())
.isEqualTo(AttackerCommand.CMD_NULL.getValue());
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment