mirror of
https://github.com/corda/corda.git
synced 2025-03-14 00:06:45 +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)
|
* (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.User
|
||||||
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
|
import net.corda.testing.node.internal.DUMMY_CONTRACTS_CORDAPP
|
||||||
import org.bouncycastle.util.io.Streams
|
import org.bouncycastle.util.io.Streams
|
||||||
import org.junit.Ignore
|
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class HashLookupCommandTest {
|
class HashLookupCommandTest {
|
||||||
@Ignore
|
|
||||||
@Test(timeout=300_000)
|
@Test(timeout=300_000)
|
||||||
fun `hash lookup command returns correct response`() {
|
fun `hash lookup command returns correct response`() {
|
||||||
val user = User("u", "p", setOf(Permissions.all()))
|
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 nodeFuture = startNode(providedName = ALICE_NAME, rpcUsers = listOf(user), startInSameProcess = true)
|
||||||
val node = nodeFuture.getOrThrow()
|
val node = nodeFuture.getOrThrow()
|
||||||
val txId = issueTransaction(node)
|
val txId = issueTransaction(node)
|
||||||
|
val txIdHashed = txId.sha256()
|
||||||
|
|
||||||
val session = connectToShell(user, node)
|
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(session, command = "hashLookup ${txId.sha256()}", expected = "Found a matching transaction with Id: $txId")
|
testCommand(user, node, command = "hashLookup ${SecureHash.randomSHA256()}", expected = "No matching transaction found")
|
||||||
testCommand(session, command = "hashLookup ${SecureHash.randomSHA256()}", expected = "No matching transaction found")
|
|
||||||
|
|
||||||
session.disconnect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
val channel = session.openChannel("exec") as ChannelExec
|
||||||
channel.setCommand(command)
|
channel.setCommand(command)
|
||||||
channel.connect(5000)
|
channel.connect(5000)
|
||||||
@ -53,11 +51,13 @@ class HashLookupCommandTest {
|
|||||||
assertTrue(channel.isConnected)
|
assertTrue(channel.isConnected)
|
||||||
|
|
||||||
val response = String(Streams.readAll(channel.inputStream))
|
val response = String(Streams.readAll(channel.inputStream))
|
||||||
|
println(response)
|
||||||
val matchFound = response.lines().any { line ->
|
val matchFound = response.lines().any { line ->
|
||||||
line.contains(expected)
|
line.contains(expected)
|
||||||
}
|
}
|
||||||
channel.disconnect()
|
channel.disconnect()
|
||||||
assertTrue(matchFound)
|
assertTrue(matchFound)
|
||||||
|
session.disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun connectToShell(user: User, node: NodeHandle): Session {
|
private fun connectToShell(user: User, node: NodeHandle): Session {
|
||||||
|
@ -19,22 +19,21 @@ import java.util.Optional;
|
|||||||
@Named("hashLookup")
|
@Named("hashLookup")
|
||||||
public class HashLookupShellCommand extends InteractiveShellCommand {
|
public class HashLookupShellCommand extends InteractiveShellCommand {
|
||||||
private static Logger logger = LoggerFactory.getLogger(HashLookupShellCommand.class);
|
private static Logger logger = LoggerFactory.getLogger(HashLookupShellCommand.class);
|
||||||
|
final private String manualText ="Checks if a transaction matching a specified Id hash value is recorded on this node.\n\n" +
|
||||||
@Command
|
"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" +
|
||||||
@Man("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" +
|
"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" +
|
"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) {
|
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\".");
|
logger.info("Executing command \"hashLookup\".");
|
||||||
|
|
||||||
if (txIdHash == null) {
|
if (txIdHash == null) {
|
||||||
out.println("Checks if a transaction matching a specified Id hash value is recorded on this node.\n\n" +
|
out.println(manualText);
|
||||||
"This is mainly intended to be used for troubleshooting notarisation issues when a\n" +
|
out.println("Please provide a hexadecimal transaction Id hash value or a transaction Id", Decoration.bold, Color.red);
|
||||||
"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);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +51,7 @@ public class HashLookupShellCommand extends InteractiveShellCommand {
|
|||||||
Optional<SecureHash> match = mapping.stream()
|
Optional<SecureHash> match = mapping.stream()
|
||||||
.map(StateMachineTransactionMapping::getTransactionId)
|
.map(StateMachineTransactionMapping::getTransactionId)
|
||||||
.filter(
|
.filter(
|
||||||
txId -> SecureHash.sha256(txId.getBytes()).equals(txIdHashParsed)
|
txId -> txId.equals(txIdHashParsed) || SecureHash.sha256(txId.getBytes()).equals(txIdHashParsed)
|
||||||
)
|
)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user