Fixed AttachmentLoadingTests (#4565)

There were two issues:
* The original "sealing violation: can't seal package net.corda.nodeapi" issue was due to the isolated CorDapp containing some code in the net.corda.nodeapi namespace. This has been moved to the isolated namespace.
* The test was not correctly creating the second transaction with the dummy command
This commit is contained in:
Shams Asari 2019-01-14 14:32:14 +00:00 committed by GitHub
parent 1bbcb8722e
commit 3b8347e150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 18 deletions

View File

@ -9,7 +9,7 @@ import net.corda.core.serialization.internal.AttachmentsClassLoaderBuilder
import net.corda.core.serialization.serialize import net.corda.core.serialization.serialize
import net.corda.core.utilities.ByteSequence import net.corda.core.utilities.ByteSequence
import net.corda.core.utilities.OpaqueBytes import net.corda.core.utilities.OpaqueBytes
import net.corda.nodeapi.DummyContractBackdoor import net.corda.isolated.contracts.DummyContractBackdoor
import net.corda.testing.core.DUMMY_NOTARY_NAME import net.corda.testing.core.DUMMY_NOTARY_NAME
import net.corda.testing.core.SerializationEnvironmentRule import net.corda.testing.core.SerializationEnvironmentRule
import net.corda.testing.core.TestIdentity import net.corda.testing.core.TestIdentity

View File

@ -1,4 +1,4 @@
package net.corda.nodeapi package net.corda.isolated.contracts
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.PartyAndReference import net.corda.core.contracts.PartyAndReference

Binary file not shown.

View File

@ -11,6 +11,9 @@ dependencies {
cordapp { cordapp {
targetPlatformVersion corda_platform_version.toInteger() targetPlatformVersion corda_platform_version.toInteger()
minimumPlatformVersion 1 minimumPlatformVersion 1
sealing {
enabled false // This needs to be disabled for AttachmentsClassLoaderSerializationTests to work
}
contract { contract {
name "Isolated Test CorDapp" name "Isolated Test CorDapp"
versionId 1 versionId 1

View File

@ -5,7 +5,6 @@ import net.corda.core.identity.AbstractParty
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.nodeapi.DummyContractBackdoor
@Suppress("UNUSED") @Suppress("UNUSED")
class AnotherDummyContract : Contract, DummyContractBackdoor { class AnotherDummyContract : Contract, DummyContractBackdoor {

View File

@ -1,4 +1,4 @@
package net.corda.nodeapi package net.corda.isolated.contracts
import net.corda.core.contracts.ContractState import net.corda.core.contracts.ContractState
import net.corda.core.contracts.PartyAndReference import net.corda.core.contracts.PartyAndReference

View File

@ -1,32 +1,34 @@
package net.corda.node.services package net.corda.node.services
import co.paralleluniverse.fibers.Suspendable import co.paralleluniverse.fibers.Suspendable
import net.corda.core.contracts.ContractState import net.corda.core.contracts.*
import net.corda.core.contracts.StateRef
import net.corda.core.flows.* import net.corda.core.flows.*
import net.corda.core.identity.AbstractParty
import net.corda.core.identity.CordaX500Name import net.corda.core.identity.CordaX500Name
import net.corda.core.identity.Party import net.corda.core.identity.Party
import net.corda.core.internal.* import net.corda.core.internal.*
import net.corda.core.internal.concurrent.transpose import net.corda.core.internal.concurrent.transpose
import net.corda.core.messaging.startFlow import net.corda.core.messaging.startFlow
import net.corda.core.serialization.MissingAttachmentsException import net.corda.core.serialization.internal.UntrustedAttachmentsException
import net.corda.core.transactions.LedgerTransaction
import net.corda.core.transactions.TransactionBuilder import net.corda.core.transactions.TransactionBuilder
import net.corda.core.utilities.getOrThrow import net.corda.core.utilities.getOrThrow
import net.corda.core.utilities.unwrap import net.corda.core.utilities.unwrap
import net.corda.testing.common.internal.checkNotOnClasspath import net.corda.testing.common.internal.checkNotOnClasspath
import net.corda.testing.core.* import net.corda.testing.core.ALICE_NAME
import net.corda.testing.core.BOB_NAME
import net.corda.testing.core.DUMMY_NOTARY_NAME
import net.corda.testing.core.singleIdentity
import net.corda.testing.driver.DriverDSL import net.corda.testing.driver.DriverDSL
import net.corda.testing.driver.DriverParameters import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver import net.corda.testing.driver.driver
import net.corda.testing.node.NotarySpec import net.corda.testing.node.NotarySpec
import net.corda.testing.node.internal.cordappsForPackages import net.corda.testing.node.internal.cordappsForPackages
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.net.URL import java.net.URL
import java.net.URLClassLoader import java.net.URLClassLoader
@Ignore("Temporarily ignored as it fails with: java.lang.SecurityException: sealing violation: can't seal package net.corda.nodeapi: already loaded")
class AttachmentLoadingTests { class AttachmentLoadingTests {
private companion object { private companion object {
val isolatedJar: URL = AttachmentLoadingTests::class.java.getResource("/isolated.jar") val isolatedJar: URL = AttachmentLoadingTests::class.java.getResource("/isolated.jar")
@ -59,11 +61,10 @@ class AttachmentLoadingTests {
val stateRef = alice.rpc.startFlowDynamic(issuanceFlowClass, 1234).returnValue.getOrThrow() val stateRef = alice.rpc.startFlowDynamic(issuanceFlowClass, 1234).returnValue.getOrThrow()
// The exception that we actually want is MissingAttachmentsException, but this is thrown in a responder flow on Bob. To work assertThatThrownBy { alice.rpc.startFlow(::ConsumeAndBroadcastFlow, stateRef, bob.nodeInfo.singleIdentity()).returnValue.getOrThrow() }
// around that it's re-thrown as a FlowException so that it can be propagated to Alice where we pick it here. // ConsumeAndBroadcastResponderFlow re-throws any non-FlowExceptions with just their class name in the message so that
assertThatThrownBy { // we can verify here Bob threw the correct exception
alice.rpc.startFlow(::ConsumeAndBroadcastFlow, stateRef, bob.nodeInfo.singleIdentity()).returnValue.getOrThrow() .hasMessage(UntrustedAttachmentsException::class.java.name)
}.hasMessage("Attempting to load Contract Attachments downloaded from the network")
} }
} }
@ -100,7 +101,10 @@ class AttachmentLoadingTests {
val notary = serviceHub.networkMapCache.notaryIdentities[0] val notary = serviceHub.networkMapCache.notaryIdentities[0]
val stateAndRef = serviceHub.toStateAndRef<ContractState>(stateRef) val stateAndRef = serviceHub.toStateAndRef<ContractState>(stateRef)
val stx = serviceHub.signInitialTransaction( val stx = serviceHub.signInitialTransaction(
TransactionBuilder(notary).addInputState(stateAndRef).addCommand(dummyCommand(ourIdentity.owningKey)) TransactionBuilder(notary)
.addInputState(stateAndRef)
.addOutputState(ConsumeContract.State())
.addCommand(Command(ConsumeContract.Cmd, ourIdentity.owningKey))
) )
stx.verify(serviceHub, checkSufficientSignatures = false) stx.verify(serviceHub, checkSufficientSignatures = false)
val session = initiateFlow(otherSide) val session = initiateFlow(otherSide)
@ -116,10 +120,24 @@ class AttachmentLoadingTests {
override fun call() { override fun call() {
try { try {
subFlow(ReceiveFinalityFlow(otherSide)) subFlow(ReceiveFinalityFlow(otherSide))
} catch (e: MissingAttachmentsException) { } catch (e: FlowException) {
throw FlowException(e.message) throw e
} catch (e: Exception) {
throw FlowException(e.javaClass.name)
} }
otherSide.send("OK") otherSide.send("OK")
} }
} }
class ConsumeContract : Contract {
override fun verify(tx: LedgerTransaction) {
// Accept everything
}
class State : ContractState {
override val participants: List<AbstractParty> get() = emptyList()
}
object Cmd : TypeOnlyCommandData()
}
} }

Binary file not shown.