Correct misleading comment in CompositeKey and minor changes to its unit test (#1321)

This commit is contained in:
Viktor Kolomeyko 2017-08-25 11:37:55 +01:00 committed by GitHub
parent 2b5e3e39a2
commit e2f402f0e4
2 changed files with 11 additions and 10 deletions

View File

@ -262,7 +262,9 @@ class CompositeKey private constructor(val threshold: Int, children: List<NodeAn
else if (n == 1) {
require(threshold == null || threshold == children.first().weight)
{ "Trying to build invalid CompositeKey, threshold value different than weight of single child node." }
children.first().node // We can assume that this node is a correct CompositeKey.
// Returning the only child node which is [PublicKey] itself. We need to avoid single-key [CompositeKey] instances,
// as there are scenarios where developers expected the underlying key and its composite versions to be equivalent.
children.first().node
} else throw IllegalArgumentException("Trying to build CompositeKey without child nodes.")
}
}

View File

@ -25,16 +25,16 @@ class CompositeKeyTests : TestDependencyInjectionBase() {
@JvmField
val tempFolder: TemporaryFolder = TemporaryFolder()
val aliceKey = generateKeyPair()
val bobKey = generateKeyPair()
val charlieKey = generateKeyPair()
private val aliceKey = generateKeyPair()
private val bobKey = generateKeyPair()
private val charlieKey = generateKeyPair()
val alicePublicKey: PublicKey = aliceKey.public
val bobPublicKey: PublicKey = bobKey.public
val charliePublicKey: PublicKey = charlieKey.public
private val alicePublicKey: PublicKey = aliceKey.public
private val bobPublicKey: PublicKey = bobKey.public
private val charliePublicKey: PublicKey = charlieKey.public
val message = OpaqueBytes("Transaction".toByteArray())
val secureHash = message.sha256()
private val message = OpaqueBytes("Transaction".toByteArray())
private val secureHash = message.sha256()
// By lazy is required so that the serialisers are configured before vals initialisation takes place (they internally invoke serialise).
val aliceSignature by lazy { aliceKey.sign(SignableData(secureHash, SignatureMetadata(1, Crypto.findSignatureScheme(alicePublicKey).schemeNumberID))) }
@ -43,7 +43,6 @@ class CompositeKeyTests : TestDependencyInjectionBase() {
@Test
fun `(Alice) fulfilled by Alice signature`() {
println(aliceKey.serialize().hash)
assertTrue { alicePublicKey.isFulfilledBy(aliceSignature.by) }
assertFalse { alicePublicKey.isFulfilledBy(charlieSignature.by) }
}