diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionReceiptQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionReceiptQuery.java index 963e48684..3ef664096 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionReceiptQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionReceiptQuery.java @@ -198,6 +198,7 @@ ExecutionState getExecutionState(Status status, Response response) { case UNKNOWN: case RECEIPT_NOT_FOUND: case RECORD_NOT_FOUND: + case PLATFORM_NOT_ACTIVE: return ExecutionState.RETRY; case OK: @@ -216,6 +217,7 @@ ExecutionState getExecutionState(Status status, Response response) { case OK: case RECEIPT_NOT_FOUND: case RECORD_NOT_FOUND: + case PLATFORM_NOT_ACTIVE: return ExecutionState.RETRY; default: diff --git a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionRecordQuery.java b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionRecordQuery.java index dd8079c00..d0cfa3d7a 100644 --- a/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionRecordQuery.java +++ b/sdk/src/main/java/com/hedera/hashgraph/sdk/TransactionRecordQuery.java @@ -206,6 +206,7 @@ ExecutionState getExecutionState(Status status, Response response) { case OK: case RECEIPT_NOT_FOUND: case RECORD_NOT_FOUND: + case PLATFORM_NOT_ACTIVE: return ExecutionState.RETRY; default: diff --git a/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java b/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java index 9048440f6..c88bef908 100644 --- a/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java +++ b/sdk/src/test/java/com/hedera/hashgraph/sdk/MockingTest.java @@ -35,7 +35,9 @@ import com.hedera.hashgraph.sdk.proto.Transaction; import com.hedera.hashgraph.sdk.proto.TransactionBody; import com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse; +import com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse; import com.hedera.hashgraph.sdk.proto.TransactionReceipt; +import com.hedera.hashgraph.sdk.proto.TransactionRecord; import com.hedera.hashgraph.sdk.proto.TransactionResponse; import io.grpc.Status; import io.grpc.stub.StreamObserver; @@ -88,6 +90,98 @@ String makeBigString(int size) { return new String(chars); } + @ParameterizedTest(name = "[{0}] Executable retries on gRPC error with PLATFORM_NOT_ACTIVE when getting receipt") + @CsvSource({"sync", "async"}) + void shouldRetryExceptionallyFunctionsCorrectlyForPlatformNotActiveGetReceipt(String sync) throws Exception { + var service = new TestCryptoService(); + var server = new TestServer("getReceiptRetry" + sync, service); + server.client.setMaxAttempts(3); + + service.buffer.enqueueResponse(TestResponse.transaction(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE)); + service.buffer.enqueueResponse(TestResponse.transactionOk()); + + com.hedera.hashgraph.sdk.TransactionResponse transactionResponse; + if (sync.equals("sync")) { + transactionResponse = new AccountCreateTransaction().execute(server.client); + } else { + transactionResponse = new AccountCreateTransaction().executeAsync(server.client).get(); + } + + service.buffer + .enqueueResponse(TestResponse.query( + Response.newBuilder().setTransactionGetReceipt( + TransactionGetReceiptResponse.newBuilder() + .setHeader(ResponseHeader.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.PLATFORM_NOT_ACTIVE)) + .setReceipt(TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build()) + .build() + ).build() + )) + .enqueueResponse(TestResponse.receipt(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE)) + .enqueueResponse(TestResponse.successfulReceipt()); + + if (sync.equals("sync")) { + transactionResponse.getReceipt(server.client); + } else { + transactionResponse.getReceiptAsync(server.client).get(); + } + } + + @ParameterizedTest(name = "[{0}] Executable retries on gRPC error with PLATFORM_NOT_ACTIVE when getting record") + @CsvSource({"sync", "async"}) + void shouldRetryExceptionallyFunctionsCorrectlyForPlatformNotActiveGetRecord(String sync) throws Exception { + var service = new TestCryptoService(); + var server = new TestServer("getRecordRetry" + sync, service); + server.client.setMaxAttempts(3); + + service.buffer.enqueueResponse(TestResponse.transaction(com.hedera.hashgraph.sdk.Status.PLATFORM_NOT_ACTIVE)); + service.buffer.enqueueResponse(TestResponse.transactionOk()); + + com.hedera.hashgraph.sdk.TransactionResponse transactionResponse; + if (sync.equals("sync")) { + transactionResponse = new AccountCreateTransaction().execute(server.client); + } else { + transactionResponse = new AccountCreateTransaction().executeAsync(server.client).get(); + } + + service.buffer + .enqueueResponse(TestResponse.successfulReceipt()) // for inner getReceipt + .enqueueResponse(TestResponse.successfulReceipt()) // for inner getCost + .enqueueResponse(TestResponse.query( + Response.newBuilder().setTransactionGetRecord( + TransactionGetRecordResponse.newBuilder() + .setHeader(ResponseHeader.newBuilder().setNodeTransactionPrecheckCode(ResponseCodeEnum.PLATFORM_NOT_ACTIVE).build()) + .setTransactionRecord(TransactionRecord.newBuilder().setReceipt( + TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build() + ).build() + ).build() + ).build() + )) + .enqueueResponse(TestResponse.query( + Response.newBuilder().setTransactionGetRecord( + TransactionGetRecordResponse.newBuilder() + .setTransactionRecord(TransactionRecord.newBuilder().setReceipt( + TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.PLATFORM_NOT_ACTIVE).build() + ).build() + ).build() + ).build() + )) + .enqueueResponse(TestResponse.query( + Response.newBuilder().setTransactionGetRecord( + TransactionGetRecordResponse.newBuilder() + .setTransactionRecord(TransactionRecord.newBuilder().setReceipt( + TransactionReceipt.newBuilder().setStatus(ResponseCodeEnum.SUCCESS).build() + ).build() + ).build() + ).build() + )); + + if (sync.equals("sync")) { + transactionResponse.getRecord(server.client); + } else { + transactionResponse.getRecordAsync(server.client).get(); + } + } + @ParameterizedTest(name = "[{0}, {1}] ContractCreateFlow functions") @CsvSource({ "sync, stakedNode", @@ -653,6 +747,11 @@ public void getTransactionReceipts(Query request, StreamObserver respo respondToQueryFromQueue(request, responseObserver); } + @Override + public void getTxRecordByTxID(Query request, StreamObserver responseObserver) { + respondToQueryFromQueue(request, responseObserver); + } + @Override public void getAccountInfo(Query request, StreamObserver responseObserver) { respondToQueryFromQueue(request, responseObserver);