Created
May 28, 2024 13:42
-
-
Save parisyup/62f2cfc21d4367df8400bfe21aa27e77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)) | |
); | |
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()); | |
var signedTransaction = txBuilder.toSignedTransaction();//sign the test to check if it fails | |
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment