use of org.hyperledger.besu.enclave.types.SendResponse in project besu by hyperledger.
the class FlexiblePrivacyControllerTest method createsPayload.
@Test
public void createsPayload() {
final PrivateTransaction privateTransaction = buildPrivateTransaction(1).signAndBuild(KEY_PAIR);
final SendResponse key = new SendResponse(KEY);
when(enclave.send(any(), any(), anyList())).thenReturn(key);
final String payload = privacyController.createPrivateMarkerTransactionPayload(privateTransaction, ADDRESS1, Optional.of(EXPECTED_PRIVACY_GROUP));
assertThat(payload).isNotNull().isEqualTo(KEY);
}
use of org.hyperledger.besu.enclave.types.SendResponse in project besu by hyperledger.
the class EnclaveTest method testSendAndReceive.
@Test
public void testSendAndReceive() {
final List<String> publicKeys = testHarness.getPublicKeys();
final SendResponse sr = enclave.send(PAYLOAD, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
final ReceiveResponse rr = enclave.receive(sr.getKey(), publicKeys.get(0));
assertThat(rr).isNotNull();
assertThat(new String(rr.getPayload(), UTF_8)).isEqualTo(PAYLOAD);
assertThat(rr.getPrivacyGroupId()).isNotNull();
}
use of org.hyperledger.besu.enclave.types.SendResponse in project besu by hyperledger.
the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.
@Test
public void testSendAndReceive() {
final List<String> publicKeys = testHarness.getPublicKeys();
final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
privateTransaction.writeTo(bytesValueRLPOutput);
final String s = bytesValueRLPOutput.encoded().toBase64String();
final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.enclave.types.SendResponse in project besu by hyperledger.
the class FlexiblePrivacyController method createPrivateMarkerTransactionPayload.
@Override
public String createPrivateMarkerTransactionPayload(final PrivateTransaction privateTransaction, final String privacyUserId, final Optional<PrivacyGroup> privacyGroup) {
LOG.trace("Storing private transaction in enclave");
final SendResponse sendResponse = sendRequest(privateTransaction, privacyGroup);
final String firstPart = sendResponse.getKey();
final Optional<String> optionalSecondPart = buildAndSendAddPayload(privateTransaction, Bytes32.wrap(privateTransaction.getPrivacyGroupId().orElseThrow()), privacyUserId);
return buildCompoundLookupId(firstPart, optionalSecondPart);
}
use of org.hyperledger.besu.enclave.types.SendResponse in project besu by hyperledger.
the class PrivGetPrivateTransactionIntegrationTest method returnsStoredPrivateTransaction.
@Test
public void returnsStoredPrivateTransaction() {
final PrivGetPrivateTransaction privGetPrivateTransaction = new PrivGetPrivateTransaction(privacyController, privacyIdProvider);
final Hash blockHash = Hash.ZERO;
final Transaction pmt = spy(privateMarkerTransaction());
when(blockchain.getTransactionByHash(eq(pmt.getHash()))).thenReturn(Optional.of(pmt));
when(blockchain.getTransactionLocation(eq(pmt.getHash()))).thenReturn(Optional.of(new TransactionLocation(blockHash, 0)));
final BlockHeader blockHeader = mock(BlockHeader.class);
when(blockHeader.getHash()).thenReturn(blockHash);
when(blockchain.getBlockHeader(eq(blockHash))).thenReturn(Optional.of(blockHeader));
final BytesValueRLPOutput bvrlp = new BytesValueRLPOutput();
privateTransaction.writeTo(bvrlp);
final String payload = Base64.getEncoder().encodeToString(bvrlp.encoded().toArrayUnsafe());
final ArrayList<String> to = Lists.newArrayList("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
final SendResponse sendResponse = enclave.send(payload, ENCLAVE_PUBLIC_KEY, to);
final Bytes hexKey = Bytes.fromBase64String(sendResponse.getKey());
when(pmt.getPayload()).thenReturn(hexKey);
final Object[] params = new Object[] { pmt.getHash() };
final JsonRpcRequestContext request = new JsonRpcRequestContext(new JsonRpcRequest("1", "priv_getPrivateTransaction", params));
final JsonRpcSuccessResponse response = (JsonRpcSuccessResponse) privGetPrivateTransaction.response(request);
final PrivateTransactionLegacyResult result = (PrivateTransactionLegacyResult) response.getResult();
assertThat(new PrivateTransactionLegacyResult(this.privateTransaction)).usingRecursiveComparison().isEqualTo(result);
}
Aggregations