mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
Test notarisation of issue transactions with time-window (#3092)
This commit is contained in:
parent
0dae108088
commit
1a6922afe0
@ -20,6 +20,7 @@ import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.utilities.NetworkHostAndPort
|
||||
import net.corda.core.utilities.Try
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.node.internal.StartedNode
|
||||
import net.corda.node.services.config.BFTSMaRtConfiguration
|
||||
import net.corda.node.services.config.NotaryConfig
|
||||
@ -31,7 +32,6 @@ import net.corda.testing.common.internal.testNetworkParameters
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.core.dummyCommand
|
||||
import net.corda.testing.core.singleIdentity
|
||||
import net.corda.testing.driver.PortAllocation
|
||||
import net.corda.testing.node.TestClock
|
||||
import net.corda.testing.node.internal.InternalMockNetwork
|
||||
import net.corda.testing.node.internal.InternalMockNetwork.MockNode
|
||||
@ -43,7 +43,6 @@ import org.junit.Assert.assertThat
|
||||
import java.nio.file.Paths
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import java.util.concurrent.ExecutionException
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
@ -168,6 +167,21 @@ class BFTNotaryServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `notarise issue tx with time-window`() {
|
||||
node.run {
|
||||
val issueTx = signInitialTransaction(notary) {
|
||||
setTimeWindow(services.clock.instant(), 30.seconds)
|
||||
addOutputState(DummyContract.SingleOwnerState(owner = info.singleIdentity()), DummyContract.PROGRAM_ID, AlwaysAcceptAttachmentConstraint)
|
||||
}
|
||||
val resultFuture = services.startFlow(NotaryFlow.Client(issueTx)).resultFuture
|
||||
|
||||
mockNet.runNetwork()
|
||||
val signatures = resultFuture.get()
|
||||
verifySignatures(signatures, issueTx.id)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `transactions can be re-notarised outside their time window`() {
|
||||
node.run {
|
||||
|
@ -10,6 +10,7 @@ import net.corda.core.identity.Party
|
||||
import net.corda.core.internal.concurrent.map
|
||||
import net.corda.core.transactions.TransactionBuilder
|
||||
import net.corda.core.utilities.getOrThrow
|
||||
import net.corda.core.utilities.seconds
|
||||
import net.corda.testing.core.DUMMY_BANK_A_NAME
|
||||
import net.corda.testing.core.singleIdentity
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
@ -20,7 +21,6 @@ import net.corda.testing.driver.InProcess
|
||||
import net.corda.testing.driver.internal.InProcessImpl
|
||||
import net.corda.testing.node.ClusterSpec
|
||||
import net.corda.testing.node.NotarySpec
|
||||
import net.corda.testing.node.internal.startFlow
|
||||
import org.junit.Test
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
@ -62,6 +62,23 @@ class RaftNotaryServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `notarise issue tx with time-window`() {
|
||||
driver(DriverParameters(
|
||||
startNodesInProcess = true,
|
||||
extraCordappPackagesToScan = listOf("net.corda.testing.contracts"),
|
||||
notarySpecs = listOf(NotarySpec(notaryName, cluster = ClusterSpec.Raft(clusterSize = 3)))
|
||||
)) {
|
||||
val bankA = startNode(providedName = DUMMY_BANK_A_NAME).map { (it as InProcess) }.getOrThrow()
|
||||
val issueTx = (bankA as InProcessImpl).database.transaction {
|
||||
val builder = DummyContract.generateInitial(Random().nextInt(), defaultNotaryIdentity, bankA.services.myInfo.singleIdentity().ref(0))
|
||||
.setTimeWindow(bankA.services.clock.instant(), 30.seconds)
|
||||
bankA.services.signInitialTransaction(builder)
|
||||
}
|
||||
bankA.startFlow(NotaryFlow.Client(issueTx)).getOrThrow()
|
||||
}
|
||||
}
|
||||
|
||||
private fun issueState(nodeHandle: InProcess, notary: Party): StateAndRef<*> {
|
||||
return (nodeHandle as InProcessImpl).database.transaction {
|
||||
|
||||
|
@ -169,6 +169,18 @@ class ValidatingNotaryServiceTests {
|
||||
assertThat(ex.error).isInstanceOf(NotaryError.TimeWindowInvalid::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `notarise issue tx with time-window`() {
|
||||
val stx = run {
|
||||
val tx = DummyContract.generateInitial(Random().nextInt(), notary, alice.ref(0))
|
||||
.setTimeWindow(Instant.now(), 30.seconds)
|
||||
aliceNode.services.signInitialTransaction(tx)
|
||||
}
|
||||
|
||||
val sig = runNotaryClient(stx).getOrThrow().single()
|
||||
assertEquals(sig.by, notary.owningKey)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should sign identical transaction multiple times (notarisation is idempotent)`() {
|
||||
val stx = run {
|
||||
|
Loading…
x
Reference in New Issue
Block a user