mirror of
https://github.com/vacp2p/status-linea-besu.git
synced 2026-01-08 21:38:15 -05:00
add sendSignedTransaction method to QuorumEnclave (#1642)
* add sendSignedTransaction method to QuorumEnclave Signed-off-by: Stefan Pingel <stefan.pingel@consensys.net>
This commit is contained in:
@@ -38,7 +38,8 @@ public class GoQuorumEnclaveTest {
|
||||
|
||||
private static final byte[] PAYLOAD = Base64.getDecoder().decode("EAAAAAAA");
|
||||
private static final String MOCK_KEY = "iOCzoGo5kwtZU0J41Z9xnGXHN6ZNukIa9MspvHtu3Jk=";
|
||||
private static final String KEY = "key";
|
||||
private static final String KEY =
|
||||
"tQEmN0d/xXJZs5OMgl8QVBIyYxu1XubAKehsSYbcOjbxai+QJQpEOs6ghrYAZizLtnM4EJdMyVeVrxO3cA9JJA==";
|
||||
private static GoQuorumEnclave enclave;
|
||||
|
||||
private RequestTransmitter vertxTransmitter;
|
||||
@@ -49,7 +50,7 @@ public class GoQuorumEnclaveTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpCheck() {
|
||||
public void upCheck() {
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/upcheck"), any()))
|
||||
.thenReturn("I'm up!");
|
||||
|
||||
@@ -57,7 +58,7 @@ public class GoQuorumEnclaveTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveThrowsWhenPayloadDoesNotExist() {
|
||||
public void receiveThrowsWhenPayloadDoesNotExist() {
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/receive"), any()))
|
||||
.thenThrow(
|
||||
new EnclaveClientException(404, "Message with hash " + MOCK_KEY + " was not found"));
|
||||
@@ -68,7 +69,7 @@ public class GoQuorumEnclaveTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceive() {
|
||||
public void sendAndReceive() {
|
||||
when(vertxTransmitter.post(any(), any(), any(), any())).thenReturn(new SendResponse(KEY));
|
||||
when(vertxTransmitter.get(any(), any(), ArgumentMatchers.contains("/receive"), any()))
|
||||
.thenReturn(new GoQuorumReceiveResponse(PAYLOAD, 0, null, null));
|
||||
@@ -83,6 +84,17 @@ public class GoQuorumEnclaveTest {
|
||||
assertThat(rr.getPayload()).isEqualTo(PAYLOAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendSignedTransaction() {
|
||||
when(vertxTransmitter.post(any(), any(), ArgumentMatchers.contains("/sendsignedtx"), any()))
|
||||
.thenReturn(new SendResponse(KEY));
|
||||
|
||||
final List<String> publicKeys = Arrays.asList("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=");
|
||||
|
||||
final SendResponse sr = enclave.sendSignedTransaction(PAYLOAD, publicKeys);
|
||||
assertThat(sr.getKey()).isEqualTo(KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upcheckReturnsFalseIfNoResponseReceived() throws URISyntaxException {
|
||||
final Vertx vertx = Vertx.vertx();
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.hyperledger.besu.enclave;
|
||||
import org.hyperledger.besu.enclave.RequestTransmitter.ResponseBodyHandler;
|
||||
import org.hyperledger.besu.enclave.types.GoQuorumReceiveResponse;
|
||||
import org.hyperledger.besu.enclave.types.GoQuorumSendRequest;
|
||||
import org.hyperledger.besu.enclave.types.GoQuorumSendSignedRequest;
|
||||
import org.hyperledger.besu.enclave.types.ReceiveRequest;
|
||||
import org.hyperledger.besu.enclave.types.SendResponse;
|
||||
|
||||
@@ -58,6 +59,16 @@ public class GoQuorumEnclave {
|
||||
(statusCode, body) -> handleJsonResponse(statusCode, body, SendResponse.class, 201));
|
||||
}
|
||||
|
||||
public SendResponse sendSignedTransaction(
|
||||
final byte[] txLookupId, final List<String> privateFor) {
|
||||
final GoQuorumSendSignedRequest request = new GoQuorumSendSignedRequest(txLookupId, privateFor);
|
||||
return post(
|
||||
JSON,
|
||||
request,
|
||||
"/sendsignedtx",
|
||||
(statusCode, body) -> handleJsonResponse(statusCode, body, SendResponse.class, 201));
|
||||
}
|
||||
|
||||
public GoQuorumReceiveResponse receive(final String payloadKey) {
|
||||
final ReceiveRequest request = new ReceiveRequest(payloadKey);
|
||||
return get(
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright ConsenSys AG.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
package org.hyperledger.besu.enclave.types;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
|
||||
@JsonPropertyOrder({"hash", "to"})
|
||||
public class GoQuorumSendSignedRequest {
|
||||
private final byte[] hash;
|
||||
private final List<String> to;
|
||||
|
||||
public GoQuorumSendSignedRequest(
|
||||
@JsonProperty(value = "hash") final byte[] hash,
|
||||
@JsonProperty(value = "to") final List<String> privateFor) {
|
||||
this.hash = hash;
|
||||
this.to = privateFor;
|
||||
}
|
||||
|
||||
public byte[] getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public List<String> getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user