diff --git a/exonum-light-client/CHANGELOG.md b/exonum-light-client/CHANGELOG.md index 2c61aa5db4..ae59776fba 100644 --- a/exonum-light-client/CHANGELOG.md +++ b/exonum-light-client/CHANGELOG.md @@ -15,6 +15,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Changed +- `TransactionResponse#getExecutionResult` now returns `ExecutionStatus` + instead of `TransactionResult`. (#1244) + ## 0.4.0 — 2019-10-09 The new release of the light client brings support for Exonum 0.12 @@ -28,7 +32,7 @@ and Exonum Java 0.8. - `ExonumClient#getBlockByHeight` and `#getBlocks` to throw `IllegalArgumentException` when blocks with heights exceeding the current blockchain height are requested (#1137) -- `Block` JSON representation to be compatible with the one used +- `Block` JSON representation to be compatible with the one used for blocks by the core. Applied `@SerializedName` annotation to all fields. (#1137) - Updated project dependencies to the newest versions. diff --git a/exonum-light-client/README.md b/exonum-light-client/README.md index 2963d54510..f4959748af 100644 --- a/exonum-light-client/README.md +++ b/exonum-light-client/README.md @@ -82,10 +82,10 @@ The following example shows how to create the transaction message. In addition please read about [transaction message structure][exonum-tx-message-builder]. ```java TransactionMessage txMessage = TransactionMessage.builder() - .serviceId((short) 1) - .transactionId((short) 2) + .serviceId(1) + .transactionId(2) .payload(data) - .sign(keys, CryptoFunctions.ed25519()); + .sign(keys); ``` * `data` is a bytes array which contains transactional information/parameters in a service-defined format. diff --git a/exonum-light-client/pom.xml b/exonum-light-client/pom.xml index bc66686853..1e27a216bd 100644 --- a/exonum-light-client/pom.xml +++ b/exonum-light-client/pom.xml @@ -61,7 +61,7 @@ - 0.8.0 + 0.9.0-SNAPSHOT 8 8 UTF-8 diff --git a/exonum-light-client/src/main/java/com/exonum/client/ExonumClient.java b/exonum-light-client/src/main/java/com/exonum/client/ExonumClient.java index b93b3e55d7..bebc66ce00 100644 --- a/exonum-light-client/src/main/java/com/exonum/client/ExonumClient.java +++ b/exonum-light-client/src/main/java/com/exonum/client/ExonumClient.java @@ -37,8 +37,8 @@ /** * Main interface for Exonum Light client. * Provides a convenient way for interaction with Exonum framework APIs. - * All the methods of the interface work in a blocking way - * i.e. invoke underlying request immediately, and block until the response can be processed + * All the methods of the interface work in a blocking way, + * i.e., invoke underlying request immediately, and block until the response can be processed * or an error occurs. In case the thread is interrupted, the blocked methods will complete * exceptionally. * diff --git a/exonum-light-client/src/main/java/com/exonum/client/ExplorerApiHelper.java b/exonum-light-client/src/main/java/com/exonum/client/ExplorerApiHelper.java index 75dd0aef78..0f5c38ddbe 100644 --- a/exonum-light-client/src/main/java/com/exonum/client/ExplorerApiHelper.java +++ b/exonum-light-client/src/main/java/com/exonum/client/ExplorerApiHelper.java @@ -18,10 +18,11 @@ package com.exonum.client; import static com.exonum.client.ExonumApi.JSON; +import static com.google.common.base.Preconditions.checkArgument; import static java.util.stream.Collectors.toList; +import com.exonum.binding.common.blockchain.ExecutionStatuses; import com.exonum.binding.common.blockchain.TransactionLocation; -import com.exonum.binding.common.blockchain.TransactionResult; import com.exonum.binding.common.hash.HashCode; import com.exonum.binding.common.message.TransactionMessage; import com.exonum.client.response.Block; @@ -29,6 +30,9 @@ import com.exonum.client.response.BlocksResponse; import com.exonum.client.response.TransactionResponse; import com.exonum.client.response.TransactionStatus; +import com.exonum.core.messages.Runtime.ErrorKind; +import com.exonum.core.messages.Runtime.ExecutionError; +import com.exonum.core.messages.Runtime.ExecutionStatus; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.gson.JsonArray; @@ -58,11 +62,11 @@ static HashCode parseSubmitTxResponse(String json) { static TransactionResponse parseGetTxResponse(String json) { GetTxResponse response = JSON.fromJson(json, GetTxResponse.class); - TransactionResult executionResult = getTransactionResult(response.getStatus()); + ExecutionStatus executionResult = getExecutionStatus(response.getStatus()); return new TransactionResponse( response.getType(), - response.getContent().getMessage(), + response.getContent(), executionResult, response.getLocation() ); @@ -87,25 +91,48 @@ static BlocksResponse parseGetBlocksResponse(String json) { ); } - private static TransactionResult getTransactionResult( + private static ExecutionStatus getExecutionStatus( GetTxResponseExecutionResult executionStatus) { if (executionStatus == null) { return null; } switch (executionStatus.getType()) { case SUCCESS: - return TransactionResult.successful(); - case ERROR: - return TransactionResult.error(executionStatus.getCode(), - executionStatus.getDescription()); + return ExecutionStatuses.success(); case PANIC: - return TransactionResult.unexpectedError(executionStatus.getDescription()); + return buildPanicExecutionStatus(executionStatus.getDescription()); + case DISPATCHER_ERROR: + return buildExecutionStatus(ErrorKind.DISPATCHER, executionStatus.getCode(), + executionStatus.getDescription()); + case RUNTIME_ERROR: + return buildExecutionStatus(ErrorKind.RUNTIME, executionStatus.getCode(), + executionStatus.getDescription()); + case SERVICE_ERROR: + return ExecutionStatuses.serviceError(executionStatus.getCode(), + executionStatus.getDescription()); default: throw new IllegalStateException("Unexpected transaction execution status: " + executionStatus.getType()); } } + @VisibleForTesting + static ExecutionStatus buildPanicExecutionStatus(String description) { + return buildExecutionStatus(ErrorKind.PANIC, 0, description); + } + + @VisibleForTesting + static ExecutionStatus buildExecutionStatus(ErrorKind errorKind, int code, + String description) { + checkArgument(0 <= code, "Error code (%s) must be non-negative", code); + return ExecutionStatus.newBuilder() + .setError(ExecutionError.newBuilder() + .setKind(errorKind) + .setCode(code) + .setDescription(description)) + .build(); + } + /** * Json object wrapper for submit transaction request. */ @@ -130,25 +157,14 @@ private static class GetTxResponse { @NonNull TransactionStatus type; @NonNull - GetTxResponseContent content; + TransactionMessage content; TransactionLocation location; JsonObject locationProof; //TODO: in scope of LC P3 GetTxResponseExecutionResult status; } /** - * Json object wrapper for get transaction response content i.e. - * {@code "$.content"}. - */ - @Value - private static class GetTxResponseContent { - JsonObject debug; // contains executable tx in json. currently not supported - @NonNull - TransactionMessage message; - } - - /** - * Json object wrapper for transaction execution result i.e. + * Json object wrapper for transaction execution result, i.e., * {@code "$.status"}. */ @Value @@ -159,16 +175,20 @@ private static class GetTxResponseExecutionResult { } /** - * Json object wrapper for transaction execution status i.e. + * Json object wrapper for transaction execution status, i.e., * {@code "$.status.type"}. */ private enum GetTxResponseExecutionStatus { @SerializedName("success") SUCCESS, - @SerializedName("error") - ERROR, @SerializedName("panic") - PANIC + PANIC, + @SerializedName("dispatcher_error") + DISPATCHER_ERROR, + @SerializedName("runtime_error") + RUNTIME_ERROR, + @SerializedName("service_error") + SERVICE_ERROR } @Value diff --git a/exonum-light-client/src/main/java/com/exonum/client/response/ConsensusStatus.java b/exonum-light-client/src/main/java/com/exonum/client/response/ConsensusStatus.java index ba7fd3ac37..0473929c36 100644 --- a/exonum-light-client/src/main/java/com/exonum/client/response/ConsensusStatus.java +++ b/exonum-light-client/src/main/java/com/exonum/client/response/ConsensusStatus.java @@ -22,8 +22,8 @@ */ public enum ConsensusStatus { /** - * Shows that consensus is active - * i.e. it is enabled and the node has enough connected peers. + * Shows that consensus is active, + * i.e., it is enabled and the node has enough connected peers. */ ACTIVE, /** diff --git a/exonum-light-client/src/main/java/com/exonum/client/response/TransactionStatus.java b/exonum-light-client/src/main/java/com/exonum/client/response/TransactionStatus.java index 567822de2c..d1b59f5c09 100644 --- a/exonum-light-client/src/main/java/com/exonum/client/response/TransactionStatus.java +++ b/exonum-light-client/src/main/java/com/exonum/client/response/TransactionStatus.java @@ -16,7 +16,7 @@ package com.exonum.client.response; -import com.exonum.binding.common.blockchain.TransactionResult; +import com.exonum.core.messages.Runtime.ExecutionStatus; import com.google.gson.annotations.SerializedName; /** @@ -31,7 +31,7 @@ public enum TransactionStatus { /** * Shows that transaction is committed to the blockchain. * Please note that a committed transaction has not necessarily completed - * successfully — use the {@linkplain TransactionResult execution result} + * successfully — use the {@linkplain ExecutionStatus execution result} * to check that. */ @SerializedName("committed") diff --git a/exonum-light-client/src/main/lombok/com/exonum/client/response/Block.java b/exonum-light-client/src/main/lombok/com/exonum/client/response/Block.java index 09c3f90dee..9c15939472 100644 --- a/exonum-light-client/src/main/lombok/com/exonum/client/response/Block.java +++ b/exonum-light-client/src/main/lombok/com/exonum/client/response/Block.java @@ -100,7 +100,6 @@ public Optional getCommitTime() { return Optional.ofNullable(commitTime); } - /** * Returns true if this block is empty: * contains no {@linkplain #getNumTransactions() transactions}. diff --git a/exonum-light-client/src/main/lombok/com/exonum/client/response/TransactionResponse.java b/exonum-light-client/src/main/lombok/com/exonum/client/response/TransactionResponse.java index ffb1f24766..4c858dd0b2 100644 --- a/exonum-light-client/src/main/lombok/com/exonum/client/response/TransactionResponse.java +++ b/exonum-light-client/src/main/lombok/com/exonum/client/response/TransactionResponse.java @@ -20,8 +20,8 @@ import static com.google.common.base.Preconditions.checkState; import com.exonum.binding.common.blockchain.TransactionLocation; -import com.exonum.binding.common.blockchain.TransactionResult; import com.exonum.binding.common.message.TransactionMessage; +import com.exonum.core.messages.Runtime.ExecutionStatus; import com.google.common.base.Objects; import lombok.Value; @@ -39,7 +39,7 @@ public class TransactionResponse { * Transaction execution result. * Not available unless the transaction is {@linkplain #isCommitted committed} to the blockchain. */ - TransactionResult executionResult; + ExecutionStatus executionResult; /** * Transaction location in the blockchain. * Not available unless the transaction is {@linkplain #isCommitted committed} to the blockchain. @@ -50,7 +50,7 @@ public class TransactionResponse { * Returns transaction execution result. * @throws IllegalStateException if the transaction is not committed yet */ - public TransactionResult getExecutionResult() { + public ExecutionStatus getExecutionResult() { checkState(status == COMMITTED, "Transaction result is available for committed transactions only"); return executionResult; diff --git a/exonum-light-client/src/test/java/com/exonum/client/ExonumHttpClientIntegrationTest.java b/exonum-light-client/src/test/java/com/exonum/client/ExonumHttpClientIntegrationTest.java index 3a44b3005e..57f0a17b31 100644 --- a/exonum-light-client/src/test/java/com/exonum/client/ExonumHttpClientIntegrationTest.java +++ b/exonum-light-client/src/test/java/com/exonum/client/ExonumHttpClientIntegrationTest.java @@ -70,10 +70,10 @@ void submitTransactionTest() throws InterruptedException { // Create request KeyPair keys = ed25519().generateKeyPair(); TransactionMessage txMessage = TransactionMessage.builder() - .serviceId((short) 1) - .transactionId((short) 2) + .serviceId(1) + .transactionId(2) .payload(new byte[]{0x00, 0x01, 0x02}) - .sign(keys, ed25519()); + .sign(keys); // Mock response String hash = "f128c720e04b8243"; String mockResponse = "{\"tx_hash\":\"" + hash + "\"}"; @@ -160,16 +160,7 @@ void getTransaction() throws InterruptedException { TransactionMessage expectedMessage = createTransactionMessage(); String mockResponse = "{\n" + " 'type': 'in-pool',\n" - + " 'content': {\n" - + " 'debug': {\n" - + " 'to': {\n" - + " 'data': []\n" - + " },\n" - + " 'amount': 10,\n" - + " 'seed': 9587307158524814255\n" - + " },\n" - + " 'message': '" + toHex(expectedMessage) + "'\n" - + " }\n" + + " 'content': '" + toHex(expectedMessage) + "'\n" + "}"; server.enqueue(new MockResponse().setBody(mockResponse)); diff --git a/exonum-light-client/src/test/java/com/exonum/client/ExplorerApiHelperTest.java b/exonum-light-client/src/test/java/com/exonum/client/ExplorerApiHelperTest.java index 794b0046c4..b146a923c5 100644 --- a/exonum-light-client/src/test/java/com/exonum/client/ExplorerApiHelperTest.java +++ b/exonum-light-client/src/test/java/com/exonum/client/ExplorerApiHelperTest.java @@ -30,9 +30,10 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.params.provider.Arguments.arguments; +import com.exonum.binding.common.blockchain.ExecutionStatuses; import com.exonum.binding.common.blockchain.TransactionLocation; -import com.exonum.binding.common.blockchain.TransactionResult; import com.exonum.binding.common.hash.HashCode; import com.exonum.binding.common.message.TransactionMessage; import com.exonum.client.response.Block; @@ -40,11 +41,42 @@ import com.exonum.client.response.BlocksResponse; import com.exonum.client.response.TransactionResponse; import com.exonum.client.response.TransactionStatus; +import com.exonum.core.messages.Runtime.ErrorKind; +import com.exonum.core.messages.Runtime.ExecutionStatus; import java.time.ZonedDateTime; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; class ExplorerApiHelperTest { + private static TransactionMessage TRANSACTION_MESSAGE = createTransactionMessage(); + private static long BLOCK_HEIGHT = 1L; + private static long INDEX_IN_BLOCK = 0L; + + private static String TEMPLATE_TRANSACTION_MESSAGE_JSON = "{\n" + + " 'type': 'committed',\n" + + " 'content': '" + toHex(TRANSACTION_MESSAGE) + "',\n" + + " 'location': {\n" + + " 'block_height': " + BLOCK_HEIGHT + ",\n" + + " 'position_in_block': " + INDEX_IN_BLOCK + "\n" + + " },\n" + + " 'location_proof': {\n" + + " 'entries': [\n" + + " [\n" + + " 0,\n" + + " 'd27f4ae6692fc00caf4e51ca7c072bab35487bb0d56272e08b6069ebadb52100'\n" + + " ]\n" + + " ],\n" + + " 'length': 1,\n" + + " 'proof': []\n" + + " },\n" + + " %s,\n" + + " 'time': '2019-12-02T21:51:36.439431Z'" + + "}"; + @Test void parseSubmitTxResponse() { String expected = "f128c720e04b8243"; @@ -56,130 +88,29 @@ void parseSubmitTxResponse() { @Test void parseGetTxResponseInPool() { - TransactionMessage expectedMessage = createTransactionMessage(); String json = "{\n" + " 'type': 'in-pool',\n" - + " 'content': {\n" - + " 'debug': {\n" - + " 'to': {\n" - + " 'data': []\n" - + " },\n" - + " 'amount': 10,\n" - + " 'seed': 9587307158524814255\n" - + " },\n" - + " 'message': '" + toHex(expectedMessage) + "'\n" - + " }\n" + + " 'content': '" + toHex(TRANSACTION_MESSAGE) + "'\n" + "}"; TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); assertThat(transactionResponse.getStatus(), is(TransactionStatus.IN_POOL)); - assertThat(transactionResponse.getMessage(), is(expectedMessage)); + assertThat(transactionResponse.getMessage(), is(TRANSACTION_MESSAGE)); assertThrows(IllegalStateException.class, transactionResponse::getExecutionResult); assertThrows(IllegalStateException.class, transactionResponse::getLocation); } - @Test - void parseGetTxResponseCommitted() { - TransactionMessage expectedMessage = createTransactionMessage(); - String json = "{\n" - + " 'type': 'committed',\n" - + " 'content': {\n" - + " 'debug': {\n" - + " 'to': {\n" - + " 'data': []\n" - + " },\n" - + " 'amount': 10,\n" - + " 'seed': 2084648087298472854\n" - + " },\n" - + " 'message': '" + toHex(expectedMessage) + "'\n" - + " },\n" - + " 'location': {\n" - + " 'block_height': 11,\n" - + " 'position_in_block': 0\n" - + " },\n" - + " 'location_proof': {\n" - + " 'val': '2f23541b10b258dfc80693ed1bf6'\n" - + " },\n" - + " 'status': {\n" - + " 'type': 'success'\n" - + " }\n" - + "}"; + @ParameterizedTest + @MethodSource("testData") + void parseGetTxResponseCommitted(ExecutionStatus executionStatus, String statusJson) { + String json = String.format(TEMPLATE_TRANSACTION_MESSAGE_JSON, statusJson); TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); assertThat(transactionResponse.getStatus(), is(TransactionStatus.COMMITTED)); - assertThat(transactionResponse.getMessage(), is(expectedMessage)); - assertThat(transactionResponse.getExecutionResult(), is(TransactionResult.successful())); - assertThat(transactionResponse.getLocation(), is(TransactionLocation.valueOf(11L, 0L))); - } - - @Test - void parseGetTxResponseCommittedWithError() { - TransactionMessage expectedMessage = createTransactionMessage(); - int errorCode = 2; - String errorDescription = "Receiver doesn't exist"; - String json = "{\n" - + " 'type': 'committed',\n" - + " 'content': {\n" - + " 'debug': {\n" - + " 'amount': 1,\n" - + " 'seed': 5019726028924803177\n" - + " },\n" - + " 'message': '" + toHex(expectedMessage) + "'\n" - + " },\n" - + " 'location': {\n" - + " 'block_height': 1,\n" - + " 'position_in_block': 0\n" - + " },\n" - + " 'location_proof': {\n" - + " 'val': 'e8a00b3747d396be45dbea3bc31cdb072'\n" - + " },\n" - + " 'status': {\n" - + " 'type': 'error',\n" - + " 'code': " + errorCode + ",\n" - + " 'description': \"" + errorDescription + "\"" - + " }\n" - + "}"; - TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); - - assertThat(transactionResponse.getStatus(), is(TransactionStatus.COMMITTED)); - assertThat(transactionResponse.getMessage(), is(expectedMessage)); - assertThat(transactionResponse.getExecutionResult(), - is(TransactionResult.error(errorCode, errorDescription))); - assertThat(transactionResponse.getLocation(), is(TransactionLocation.valueOf(1L, 0L))); - } - - @Test - void parseGetTxResponseCommittedWithPanic() { - TransactionMessage expectedMessage = createTransactionMessage(); - String errorDescription = "panic happens"; - String json = "{\n" - + " 'type': 'committed',\n" - + " 'content': {\n" - + " 'debug': {\n" - + " 'amount': 1,\n" - + " 'seed': 5019726028924803177\n" - + " },\n" - + " 'message': '" + toHex(expectedMessage) + "'\n" - + " },\n" - + " 'location': {\n" - + " 'block_height': 1,\n" - + " 'position_in_block': 0\n" - + " },\n" - + " 'location_proof': {\n" - + " 'val': 'e8a00b3747d396be45dbea3bc31cdb072'\n" - + " },\n" - + " 'status': {\n" - + " 'type': 'panic',\n" - + " 'description': '" + errorDescription + "'" - + " }\n" - + "}"; - TransactionResponse transactionResponse = ExplorerApiHelper.parseGetTxResponse(json); - - assertThat(transactionResponse.getStatus(), is(TransactionStatus.COMMITTED)); - assertThat(transactionResponse.getMessage(), is(expectedMessage)); - assertThat(transactionResponse.getExecutionResult(), - is(TransactionResult.unexpectedError(errorDescription))); - assertThat(transactionResponse.getLocation(), is(TransactionLocation.valueOf(1L, 0L))); + assertThat(transactionResponse.getMessage(), is(TRANSACTION_MESSAGE)); + assertThat(transactionResponse.getExecutionResult(), is(executionStatus)); + assertThat(transactionResponse.getLocation(), + is(TransactionLocation.valueOf(BLOCK_HEIGHT, INDEX_IN_BLOCK))); } @Test @@ -240,4 +171,38 @@ void parseGetBlocksResponse() { assertThat(response.getBlocksRangeEnd(), is(288L)); } + private static Stream testData() { + String successStatus = "'status': {\n" + + " 'type': 'success'\n" + + "}\n"; + + int errorCode = 1; + String errorDescription = "Some error"; + String errorStatusTemplate = "'status': {\n" + + " 'type': '%s',\n" + + " 'code': " + errorCode + ",\n" + + " 'description': \"" + errorDescription + "\"" + + "}\n"; + + String serviceErrorStatus = String.format(errorStatusTemplate, "service_error"); + String dispatcherErrorStatus = String.format(errorStatusTemplate, "dispatcher_error"); + String runtimeErrorStatus = String.format(errorStatusTemplate, "runtime_error"); + + String panicStatus = "'status': {\n" + + " 'type': 'panic',\n" + + " 'description': \"" + errorDescription + "\"" + + "}\n"; + + return Stream.of( + arguments(ExecutionStatuses.success(), successStatus), + arguments(ExecutionStatuses.serviceError(errorCode, errorDescription), serviceErrorStatus), + arguments(ExplorerApiHelper.buildExecutionStatus(ErrorKind.DISPATCHER, errorCode, + errorDescription), + dispatcherErrorStatus), + arguments(ExplorerApiHelper.buildExecutionStatus(ErrorKind.RUNTIME, errorCode, + errorDescription), + runtimeErrorStatus), + arguments(ExplorerApiHelper.buildPanicExecutionStatus(errorDescription), panicStatus) + ); + } } diff --git a/exonum-light-client/src/test/java/com/exonum/client/TestUtils.java b/exonum-light-client/src/test/java/com/exonum/client/TestUtils.java index 431802d7f3..5330c1e424 100644 --- a/exonum-light-client/src/test/java/com/exonum/client/TestUtils.java +++ b/exonum-light-client/src/test/java/com/exonum/client/TestUtils.java @@ -26,10 +26,10 @@ final class TestUtils { static TransactionMessage createTransactionMessage() { return TransactionMessage.builder() - .serviceId((short) 10) - .transactionId((short) 15) + .serviceId(10) + .transactionId(15) .payload(new byte[]{0x01, 0x02, 0x03}) - .sign(ed25519().generateKeyPair(), ed25519()); + .sign(ed25519().generateKeyPair()); } static String toHex(TransactionMessage message) { diff --git a/exonum-light-client/src/test/java/com/exonum/client/response/TransactionResponseTest.java b/exonum-light-client/src/test/java/com/exonum/client/response/TransactionResponseTest.java index dc93e1be97..693303471c 100644 --- a/exonum-light-client/src/test/java/com/exonum/client/response/TransactionResponseTest.java +++ b/exonum-light-client/src/test/java/com/exonum/client/response/TransactionResponseTest.java @@ -24,9 +24,11 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; +import com.exonum.binding.common.blockchain.ExecutionStatuses; import com.exonum.binding.common.blockchain.TransactionLocation; -import com.exonum.binding.common.blockchain.TransactionResult; import com.exonum.binding.common.message.TransactionMessage; +import com.exonum.core.messages.Runtime.ExecutionStatus; +import com.google.protobuf.ByteString; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -51,7 +53,7 @@ void toStringCommittedTxTest() { TransactionResponse response = new TransactionResponse(COMMITTED, withTxMessage(), - TransactionResult.successful(), + ExecutionStatuses.success(), withTxLocation()); assertThat(response.toString(), allOf( @@ -63,15 +65,19 @@ void toStringCommittedTxTest() { @Test void equalsTest() { EqualsVerifier.forClass(TransactionResponse.class) + .withPrefabValues( + ByteString.class, ByteString.copyFromUtf8("a"), ByteString.copyFromUtf8("b")) + .withPrefabValues( + ExecutionStatus.class, ExecutionStatuses.success(), ExecutionStatuses.serviceError(1)) .verify(); } private static TransactionMessage withTxMessage() { return TransactionMessage.builder() - .serviceId((short) 1) - .transactionId((short) 1) + .serviceId(1) + .transactionId(1) .payload(new byte[]{}) - .sign(ed25519().generateKeyPair(), ed25519()); + .sign(ed25519().generateKeyPair()); } private static TransactionLocation withTxLocation() {