From cbb9ca52b8d84aafc2bd6348c4ebe23dc2dfb0c5 Mon Sep 17 00:00:00 2001 From: Puneetha Date: Mon, 4 Mar 2019 15:21:54 +0000 Subject: [PATCH] Wait for private Tx receipt in acceptance tests. --- .../acceptance/dsl/AcceptanceTestBase.java | 5 +++ ...ectSuccessfulEeaGetTransactionReceipt.java | 36 +++++++++++++++++++ .../tests/acceptance/dsl/jsonrpc/Eea.java | 32 +++++++++++++++++ .../dsl/transaction/eea/EeaTransactions.java | 21 +++++++++++ ...loyPrivateSmartContractAcceptanceTest.java | 20 +++++++---- .../privacy/EeaGetTransactionReceipt.java | 6 ++++ .../internal/response/JsonRpcError.java | 3 +- 7 files changed, 116 insertions(+), 7 deletions(-) create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eea/ExpectSuccessfulEeaGetTransactionReceipt.java create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eea.java create mode 100644 acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eea/EeaTransactions.java diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java index c7c5d8889b..a19a446ab7 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/AcceptanceTestBase.java @@ -17,6 +17,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.contract.ContractVerifier; import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Admin; import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Clique; +import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eea; import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Eth; import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Ibft; import tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc.Login; @@ -27,6 +28,7 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.node.factory.PantheonNodeFactory; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.clique.CliqueTransactions; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eth.EthTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ibft.IbftTransactions; import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetTransactions; @@ -47,6 +49,7 @@ public class AcceptanceTestBase { protected final Ibft ibft; protected final Web3 web3; protected final Eth eth; + protected final Eea eea; protected final Login login; protected final Net net; protected final Perm perm; @@ -57,9 +60,11 @@ public class AcceptanceTestBase { protected AcceptanceTestBase() { final EthTransactions ethTransactions = new EthTransactions(); + final EeaTransactions eeaTransactions = new EeaTransactions(); accounts = new Accounts(ethTransactions); blockchain = new Blockchain(ethTransactions); eth = new Eth(ethTransactions); + eea = new Eea(eeaTransactions); cliqueTransactions = new CliqueTransactions(); ibftTransactions = new IbftTransactions(); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eea/ExpectSuccessfulEeaGetTransactionReceipt.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eea/ExpectSuccessfulEeaGetTransactionReceipt.java new file mode 100644 index 0000000000..778c624a6a --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/condition/eea/ExpectSuccessfulEeaGetTransactionReceipt.java @@ -0,0 +1,36 @@ +/* + * Copyright 2018 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. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea; + +import static org.assertj.core.api.Assertions.assertThat; + +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.ResponseTypes; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaGetTransactionReceiptTransaction; + +public class ExpectSuccessfulEeaGetTransactionReceipt implements Condition { + + private final EeaGetTransactionReceiptTransaction transaction; + + public ExpectSuccessfulEeaGetTransactionReceipt( + final EeaGetTransactionReceiptTransaction transaction) { + this.transaction = transaction; + } + + @Override + public void verify(final Node node) { + final ResponseTypes.PrivateTransactionReceipt response = node.execute(transaction); + assertThat(response.getContractAddress()).isNotEqualTo("0x"); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eea.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eea.java new file mode 100644 index 0000000000..594363d601 --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/jsonrpc/Eea.java @@ -0,0 +1,32 @@ +/* + * Copyright 2019 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. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.jsonrpc; + +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; +import tech.pegasys.pantheon.tests.acceptance.dsl.condition.eea.ExpectSuccessfulEeaGetTransactionReceipt; +import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea.EeaTransactions; + +public class Eea { + + EeaTransactions transactions; + + public Eea(final EeaTransactions transactions) { + this.transactions = transactions; + } + + public Condition expectSuccessfulTransactionReceipt( + final String transactionHash, final String publicKey) { + return new ExpectSuccessfulEeaGetTransactionReceipt( + transactions.getTransactionReceipt(transactionHash, publicKey)); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eea/EeaTransactions.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eea/EeaTransactions.java new file mode 100644 index 0000000000..2dcd4781db --- /dev/null +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/transaction/eea/EeaTransactions.java @@ -0,0 +1,21 @@ +/* + * Copyright 2019 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. + */ +package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.eea; + +public class EeaTransactions { + + public EeaGetTransactionReceiptTransaction getTransactionReceipt( + final String transactionHash, final String pubKey) { + return new EeaGetTransactionReceiptTransaction(transactionHash, pubKey); + } +} diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/DeployPrivateSmartContractAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/DeployPrivateSmartContractAcceptanceTest.java index d5ed9e1042..cef169d26f 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/DeployPrivateSmartContractAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/privacy/DeployPrivateSmartContractAcceptanceTest.java @@ -170,8 +170,10 @@ public void deployingMustGiveValidReceipt() { final String signedRawDeployTransaction = toRlp(DEPLOY_CONTRACT); final String transactionHash = minerNode.execute(transactions.createPrivateRawTransaction(signedRawDeployTransaction)); - minerNode.waitUntil(wait.chainHeadHasProgressedByAtLeast(minerNode, 2)); - waitFor(() -> minerNode.verify(eth.expectSuccessfulTransactionReceipt(transactionHash))); + waitFor( + 90, + () -> + minerNode.verify(eea.expectSuccessfulTransactionReceipt(transactionHash, PUBLIC_KEY))); TransactionReceipt txReceipt = minerNode.execute(transactions.getTransactionReceipt(transactionHash)).get(); @@ -184,8 +186,11 @@ public void deployingMustGiveValidReceipt() { final String transactionHashSet = minerNode.execute( transactions.createPrivateRawTransaction(signedRawSetFunctionTransaction)); - minerNode.waitUntil(wait.chainHeadHasProgressedByAtLeast(minerNode, 2)); - waitFor(() -> minerNode.verify(eth.expectSuccessfulTransactionReceipt(transactionHashSet))); + waitFor( + 90, + () -> + minerNode.verify( + eea.expectSuccessfulTransactionReceipt(transactionHashSet, PUBLIC_KEY))); PrivateTransactionReceipt privateTxReceiptSet = minerNode.execute( transactions.getPrivateTransactionReceipt(transactionHashSet, PUBLIC_KEY)); @@ -196,8 +201,11 @@ public void deployingMustGiveValidReceipt() { final String transactionHashGet = minerNode.execute( transactions.createPrivateRawTransaction(signedRawGetFunctionTransaction)); - minerNode.waitUntil(wait.chainHeadHasProgressedByAtLeast(minerNode, 2)); - waitFor(() -> minerNode.verify(eth.expectSuccessfulTransactionReceipt(transactionHashGet))); + waitFor( + 90, + () -> + minerNode.verify( + eea.expectSuccessfulTransactionReceipt(transactionHashGet, PUBLIC_KEY))); PrivateTransactionReceipt privateTxReceiptGet = minerNode.execute( transactions.getPrivateTransactionReceipt(transactionHashGet, PUBLIC_KEY)); diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetTransactionReceipt.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetTransactionReceipt.java index 1e8bc5f369..0f8db42718 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetTransactionReceipt.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaGetTransactionReceipt.java @@ -25,6 +25,8 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.parameters.JsonRpcParameter; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.queries.BlockchainQueries; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcError; +import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcErrorResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.response.JsonRpcSuccessResponse; import tech.pegasys.pantheon.ethereum.jsonrpc.internal.results.privacy.PrivateTransactionReceiptResult; @@ -115,6 +117,10 @@ public JsonRpcResponse response(final JsonRpcRequest request) { } }) .orElse(null); + if (result == null) { + return new JsonRpcErrorResponse( + request.getId(), JsonRpcError.PRIVATE_TRANSACTION_RECEIPT_ERROR); + } return new JsonRpcSuccessResponse(request.getId(), result); } } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java index 260cd3b594..8b174171f3 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/response/JsonRpcError.java @@ -85,7 +85,8 @@ public enum JsonRpcError { // Private transaction errors ENCLAVE_IS_DOWN(-50100, "Enclave is down"), - UNIMPLEMENTED_PRIVATE_TRANSACTION_TYPE(-50100, "Unimplemented private transaction type"); + UNIMPLEMENTED_PRIVATE_TRANSACTION_TYPE(-50100, "Unimplemented private transaction type"), + PRIVATE_TRANSACTION_RECEIPT_ERROR(-50100, "Error generating the private transaction receipt"); private final int code; private final String message;