mirror of
https://github.com/corda/corda.git
synced 2025-01-30 16:14:39 +00:00
CORDA-2528 - Update contract testing documentation (#4977)
This commit is contained in:
parent
750033540a
commit
5a0b2b6f48
@ -15,6 +15,33 @@ This tutorial will take you through the steps required to write a contract test
|
|||||||
The testing DSL allows one to define a piece of the ledger with transactions referring to each other, and ways of
|
The testing DSL allows one to define a piece of the ledger with transactions referring to each other, and ways of
|
||||||
verifying their correctness.
|
verifying their correctness.
|
||||||
|
|
||||||
|
Setting up the test
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Before writing the individual tests, the general test setup must be configured:
|
||||||
|
|
||||||
|
.. container:: codeset
|
||||||
|
|
||||||
|
.. sourcecode:: kotlin
|
||||||
|
|
||||||
|
class CommercialPaperTest {
|
||||||
|
private val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
|
||||||
|
private val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
||||||
|
private val ledgerServices = MockServices(listOf("net.corda.finance.schemas"), megaCorp, miniCorp)
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
.. sourcecode:: java
|
||||||
|
|
||||||
|
public class CommercialPaperTest {
|
||||||
|
private TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
|
||||||
|
private TestIdentity miniCorp = new TestIdentity(new CordaX500Name("MiniCorp", "London", "GB"));
|
||||||
|
MockServices ledgerServices = new MockServices(Arrays.asList("net.corda.finance.schemas"), megaCorp, miniCorp);
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
The ``ledgerServices`` object will provide configuration to the ``ledger`` DSL in the individual tests.
|
||||||
|
|
||||||
Testing single transactions
|
Testing single transactions
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
@ -27,22 +54,19 @@ We start with the empty ledger:
|
|||||||
class CommercialPaperTest {
|
class CommercialPaperTest {
|
||||||
@Test
|
@Test
|
||||||
fun emptyLedger() {
|
fun emptyLedger() {
|
||||||
ledger {
|
ledgerServices.ledger {
|
||||||
}
|
|
||||||
}
|
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.. sourcecode:: java
|
.. sourcecode:: java
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static net.corda.testing.NodeTestUtils.ledger;
|
|
||||||
|
|
||||||
public class CommercialPaperTest {
|
public class CommercialPaperTest {
|
||||||
@Test
|
@Test
|
||||||
public void emptyLedger() {
|
public void emptyLedger() {
|
||||||
ledger(l -> {
|
ledger(ledgerServices, l -> {
|
||||||
|
...
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -90,7 +114,7 @@ Let's add a ``CommercialPaper`` transaction:
|
|||||||
@Test
|
@Test
|
||||||
public void simpleCPDoesntCompile() {
|
public void simpleCPDoesntCompile() {
|
||||||
ICommercialPaperState inState = getPaper();
|
ICommercialPaperState inState = getPaper();
|
||||||
ledger(l -> {
|
ledger(ledgerServices, l -> {
|
||||||
l.transaction(tx -> {
|
l.transaction(tx -> {
|
||||||
tx.input(inState);
|
tx.input(inState);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user