mirror of
https://github.com/corda/corda.git
synced 2025-06-18 15:18:16 +00:00
CORDA-3584: Now cope with 2 contract jars with same hash but different name (#5952)
* CORDA-3484: Now cope with 2 contract jars with same hash but different name, we just select one and use that. * ENT-3584: Contract jars are now generated on the fly. * CORDA-3584: Reverted changes to CordappProviderImpl. Exception is raised if node started with multiple jars with same hash. * ENT-3584: Fixing test failure. * CORDA-3584: Switch to test extension method instead of reflection to access internal member. * ENT-3584: Address review comment. Dont fully qualify exception. * CORDA-3584: Address review comment and converted lazy to a resettable one. * CORDA-3584: Removed unused logger. * CORDA-3584: Fixed visibility. * CORDA-3584: Removed synchronized * CORDA-3584: Removed CordappResolver * CORDA-3584: Reverted change in gradle file and fixed test. * CORDA-3584: Removed V3 from test description as it wasn't actually V3 specific. * CORDA-3584: Address review comment. Let classes be garbage collected.
This commit is contained in:
@ -1,92 +0,0 @@
|
||||
package net.corda.core.internal.cordapp
|
||||
|
||||
import net.corda.core.crypto.SecureHash
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.lang.IllegalStateException
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class CordappResolverTest {
|
||||
@Before
|
||||
@After
|
||||
fun clearCordappInfoResolver() {
|
||||
CordappResolver.clear()
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `the correct cordapp resolver is used after calling withCordappInfo`() {
|
||||
val defaultTargetVersion = 222
|
||||
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = defaultTargetVersion
|
||||
))
|
||||
assertEquals(defaultTargetVersion, CordappResolver.currentTargetVersion)
|
||||
|
||||
val expectedTargetVersion = 555
|
||||
CordappResolver.withTestCordapp(targetPlatformVersion = expectedTargetVersion) {
|
||||
val actualTargetVersion = CordappResolver.currentTargetVersion
|
||||
assertEquals(expectedTargetVersion, actualTargetVersion)
|
||||
}
|
||||
assertEquals(defaultTargetVersion, CordappResolver.currentTargetVersion)
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `when the same cordapp is registered for the same class multiple times, the resolver deduplicates and returns it as the current one`() {
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = 222
|
||||
))
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 2,
|
||||
targetPlatformVersion = 456
|
||||
))
|
||||
assertThat(CordappResolver.currentCordapp).isNotNull()
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `when different cordapps are registered for the same (non-contract) class, the resolver returns null`() {
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf("ContractClass1"),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = 222,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
))
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf("ContractClass2"),
|
||||
minimumPlatformVersion = 2,
|
||||
targetPlatformVersion = 456,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
))
|
||||
assertThat(CordappResolver.currentCordapp).isNull()
|
||||
}
|
||||
|
||||
@Test(timeout=300_000)
|
||||
fun `when different cordapps are registered for the same (contract) class, the resolver throws an exception`() {
|
||||
val firstCordapp = CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = 222,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
)
|
||||
val secondCordapp = CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 2,
|
||||
targetPlatformVersion = 456,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
)
|
||||
|
||||
CordappResolver.register(firstCordapp)
|
||||
assertThatThrownBy { CordappResolver.register(secondCordapp) }
|
||||
.isInstanceOf(IllegalStateException::class.java)
|
||||
.hasMessageContaining("More than one CorDapp installed on the node for contract ${javaClass.name}. " +
|
||||
"Please remove the previous version when upgrading to a new version.")
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user