Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding java chaincode for private-data sample #345

Merged

Conversation

sijocherian
Copy link
Contributor

@sijocherian sijocherian commented Oct 7, 2020

-Reflects all transactions as in chaincode-go
-Tested with application JS

@sijocherian sijocherian force-pushed the asset-privatedata.javachaincode branch from f06fed4 to dc7aacf Compare October 11, 2020 03:03
@sijocherian sijocherian marked this pull request as ready for review October 11, 2020 03:07
@sijocherian sijocherian requested a review from a team as a code owner October 11, 2020 03:07
errorMessage = String.format("Empty input in Transient map: color");
}
if (size <= 0) {
errorMessage = String.format("Empty input in Transient map: size");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If empty it would be <= 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size being int, will have default of 0. But I just realized that json.getInt() will throw Exception if key is not present.

For parity with chaicode-go, I will keep the error check, but will alter the json parsing to deal with empty values in transient map. Let me know if you think, otherwise.

errorMessage = String.format("Empty input in Transient map: size");
}
if (appraisedValue <= 0) {
errorMessage = String.format("Empty input in Transient map: appraisedValue");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If empty it would be <= 0 ?

Comment on lines 310 to 311
System.out.printf("CreateAsset Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, assetID);
System.out.printf(" Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, new String(asset.serialize()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using some convention of indents?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using an indent thinking it is easier to read, but it is probably not useful when reading chaincode logs. I will remove indent.

ChaincodeStub stub = ctx.getStub();

CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
System.out.printf(" ReadTransferAgreement Put: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get not Put.
Are you using some convention of indents?

System.err.println(errorMessage);
throw new ChaincodeException(errorMessage, AssetTransferErrors.INCOMPLETE_INPUT.toString());
}
if (assetPriv.getAppraisedValue() <= 0) { // appraisedValue field must be a positive integer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If appraised value wasn't passed, would it be 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verified that if appraisedVal is not passed, it goes into catch block in ln 367

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

public final class AssetTransferTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is good, although I don't think we necessarily need it for every sample.
I would rather see an integration test using the existing javascript application in ci/azure-pipelines.yml , that would ensure everything works end-to-end and that there is functional parity between the go chaincode and java chaincode. Not to mention it would be less work to re-use the existing application to drive the end-to-end test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with JS-app & CI-pipeline to drive auto integration test.

I still think few good/complex chaincode unit test samples, goes a long way for chaincode developer experience.
Unit tests (especially) in chaincode saves a lot of dev time. This test shows some advanced ClientIdentity & Context mocking in java. If we have further discussion here on this and find this useful, I can extend the PrivData tutorial to describe the unit-test.

My personal experience was chaincode dev iteration takes longer than normal development, if you have to deploy to a network and test with some kind of app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! I agree it would be good to mention the unit test approach in the https://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html tutorial as a baseline, and then mention any of the more advanced approaches in the other advanced tutorials.

Java chaincode that can be deployed via test-network, with shortname 'private'
Unit test for core transactions
Bugfix for QueryAsset txn function signature
Incorporated PR feedback

Signed-off-by: Sijo Cherian <sijo@ibm.com>
@sijocherian sijocherian force-pushed the asset-privatedata.javachaincode branch from dc7aacf to dfa4cf7 Compare October 27, 2020 14:48
@sijocherian
Copy link
Contributor Author

Incorporated PR so far. Ready for another look.

@sijocherian
Copy link
Contributor Author

This one is ready for review.

Copy link
Contributor

@denyeart denyeart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Sijo! Sorry it took me a while to re-review...

@denyeart denyeart merged commit a80dc20 into hyperledger:master Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants