Check the tx type in NotaryChangeProtocol and add a TODO to write a test for this once the protocol framework propagates exceptions.

This commit is contained in:
Mike Hearn
2016-09-06 16:20:11 +02:00
parent 423aff477a
commit 1d272f89c2
3 changed files with 7 additions and 4 deletions

View File

@ -37,7 +37,7 @@ abstract class BaseTransaction(
val timestamp: Timestamp? val timestamp: Timestamp?
) : NamedByHash { ) : NamedByHash {
fun checkInvariants() { protected fun checkInvariants() {
if (notary == null) check(inputs.isEmpty()) { "The notary must be specified explicitly for any transaction that has inputs." } if (notary == null) check(inputs.isEmpty()) { "The notary must be specified explicitly for any transaction that has inputs." }
if (timestamp != null) check(notary != null) { "If a timestamp is provided, there must be a notary." } if (timestamp != null) check(notary != null) { "If a timestamp is provided, there must be a notary." }
} }

View File

@ -76,13 +76,15 @@ object NotaryChangeProtocol: AbstractStateReplacementProtocol<Party>() {
val state = proposal.stateRef val state = proposal.stateRef
val proposedTx = proposal.stx.tx val proposedTx = proposal.stx.tx
require(proposedTx.inputs.contains(state)) { "The proposed state $state is not in the proposed transaction inputs" } require(state in proposedTx.inputs) { "The proposed state $state is not in the proposed transaction inputs" }
require(proposedTx.type.javaClass == TransactionType.NotaryChange::class.java) {
"The proposed transaction is not a notary change transaction."
}
// An example requirement // An example requirement
val blacklist = listOf("Evil Notary") val blacklist = listOf("Evil Notary")
require(!blacklist.contains(newNotary.name)) { "The proposed new notary $newNotary is not trusted by the party" } require(!blacklist.contains(newNotary.name)) { "The proposed new notary $newNotary is not trusted by the party" }
// TODO: Verify the type!
proposal proposal
} }

View File

@ -7,13 +7,13 @@ import com.r3corda.core.seconds
import com.r3corda.core.utilities.DUMMY_NOTARY import com.r3corda.core.utilities.DUMMY_NOTARY
import com.r3corda.core.utilities.DUMMY_NOTARY_KEY import com.r3corda.core.utilities.DUMMY_NOTARY_KEY
import com.r3corda.node.internal.AbstractNode import com.r3corda.node.internal.AbstractNode
import com.r3corda.testing.node.MockNetwork
import com.r3corda.node.services.network.NetworkMapService import com.r3corda.node.services.network.NetworkMapService
import com.r3corda.node.services.transactions.SimpleNotaryService import com.r3corda.node.services.transactions.SimpleNotaryService
import com.r3corda.protocols.NotaryChangeProtocol import com.r3corda.protocols.NotaryChangeProtocol
import com.r3corda.protocols.NotaryChangeProtocol.Instigator import com.r3corda.protocols.NotaryChangeProtocol.Instigator
import com.r3corda.protocols.StateReplacementException import com.r3corda.protocols.StateReplacementException
import com.r3corda.protocols.StateReplacementRefused import com.r3corda.protocols.StateReplacementRefused
import com.r3corda.testing.node.MockNetwork
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
@ -93,6 +93,7 @@ class NotaryChangeTests {
// - The requesting party wants to change additional state fields // - The requesting party wants to change additional state fields
// - Multiple states in a single "notary change" transaction // - Multiple states in a single "notary change" transaction
// - Transaction contains additional states and commands with business logic // - Transaction contains additional states and commands with business logic
// - The transaction type is not a notary change transaction at all.
} }
fun issueState(node: AbstractNode): StateAndRef<*> { fun issueState(node: AbstractNode): StateAndRef<*> {