mirror of
https://github.com/corda/corda.git
synced 2025-06-19 23:53:52 +00:00
Clean-up.
This commit is contained in:
@ -51,8 +51,6 @@ import net.corda.finance.test.flows.CashIssueWithObserversFlow
|
|||||||
import net.corda.finance.test.flows.CashPaymentWithObserversFlow
|
import net.corda.finance.test.flows.CashPaymentWithObserversFlow
|
||||||
import net.corda.node.services.persistence.DBTransactionStorage
|
import net.corda.node.services.persistence.DBTransactionStorage
|
||||||
import net.corda.node.services.persistence.DBTransactionStorageLedgerRecovery
|
import net.corda.node.services.persistence.DBTransactionStorageLedgerRecovery
|
||||||
import net.corda.node.services.persistence.DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord
|
|
||||||
import net.corda.node.services.persistence.DBTransactionStorageLedgerRecovery.DBSenderDistributionRecord
|
|
||||||
import net.corda.node.services.persistence.HashedDistributionList
|
import net.corda.node.services.persistence.HashedDistributionList
|
||||||
import net.corda.node.services.persistence.ReceiverDistributionRecord
|
import net.corda.node.services.persistence.ReceiverDistributionRecord
|
||||||
import net.corda.node.services.persistence.SenderDistributionRecord
|
import net.corda.node.services.persistence.SenderDistributionRecord
|
||||||
@ -76,8 +74,8 @@ import net.corda.testing.node.internal.enclosedCordapp
|
|||||||
import net.corda.testing.node.internal.findCordapp
|
import net.corda.testing.node.internal.findCordapp
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
|
||||||
import java.sql.SQLException
|
import java.sql.SQLException
|
||||||
import java.util.Random
|
import java.util.Random
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@ -358,10 +356,12 @@ class FinalityFlowTests : WithFinality {
|
|||||||
assertEquals(StatesToRecord.ALL_VISIBLE, this[0].statesToRecord)
|
assertEquals(StatesToRecord.ALL_VISIBLE, this[0].statesToRecord)
|
||||||
assertEquals(BOB_NAME.hashCode().toLong(), this[0].peerPartyId)
|
assertEquals(BOB_NAME.hashCode().toLong(), this[0].peerPartyId)
|
||||||
}
|
}
|
||||||
val rdr = getReceiverRecoveryData(stx.id, bobNode, aliceNode).apply {
|
val rdr = getReceiverRecoveryData(stx.id, bobNode).apply {
|
||||||
assertEquals(StatesToRecord.ONLY_RELEVANT, this?.statesToRecord)
|
assertNotNull(this)
|
||||||
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this?.initiatorPartyId)
|
val hashedDL = HashedDistributionList.decrypt(this!!.encryptedDistributionList.bytes, aliceNode.internals.encryptionService)
|
||||||
assertEquals(mapOf(BOB_NAME.hashCode().toLong() to StatesToRecord.ALL_VISIBLE), this?.peersToStatesToRecord)
|
assertEquals(StatesToRecord.ONLY_RELEVANT, hashedDL.senderStatesToRecord)
|
||||||
|
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this.initiatorPartyId)
|
||||||
|
assertEquals(mapOf(BOB_NAME.hashCode().toLong() to StatesToRecord.ALL_VISIBLE), hashedDL.peerHashToStatesToRecord)
|
||||||
}
|
}
|
||||||
validateSenderAndReceiverTimestamps(sdrs, rdr!!)
|
validateSenderAndReceiverTimestamps(sdrs, rdr!!)
|
||||||
}
|
}
|
||||||
@ -391,14 +391,16 @@ class FinalityFlowTests : WithFinality {
|
|||||||
assertEquals(StatesToRecord.ALL_VISIBLE, this[1].statesToRecord)
|
assertEquals(StatesToRecord.ALL_VISIBLE, this[1].statesToRecord)
|
||||||
assertEquals(CHARLIE_NAME.hashCode().toLong(), this[1].peerPartyId)
|
assertEquals(CHARLIE_NAME.hashCode().toLong(), this[1].peerPartyId)
|
||||||
}
|
}
|
||||||
val rdr = getReceiverRecoveryData(stx.id, bobNode, aliceNode).apply {
|
val rdr = getReceiverRecoveryData(stx.id, bobNode).apply {
|
||||||
assertEquals(StatesToRecord.ONLY_RELEVANT, this?.statesToRecord)
|
assertNotNull(this)
|
||||||
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this?.initiatorPartyId)
|
val hashedDL = HashedDistributionList.decrypt(this!!.encryptedDistributionList.bytes, aliceNode.internals.encryptionService)
|
||||||
|
assertEquals(StatesToRecord.ONLY_RELEVANT, hashedDL.senderStatesToRecord)
|
||||||
|
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this.initiatorPartyId)
|
||||||
// note: Charlie assertion here is using the hinted StatesToRecord value passed to it from Alice
|
// note: Charlie assertion here is using the hinted StatesToRecord value passed to it from Alice
|
||||||
assertEquals(mapOf(
|
assertEquals(mapOf(
|
||||||
BOB_NAME.hashCode().toLong() to StatesToRecord.ONLY_RELEVANT,
|
BOB_NAME.hashCode().toLong() to StatesToRecord.ONLY_RELEVANT,
|
||||||
CHARLIE_NAME.hashCode().toLong() to StatesToRecord.ALL_VISIBLE
|
CHARLIE_NAME.hashCode().toLong() to StatesToRecord.ALL_VISIBLE
|
||||||
), distList.peerHashToStatesToRecord)
|
), hashedDL.peerHashToStatesToRecord)
|
||||||
}
|
}
|
||||||
validateSenderAndReceiverTimestamps(sdrs, rdr!!)
|
validateSenderAndReceiverTimestamps(sdrs, rdr!!)
|
||||||
|
|
||||||
@ -417,12 +419,12 @@ class FinalityFlowTests : WithFinality {
|
|||||||
assertEquals(2, this.size)
|
assertEquals(2, this.size)
|
||||||
assertEquals(this[0].timestamp, this[1].timestamp)
|
assertEquals(this[0].timestamp, this[1].timestamp)
|
||||||
}
|
}
|
||||||
getReceiverRecoveryData(stx3.id, bobNode, aliceNode).apply {
|
getReceiverRecoveryData(stx3.id, bobNode).apply {
|
||||||
assertThat(getReceiverRecoveryData(stx3.id, bobNode, aliceNode)).isNotNull
|
assertThat(this).isNotNull
|
||||||
assertEquals(senderDistributionRecords[0].timestamp, this!!.timestamp)
|
assertEquals(senderDistributionRecords[0].timestamp, this!!.timestamp)
|
||||||
}
|
}
|
||||||
getReceiverRecoveryData(stx3.id, charlieNode, aliceNode).apply {
|
getReceiverRecoveryData(stx3.id, charlieNode).apply {
|
||||||
assertThat(getReceiverRecoveryData(stx3.id, charlieNode, aliceNode)).isNotNull
|
assertThat(this).isNotNull
|
||||||
assertEquals(senderDistributionRecords[0].timestamp, this!!.timestamp)
|
assertEquals(senderDistributionRecords[0].timestamp, this!!.timestamp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,10 +453,12 @@ class FinalityFlowTests : WithFinality {
|
|||||||
assertEquals(StatesToRecord.ONLY_RELEVANT, this[0].statesToRecord)
|
assertEquals(StatesToRecord.ONLY_RELEVANT, this[0].statesToRecord)
|
||||||
assertEquals(BOB_NAME.hashCode().toLong(), this[0].peerPartyId)
|
assertEquals(BOB_NAME.hashCode().toLong(), this[0].peerPartyId)
|
||||||
}
|
}
|
||||||
val rdr = getReceiverRecoveryData(stx.id, bobNode, aliceNode).apply {
|
val rdr = getReceiverRecoveryData(stx.id, bobNode).apply {
|
||||||
assertEquals(StatesToRecord.ONLY_RELEVANT, this?.statesToRecord)
|
assertNotNull(this)
|
||||||
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this?.initiatorPartyId)
|
val hashedDL = HashedDistributionList.decrypt(this!!.encryptedDistributionList.bytes, aliceNode.internals.encryptionService)
|
||||||
assertEquals(mapOf(BOB_NAME.hashCode().toLong() to StatesToRecord.ONLY_RELEVANT), this?.peersToStatesToRecord)
|
assertEquals(StatesToRecord.ONLY_RELEVANT, hashedDL.senderStatesToRecord)
|
||||||
|
assertEquals(aliceNode.info.singleIdentity().name.hashCode().toLong(), this.initiatorPartyId)
|
||||||
|
assertEquals(mapOf(BOB_NAME.hashCode().toLong() to StatesToRecord.ONLY_RELEVANT), hashedDL.peerHashToStatesToRecord)
|
||||||
}
|
}
|
||||||
validateSenderAndReceiverTimestamps(sdr, rdr!!)
|
validateSenderAndReceiverTimestamps(sdr, rdr!!)
|
||||||
}
|
}
|
||||||
@ -466,24 +470,16 @@ class FinalityFlowTests : WithFinality {
|
|||||||
DBTransactionStorageLedgerRecovery.DBSenderDistributionRecord::class.java
|
DBTransactionStorageLedgerRecovery.DBSenderDistributionRecord::class.java
|
||||||
).setParameter("transactionId", id.toString()).resultList
|
).setParameter("transactionId", id.toString()).resultList
|
||||||
}
|
}
|
||||||
return fromDb.map { it.toSenderDistributionRecord() }.also { println("SenderDistributionRecord\n$it") }
|
return fromDb.map { it.toSenderDistributionRecord() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getReceiverRecoveryData(txId: SecureHash, receiver: TestStartedNode, sender: TestStartedNode): ReceiverDistributionRecord? {
|
private fun getReceiverRecoveryData(txId: SecureHash, receiver: TestStartedNode): ReceiverDistributionRecord? {
|
||||||
val fromDb = receiver.database.transaction {
|
return receiver.database.transaction {
|
||||||
session.createQuery(
|
session.createQuery(
|
||||||
"from ${DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java.name} where txId = :transactionId",
|
"from ${DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java.name} where txId = :transactionId",
|
||||||
DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java
|
DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java
|
||||||
).setParameter("transactionId", txId.toString()).resultList
|
).setParameter("transactionId", txId.toString()).resultList
|
||||||
}.singleOrNull()
|
}.singleOrNull()?.toReceiverDistributionRecord()
|
||||||
|
|
||||||
// The receiver should not be able to decrypt the distribution list
|
|
||||||
assertThrows<Exception> {
|
|
||||||
fromDb?.toReceiverDistributionRecord(receiver.internals.encryptionService)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only the sender can
|
|
||||||
return fromDb?.toReceiverDistributionRecord(sender.internals.encryptionService)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@StartableByRPC
|
@StartableByRPC
|
||||||
|
@ -101,8 +101,7 @@ class DBTransactionStorageLedgerRecovery(private val database: CordaPersistence,
|
|||||||
receiverStatesToRecord = receiverStatesToRecord
|
receiverStatesToRecord = receiverStatesToRecord
|
||||||
)
|
)
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun toReceiverDistributionRecord(encryptionService: EncryptionService): ReceiverDistributionRecord {
|
fun toReceiverDistributionRecord(): ReceiverDistributionRecord {
|
||||||
val hashedDL = HashedDistributionList.decrypt(this.distributionList, encryptionService)
|
|
||||||
return ReceiverDistributionRecord(
|
return ReceiverDistributionRecord(
|
||||||
SecureHash.parse(this.txId),
|
SecureHash.parse(this.txId),
|
||||||
this.compositeKey.peerPartyId,
|
this.compositeKey.peerPartyId,
|
||||||
|
@ -331,7 +331,7 @@ class DBTransactionStorageLedgerRecoveryTests {
|
|||||||
session.createQuery(
|
session.createQuery(
|
||||||
"from ${DBTransactionStorage.DBTransaction::class.java.name} where txId = :transactionId",
|
"from ${DBTransactionStorage.DBTransaction::class.java.name} where txId = :transactionId",
|
||||||
DBTransactionStorage.DBTransaction::class.java
|
DBTransactionStorage.DBTransaction::class.java
|
||||||
).setParameter("transactionId", id.toString()).resultList
|
).setParameter("transactionId", txId.toString()).resultList
|
||||||
}
|
}
|
||||||
assertEquals(1, fromDb.size)
|
assertEquals(1, fromDb.size)
|
||||||
return fromDb[0]
|
return fromDb[0]
|
||||||
@ -355,12 +355,12 @@ class DBTransactionStorageLedgerRecoveryTests {
|
|||||||
private fun readReceiverDistributionRecordFromDB(txId: SecureHash): ReceiverDistributionRecord {
|
private fun readReceiverDistributionRecordFromDB(txId: SecureHash): ReceiverDistributionRecord {
|
||||||
val fromDb = database.transaction {
|
val fromDb = database.transaction {
|
||||||
session.createQuery(
|
session.createQuery(
|
||||||
"from ${DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java.name} where txId = :transactionId",
|
"from ${DBReceiverDistributionRecord::class.java.name} where txId = :transactionId",
|
||||||
DBTransactionStorageLedgerRecovery.DBReceiverDistributionRecord::class.java
|
DBReceiverDistributionRecord::class.java
|
||||||
).setParameter("transactionId", id.toString()).resultList
|
).setParameter("transactionId", txId.toString()).resultList
|
||||||
}
|
}
|
||||||
assertEquals(1, fromDb.size)
|
assertEquals(1, fromDb.size)
|
||||||
return fromDb[0].toReceiverDistributionRecord(encryptionService)
|
return fromDb[0].toReceiverDistributionRecord()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun newTransactionRecovery(cacheSizeBytesOverride: Long? = null, clock: CordaClock = SimpleClock(Clock.systemUTC())) {
|
private fun newTransactionRecovery(cacheSizeBytesOverride: Long? = null, clock: CordaClock = SimpleClock(Clock.systemUTC())) {
|
||||||
@ -415,15 +415,5 @@ class DBTransactionStorageLedgerRecoveryTests {
|
|||||||
|
|
||||||
private fun notarySig(txId: SecureHash) =
|
private fun notarySig(txId: SecureHash) =
|
||||||
DUMMY_NOTARY.keyPair.sign(SignableData(txId, SignatureMetadata(1, Crypto.findSignatureScheme(DUMMY_NOTARY.publicKey).schemeNumberID)))
|
DUMMY_NOTARY.keyPair.sign(SignableData(txId, SignatureMetadata(1, Crypto.findSignatureScheme(DUMMY_NOTARY.publicKey).schemeNumberID)))
|
||||||
|
|
||||||
private fun SenderDistributionList.toWire(): ByteArray {
|
|
||||||
val hashedPeersToStatesToRecord = this.peersToStatesToRecord.mapKeys { (peer) -> partyInfoCache.getPartyIdByCordaX500Name(peer) }
|
|
||||||
val hashedDistributionList = HashedDistributionList(
|
|
||||||
this.senderStatesToRecord,
|
|
||||||
hashedPeersToStatesToRecord,
|
|
||||||
HashedDistributionList.PublicHeader(now())
|
|
||||||
)
|
|
||||||
return hashedDistributionList.encrypt(encryptionService)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user