mirror of
https://github.com/corda/corda.git
synced 2025-03-13 07:54:32 +00:00
fixed EG-465+tests+manual
This commit is contained in:
parent
6400fd51a5
commit
39899378aa
@ -9,4 +9,4 @@ package net.corda.common.logging
|
||||
* (originally added to source control for ease of use)
|
||||
*/
|
||||
|
||||
internal const val CURRENT_MAJOR_RELEASE = "4.6-SNAPSHOT"
|
||||
internal const val CURRENT_MAJOR_RELEASE = "4.6-SNAPSHOT"
|
@ -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)
|
||||
@ -53,11 +51,13 @@ class HashLookupCommandTest {
|
||||
assertTrue(channel.isConnected)
|
||||
|
||||
val response = String(Streams.readAll(channel.inputStream))
|
||||
println(response)
|
||||
val matchFound = response.lines().any { line ->
|
||||
line.contains(expected)
|
||||
}
|
||||
channel.disconnect()
|
||||
assertTrue(matchFound)
|
||||
session.disconnect()
|
||||
}
|
||||
|
||||
private fun connectToShell(user: User, node: NodeHandle): Session {
|
||||
|
@ -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"
|
||||
)
|
||||
"Example usage: hashLookup E470FD8A6350A74217B0A99EA5FB71F091C84C64AD0DE0E72ECC10421D03AAC9";
|
||||
|
||||
@Command
|
||||
@Man(manualText)
|
||||
|
||||
public void main(@Usage("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<SecureHash> 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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user