mirror of
https://github.com/corda/corda.git
synced 2025-03-21 11:35:57 +00:00
Minor: Add a test to ensure "identical" issue transactions have different ids (#1145)
* Add a test to ensure identical issue transactions have different ids * Fix a PMT test
This commit is contained in:
parent
f6e05aeae9
commit
a60ccded75
@ -447,6 +447,7 @@ fun JarInputStream.extractFile(path: String, outputTo: OutputStream) {
|
||||
*/
|
||||
@CordaSerializable
|
||||
class PrivacySalt(bytes: ByteArray) : OpaqueBytes(bytes) {
|
||||
/** Constructs a salt with a randomly-generated 32 byte value. */
|
||||
constructor() : this(secureRandomBytes(32))
|
||||
|
||||
init {
|
||||
|
@ -15,6 +15,7 @@ import org.junit.Test
|
||||
import java.security.KeyPair
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
class TransactionTests : TestDependencyInjectionBase() {
|
||||
private fun makeSigned(wtx: WireTransaction, vararg keys: KeyPair, notarySig: Boolean = true): SignedTransaction {
|
||||
@ -152,4 +153,23 @@ class TransactionTests : TestDependencyInjectionBase() {
|
||||
|
||||
assertFailsWith<TransactionVerificationException.NotaryChangeInWrongTransactionType> { buildTransaction() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `transactions with identical contents must have different ids`() {
|
||||
val outputState = TransactionState(DummyContract.SingleOwnerState(0, ALICE), DUMMY_NOTARY)
|
||||
fun buildTransaction() = WireTransaction(
|
||||
inputs = emptyList(),
|
||||
attachments = emptyList(),
|
||||
outputs = listOf(outputState),
|
||||
commands = listOf(dummyCommand(DUMMY_KEY_1.public, DUMMY_KEY_2.public)),
|
||||
notary = null,
|
||||
timeWindow = null,
|
||||
privacySalt = PrivacySalt() // Randomly-generated – used for calculating the id
|
||||
)
|
||||
|
||||
val issueTx1 = buildTransaction()
|
||||
val issueTx2 = buildTransaction()
|
||||
|
||||
assertNotEquals(issueTx1.id, issueTx2.id)
|
||||
}
|
||||
}
|
||||
|
@ -127,8 +127,11 @@ class PartialMerkleTreeTest : TestDependencyInjectionBase() {
|
||||
|
||||
@Test
|
||||
fun `same transactions with different notaries have different ids`() {
|
||||
val wtx1 = makeSimpleCashWtx(DUMMY_NOTARY)
|
||||
val wtx2 = makeSimpleCashWtx(MEGA_CORP)
|
||||
// We even use the same privacySalt, and thus the only difference between the two transactions is the notary party.
|
||||
val privacySalt = PrivacySalt()
|
||||
val wtx1 = makeSimpleCashWtx(DUMMY_NOTARY, privacySalt)
|
||||
val wtx2 = makeSimpleCashWtx(MEGA_CORP, privacySalt)
|
||||
assertEquals(wtx1.privacySalt, wtx2.privacySalt)
|
||||
assertNotEquals(wtx1.id, wtx2.id)
|
||||
}
|
||||
|
||||
@ -235,14 +238,20 @@ class PartialMerkleTreeTest : TestDependencyInjectionBase() {
|
||||
hm1.serialize()
|
||||
}
|
||||
|
||||
private fun makeSimpleCashWtx(notary: Party, timeWindow: TimeWindow? = null, attachments: List<SecureHash> = emptyList()): WireTransaction {
|
||||
private fun makeSimpleCashWtx(
|
||||
notary: Party,
|
||||
privacySalt: PrivacySalt = PrivacySalt(),
|
||||
timeWindow: TimeWindow? = null,
|
||||
attachments: List<SecureHash> = emptyList()
|
||||
): WireTransaction {
|
||||
return WireTransaction(
|
||||
inputs = testTx.inputs,
|
||||
attachments = attachments,
|
||||
outputs = testTx.outputs,
|
||||
commands = testTx.commands,
|
||||
notary = notary,
|
||||
timeWindow = timeWindow
|
||||
timeWindow = timeWindow,
|
||||
privacySalt = privacySalt
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user