mirror of
https://github.com/corda/corda.git
synced 2024-12-28 16:58:55 +00:00
Remove Java parts and unused resources
This commit is contained in:
parent
894e407057
commit
1241c79d7c
@ -1,23 +0,0 @@
|
|||||||
package net.corda.ptflows.contracts;
|
|
||||||
|
|
||||||
|
|
||||||
import net.corda.core.contracts.Amount;
|
|
||||||
import net.corda.core.contracts.ContractState;
|
|
||||||
import net.corda.core.contracts.Issued;
|
|
||||||
import net.corda.core.identity.AbstractParty;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Currency;
|
|
||||||
|
|
||||||
/* This is an interface solely created to demonstrate that the same kotlin tests can be run against
|
|
||||||
* either a Java implementation of the CommercialPaper or a kotlin implementation.
|
|
||||||
* Normally one would not duplicate an implementation in different languages for obvious reasons, but it demonstrates that
|
|
||||||
* ultimately either language can be used against a common test framework (and therefore can be used for real).
|
|
||||||
*/
|
|
||||||
public interface IPtCommercialPaperState extends ContractState {
|
|
||||||
IPtCommercialPaperState withOwner(AbstractParty newOwner);
|
|
||||||
|
|
||||||
IPtCommercialPaperState withFaceValue(Amount<Issued<Currency>> newFaceValue);
|
|
||||||
|
|
||||||
IPtCommercialPaperState withMaturityDate(Instant newMaturityDate);
|
|
||||||
}
|
|
@ -1,267 +0,0 @@
|
|||||||
package net.corda.ptflows.contracts;
|
|
||||||
|
|
||||||
|
|
||||||
import co.paralleluniverse.fibers.Suspendable;
|
|
||||||
import kotlin.Unit;
|
|
||||||
import net.corda.core.contracts.*;
|
|
||||||
import net.corda.core.crypto.NullKeys.NullPublicKey;
|
|
||||||
import net.corda.core.identity.AbstractParty;
|
|
||||||
import net.corda.core.identity.AnonymousParty;
|
|
||||||
import net.corda.core.identity.Party;
|
|
||||||
import net.corda.core.identity.PartyAndCertificate;
|
|
||||||
import net.corda.core.node.ServiceHub;
|
|
||||||
import net.corda.core.transactions.LedgerTransaction;
|
|
||||||
import net.corda.core.transactions.TransactionBuilder;
|
|
||||||
import net.corda.ptflows.contracts.asset.PtCash;
|
|
||||||
import net.corda.ptflows.utils.StateSummingUtilitiesKt;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Currency;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static net.corda.core.contracts.ContractsDSL.requireSingleCommand;
|
|
||||||
import static net.corda.core.contracts.ContractsDSL.requireThat;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a Java version of the CommercialPaper contract (chosen because it's simple). This demonstrates how the
|
|
||||||
* use of Kotlin for implementation of the framework does not impose the same language choice on contract developers.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public class JavaPtCommercialPaper implements Contract {
|
|
||||||
static final String JCP_PROGRAM_ID = "net.corda.ptflows.contracts.JavaPtCommercialPaper";
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public static class State implements OwnableState, IPtCommercialPaperState {
|
|
||||||
private PartyAndReference issuance;
|
|
||||||
private AbstractParty owner;
|
|
||||||
private Amount<Issued<Currency>> faceValue;
|
|
||||||
private Instant maturityDate;
|
|
||||||
|
|
||||||
public State() {
|
|
||||||
} // For serialization
|
|
||||||
|
|
||||||
public State(PartyAndReference issuance, AbstractParty owner, Amount<Issued<Currency>> faceValue,
|
|
||||||
Instant maturityDate) {
|
|
||||||
this.issuance = issuance;
|
|
||||||
this.owner = owner;
|
|
||||||
this.faceValue = faceValue;
|
|
||||||
this.maturityDate = maturityDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public State copy() {
|
|
||||||
return new State(this.issuance, this.owner, this.faceValue, this.maturityDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPtCommercialPaperState withOwner(AbstractParty newOwner) {
|
|
||||||
return new State(this.issuance, newOwner, this.faceValue, this.maturityDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CommandAndState withNewOwner(@NotNull AbstractParty newOwner) {
|
|
||||||
return new CommandAndState(new Commands.Move(), new State(this.issuance, newOwner, this.faceValue, this.maturityDate));
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPtCommercialPaperState withFaceValue(Amount<Issued<Currency>> newFaceValue) {
|
|
||||||
return new State(this.issuance, this.owner, newFaceValue, this.maturityDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IPtCommercialPaperState withMaturityDate(Instant newMaturityDate) {
|
|
||||||
return new State(this.issuance, this.owner, this.faceValue, newMaturityDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public PartyAndReference getIssuance() {
|
|
||||||
return issuance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public AbstractParty getOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Amount<Issued<Currency>> getFaceValue() {
|
|
||||||
return faceValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Instant getMaturityDate() {
|
|
||||||
return maturityDate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object that) {
|
|
||||||
if (this == that) return true;
|
|
||||||
if (that == null || getClass() != that.getClass()) return false;
|
|
||||||
|
|
||||||
State state = (State) that;
|
|
||||||
|
|
||||||
if (issuance != null ? !issuance.equals(state.issuance) : state.issuance != null) return false;
|
|
||||||
if (owner != null ? !owner.equals(state.owner) : state.owner != null) return false;
|
|
||||||
if (faceValue != null ? !faceValue.equals(state.faceValue) : state.faceValue != null) return false;
|
|
||||||
if (maturityDate != null ? !maturityDate.equals(state.maturityDate) : state.maturityDate != null)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = issuance != null ? issuance.hashCode() : 0;
|
|
||||||
result = 31 * result + (owner != null ? owner.hashCode() : 0);
|
|
||||||
result = 31 * result + (faceValue != null ? faceValue.hashCode() : 0);
|
|
||||||
result = 31 * result + (maturityDate != null ? maturityDate.hashCode() : 0);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
State withoutOwner() {
|
|
||||||
return new State(issuance, new AnonymousParty(NullPublicKey.INSTANCE), faceValue, maturityDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<AbstractParty> getParticipants() {
|
|
||||||
return Collections.singletonList(this.owner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Commands extends CommandData {
|
|
||||||
class Move implements Commands {
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return obj instanceof Move;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Redeem implements Commands {
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return obj instanceof Redeem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Issue implements Commands {
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
return obj instanceof Issue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private List<CommandWithParties<Commands>> extractCommands(@NotNull LedgerTransaction tx) {
|
|
||||||
return tx.getCommands()
|
|
||||||
.stream()
|
|
||||||
.filter((CommandWithParties<CommandData> command) -> command.getValue() instanceof Commands)
|
|
||||||
.map((CommandWithParties<CommandData> command) -> new CommandWithParties<>(command.getSigners(), command.getSigningParties(), (Commands) command.getValue()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void verify(@NotNull LedgerTransaction tx) throws IllegalArgumentException {
|
|
||||||
|
|
||||||
// Group by everything except owner: any modification to the CP at all is considered changing it fundamentally.
|
|
||||||
final List<LedgerTransaction.InOutGroup<State, State>> groups = tx.groupStates(State.class, State::withoutOwner);
|
|
||||||
|
|
||||||
// There are two possible things that can be done with this CP. The first is trading it. The second is redeeming
|
|
||||||
// it for cash on or after the maturity date.
|
|
||||||
final List<CommandWithParties<CommandData>> commands = tx.getCommands().stream().filter(
|
|
||||||
it -> it.getValue() instanceof Commands
|
|
||||||
).collect(Collectors.toList());
|
|
||||||
final CommandWithParties<CommandData> command = onlyElementOf(commands);
|
|
||||||
final TimeWindow timeWindow = tx.getTimeWindow();
|
|
||||||
|
|
||||||
for (final LedgerTransaction.InOutGroup<State, State> group : groups) {
|
|
||||||
final List<State> inputs = group.getInputs();
|
|
||||||
final List<State> outputs = group.getOutputs();
|
|
||||||
if (command.getValue() instanceof Commands.Move) {
|
|
||||||
final CommandWithParties<Commands.Move> cmd = requireSingleCommand(tx.getCommands(), Commands.Move.class);
|
|
||||||
// There should be only a single input due to aggregation above
|
|
||||||
final State input = onlyElementOf(inputs);
|
|
||||||
|
|
||||||
if (!cmd.getSigners().contains(input.getOwner().getOwningKey()))
|
|
||||||
throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP");
|
|
||||||
|
|
||||||
// Check the output CP state is the same as the input state, ignoring the owner field.
|
|
||||||
if (outputs.size() != 1) {
|
|
||||||
throw new IllegalStateException("the state is propagated");
|
|
||||||
}
|
|
||||||
} else if (command.getValue() instanceof Commands.Redeem) {
|
|
||||||
final CommandWithParties<Commands.Redeem> cmd = requireSingleCommand(tx.getCommands(), Commands.Redeem.class);
|
|
||||||
|
|
||||||
// There should be only a single input due to aggregation above
|
|
||||||
final State input = onlyElementOf(inputs);
|
|
||||||
|
|
||||||
if (!cmd.getSigners().contains(input.getOwner().getOwningKey()))
|
|
||||||
throw new IllegalStateException("Failed requirement: the transaction is signed by the owner of the CP");
|
|
||||||
|
|
||||||
final Instant time = null == timeWindow
|
|
||||||
? null
|
|
||||||
: timeWindow.getUntilTime();
|
|
||||||
final Amount<Issued<Currency>> received = StateSummingUtilitiesKt.sumCashBy(tx.getOutputStates(), input.getOwner());
|
|
||||||
|
|
||||||
requireThat(require -> {
|
|
||||||
require.using("must be timestamped", timeWindow != null);
|
|
||||||
require.using("received amount equals the face value: "
|
|
||||||
+ received + " vs " + input.getFaceValue(), received.equals(input.getFaceValue()));
|
|
||||||
require.using("the paper must have matured", time != null && !time.isBefore(input.getMaturityDate()));
|
|
||||||
require.using("the received amount equals the face value", input.getFaceValue().equals(received));
|
|
||||||
require.using("the paper must be destroyed", outputs.isEmpty());
|
|
||||||
return Unit.INSTANCE;
|
|
||||||
});
|
|
||||||
} else if (command.getValue() instanceof Commands.Issue) {
|
|
||||||
final CommandWithParties<Commands.Issue> cmd = requireSingleCommand(tx.getCommands(), Commands.Issue.class);
|
|
||||||
final State output = onlyElementOf(outputs);
|
|
||||||
final Instant time = null == timeWindow
|
|
||||||
? null
|
|
||||||
: timeWindow.getUntilTime();
|
|
||||||
|
|
||||||
requireThat(require -> {
|
|
||||||
require.using("output values sum to more than the inputs", inputs.isEmpty());
|
|
||||||
require.using("output values sum to more than the inputs", output.faceValue.getQuantity() > 0);
|
|
||||||
require.using("must be timestamped", timeWindow != null);
|
|
||||||
require.using("the maturity date is not in the past", time != null && time.isBefore(output.getMaturityDate()));
|
|
||||||
require.using("output states are issued by a command signer", cmd.getSigners().contains(output.issuance.getParty().getOwningKey()));
|
|
||||||
return Unit.INSTANCE;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder generateIssue(@NotNull PartyAndReference issuance, @NotNull Amount<Issued<Currency>> faceValue, @Nullable Instant maturityDate, @NotNull Party notary, Integer encumbrance) {
|
|
||||||
State state = new State(issuance, issuance.getParty(), faceValue, maturityDate);
|
|
||||||
TransactionState output = new TransactionState<>(state, JCP_PROGRAM_ID, notary, encumbrance);
|
|
||||||
return new TransactionBuilder(notary).withItems(output, new Command<>(new Commands.Issue(), issuance.getParty().getOwningKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransactionBuilder generateIssue(@NotNull PartyAndReference issuance, @NotNull Amount<Issued<Currency>> faceValue, @Nullable Instant maturityDate, @NotNull Party notary) {
|
|
||||||
return generateIssue(issuance, faceValue, maturityDate, notary, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suspendable
|
|
||||||
public void generateRedeem(final TransactionBuilder tx,
|
|
||||||
final StateAndRef<State> paper,
|
|
||||||
final ServiceHub services,
|
|
||||||
final PartyAndCertificate ourIdentity) throws InsufficientBalanceException {
|
|
||||||
PtCash.generateSpend(services, tx, Structures.withoutIssuer(paper.getState().getData().getFaceValue()), ourIdentity, paper.getState().getData().getOwner(), Collections.emptySet());
|
|
||||||
tx.addInputState(paper);
|
|
||||||
tx.addCommand(new Command<>(new Commands.Redeem(), paper.getState().getData().getOwner().getOwningKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generateMove(TransactionBuilder tx, StateAndRef<State> paper, AbstractParty newOwner) {
|
|
||||||
tx.addInputState(paper);
|
|
||||||
tx.addOutputState(new TransactionState<>(new State(paper.getState().getData().getIssuance(), newOwner, paper.getState().getData().getFaceValue(), paper.getState().getData().getMaturityDate()), JCP_PROGRAM_ID, paper.getState().getNotary(), paper.getState().getEncumbrance()));
|
|
||||||
tx.addCommand(new Command<>(new Commands.Move(), paper.getState().getData().getOwner().getOwningKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> T onlyElementOf(Iterable<T> iterable) {
|
|
||||||
Iterator<T> iter = iterable.iterator();
|
|
||||||
T item = iter.next();
|
|
||||||
if (iter.hasNext()) {
|
|
||||||
throw new IllegalArgumentException("Iterable has more than one element!");
|
|
||||||
}
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
}
|
|
@ -55,7 +55,7 @@ class PtCommercialPaper : Contract {
|
|||||||
override val owner: AbstractParty,
|
override val owner: AbstractParty,
|
||||||
val faceValue: Amount<Issued<Currency>>,
|
val faceValue: Amount<Issued<Currency>>,
|
||||||
val maturityDate: Instant
|
val maturityDate: Instant
|
||||||
) : OwnableState, QueryableState, IPtCommercialPaperState{
|
) : OwnableState, QueryableState{
|
||||||
override val participants = listOf(owner)
|
override val participants = listOf(owner)
|
||||||
|
|
||||||
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
override fun withNewOwner(newOwner: AbstractParty) = CommandAndState(Commands.Move(), copy(owner = newOwner))
|
||||||
@ -63,10 +63,10 @@ class PtCommercialPaper : Contract {
|
|||||||
override fun toString() = "${Emoji.newspaper}CommercialPaper(of $faceValue redeemable on $maturityDate by '$issuance', owned by $owner)"
|
override fun toString() = "${Emoji.newspaper}CommercialPaper(of $faceValue redeemable on $maturityDate by '$issuance', owned by $owner)"
|
||||||
|
|
||||||
// Although kotlin is smart enough not to need these, as we are using the ICommercialPaperState, we need to declare them explicitly for use later,
|
// Although kotlin is smart enough not to need these, as we are using the ICommercialPaperState, we need to declare them explicitly for use later,
|
||||||
override fun withOwner(newOwner: AbstractParty): IPtCommercialPaperState = copy(owner = newOwner)
|
fun withOwner(newOwner: AbstractParty): State = copy(owner = newOwner)
|
||||||
|
|
||||||
override fun withFaceValue(newFaceValue: Amount<Issued<Currency>>): IPtCommercialPaperState = copy(faceValue = newFaceValue)
|
fun withFaceValue(newFaceValue: Amount<Issued<Currency>>): State = copy(faceValue = newFaceValue)
|
||||||
override fun withMaturityDate(newMaturityDate: Instant): IPtCommercialPaperState = copy(maturityDate = newMaturityDate)
|
fun withMaturityDate(newMaturityDate: Instant): State = copy(maturityDate = newMaturityDate)
|
||||||
|
|
||||||
/** Object Relational Mapping support. */
|
/** Object Relational Mapping support. */
|
||||||
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(PtCommercialPaperSchemaV1)
|
override fun supportedSchemas(): Iterable<MappedSchema> = listOf(PtCommercialPaperSchemaV1)
|
||||||
|
@ -23,8 +23,8 @@ object PtCashSchema
|
|||||||
object PtCashSchemaV1 : MappedSchema(schemaFamily = PtCashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
object PtCashSchemaV1 : MappedSchema(schemaFamily = PtCashSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCashState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "contract_cash_states",
|
@Table(name = "contract_cash_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_idx", columnList = "ccy_code"),
|
||||||
Index(name = "pennies_idx", columnList = "pennies")))
|
Index(name = "pennies_idx", columnList = "pennies")))
|
||||||
class PersistentCashState(
|
class PersistentCashState(
|
||||||
/** X500Name of owner party **/
|
/** X500Name of owner party **/
|
||||||
@Column(name = "owner_name")
|
@Column(name = "owner_name")
|
||||||
|
@ -21,9 +21,9 @@ object PtCommercialPaperSchema
|
|||||||
object PtCommercialPaperSchemaV1 : MappedSchema(schemaFamily = PtCommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
object PtCommercialPaperSchemaV1 : MappedSchema(schemaFamily = PtCommercialPaperSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCommercialPaperState::class.java)) {
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "cp_states",
|
@Table(name = "cp_states",
|
||||||
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
indexes = arrayOf(Index(name = "ccy_code_index", columnList = "ccy_code"),
|
||||||
Index(name = "maturity_index", columnList = "maturity_instant"),
|
Index(name = "maturity_index", columnList = "maturity_instant"),
|
||||||
Index(name = "face_value_index", columnList = "face_value")))
|
Index(name = "face_value_index", columnList = "face_value")))
|
||||||
class PersistentCommercialPaperState(
|
class PersistentCommercialPaperState(
|
||||||
@Column(name = "issuance_key")
|
@Column(name = "issuance_key")
|
||||||
var issuanceParty: String,
|
var issuanceParty: String,
|
||||||
|
@ -1 +0,0 @@
|
|||||||
2015-01-01,2015-04-03,2015-04-06,2015-05-04,2015-05-25,2015-08-31,2015-12-25,2015-12-28,2016-01-01,2016-03-25,2016-03-28,2016-05-02,2016-05-30,2016-08-29,2016-12-26,2016-12-27,2017-01-02,2017-04-14,2017-04-17,2017-05-01,2017-05-29,2017-08-28,2017-12-25,2017-12-26,2018-01-01,2018-03-30,2018-04-02,2018-05-07,2018-05-28,2018-08-27,2018-12-25,2018-12-26,2019-01-01,2019-04-19,2019-04-22,2019-05-06,2019-05-27,2019-08-26,2019-12-25,2019-12-26,2020-01-01,2020-04-10,2020-04-13,2020-05-04,2020-05-25,2020-08-31,2020-12-25,2020-12-28,2021-01-01,2021-04-02,2021-04-05,2021-05-03,2021-05-31,2021-08-30,2021-12-27,2021-12-28,2022-01-03,2022-04-15,2022-04-18,2022-05-02,2022-05-30,2022-08-29,2022-12-26,2022-12-27,2023-01-02,2023-04-07,2023-04-10,2023-05-01,2023-05-29,2023-08-28,2023-12-25,2023-12-26,2024-01-01,2024-03-29,2024-04-01,2024-05-06,2024-05-27,2024-08-26,2024-12-25,2024-12-26
|
|
@ -1 +0,0 @@
|
|||||||
2015-01-01,2015-01-19,2015-02-16,2015-02-18,2015-05-25,2015-07-03,2015-09-07,2015-10-12,2015-11-11,2015-11-26,2015-12-25,2016-01-01,2016-01-18,2016-02-10,2016-02-15,2016-05-30,2016-07-04,2016-09-05,2016-10-10,2016-11-11,2016-11-24,2016-12-26,2017-01-02,2017-01-16,2017-02-20,2017-03-01,2017-05-29,2017-07-04,2017-09-04,2017-10-09,2017-11-10,2017-11-23,2017-12-25,2018-01-01,2018-01-15,2018-02-14,2018-02-19,2018-05-28,2018-07-04,2018-09-03,2018-10-08,2018-11-12,2018-11-22,2018-12-25,2019-01-01,2019-01-21,2019-02-18,2019-03-06,2019-05-27,2019-07-04,2019-09-02,2019-10-14,2019-11-11,2019-11-28,2019-12-25,2020-01-01,2020-01-20,2020-02-17,2020-02-26,2020-05-25,2020-07-03,2020-09-07,2020-10-12,2020-11-11,2020-11-26,2020-12-25,2021-01-01,2021-01-18,2021-02-15,2021-02-17,2021-05-31,2021-07-05,2021-09-06,2021-10-11,2021-11-11,2021-11-25,2021-12-24,2022-01-17,2022-02-21,2022-03-02,2022-05-30,2022-07-04,2022-09-05,2022-10-10,2022-11-11,2022-11-24,2022-12-26,2023-01-02,2023-01-16,2023-02-20,2023-02-22,2023-05-29,2023-07-04,2023-09-04,2023-10-09,2023-11-10,2023-11-23,2023-12-25,2024-01-01,2024-01-15,2024-02-14,2024-02-19,2024-05-27,2024-07-04,2024-09-02,2024-10-14,2024-11-11,2024-11-28,2024-12-25
|
|
File diff suppressed because it is too large
Load Diff
@ -26,30 +26,17 @@ import kotlin.test.assertTrue
|
|||||||
|
|
||||||
// TODO: The generate functions aren't tested by these tests: add them.
|
// TODO: The generate functions aren't tested by these tests: add them.
|
||||||
|
|
||||||
interface IPtCommercialPaperTestTemplate {
|
interface PtCommercialPaperTestTemplate {
|
||||||
fun getPaper(): IPtCommercialPaperState
|
fun getPaper(): PtCommercialPaper.State
|
||||||
fun getIssueCommand(notary: Party): CommandData
|
fun getIssueCommand(notary: Party): CommandData
|
||||||
fun getRedeemCommand(notary: Party): CommandData
|
fun getRedeemCommand(notary: Party): CommandData
|
||||||
fun getMoveCommand(): CommandData
|
fun getMoveCommand(): CommandData
|
||||||
fun getContract(): ContractClassName
|
fun getContract(): ContractClassName
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaCommercialPaperTest : IPtCommercialPaperTestTemplate {
|
|
||||||
override fun getPaper(): IPtCommercialPaperState = JavaPtCommercialPaper.State(
|
|
||||||
MEGA_CORP.ref(123),
|
|
||||||
MEGA_CORP,
|
|
||||||
1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
|
||||||
TEST_TX_TIME + 7.days
|
|
||||||
)
|
|
||||||
|
|
||||||
override fun getIssueCommand(notary: Party): CommandData = JavaPtCommercialPaper.Commands.Issue()
|
class KotlinCommercialPaperTest : PtCommercialPaperTestTemplate {
|
||||||
override fun getRedeemCommand(notary: Party): CommandData = JavaPtCommercialPaper.Commands.Redeem()
|
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State(
|
||||||
override fun getMoveCommand(): CommandData = JavaPtCommercialPaper.Commands.Move()
|
|
||||||
override fun getContract() = JavaPtCommercialPaper.JCP_PROGRAM_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
class KotlinCommercialPaperTest : IPtCommercialPaperTestTemplate {
|
|
||||||
override fun getPaper(): IPtCommercialPaperState = PtCommercialPaper.State(
|
|
||||||
issuance = MEGA_CORP.ref(123),
|
issuance = MEGA_CORP.ref(123),
|
||||||
owner = MEGA_CORP,
|
owner = MEGA_CORP,
|
||||||
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
||||||
@ -62,8 +49,8 @@ class KotlinCommercialPaperTest : IPtCommercialPaperTestTemplate {
|
|||||||
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID
|
override fun getContract() = PtCommercialPaper.CP_PROGRAM_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
class KotlinCommercialPaperLegacyTest : IPtCommercialPaperTestTemplate {
|
class KotlinCommercialPaperLegacyTest : PtCommercialPaperTestTemplate {
|
||||||
override fun getPaper(): IPtCommercialPaperState = PtCommercialPaper.State(
|
override fun getPaper(): PtCommercialPaper.State = PtCommercialPaper.State(
|
||||||
issuance = MEGA_CORP.ref(123),
|
issuance = MEGA_CORP.ref(123),
|
||||||
owner = MEGA_CORP,
|
owner = MEGA_CORP,
|
||||||
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
faceValue = 1000.DOLLARS `issued by` MEGA_CORP.ref(123),
|
||||||
@ -80,11 +67,11 @@ class KotlinCommercialPaperLegacyTest : IPtCommercialPaperTestTemplate {
|
|||||||
class CommercialPaperTestsGeneric {
|
class CommercialPaperTestsGeneric {
|
||||||
companion object {
|
companion object {
|
||||||
@Parameterized.Parameters @JvmStatic
|
@Parameterized.Parameters @JvmStatic
|
||||||
fun data() = listOf(JavaCommercialPaperTest(), KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest())
|
fun data() = listOf(KotlinCommercialPaperTest(), KotlinCommercialPaperLegacyTest())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Parameterized.Parameter
|
@Parameterized.Parameter
|
||||||
lateinit var thisTest: IPtCommercialPaperTestTemplate
|
lateinit var thisTest: PtCommercialPaperTestTemplate
|
||||||
|
|
||||||
val issuer = MEGA_CORP.ref(123)
|
val issuer = MEGA_CORP.ref(123)
|
||||||
|
|
||||||
@ -100,7 +87,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
|
|
||||||
// Some CP is issued onto the ledger by MegaCorp.
|
// Some CP is issued onto the ledger by MegaCorp.
|
||||||
transaction("Issuance") {
|
transaction("Issuance") {
|
||||||
attachments(CP_PROGRAM_ID, JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
|
||||||
output(thisTest.getContract(), "paper") { thisTest.getPaper() }
|
output(thisTest.getContract(), "paper") { thisTest.getPaper() }
|
||||||
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
||||||
timeWindow(TEST_TX_TIME)
|
timeWindow(TEST_TX_TIME)
|
||||||
@ -110,11 +97,11 @@ class CommercialPaperTestsGeneric {
|
|||||||
// The CP is sold to alice for her $900, $100 less than the face value. At 10% interest after only 7 days,
|
// The CP is sold to alice for her $900, $100 less than the face value. At 10% interest after only 7 days,
|
||||||
// that sounds a bit too good to be true!
|
// that sounds a bit too good to be true!
|
||||||
transaction("Trade") {
|
transaction("Trade") {
|
||||||
attachments(PtCash.PROGRAM_ID, JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachments(PtCash.PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
|
||||||
input("paper")
|
input("paper")
|
||||||
input("alice's $900")
|
input("alice's $900")
|
||||||
output(PtCash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP }
|
output(PtCash.PROGRAM_ID, "borrowed $900") { 900.DOLLARS.CASH `issued by` issuer `owned by` MEGA_CORP }
|
||||||
output(thisTest.getContract(), "alice's paper") { "paper".output<IPtCommercialPaperState>().withOwner(ALICE) }
|
output(thisTest.getContract(), "alice's paper") { "paper".output<PtCommercialPaper.State>().withOwner(ALICE) }
|
||||||
command(ALICE_PUBKEY) { PtCash.Commands.Move() }
|
command(ALICE_PUBKEY) { PtCash.Commands.Move() }
|
||||||
command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() }
|
command(MEGA_CORP_PUBKEY) { thisTest.getMoveCommand() }
|
||||||
this.verifies()
|
this.verifies()
|
||||||
@ -123,7 +110,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
// Time passes, and Alice redeem's her CP for $1000, netting a $100 profit. MegaCorp has received $1200
|
// Time passes, and Alice redeem's her CP for $1000, netting a $100 profit. MegaCorp has received $1200
|
||||||
// as a single payment from somewhere and uses it to pay Alice off, keeping the remaining $200 as change.
|
// as a single payment from somewhere and uses it to pay Alice off, keeping the remaining $200 as change.
|
||||||
transaction("Redemption") {
|
transaction("Redemption") {
|
||||||
attachments(CP_PROGRAM_ID, JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachments(CP_PROGRAM_ID, PtCommercialPaper.CP_PROGRAM_ID)
|
||||||
input("alice's paper")
|
input("alice's paper")
|
||||||
input("some profits")
|
input("some profits")
|
||||||
|
|
||||||
@ -150,7 +137,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
timeWindow(TEST_TX_TIME + 8.days)
|
timeWindow(TEST_TX_TIME + 8.days)
|
||||||
|
|
||||||
tweak {
|
tweak {
|
||||||
output(thisTest.getContract()) { "paper".output<IPtCommercialPaperState>() }
|
output(thisTest.getContract()) { "paper".output<PtCommercialPaper.State>() }
|
||||||
this `fails with` "must be destroyed"
|
this `fails with` "must be destroyed"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +150,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun `key mismatch at issue`() {
|
fun `key mismatch at issue`() {
|
||||||
transaction {
|
transaction {
|
||||||
attachment(CP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
attachment(JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
output(thisTest.getContract()) { thisTest.getPaper() }
|
output(thisTest.getContract()) { thisTest.getPaper() }
|
||||||
command(MINI_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
command(MINI_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
||||||
timeWindow(TEST_TX_TIME)
|
timeWindow(TEST_TX_TIME)
|
||||||
@ -175,7 +162,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun `face value is not zero`() {
|
fun `face value is not zero`() {
|
||||||
transaction {
|
transaction {
|
||||||
attachment(CP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
attachment(JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
output(thisTest.getContract()) { thisTest.getPaper().withFaceValue(0.DOLLARS `issued by` issuer) }
|
output(thisTest.getContract()) { thisTest.getPaper().withFaceValue(0.DOLLARS `issued by` issuer) }
|
||||||
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
||||||
timeWindow(TEST_TX_TIME)
|
timeWindow(TEST_TX_TIME)
|
||||||
@ -187,7 +174,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun `maturity date not in the past`() {
|
fun `maturity date not in the past`() {
|
||||||
transaction {
|
transaction {
|
||||||
attachment(CP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
attachment(JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
output(thisTest.getContract()) { thisTest.getPaper().withMaturityDate(TEST_TX_TIME - 10.days) }
|
output(thisTest.getContract()) { thisTest.getPaper().withMaturityDate(TEST_TX_TIME - 10.days) }
|
||||||
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
||||||
timeWindow(TEST_TX_TIME)
|
timeWindow(TEST_TX_TIME)
|
||||||
@ -199,7 +186,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun `issue cannot replace an existing state`() {
|
fun `issue cannot replace an existing state`() {
|
||||||
transaction {
|
transaction {
|
||||||
attachment(CP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
attachment(JavaPtCommercialPaper.JCP_PROGRAM_ID)
|
attachment(CP_PROGRAM_ID)
|
||||||
input(thisTest.getContract(), thisTest.getPaper())
|
input(thisTest.getContract(), thisTest.getPaper())
|
||||||
output(thisTest.getContract()) { thisTest.getPaper() }
|
output(thisTest.getContract()) { thisTest.getPaper() }
|
||||||
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
command(MEGA_CORP_PUBKEY) { thisTest.getIssueCommand(DUMMY_NOTARY) }
|
||||||
|
Loading…
Reference in New Issue
Block a user