mirror of
https://github.com/corda/corda.git
synced 2025-06-13 12:48:18 +00:00
merged OS into master
This commit is contained in:
@ -80,14 +80,20 @@ task deployNodes(type: net.corda.plugins.Cordform, dependsOn: ['jar']) {
|
||||
name "O=Notary Service,OU=corda,L=London,C=GB"
|
||||
notary = [validating : true]
|
||||
p2pPort 10002
|
||||
rpcPort 10003
|
||||
rpcSettings {
|
||||
address "localhost:10003"
|
||||
adminAddress "localhost:10013"
|
||||
}
|
||||
webPort 10004
|
||||
cordapps = []
|
||||
}
|
||||
node {
|
||||
name "O=Alice Corp,L=London,C=GB"
|
||||
p2pPort 10005
|
||||
rpcPort 10006
|
||||
rpcSettings {
|
||||
address "localhost:10006"
|
||||
adminAddress "localhost:10016"
|
||||
}
|
||||
webPort 10007
|
||||
cordapps = []
|
||||
rpcUsers = [
|
||||
|
@ -27,6 +27,7 @@ import net.corda.finance.contracts.asset.Cash
|
||||
import net.corda.testing.contracts.DummyContract
|
||||
import net.corda.testing.contracts.DummyState
|
||||
import java.security.PublicKey
|
||||
import java.security.Signature
|
||||
import java.time.Instant
|
||||
|
||||
// ``InitiatorFlow`` is our first flow, and will communicate with
|
||||
@ -205,6 +206,19 @@ class InitiatorFlow(val arg1: Boolean, val arg2: Int, private val counterparty:
|
||||
val packet3: UntrustworthyData<Any> = regulatorSession.receive<Any>()
|
||||
// DOCEND 06
|
||||
|
||||
// We may also batch receives in order to increase performance. This
|
||||
// ensures that only a single checkpoint is created for all received
|
||||
// messages.
|
||||
// Type-safe variant:
|
||||
val signatures: List<UntrustworthyData<Signature>> =
|
||||
receiveAll(Signature::class.java, listOf(counterpartySession, regulatorSession))
|
||||
// Dynamic variant:
|
||||
val messages: Map<FlowSession, UntrustworthyData<*>> =
|
||||
receiveAllMap(mapOf(
|
||||
counterpartySession to Boolean::class.java,
|
||||
regulatorSession to String::class.java
|
||||
))
|
||||
|
||||
/**-----------------------------------
|
||||
* EXTRACTING STATES FROM THE VAULT *
|
||||
-----------------------------------**/
|
||||
|
@ -7,39 +7,66 @@ import net.corda.core.identity.CordaX500Name;
|
||||
import net.corda.finance.contracts.ICommercialPaperState;
|
||||
import net.corda.finance.contracts.JavaCommercialPaper;
|
||||
import net.corda.finance.contracts.asset.Cash;
|
||||
import net.corda.testing.node.MockServices;
|
||||
import net.corda.testing.core.TestIdentity;
|
||||
import net.corda.testing.node.MockServices;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.security.PublicKey;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static net.corda.core.crypto.Crypto.generateKeyPair;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static net.corda.finance.Currencies.DOLLARS;
|
||||
import static net.corda.finance.Currencies.issuedBy;
|
||||
import static net.corda.finance.contracts.JavaCommercialPaper.JCP_PROGRAM_ID;
|
||||
import static net.corda.testing.core.TestConstants.*;
|
||||
import static net.corda.testing.node.MockServicesKt.makeTestIdentityService;
|
||||
import static net.corda.testing.node.NodeTestUtils.ledger;
|
||||
import static net.corda.testing.node.NodeTestUtils.transaction;
|
||||
import static net.corda.testing.core.TestConstants.ALICE_NAME;
|
||||
import static net.corda.testing.core.TestConstants.BOB_NAME;
|
||||
import static net.corda.testing.core.TestConstants.TEST_TX_TIME;
|
||||
|
||||
public class CommercialPaperTest {
|
||||
private static final TestIdentity ALICE = new TestIdentity(ALICE_NAME, 70L);
|
||||
private static final PublicKey BIG_CORP_PUBKEY = generateKeyPair().getPublic();
|
||||
private static final TestIdentity BOB = new TestIdentity(BOB_NAME, 80L);
|
||||
private static final TestIdentity MEGA_CORP = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
|
||||
|
||||
private static final TestIdentity alice = new TestIdentity(ALICE_NAME, 70L);
|
||||
private static final TestIdentity bigCorp = new TestIdentity(new CordaX500Name("BigCorp", "New York", "GB"));
|
||||
private static final TestIdentity bob = new TestIdentity(BOB_NAME, 80L);
|
||||
private static final TestIdentity megaCorp = new TestIdentity(new CordaX500Name("MegaCorp", "London", "GB"));
|
||||
private final byte[] defaultRef = {123};
|
||||
private final MockServices ledgerServices = new MockServices(MEGA_CORP);
|
||||
private MockServices ledgerServices;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// DOCSTART 11
|
||||
ledgerServices = new MockServices(
|
||||
// A list of packages to scan for cordapps
|
||||
singletonList("net.corda.finance.contracts"),
|
||||
// The identity represented by this set of mock services. Defaults to a test identity.
|
||||
// You can also use the alternative parameter initialIdentityName which accepts a
|
||||
// [CordaX500Name]
|
||||
megaCorp,
|
||||
// An implementation of [IdentityService], which contains a list of all identities known
|
||||
// to the node. Use [makeTestIdentityService] which returns an implementation of
|
||||
// [InMemoryIdentityService] with the given identities
|
||||
makeTestIdentityService(megaCorp.getIdentity())
|
||||
);
|
||||
// DOCEND 11
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
// DOCSTART 12
|
||||
private final MockServices simpleLedgerServices = new MockServices(
|
||||
// This is the identity of the node
|
||||
megaCorp,
|
||||
// Other identities the test node knows about
|
||||
bigCorp,
|
||||
alice
|
||||
);
|
||||
// DOCEND 12
|
||||
|
||||
// DOCSTART 1
|
||||
private ICommercialPaperState getPaper() {
|
||||
return new JavaCommercialPaper.State(
|
||||
MEGA_CORP.ref(defaultRef),
|
||||
MEGA_CORP.getParty(),
|
||||
issuedBy(DOLLARS(1000), MEGA_CORP.ref(defaultRef)),
|
||||
megaCorp.ref(defaultRef),
|
||||
megaCorp.getParty(),
|
||||
issuedBy(DOLLARS(1000), megaCorp.ref(defaultRef)),
|
||||
TEST_TX_TIME.plus(7, ChronoUnit.DAYS)
|
||||
);
|
||||
}
|
||||
@ -69,7 +96,7 @@ public class CommercialPaperTest {
|
||||
ledger(ledgerServices, l -> {
|
||||
l.transaction(tx -> {
|
||||
tx.input(JCP_PROGRAM_ID, inState);
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
return tx.verifies();
|
||||
});
|
||||
@ -85,7 +112,7 @@ public class CommercialPaperTest {
|
||||
ledger(ledgerServices, l -> {
|
||||
l.transaction(tx -> {
|
||||
tx.input(JCP_PROGRAM_ID, inState);
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
return tx.failsWith("the state is propagated");
|
||||
});
|
||||
@ -96,15 +123,15 @@ public class CommercialPaperTest {
|
||||
|
||||
// DOCSTART 5
|
||||
@Test
|
||||
public void simpleCPMoveSuccess() {
|
||||
public void simpleCPMoveSuccessAndFailure() {
|
||||
ICommercialPaperState inState = getPaper();
|
||||
ledger(ledgerServices, l -> {
|
||||
l.transaction(tx -> {
|
||||
tx.input(JCP_PROGRAM_ID, inState);
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.failsWith("the state is propagated");
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inState.withOwner(ALICE.getParty()));
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inState.withOwner(alice.getParty()));
|
||||
return tx.verifies();
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
@ -112,6 +139,24 @@ public class CommercialPaperTest {
|
||||
}
|
||||
// DOCEND 5
|
||||
|
||||
// DOCSTART 13
|
||||
@Test
|
||||
public void simpleCPMoveSuccess() {
|
||||
ICommercialPaperState inState = getPaper();
|
||||
ledger(ledgerServices, l -> {
|
||||
l.transaction(tx -> {
|
||||
tx.input(JCP_PROGRAM_ID, inState);
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inState.withOwner(alice.getParty()));
|
||||
return tx.verifies();
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
// DOCEND 13
|
||||
|
||||
// DOCSTART 6
|
||||
@Test
|
||||
public void simpleIssuanceWithTweak() {
|
||||
@ -120,11 +165,11 @@ public class CommercialPaperTest {
|
||||
tx.output(JCP_PROGRAM_ID, "paper", getPaper()); // Some CP is issued onto the ledger by MegaCorp.
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.tweak(tw -> {
|
||||
tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue());
|
||||
tw.command(bigCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tw.timeWindow(TEST_TX_TIME);
|
||||
return tw.failsWith("output states are issued by a command signer");
|
||||
});
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
return tx.verifies();
|
||||
});
|
||||
@ -140,11 +185,11 @@ public class CommercialPaperTest {
|
||||
tx.output(JCP_PROGRAM_ID, "paper", getPaper()); // Some CP is issued onto the ledger by MegaCorp.
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.tweak(tw -> {
|
||||
tw.command(BIG_CORP_PUBKEY, new JavaCommercialPaper.Commands.Issue());
|
||||
tw.command(bigCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tw.timeWindow(TEST_TX_TIME);
|
||||
return tw.failsWith("output states are issued by a command signer");
|
||||
});
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
return tx.verifies();
|
||||
});
|
||||
@ -154,11 +199,11 @@ public class CommercialPaperTest {
|
||||
// DOCSTART 8
|
||||
@Test
|
||||
public void chainCommercialPaper() {
|
||||
PartyAndReference issuer = MEGA_CORP.ref(defaultRef);
|
||||
PartyAndReference issuer = megaCorp.ref(defaultRef);
|
||||
ledger(ledgerServices, l -> {
|
||||
l.unverifiedTransaction(tx -> {
|
||||
tx.output(Cash.PROGRAM_ID, "alice's $900",
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty()));
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), alice.getParty()));
|
||||
tx.attachments(Cash.PROGRAM_ID);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
@ -166,7 +211,7 @@ public class CommercialPaperTest {
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
l.transaction("Issuance", tx -> {
|
||||
tx.output(JCP_PROGRAM_ID, "paper", getPaper());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
return tx.verifies();
|
||||
@ -175,11 +220,11 @@ public class CommercialPaperTest {
|
||||
l.transaction("Trade", tx -> {
|
||||
tx.input("paper");
|
||||
tx.input("alice's $900");
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty()));
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), megaCorp.getParty()));
|
||||
JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper");
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty()));
|
||||
tx.command(ALICE.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(alice.getParty()));
|
||||
tx.command(alice.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
return tx.verifies();
|
||||
});
|
||||
return Unit.INSTANCE;
|
||||
@ -190,11 +235,11 @@ public class CommercialPaperTest {
|
||||
// DOCSTART 9
|
||||
@Test
|
||||
public void chainCommercialPaperDoubleSpend() {
|
||||
PartyAndReference issuer = MEGA_CORP.ref(defaultRef);
|
||||
PartyAndReference issuer = megaCorp.ref(defaultRef);
|
||||
ledger(ledgerServices, l -> {
|
||||
l.unverifiedTransaction(tx -> {
|
||||
tx.output(Cash.PROGRAM_ID, "alice's $900",
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty()));
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), alice.getParty()));
|
||||
tx.attachments(Cash.PROGRAM_ID);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
@ -202,7 +247,7 @@ public class CommercialPaperTest {
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
l.transaction("Issuance", tx -> {
|
||||
tx.output(Cash.PROGRAM_ID, "paper", getPaper());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
return tx.verifies();
|
||||
@ -211,11 +256,11 @@ public class CommercialPaperTest {
|
||||
l.transaction("Trade", tx -> {
|
||||
tx.input("paper");
|
||||
tx.input("alice's $900");
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty()));
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), megaCorp.getParty()));
|
||||
JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper");
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty()));
|
||||
tx.command(ALICE.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(alice.getParty()));
|
||||
tx.command(alice.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
return tx.verifies();
|
||||
});
|
||||
|
||||
@ -223,8 +268,8 @@ public class CommercialPaperTest {
|
||||
tx.input("paper");
|
||||
JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper");
|
||||
// We moved a paper to other pubkey.
|
||||
tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(BOB.getParty()));
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(bob.getParty()));
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
return tx.verifies();
|
||||
});
|
||||
l.fails();
|
||||
@ -236,11 +281,11 @@ public class CommercialPaperTest {
|
||||
// DOCSTART 10
|
||||
@Test
|
||||
public void chainCommercialPaperTweak() {
|
||||
PartyAndReference issuer = MEGA_CORP.ref(defaultRef);
|
||||
PartyAndReference issuer = megaCorp.ref(defaultRef);
|
||||
ledger(ledgerServices, l -> {
|
||||
l.unverifiedTransaction(tx -> {
|
||||
tx.output(Cash.PROGRAM_ID, "alice's $900",
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), ALICE.getParty()));
|
||||
new Cash.State(issuedBy(DOLLARS(900), issuer), alice.getParty()));
|
||||
tx.attachments(Cash.PROGRAM_ID);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
@ -248,7 +293,7 @@ public class CommercialPaperTest {
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
l.transaction("Issuance", tx -> {
|
||||
tx.output(Cash.PROGRAM_ID, "paper", getPaper());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Issue());
|
||||
tx.attachments(JCP_PROGRAM_ID);
|
||||
tx.timeWindow(TEST_TX_TIME);
|
||||
return tx.verifies();
|
||||
@ -257,11 +302,11 @@ public class CommercialPaperTest {
|
||||
l.transaction("Trade", tx -> {
|
||||
tx.input("paper");
|
||||
tx.input("alice's $900");
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), MEGA_CORP.getParty()));
|
||||
tx.output(Cash.PROGRAM_ID, "borrowed $900", new Cash.State(issuedBy(DOLLARS(900), issuer), megaCorp.getParty()));
|
||||
JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper");
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(ALICE.getParty()));
|
||||
tx.command(ALICE.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.output(JCP_PROGRAM_ID, "alice's paper", inputPaper.withOwner(alice.getParty()));
|
||||
tx.command(alice.getPublicKey(), new Cash.Commands.Move());
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
return tx.verifies();
|
||||
});
|
||||
|
||||
@ -270,8 +315,8 @@ public class CommercialPaperTest {
|
||||
tx.input("paper");
|
||||
JavaCommercialPaper.State inputPaper = l.retrieveOutput(JavaCommercialPaper.State.class, "paper");
|
||||
// We moved a paper to another pubkey.
|
||||
tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(BOB.getParty()));
|
||||
tx.command(MEGA_CORP.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
tx.output(JCP_PROGRAM_ID, "bob's paper", inputPaper.withOwner(bob.getParty()));
|
||||
tx.command(megaCorp.getPublicKey(), new JavaCommercialPaper.Commands.Move());
|
||||
return tx.verifies();
|
||||
});
|
||||
lw.fails();
|
||||
|
@ -13,7 +13,6 @@ import net.corda.testing.node.StartedMockNode
|
||||
import net.corda.testing.node.startFlow
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@ -37,7 +36,6 @@ class FxTransactionBuildTutorialTest {
|
||||
mockNet.stopNodes()
|
||||
}
|
||||
|
||||
@Ignore("Pending fix from corda")
|
||||
@Test
|
||||
fun `Run ForeignExchangeFlow to completion`() {
|
||||
// Use NodeA as issuer and create some dollars
|
||||
|
@ -18,6 +18,7 @@ import net.corda.testing.core.*
|
||||
import net.corda.testing.internal.rigorousMock
|
||||
import net.corda.testing.node.MockServices
|
||||
import net.corda.testing.node.ledger
|
||||
import net.corda.testing.node.makeTestIdentityService
|
||||
import net.corda.testing.node.transaction
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -25,30 +26,46 @@ import org.junit.Test
|
||||
class CommercialPaperTest {
|
||||
private companion object {
|
||||
val alice = TestIdentity(ALICE_NAME, 70)
|
||||
val BIG_CORP_PUBKEY = generateKeyPair().public
|
||||
val BOB = TestIdentity(BOB_NAME, 80).party
|
||||
val DUMMY_NOTARY = TestIdentity(DUMMY_NOTARY_NAME, 20).party
|
||||
val bob = TestIdentity(BOB_NAME, 80)
|
||||
val bigCorp = TestIdentity((CordaX500Name("BigCorp", "New York", "GB")))
|
||||
val dummyNotary = TestIdentity(DUMMY_NOTARY_NAME, 20)
|
||||
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
||||
val ALICE get() = alice.party
|
||||
val ALICE_PUBKEY get() = alice.publicKey
|
||||
val MEGA_CORP get() = megaCorp.party
|
||||
val MEGA_CORP_PUBKEY get() = megaCorp.publicKey
|
||||
}
|
||||
|
||||
@Rule
|
||||
@JvmField
|
||||
val testSerialization = SerializationEnvironmentRule()
|
||||
private val ledgerServices = MockServices(emptyList(), MEGA_CORP.name, rigorousMock<IdentityService>().also {
|
||||
doReturn(MEGA_CORP).whenever(it).partyFromKey(MEGA_CORP_PUBKEY)
|
||||
doReturn(null).whenever(it).partyFromKey(BIG_CORP_PUBKEY)
|
||||
doReturn(null).whenever(it).partyFromKey(ALICE_PUBKEY)
|
||||
// DOCSTART 11
|
||||
private val ledgerServices = MockServices(
|
||||
// A list of packages to scan for cordapps
|
||||
listOf("net.corda.finance.contracts"),
|
||||
// The identity represented by this set of mock services. Defaults to a test identity.
|
||||
// You can also use the alternative parameter initialIdentityName which accepts a
|
||||
// [CordaX500Name]
|
||||
megaCorp,
|
||||
rigorousMock<IdentityService>().also {
|
||||
doReturn(megaCorp.party).whenever(it).partyFromKey(megaCorp.publicKey)
|
||||
doReturn(null).whenever(it).partyFromKey(bigCorp.publicKey)
|
||||
doReturn(null).whenever(it).partyFromKey(alice.publicKey)
|
||||
})
|
||||
// DOCEND 11
|
||||
|
||||
// DOCSTART 12
|
||||
@Suppress("unused")
|
||||
private val simpleLedgerServices = MockServices(
|
||||
// This is the identity of the node
|
||||
megaCorp,
|
||||
// Other identities the test node knows about
|
||||
bigCorp,
|
||||
alice
|
||||
)
|
||||
// DOCEND 12
|
||||
|
||||
// DOCSTART 1
|
||||
fun getPaper(): ICommercialPaperState = CommercialPaper.State(
|
||||
issuance = MEGA_CORP.ref(123),
|
||||
owner = MEGA_CORP,
|
||||
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
||||
issuance = megaCorp.party.ref(123),
|
||||
owner = megaCorp.party,
|
||||
faceValue = 1000.DOLLARS `issued by` megaCorp.party.ref(123),
|
||||
maturityDate = TEST_TX_TIME + 7.days
|
||||
)
|
||||
// DOCEND 1
|
||||
@ -58,7 +75,7 @@ class CommercialPaperTest {
|
||||
@Test(expected = IllegalStateException::class)
|
||||
fun simpleCP() {
|
||||
val inState = getPaper()
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
attachments(CP_PROGRAM_ID)
|
||||
input(CP_PROGRAM_ID, inState)
|
||||
@ -73,10 +90,10 @@ class CommercialPaperTest {
|
||||
@Test(expected = TransactionVerificationException.ContractRejection::class)
|
||||
fun simpleCPMove() {
|
||||
val inState = getPaper()
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
input(CP_PROGRAM_ID, inState)
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
verifies()
|
||||
}
|
||||
@ -88,10 +105,10 @@ class CommercialPaperTest {
|
||||
@Test
|
||||
fun simpleCPMoveFails() {
|
||||
val inState = getPaper()
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
input(CP_PROGRAM_ID, inState)
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
`fails with`("the state is propagated")
|
||||
}
|
||||
@ -101,35 +118,52 @@ class CommercialPaperTest {
|
||||
|
||||
// DOCSTART 5
|
||||
@Test
|
||||
fun simpleCPMoveSuccess() {
|
||||
fun simpleCPMoveFailureAndSuccess() {
|
||||
val inState = getPaper()
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
input(CP_PROGRAM_ID, inState)
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
`fails with`("the state is propagated")
|
||||
output(CP_PROGRAM_ID, "alice's paper", inState.withOwner(ALICE))
|
||||
output(CP_PROGRAM_ID, "alice's paper", inState.withOwner(alice.party))
|
||||
verifies()
|
||||
}
|
||||
}
|
||||
}
|
||||
// DOCEND 5
|
||||
|
||||
// DOCSTART 13
|
||||
@Test
|
||||
fun simpleCPMoveSuccess() {
|
||||
val inState = getPaper()
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
input(CP_PROGRAM_ID, inState)
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
timeWindow(TEST_TX_TIME)
|
||||
output(CP_PROGRAM_ID, "alice's paper", inState.withOwner(alice.party))
|
||||
verifies()
|
||||
}
|
||||
}
|
||||
}
|
||||
// DOCEND 13
|
||||
|
||||
// DOCSTART 6
|
||||
@Test
|
||||
fun `simple issuance with tweak`() {
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
transaction {
|
||||
output(CP_PROGRAM_ID, "paper", getPaper()) // Some CP is issued onto the ledger by MegaCorp.
|
||||
attachments(CP_PROGRAM_ID)
|
||||
tweak {
|
||||
// The wrong pubkey.
|
||||
command(BIG_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(bigCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
timeWindow(TEST_TX_TIME)
|
||||
`fails with`("output states are issued by a command signer")
|
||||
}
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
timeWindow(TEST_TX_TIME)
|
||||
verifies()
|
||||
}
|
||||
@ -140,16 +174,16 @@ class CommercialPaperTest {
|
||||
// DOCSTART 7
|
||||
@Test
|
||||
fun `simple issuance with tweak and top level transaction`() {
|
||||
ledgerServices.transaction(DUMMY_NOTARY) {
|
||||
ledgerServices.transaction(dummyNotary.party) {
|
||||
output(CP_PROGRAM_ID, "paper", getPaper()) // Some CP is issued onto the ledger by MegaCorp.
|
||||
attachments(CP_PROGRAM_ID)
|
||||
tweak {
|
||||
// The wrong pubkey.
|
||||
command(BIG_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(bigCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
timeWindow(TEST_TX_TIME)
|
||||
`fails with`("output states are issued by a command signer")
|
||||
}
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
timeWindow(TEST_TX_TIME)
|
||||
verifies()
|
||||
}
|
||||
@ -159,17 +193,17 @@ class CommercialPaperTest {
|
||||
// DOCSTART 8
|
||||
@Test
|
||||
fun `chain commercial paper`() {
|
||||
val issuer = MEGA_CORP.ref(123)
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
val issuer = megaCorp.party.ref(123)
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
unverifiedTransaction {
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy ALICE)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy alice.party)
|
||||
}
|
||||
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
transaction("Issuance") {
|
||||
output(CP_PROGRAM_ID, "paper", getPaper())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
timeWindow(TEST_TX_TIME)
|
||||
verifies()
|
||||
@ -179,10 +213,10 @@ class CommercialPaperTest {
|
||||
transaction("Trade") {
|
||||
input("paper")
|
||||
input("alice's $900")
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
|
||||
command(ALICE_PUBKEY, Cash.Commands.Move())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy megaCorp.party)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(alice.party))
|
||||
command(alice.publicKey, Cash.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
}
|
||||
@ -192,17 +226,17 @@ class CommercialPaperTest {
|
||||
// DOCSTART 9
|
||||
@Test
|
||||
fun `chain commercial paper double spend`() {
|
||||
val issuer = MEGA_CORP.ref(123)
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
val issuer = megaCorp.party.ref(123)
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
unverifiedTransaction {
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy ALICE)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy alice.party)
|
||||
}
|
||||
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
transaction("Issuance") {
|
||||
output(CP_PROGRAM_ID, "paper", getPaper())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
timeWindow(TEST_TX_TIME)
|
||||
verifies()
|
||||
@ -211,18 +245,18 @@ class CommercialPaperTest {
|
||||
transaction("Trade") {
|
||||
input("paper")
|
||||
input("alice's $900")
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
|
||||
command(ALICE_PUBKEY, Cash.Commands.Move())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy megaCorp.party)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(alice.party))
|
||||
command(alice.publicKey, Cash.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
|
||||
transaction {
|
||||
input("paper")
|
||||
// We moved a paper to another pubkey.
|
||||
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(BOB))
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(bob.party))
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
|
||||
@ -234,17 +268,17 @@ class CommercialPaperTest {
|
||||
// DOCSTART 10
|
||||
@Test
|
||||
fun `chain commercial tweak`() {
|
||||
val issuer = MEGA_CORP.ref(123)
|
||||
ledgerServices.ledger(DUMMY_NOTARY) {
|
||||
val issuer = megaCorp.party.ref(123)
|
||||
ledgerServices.ledger(dummyNotary.party) {
|
||||
unverifiedTransaction {
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy ALICE)
|
||||
output(Cash.PROGRAM_ID, "alice's $900", 900.DOLLARS.CASH issuedBy issuer ownedBy alice.party)
|
||||
}
|
||||
|
||||
// Some CP is issued onto the ledger by MegaCorp.
|
||||
transaction("Issuance") {
|
||||
output(CP_PROGRAM_ID, "paper", getPaper())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Issue())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Issue())
|
||||
attachments(CP_PROGRAM_ID)
|
||||
timeWindow(TEST_TX_TIME)
|
||||
verifies()
|
||||
@ -253,10 +287,10 @@ class CommercialPaperTest {
|
||||
transaction("Trade") {
|
||||
input("paper")
|
||||
input("alice's $900")
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy MEGA_CORP)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(ALICE))
|
||||
command(ALICE_PUBKEY, Cash.Commands.Move())
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
output(Cash.PROGRAM_ID, "borrowed $900", 900.DOLLARS.CASH issuedBy issuer ownedBy megaCorp.party)
|
||||
output(CP_PROGRAM_ID, "alice's paper", "paper".output<ICommercialPaperState>().withOwner(alice.party))
|
||||
command(alice.publicKey, Cash.Commands.Move())
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
|
||||
@ -264,8 +298,8 @@ class CommercialPaperTest {
|
||||
transaction {
|
||||
input("paper")
|
||||
// We moved a paper to another pubkey.
|
||||
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(BOB))
|
||||
command(MEGA_CORP_PUBKEY, CommercialPaper.Commands.Move())
|
||||
output(CP_PROGRAM_ID, "bob's paper", "paper".output<ICommercialPaperState>().withOwner(bob.party))
|
||||
command(megaCorp.publicKey, CommercialPaper.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
fails()
|
||||
|
Reference in New Issue
Block a user