Skip to content

Instantly share code, notes, and snippets.

View parisyup's full-sized avatar

Faris Alblooki parisyup

View GitHub Profile
// Only Two Participants
results["Only Two Participants"] = try {
val iouState = IOUState(
amount = 10,
paid = 3,
lender = myInfo.name,
borrower = otherMember.name,
linearId = UUID.randomUUID(),
participants = listOf(myInfo.ledgerKeys.first())
)
@Suspendable
private String testOnlyTwoParticipants(MemberInfo myInfo, MemberInfo otherMember, NotaryInfo notary) {
try {
IOUState iouState = new IOUState(
10,
myInfo.getName(),
otherMember.getName(),
3,
UUID.randomUUID(),
Collections.singletonList(myInfo.getLedgerKeys().get(0))
"Fail"
} catch (e:Exception) {
val exceptionMessage = e.message ?: "No exception message"
if (exceptionMessage.contains("Requires a single command.")) {
"Pass" }
else {
"Contract failed but with a different Exception: ${e.message}"
}
}
return "Fail";//no error found. Contract failed.
} catch (Exception e) {//catching the error to see if the contract passed
//check if gotten the expected error
String exceptionMessage = e.getMessage() != null ? e.getMessage() : "No exception message";
if (exceptionMessage.contains("Require a single command")) {
return "Pass"; //expected error found so the contract passes the test
} else {
return "Contract failed but with a different Exception: " + e.getMessage();//different error thrown. Contract failed
val txBuilder = ledgerService.createTransactionBuilder()
.setNotary(notary.name)
.setTimeWindowBetween(Instant.now(), Instant.now().plusMillis(Duration.ofDays(1).toMillis()))
.addOutputState(iouState)
.addInputState(inputStateRef)
.addCommand(IOUContract.Issue())
.addCommand(IOUContract.Transfer())
.addSignatories(iouState.participants)
var txBuilder = ledgerService.createTransactionBuilder() //build sample transaction to test
.setNotary(notary.getName())
.setTimeWindowBetween(Instant.now(), Instant.now().plusMillis(Duration.ofDays(1).toMillis()))
.addOutputState(iouState)
.addInputState(inputStateRef)
.addCommand(new IOUContract.Issue())
.addCommand(new IOUContract.Transfer())
.addSignatories(iouState.getParticipants());
val iouState = IOUState(
amount = 10,
paid = 3,
lender = myInfo.name,
borrower = otherMember.name,
linearId = UUID.randomUUID(),
participants = listOf(myInfo.ledgerKeys.first(), otherMember.ledgerKeys.first())
)
IOUState iouState = new IOUState( //create sample output state for the test
10,
myInfo.getName(),
otherMember.getName(),
3,
UUID.randomUUID(),
Arrays.asList(myInfo.getLedgerKeys().get(0), otherMember.getLedgerKeys().get(0))
);
@Suspendable
private String testMultipleCommandsNotPermitted(MemberInfo myInfo, MemberInfo otherMember, NotaryInfo notary) {
try {
IOUState iouState = new IOUState( //create sample output state for the test
10,
myInfo.getName(),
otherMember.getName(),
3,
UUID.randomUUID(),
Arrays.asList(myInfo.getLedgerKeys().get(0), otherMember.getLedgerKeys().get(0))
// Multiple Commands not permitted
results["Multiple Commands not permitted"] = try {
val iouState = IOUState(
amount = 10,
paid = 3,
lender = myInfo.name,
borrower = otherMember.name,
linearId = UUID.randomUUID(),
participants = listOf(myInfo.ledgerKeys.first(), otherMember.ledgerKeys.first())
)