diff --git a/core-tests/src/test/kotlin/net/corda/coretests/contracts/RotatedKeysTest.kt b/core-tests/src/test/kotlin/net/corda/coretests/contracts/RotatedKeysTest.kt index 8e0da67b8d..3c6a0d9e98 100644 --- a/core-tests/src/test/kotlin/net/corda/coretests/contracts/RotatedKeysTest.kt +++ b/core-tests/src/test/kotlin/net/corda/coretests/contracts/RotatedKeysTest.kt @@ -1,16 +1,31 @@ package net.corda.coretests.contracts +import net.corda.core.contracts.CordaRotatedKeys import net.corda.core.contracts.RotatedKeys import net.corda.core.crypto.CompositeKey import net.corda.core.crypto.sha256 +import net.corda.core.identity.CordaX500Name import net.corda.core.internal.hash +import net.corda.core.internal.retrieveRotatedKeys +import net.corda.core.node.ServiceHub +import net.corda.testing.core.TestIdentity import net.corda.testing.core.internal.JarSignatureTestUtils.generateKey import net.corda.testing.core.internal.SelfCleaningDir +import net.corda.testing.node.MockServices import org.junit.Test +import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue class RotatedKeysTest { + + @Test(timeout = 300_000) + fun `validateDefaultRotatedKeysAreRetrievableFromMockServices`() { + val services: ServiceHub = MockServices(TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))) + val rotatedKeys = services.retrieveRotatedKeys() + assertEquals( CordaRotatedKeys.keys.rotatedSigningKeys, rotatedKeys.rotatedSigningKeys) + } + @Test(timeout = 300_000) fun `when input and output keys are the same canBeTransitioned returns true`() { SelfCleaningDir().use { file -> diff --git a/core/src/main/kotlin/net/corda/core/internal/TransactionUtils.kt b/core/src/main/kotlin/net/corda/core/internal/TransactionUtils.kt index 299a898267..941f2db3e3 100644 --- a/core/src/main/kotlin/net/corda/core/internal/TransactionUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/TransactionUtils.kt @@ -13,6 +13,7 @@ import net.corda.core.node.ServicesForResolution import net.corda.core.serialization.* import net.corda.core.transactions.* import net.corda.core.utilities.OpaqueBytes +import net.corda.core.utilities.contextLogger import java.io.ByteArrayOutputStream import java.security.PublicKey import kotlin.reflect.KClass @@ -27,7 +28,9 @@ fun ServiceHub.retrieveRotatedKeys(): RotatedKeys { if (clazz.name == "net.corda.testing.node.MockServices") { return clazz.getDeclaredMethod("getRotatedKeys").apply { isAccessible = true }.invoke(this) as RotatedKeys } - clazz = clazz.superclass ?: throw ClassCastException("${javaClass.name} is not a ServiceHub") + clazz = clazz.superclass ?: return CordaRotatedKeys.keys.also { + this.contextLogger().warn("${javaClass.name} is not a MockServices instance - returning default rotated keys") + } } }