From 753a2af556705ca2b1290e91c23e6221df4e07ee Mon Sep 17 00:00:00 2001 From: pnemeth Date: Fri, 8 May 2020 10:55:36 +0100 Subject: [PATCH] EG-465 hashLookup returns "No matching transaction found" for any transaction hash - Updated command to support transaction id-s as well (not just hashes of transactions) (#6224) * fixed EG-465+tests+manual * Revert "fixed EG-465+tests+manual" This reverts commit 39899378 * reverted Constants.kt * fixed EG-465+tests+manual"" This reverts commit c96acf31e45ae605c0ee930aaa083eb470293c81. * unused import --- .../tools/shell/HashLookupCommandTest.kt | 17 +++++++------- .../tools/shell/HashLookupShellCommand.java | 23 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt b/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt index ad1b89c43a..2376081a4a 100644 --- a/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt +++ b/tools/shell/src/integration-test/kotlin/net/corda/tools/shell/HashLookupCommandTest.kt @@ -21,12 +21,11 @@ import net.corda.testing.driver.driver import net.corda.testing.node.User import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP import org.bouncycastle.util.io.Streams -import org.junit.Ignore import org.junit.Test import kotlin.test.assertTrue class HashLookupCommandTest { - @Ignore + @Test(timeout=300_000) fun `hash lookup command returns correct response`() { val user = User("u", "p", setOf(Permissions.all())) @@ -35,17 +34,16 @@ class HashLookupCommandTest { val nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true) val node = nodeFuture.getOrThrow() val txId = issueTransaction(node) + val txIdHashed = txId.sha256() - val session = connectToShell(user, node) - - testCommand(session, command = "hashLookup ${txId.sha256()}", expected = "Found a matching transaction with Id: $txId") - testCommand(session, command = "hashLookup ${SecureHash.randomSHA256()}", expected = "No matching transaction found") - - session.disconnect() + testCommand(user, node, command = "hashLookup $txId", expected = "Found a matching transaction with Id: $txId") + testCommand(user, node, command = "hashLookup $txIdHashed", expected = "Found a matching transaction with Id: $txId") + testCommand(user, node, command = "hashLookup ${SecureHash.randomSHA256()}", expected = "No matching transaction found") } } - private fun testCommand(session: Session, command: String, expected: String) { + private fun testCommand(user: User, node: NodeHandle, command: String, expected: String) { + val session = connectToShell(user, node) val channel = session.openChannel("exec") as ChannelExec channel.setCommand(command) channel.connect(5000) @@ -58,6 +56,7 @@ class HashLookupCommandTest { } channel.disconnect() assertTrue(matchFound) + session.disconnect() } private fun connectToShell(user: User, node: NodeHandle): Session { diff --git a/tools/shell/src/main/java/net/corda/tools/shell/HashLookupShellCommand.java b/tools/shell/src/main/java/net/corda/tools/shell/HashLookupShellCommand.java index 831fc18b4c..3fcd803d8e 100644 --- a/tools/shell/src/main/java/net/corda/tools/shell/HashLookupShellCommand.java +++ b/tools/shell/src/main/java/net/corda/tools/shell/HashLookupShellCommand.java @@ -19,22 +19,21 @@ import java.util.Optional; @Named("hashLookup") public class HashLookupShellCommand extends InteractiveShellCommand { private static Logger logger = LoggerFactory.getLogger(HashLookupShellCommand.class); - - @Command - @Man("Checks if a transaction matching a specified Id hash value is recorded on this node.\n\n" + + final private String manualText ="Checks if a transaction matching a specified Id hash value is recorded on this node.\n\n" + + "Both the transaction Id and the hashed value of a transaction Id (as returned by the Notary in case of a double-spend) is a valid input.\n" + "This is mainly intended to be used for troubleshooting notarisation issues when a\n" + "state is claimed to be already consumed by another transaction.\n\n" + - "Example usage: hashLookup E470FD8A6350A74217B0A99EA5FB71F091C84C64AD0DE0E72ECC10421D03AAC9" - ) - public void main(@Usage("A hexadecimal SHA-256 hash value representing the hashed transaction Id") @Argument(unquote = false) String txIdHash) { + "Example usage: hashLookup E470FD8A6350A74217B0A99EA5FB71F091C84C64AD0DE0E72ECC10421D03AAC9"; + + @Command + @Man(manualText) + + public void main(@Usage("A transaction Id or a hexadecimal SHA-256 hash value representing the hashed transaction Id") @Argument(unquote = false) String txIdHash) { logger.info("Executing command \"hashLookup\"."); if (txIdHash == null) { - out.println("Checks if a transaction matching a specified Id hash value is recorded on this node.\n\n" + - "This is mainly intended to be used for troubleshooting notarisation issues when a\n" + - "state is claimed to be already consumed by another transaction.\n\n" + - "Example usage: hashLookup E470FD8A6350A74217B0A99EA5FB71F091C84C64AD0DE0E72ECC10421D03AAC9"); - out.println("Please provide a hexadecimal transaction Id hash value", Decoration.bold, Color.red); + out.println(manualText); + out.println("Please provide a hexadecimal transaction Id hash value or a transaction Id", Decoration.bold, Color.red); return; } @@ -52,7 +51,7 @@ public class HashLookupShellCommand extends InteractiveShellCommand { Optional match = mapping.stream() .map(StateMachineTransactionMapping::getTransactionId) .filter( - txId -> SecureHash.sha256(txId.getBytes()).equals(txIdHashParsed) + txId -> txId.equals(txIdHashParsed) || SecureHash.sha256(txId.getBytes()).equals(txIdHashParsed) ) .findFirst();