From 622537f0e0b7730008964bfeff41ceecff5f35f5 Mon Sep 17 00:00:00 2001 From: Dmitry Timofeev Date: Wed, 13 Nov 2019 20:28:04 +0200 Subject: [PATCH 1/2] Remove Transaction#info: [ECR-3793] This operation is no longer used by the framework. --- .../binding/core/transaction/Transaction.java | 31 ++----- .../core/transaction/TransactionTest.java | 42 --------- .../transactions/SetEntryTransaction.java | 89 ------------------- .../SetEntryTransactionIntegrationTest.java | 81 ----------------- 4 files changed, 7 insertions(+), 236 deletions(-) delete mode 100644 exonum-java-binding/core/src/test/java/com/exonum/binding/core/transaction/TransactionTest.java delete mode 100644 exonum-java-binding/fakes/src/main/java/com/exonum/binding/fakes/services/transactions/SetEntryTransaction.java delete mode 100644 exonum-java-binding/fakes/src/test/java/com/exonum/binding/fakes/services/transactions/SetEntryTransactionIntegrationTest.java diff --git a/exonum-java-binding/core/src/main/java/com/exonum/binding/core/transaction/Transaction.java b/exonum-java-binding/core/src/main/java/com/exonum/binding/core/transaction/Transaction.java index 5a40088fe3..552c7e4a3b 100644 --- a/exonum-java-binding/core/src/main/java/com/exonum/binding/core/transaction/Transaction.java +++ b/exonum-java-binding/core/src/main/java/com/exonum/binding/core/transaction/Transaction.java @@ -16,6 +16,8 @@ package com.exonum.binding.core.transaction; +import com.exonum.core.messages.Runtime.ExecutionError; + /** * An Exonum transaction. * @@ -31,34 +33,15 @@ public interface Transaction { * @param context a transaction execution context, which allows to access the information about * this transaction and modify the blockchain state through the included database fork * @throws TransactionExecutionException if the transaction cannot be executed normally - * and has to be rolled back. The transaction will be committed as failed (status "error"), - * the error code with the optional description will be saved into the storage. The client - * can request the error code to know the reason of the failure + * and has to be rolled back. The transaction will be committed as failed (error kind + * {@linkplain com.exonum.core.messages.Runtime.ErrorKind#SERVICE SERVICE}), + * the {@linkplain ExecutionError#getCode() error code} with the optional description + * will be saved into the storage. The client can request the error code to know the reason + * of the failure * @throws RuntimeException if an unexpected error occurs. A correct transaction implementation * must not throw such exceptions. The transaction will be committed as failed * (status "panic") */ void execute(TransactionContext context) throws TransactionExecutionException; - /** - * Returns the information about this transaction in JSON format. - * For example, it is included in the blockchain explorer response to - * a - * transaction request as 'content.debug'. - * - *

By default, no information is provided. If needed, it can be easily implemented - * with {@linkplain com.exonum.binding.common.serialization.json.JsonSerializer Gson}: - * - *


-   *   @Override
-   *   public String info() {
-   *     return JsonSerializer.json().toJson(this);
-   *   }
-   * 
- */ - default String info() { - // Empty object by default - return "{}"; - } - } diff --git a/exonum-java-binding/core/src/test/java/com/exonum/binding/core/transaction/TransactionTest.java b/exonum-java-binding/core/src/test/java/com/exonum/binding/core/transaction/TransactionTest.java deleted file mode 100644 index 47be68ef19..0000000000 --- a/exonum-java-binding/core/src/test/java/com/exonum/binding/core/transaction/TransactionTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2019 The Exonum Team - * - * 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 com.exonum.binding.core.transaction; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import java.util.Map; -import org.junit.jupiter.api.Test; - -class TransactionTest { - - @Test - void infoIsEmptyByDefault() { - Transaction tx = context -> { - // no-op - }; - - String info = tx.info(); - - // Check it is correctly deserialized to an empty object - Gson gson = new Gson(); - Map deserialized = gson.fromJson(info, new TypeToken>() { - }.getType()); - assertThat(deserialized).isEmpty(); - } -} diff --git a/exonum-java-binding/fakes/src/main/java/com/exonum/binding/fakes/services/transactions/SetEntryTransaction.java b/exonum-java-binding/fakes/src/main/java/com/exonum/binding/fakes/services/transactions/SetEntryTransaction.java deleted file mode 100644 index 431f788ebe..0000000000 --- a/exonum-java-binding/fakes/src/main/java/com/exonum/binding/fakes/services/transactions/SetEntryTransaction.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2018 The Exonum Team - * - * 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 com.exonum.binding.fakes.services.transactions; - -import static com.exonum.binding.common.serialization.StandardSerializers.hash; -import static com.exonum.binding.common.serialization.StandardSerializers.publicKey; -import static com.exonum.binding.common.serialization.StandardSerializers.string; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.exonum.binding.common.crypto.PublicKey; -import com.exonum.binding.common.hash.HashCode; -import com.exonum.binding.core.storage.database.Fork; -import com.exonum.binding.core.storage.indices.EntryIndexProxy; -import com.exonum.binding.core.transaction.Transaction; -import com.exonum.binding.core.transaction.TransactionContext; -import com.google.common.annotations.VisibleForTesting; - -/** - * A transaction whose behaviour can be configured. It's not a mock: it writes a given value - * into the database in its {@link #execute(TransactionContext)}. - * - *

Such transaction is supposed to be used in TransactionProxy integration tests. - */ -public final class SetEntryTransaction implements Transaction { - - @VisibleForTesting - static final String ENTRY_NAME = "test_entry"; - @VisibleForTesting - static final String TX_HASH_NAME = "tx_hash"; - @VisibleForTesting - static final String AUTHOR_PK_NAME = "author_pk"; - - private final String value; - private final String info; - - /** - * Creates a transaction with a pre-configured behaviour. - * - * @param value a value to put into an entry {@link #ENTRY_NAME} - * @param info a value to be returned as this transaction text representation - * {@link Transaction#info()} - */ - public SetEntryTransaction(String value, String info) { - this.value = checkNotNull(value); - this.info = checkNotNull(info); - } - - @Override - public void execute(TransactionContext context) { - Fork fork = context.getFork(); - EntryIndexProxy entry = createTestEntry(fork); - entry.set(value); - EntryIndexProxy txHash = createTxHashEntry(fork); - txHash.set(context.getTransactionMessageHash()); - EntryIndexProxy authorPk = createAuthorPkEntry(fork); - authorPk.set(context.getAuthorPk()); - } - - @Override - public String info() { - return info; - } - - private EntryIndexProxy createTestEntry(Fork view) { - return EntryIndexProxy.newInstance(ENTRY_NAME, view, string()); - } - - private EntryIndexProxy createTxHashEntry(Fork view) { - return EntryIndexProxy.newInstance(TX_HASH_NAME, view, hash()); - } - - private EntryIndexProxy createAuthorPkEntry(Fork view) { - return EntryIndexProxy.newInstance(AUTHOR_PK_NAME, view, publicKey()); - } -} diff --git a/exonum-java-binding/fakes/src/test/java/com/exonum/binding/fakes/services/transactions/SetEntryTransactionIntegrationTest.java b/exonum-java-binding/fakes/src/test/java/com/exonum/binding/fakes/services/transactions/SetEntryTransactionIntegrationTest.java deleted file mode 100644 index e609d7cbec..0000000000 --- a/exonum-java-binding/fakes/src/test/java/com/exonum/binding/fakes/services/transactions/SetEntryTransactionIntegrationTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2018 The Exonum Team - * - * 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 com.exonum.binding.fakes.services.transactions; - -import static com.exonum.binding.common.serialization.StandardSerializers.hash; -import static com.exonum.binding.common.serialization.StandardSerializers.publicKey; -import static com.exonum.binding.common.serialization.StandardSerializers.string; -import static com.exonum.binding.fakes.services.transactions.ContextUtils.newContext; -import static com.exonum.binding.fakes.services.transactions.SetEntryTransaction.AUTHOR_PK_NAME; -import static com.exonum.binding.fakes.services.transactions.SetEntryTransaction.ENTRY_NAME; -import static com.exonum.binding.fakes.services.transactions.SetEntryTransaction.TX_HASH_NAME; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import com.exonum.binding.common.crypto.PublicKey; -import com.exonum.binding.common.hash.HashCode; -import com.exonum.binding.core.proxy.Cleaner; -import com.exonum.binding.core.proxy.CloseFailuresException; -import com.exonum.binding.core.storage.database.Fork; -import com.exonum.binding.core.storage.database.Snapshot; -import com.exonum.binding.core.storage.database.TemporaryDb; -import com.exonum.binding.core.storage.indices.EntryIndexProxy; -import com.exonum.binding.core.transaction.TransactionContext; -import com.exonum.binding.test.RequiresNativeLibrary; -import org.junit.jupiter.api.Test; - -@RequiresNativeLibrary -class SetEntryTransactionIntegrationTest { - - @Test - void executePutsTheValueIntoEntry() throws CloseFailuresException { - try (TemporaryDb database = TemporaryDb.newInstance(); - Cleaner cleaner = new Cleaner()) { - String value = "A value to set into entry"; - Fork fork = database.createFork(cleaner); - - SetEntryTransaction tx = new SetEntryTransaction(value, ""); - - // Execute the transaction - TransactionContext context = newContext(fork); - tx.execute(context); - - database.merge(fork); - - Snapshot snapshot = database.createSnapshot(cleaner); - - //assert value - EntryIndexProxy entry = EntryIndexProxy.newInstance(ENTRY_NAME, snapshot, string()); - assertTrue(entry.isPresent()); - assertThat(entry.get(), equalTo(value)); - - //assert tx message hash - EntryIndexProxy hashEntry = EntryIndexProxy - .newInstance(TX_HASH_NAME, snapshot, hash()); - assertTrue(hashEntry.isPresent()); - assertThat(hashEntry.get(), equalTo(context.getTransactionMessageHash())); - - //assert author's key - EntryIndexProxy keyEntry = - EntryIndexProxy.newInstance(AUTHOR_PK_NAME, snapshot, publicKey()); - assertTrue(keyEntry.isPresent()); - assertThat(keyEntry.get(), equalTo(context.getAuthorPk())); - } - } - -} From fe3ec611d5666b8875213a4efcaf2f985d024d9e Mon Sep 17 00:00:00 2001 From: Dmitry Timofeev Date: Tue, 19 Nov 2019 12:35:02 +0200 Subject: [PATCH 2/2] And crypto --- .../transactions/CreateWalletTx.java | 6 ------ .../cryptocurrency/transactions/TransferTx.java | 6 ------ .../CreateWalletTxIntegrationTest.java | 13 ------------- .../transactions/TransferTxIntegrationTest.java | 17 ----------------- 4 files changed, 42 deletions(-) diff --git a/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTx.java b/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTx.java index e62aed02f4..cce09ddb98 100644 --- a/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTx.java +++ b/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTx.java @@ -17,7 +17,6 @@ package com.exonum.binding.cryptocurrency.transactions; import static com.exonum.binding.common.serialization.StandardSerializers.protobuf; -import static com.exonum.binding.common.serialization.json.JsonSerializer.json; import static com.exonum.binding.cryptocurrency.transactions.TransactionError.WALLET_ALREADY_EXISTS; import static com.google.common.base.Preconditions.checkArgument; @@ -75,11 +74,6 @@ public void execute(TransactionContext context) throws TransactionExecutionExcep wallets.put(ownerPublicKey, wallet); } - @Override - public String info() { - return json().toJson(this); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/TransferTx.java b/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/TransferTx.java index 5f3a469880..05d05993f1 100644 --- a/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/TransferTx.java +++ b/exonum-java-binding/cryptocurrency-demo/src/main/java/com/exonum/binding/cryptocurrency/transactions/TransferTx.java @@ -17,7 +17,6 @@ package com.exonum.binding.cryptocurrency.transactions; import static com.exonum.binding.common.serialization.StandardSerializers.protobuf; -import static com.exonum.binding.common.serialization.json.JsonSerializer.json; import static com.exonum.binding.cryptocurrency.transactions.TransactionError.INSUFFICIENT_FUNDS; import static com.exonum.binding.cryptocurrency.transactions.TransactionError.SAME_SENDER_AND_RECEIVER; import static com.exonum.binding.cryptocurrency.transactions.TransactionError.UNKNOWN_RECEIVER; @@ -110,11 +109,6 @@ private static void checkExecution(boolean precondition, byte errorCode) } } - @Override - public String info() { - return json().toJson(this); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTxIntegrationTest.java b/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTxIntegrationTest.java index 92bd43d35e..cb3186d908 100644 --- a/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTxIntegrationTest.java +++ b/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/CreateWalletTxIntegrationTest.java @@ -17,7 +17,6 @@ package com.exonum.binding.cryptocurrency.transactions; import static com.exonum.binding.common.blockchain.ExecutionStatuses.serviceError; -import static com.exonum.binding.common.serialization.json.JsonSerializer.json; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.ARTIFACT_FILENAME; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.ARTIFACT_ID; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.SERVICE_ID; @@ -119,18 +118,6 @@ void executeAlreadyExistingWalletTx(TestKit testKit) { assertThat(txResult).hasValue(expectedTransactionResult); } - @Test - void info() { - CreateWalletTx tx = new CreateWalletTx(DEFAULT_INITIAL_BALANCE); - - String info = tx.info(); - - CreateWalletTx txParams = json() - .fromJson(info, CreateWalletTx.class); - - assertThat(txParams).isEqualTo(tx); - } - @Test void verifyEquals() { EqualsVerifier diff --git a/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/TransferTxIntegrationTest.java b/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/TransferTxIntegrationTest.java index 200d63cbc9..9749f5acc3 100644 --- a/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/TransferTxIntegrationTest.java +++ b/exonum-java-binding/cryptocurrency-demo/src/test/java/com/exonum/binding/cryptocurrency/transactions/TransferTxIntegrationTest.java @@ -17,7 +17,6 @@ package com.exonum.binding.cryptocurrency.transactions; import static com.exonum.binding.common.blockchain.ExecutionStatuses.serviceError; -import static com.exonum.binding.common.serialization.json.JsonSerializer.json; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.ARTIFACT_FILENAME; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.ARTIFACT_ID; import static com.exonum.binding.cryptocurrency.transactions.PredefinedServiceParameters.SERVICE_ID; @@ -40,7 +39,6 @@ import com.exonum.binding.core.blockchain.Blockchain; import com.exonum.binding.core.storage.database.Snapshot; import com.exonum.binding.core.storage.indices.ProofMapIndexProxy; -import com.exonum.binding.core.transaction.Transaction; import com.exonum.binding.cryptocurrency.CryptocurrencySchema; import com.exonum.binding.cryptocurrency.PredefinedOwnerKeys; import com.exonum.binding.cryptocurrency.Wallet; @@ -48,7 +46,6 @@ import com.exonum.binding.testkit.TestKit; import com.exonum.binding.testkit.TestKitExtension; import com.exonum.core.messages.Runtime.ExecutionStatus; -import com.google.common.reflect.TypeToken; import java.util.Optional; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.jupiter.api.Test; @@ -223,20 +220,6 @@ void executeTransfer_InsufficientFunds(TestKit testKit) { assertThat(txResult).hasValue(expectedTransactionResult); } - @Test - void info() { - long seed = Long.MAX_VALUE - 1L; - TransferTx tx = new TransferTx(seed, TO_KEY_PAIR.getPublicKey(), 50L); - - String info = tx.info(); - - // Check the transaction parameters in JSON - Transaction txParameters = json().fromJson(info, new TypeToken() { - }.getType()); - - assertThat(txParameters).isEqualTo(tx); - } - @Test void verifyEquals() { EqualsVerifier