diff --git a/core/src/test/kotlin/net/corda/core/transactions/AttachmentsClassLoaderSerializationTests.kt b/core/src/test/kotlin/net/corda/core/transactions/AttachmentsClassLoaderSerializationTests.kt index 9bab097e2b..a6150099ed 100644 --- a/core/src/test/kotlin/net/corda/core/transactions/AttachmentsClassLoaderSerializationTests.kt +++ b/core/src/test/kotlin/net/corda/core/transactions/AttachmentsClassLoaderSerializationTests.kt @@ -9,7 +9,7 @@ import net.corda.core.serialization.internal.AttachmentsClassLoaderBuilder import net.corda.core.serialization.serialize import net.corda.core.utilities.ByteSequence 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.SerializationEnvironmentRule import net.corda.testing.core.TestIdentity diff --git a/core/src/test/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt b/core/src/test/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt similarity index 94% rename from core/src/test/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt rename to core/src/test/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt index 7bd73fc16b..98e23bc427 100644 --- a/core/src/test/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt +++ b/core/src/test/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt @@ -1,4 +1,4 @@ -package net.corda.nodeapi +package net.corda.isolated.contracts import net.corda.core.contracts.ContractState import net.corda.core.contracts.PartyAndReference diff --git a/core/src/test/resources/isolated.jar b/core/src/test/resources/isolated.jar index 47372978cc..8026639a7e 100644 Binary files a/core/src/test/resources/isolated.jar and b/core/src/test/resources/isolated.jar differ diff --git a/isolated/build.gradle b/isolated/build.gradle index 575edbd599..45bd72e4af 100644 --- a/isolated/build.gradle +++ b/isolated/build.gradle @@ -11,6 +11,9 @@ dependencies { cordapp { targetPlatformVersion corda_platform_version.toInteger() minimumPlatformVersion 1 + sealing { + enabled false // This needs to be disabled for AttachmentsClassLoaderSerializationTests to work + } contract { name "Isolated Test CorDapp" versionId 1 diff --git a/isolated/src/main/kotlin/net/corda/isolated/contracts/AnotherDummyContract.kt b/isolated/src/main/kotlin/net/corda/isolated/contracts/AnotherDummyContract.kt index 3d3e3b09f7..994e6c49d7 100644 --- a/isolated/src/main/kotlin/net/corda/isolated/contracts/AnotherDummyContract.kt +++ b/isolated/src/main/kotlin/net/corda/isolated/contracts/AnotherDummyContract.kt @@ -5,7 +5,6 @@ import net.corda.core.identity.AbstractParty import net.corda.core.identity.Party import net.corda.core.transactions.LedgerTransaction import net.corda.core.transactions.TransactionBuilder -import net.corda.nodeapi.DummyContractBackdoor @Suppress("UNUSED") class AnotherDummyContract : Contract, DummyContractBackdoor { diff --git a/isolated/src/main/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt b/isolated/src/main/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt similarity index 91% rename from isolated/src/main/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt rename to isolated/src/main/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt index 2b6e9c2eac..4598e78859 100644 --- a/isolated/src/main/kotlin/net/corda/nodeapi/DummyContractBackdoor.kt +++ b/isolated/src/main/kotlin/net/corda/isolated/contracts/DummyContractBackdoor.kt @@ -1,4 +1,4 @@ -package net.corda.nodeapi +package net.corda.isolated.contracts import net.corda.core.contracts.ContractState import net.corda.core.contracts.PartyAndReference diff --git a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt index 6b5deb01dd..c4f5525eec 100644 --- a/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt +++ b/node/src/integration-test/kotlin/net/corda/node/services/AttachmentLoadingTests.kt @@ -1,32 +1,34 @@ package net.corda.node.services import co.paralleluniverse.fibers.Suspendable -import net.corda.core.contracts.ContractState -import net.corda.core.contracts.StateRef +import net.corda.core.contracts.* import net.corda.core.flows.* +import net.corda.core.identity.AbstractParty import net.corda.core.identity.CordaX500Name import net.corda.core.identity.Party import net.corda.core.internal.* import net.corda.core.internal.concurrent.transpose 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.utilities.getOrThrow import net.corda.core.utilities.unwrap 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.DriverParameters import net.corda.testing.driver.driver import net.corda.testing.node.NotarySpec import net.corda.testing.node.internal.cordappsForPackages import org.assertj.core.api.Assertions.assertThatThrownBy -import org.junit.Ignore import org.junit.Test import java.net.URL 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 { private companion object { val isolatedJar: URL = AttachmentLoadingTests::class.java.getResource("/isolated.jar") @@ -59,11 +61,10 @@ class AttachmentLoadingTests { 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 - // around that it's re-thrown as a FlowException so that it can be propagated to Alice where we pick it here. - assertThatThrownBy { - alice.rpc.startFlow(::ConsumeAndBroadcastFlow, stateRef, bob.nodeInfo.singleIdentity()).returnValue.getOrThrow() - }.hasMessage("Attempting to load Contract Attachments downloaded from the network") + assertThatThrownBy { alice.rpc.startFlow(::ConsumeAndBroadcastFlow, stateRef, bob.nodeInfo.singleIdentity()).returnValue.getOrThrow() } + // ConsumeAndBroadcastResponderFlow re-throws any non-FlowExceptions with just their class name in the message so that + // we can verify here Bob threw the correct exception + .hasMessage(UntrustedAttachmentsException::class.java.name) } } @@ -100,7 +101,10 @@ class AttachmentLoadingTests { val notary = serviceHub.networkMapCache.notaryIdentities[0] val stateAndRef = serviceHub.toStateAndRef(stateRef) 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) val session = initiateFlow(otherSide) @@ -116,10 +120,24 @@ class AttachmentLoadingTests { override fun call() { try { subFlow(ReceiveFinalityFlow(otherSide)) - } catch (e: MissingAttachmentsException) { - throw FlowException(e.message) + } catch (e: FlowException) { + throw e + } catch (e: Exception) { + throw FlowException(e.javaClass.name) } otherSide.send("OK") } } + + class ConsumeContract : Contract { + override fun verify(tx: LedgerTransaction) { + // Accept everything + } + + class State : ContractState { + override val participants: List get() = emptyList() + } + + object Cmd : TypeOnlyCommandData() + } } diff --git a/node/src/integration-test/resources/isolated.jar b/node/src/integration-test/resources/isolated.jar index 47372978cc..8026639a7e 100644 Binary files a/node/src/integration-test/resources/isolated.jar and b/node/src/integration-test/resources/isolated.jar differ diff --git a/node/src/test/resources/isolated.jar b/node/src/test/resources/isolated.jar index 47372978cc..8026639a7e 100644 Binary files a/node/src/test/resources/isolated.jar and b/node/src/test/resources/isolated.jar differ diff --git a/serialization/src/test/resources/isolated.jar b/serialization/src/test/resources/isolated.jar index 47372978cc..8026639a7e 100644 Binary files a/serialization/src/test/resources/isolated.jar and b/serialization/src/test/resources/isolated.jar differ