mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
Detect duplicate inputs in NotaryFlow
Throw NotaryException when duplicate inputs are detected.
This commit is contained in:
@ -95,15 +95,34 @@ class NotaryServiceTests {
|
||||
|
||||
val firstAttempt = NotaryFlow.Client(stx)
|
||||
val secondAttempt = NotaryFlow.Client(stx)
|
||||
clientNode.services.startFlow(firstAttempt)
|
||||
val future = clientNode.services.startFlow(secondAttempt)
|
||||
val f1 = clientNode.services.startFlow(firstAttempt)
|
||||
val f2 = clientNode.services.startFlow(secondAttempt)
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
future.resultFuture.getOrThrow()
|
||||
assertEquals(f1.resultFuture.getOrThrow(), f2.resultFuture.getOrThrow())
|
||||
}
|
||||
|
||||
@Test fun `should report conflict when inputs are reused accross transactions`() {
|
||||
@Test fun `should report conflict when inputs are reused within a single transactions`() {
|
||||
val stx = run {
|
||||
val inputState = issueState(clientNode)
|
||||
// Use inputState twice as input of a single transaction.
|
||||
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState, inputState)
|
||||
tx.signWith(clientNode.keyPair!!)
|
||||
tx.toSignedTransaction(false)
|
||||
}
|
||||
|
||||
val future = clientNode.services.startFlow(NotaryFlow.Client(stx))
|
||||
|
||||
net.runNetwork()
|
||||
|
||||
val ex = assertFailsWith(NotaryException::class) { future.resultFuture.getOrThrow() }
|
||||
val notaryError = ex.error as NotaryError.Conflict
|
||||
assertEquals(notaryError.tx, stx.tx)
|
||||
notaryError.conflict.verified()
|
||||
}
|
||||
|
||||
@Test fun `should report conflict when inputs are reused across transactions`() {
|
||||
val inputState = issueState(clientNode)
|
||||
val stx = run {
|
||||
val tx = TransactionType.General.Builder(notaryNode.info.notaryIdentity).withItems(inputState)
|
||||
|
Reference in New Issue
Block a user