Update RaftNotaryServiceTest to support idempotent notary behaviour

This commit is contained in:
Andrius Dagys 2017-01-06 14:32:03 +00:00
parent 59456cb6b1
commit 15363e686a

View File

@ -36,52 +36,51 @@ class RaftNotaryServiceTests : NodeBasedTest() {
val (masterNode, alice) = Futures.allAsList(createNotaryCluster(), startNode("Alice")).getOrThrow() val (masterNode, alice) = Futures.allAsList(createNotaryCluster(), startNode("Alice")).getOrThrow()
val notaryParty = alice.netMapCache.getNotary(notaryName)!! val notaryParty = alice.netMapCache.getNotary(notaryName)!!
val notaryNodeKeyPair = databaseTransaction(masterNode.database) { masterNode.services.notaryIdentityKey }
val aliceKey = databaseTransaction(alice.database) { alice.services.legalIdentityKey }
val stx = run { val inputState = issueState(alice, notaryParty, notaryNodeKeyPair)
val notaryNodeKeyPair = databaseTransaction(masterNode.database) {
masterNode.services.notaryIdentityKey val firstSpendTx = TransactionType.General.Builder(notaryParty).withItems(inputState).run {
} signWith(aliceKey)
val inputState = issueState(alice, notaryParty, notaryNodeKeyPair) toSignedTransaction(false)
val tx = TransactionType.General.Builder(notaryParty).withItems(inputState)
val aliceKey = databaseTransaction(alice.database) {
alice.services.legalIdentityKey
}
tx.signWith(aliceKey)
tx.toSignedTransaction(false)
} }
val firstSpend = alice.services.startFlow(NotaryFlow.Client(firstSpendTx))
val buildFlow = { NotaryFlow.Client(stx) }
val firstSpend = alice.services.startFlow(buildFlow())
firstSpend.resultFuture.getOrThrow() firstSpend.resultFuture.getOrThrow()
val secondSpend = alice.services.startFlow(buildFlow()) val secondSpendTx = TransactionType.General.Builder(notaryParty).withItems(inputState).run {
val dummyState = DummyContract.SingleOwnerState(0, alice.info.legalIdentity.owningKey)
addOutputState(dummyState)
signWith(aliceKey)
toSignedTransaction(false)
}
val secondSpend = alice.services.startFlow(NotaryFlow.Client(secondSpendTx))
val ex = assertFailsWith(NotaryException::class) { secondSpend.resultFuture.getOrThrow() } val ex = assertFailsWith(NotaryException::class) { secondSpend.resultFuture.getOrThrow() }
val error = ex.error as NotaryError.Conflict val error = ex.error as NotaryError.Conflict
assertEquals(error.tx, stx.tx) assertEquals(error.tx, secondSpendTx.tx)
} }
private fun createNotaryCluster(): ListenableFuture<Node> { private fun createNotaryCluster(): ListenableFuture<Node> {
val notaryService = ServiceInfo(RaftValidatingNotaryService.type, notaryName) val notaryService = ServiceInfo(RaftValidatingNotaryService.type, notaryName)
val notaryAddresses = getFreeLocalPorts("localhost", clusterSize).map { it.toString() } val notaryAddresses = getFreeLocalPorts("localhost", clusterSize).map { it.toString() }
ServiceIdentityGenerator.generateToDisk( ServiceIdentityGenerator.generateToDisk(
(0 until clusterSize).map { tempFolder.root.toPath() / "Notary$it" }, (0 until clusterSize).map { tempFolder.root.toPath() / "Notary$it" },
notaryService.type.id, notaryService.type.id,
notaryName) notaryName)
val masterNode = startNode( val masterNode = startNode(
"Notary0", "Notary0",
advertisedServices = setOf(notaryService), advertisedServices = setOf(notaryService),
configOverrides = mapOf("notaryNodeAddress" to notaryAddresses[0])) configOverrides = mapOf("notaryNodeAddress" to notaryAddresses[0]))
val remainingNodes = (1 until clusterSize).map { val remainingNodes = (1 until clusterSize).map {
startNode( startNode(
"Notary$it", "Notary$it",
advertisedServices = setOf(notaryService), advertisedServices = setOf(notaryService),
configOverrides = mapOf( configOverrides = mapOf(
"notaryNodeAddress" to notaryAddresses[it], "notaryNodeAddress" to notaryAddresses[it],
"notaryClusterAddresses" to listOf(notaryAddresses[0]))) "notaryClusterAddresses" to listOf(notaryAddresses[0])))
} }
return Futures.allAsList(remainingNodes).flatMap { masterNode } return Futures.allAsList(remainingNodes).flatMap { masterNode }