Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Wait for transaction to be mined before getting the Transaction receipt.
Browse files Browse the repository at this point in the history
  • Loading branch information
Puneetha17 committed Apr 25, 2019
1 parent 0cb92b4 commit 8a662b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.tests.web3j.privacy;

import static java.nio.charset.StandardCharsets.UTF_8;
import static tech.pegasys.pantheon.tests.acceptance.dsl.WaitUtils.waitFor;

import tech.pegasys.orion.testutil.OrionTestHarness;
import tech.pegasys.pantheon.crypto.SECP256K1;
Expand Down Expand Up @@ -98,9 +99,12 @@ public void deployingMustGiveValidReceipt() {

@Test
public void privateSmartContractMustEmitEvents() {
minerNode.execute(privateTransactions.deployPrivateSmartContract(deployContract));
String transactionHash =
minerNode.execute(privateTransactions.deployPrivateSmartContract(deployContract));

final String transactionHash =
waitForTransactionToBeMined(transactionHash);

transactionHash =
minerNode.execute(privateTransactions.createPrivateRawTransaction(storeValue));

privateTransactionVerifier.validEventReturned("1000").verify(minerNode, transactionHash);
Expand All @@ -109,12 +113,17 @@ public void privateSmartContractMustEmitEvents() {
@Test
public void privateSmartContractMustReturnValues() {

minerNode.execute(privateTransactions.deployPrivateSmartContract(deployContract));
String transactionHash =
minerNode.execute(privateTransactions.deployPrivateSmartContract(deployContract));

minerNode.execute(privateTransactions.createPrivateRawTransaction(storeValue));
waitForTransactionToBeMined(transactionHash);

final String transactionHash =
minerNode.execute(privateTransactions.createPrivateRawTransaction(getValue));
transactionHash =
minerNode.execute(privateTransactions.createPrivateRawTransaction(storeValue));

waitForTransactionToBeMined(transactionHash);

transactionHash = minerNode.execute(privateTransactions.createPrivateRawTransaction(getValue));

privateTransactionVerifier.validOutputReturned("1000").verify(minerNode, transactionHash);
}
Expand All @@ -123,4 +132,8 @@ public void privateSmartContractMustReturnValues() {
public void tearDown() {
enclave.getOrion().stop();
}

public void waitForTransactionToBeMined(final String transactionHash) {
waitFor(() -> minerNode.verify(eea.expectSuccessfulTransactionReceipt(transactionHash)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
PrivateTransaction privateTransaction;
String privacyGroupId;
try {
privateTransaction = getTransactionFromEnclave(transaction, publicKey);
privacyGroupId = getPrivacyGroupIdFromEnclave(transaction, publicKey);
ReceiveResponse receiveResponse = getReceiveResponseFromEnclave(transaction, publicKey);
LOG.trace("Received transaction information from Enclave");

final BytesValueRLPInput bytesValueRLPInput =
new BytesValueRLPInput(
BytesValue.wrap(Base64.getDecoder().decode(receiveResponse.getPayload())), false);

privateTransaction = PrivateTransaction.readFrom(bytesValueRLPInput);
privacyGroupId = receiveResponse.getPrivacyGroupId();
} catch (Exception e) {
LOG.error("Failed to fetch transaction from Enclave with error " + e.getMessage());
return new JsonRpcSuccessResponse(
Expand Down Expand Up @@ -151,26 +158,13 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
return new JsonRpcSuccessResponse(request.getId(), result);
}

private String getPrivacyGroupIdFromEnclave(final Transaction transaction, final String publicKey)
throws IOException {
LOG.trace("Fetching transaction information from Enclave");
final ReceiveRequest enclaveRequest =
new ReceiveRequest(new String(transaction.getPayload().extractArray(), UTF_8), publicKey);
ReceiveResponse enclaveResponse = enclave.receive(enclaveRequest);
LOG.trace("Received transaction information from Enclave");
return enclaveResponse.getPrivacyGroupId();
}

private PrivateTransaction getTransactionFromEnclave(
private ReceiveResponse getReceiveResponseFromEnclave(
final Transaction transaction, final String publicKey) throws IOException {
LOG.trace("Fetching transaction information from Enclave");
final ReceiveRequest enclaveRequest =
new ReceiveRequest(new String(transaction.getPayload().extractArray(), UTF_8), publicKey);
ReceiveResponse enclaveResponse = enclave.receive(enclaveRequest);
final BytesValueRLPInput bytesValueRLPInput =
new BytesValueRLPInput(
BytesValue.wrap(Base64.getDecoder().decode(enclaveResponse.getPayload())), false);
LOG.trace("Received transaction information from Enclave");
return PrivateTransaction.readFrom(bytesValueRLPInput);
return enclaveResponse;
}
}

0 comments on commit 8a662b0

Please sign in to comment.