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

Fix and test for duplicated fields (#680) #989

Merged
merged 5 commits into from
Sep 24, 2019

Conversation

kostind
Copy link
Contributor

@kostind kostind commented Aug 13, 2019

What does this PR do?

Changes SolidityFunctionWrapper in order to don't use upper case for function names which will be duplicated.

Where should the reviewer start?

SolidityFunctionWrapper
SolidityFunctionWrapperGeneratorTest

Why is it needed?

To fix bug with code generation for contracts with duplicate fields.

Extra

Java class generated from DuplicateField contract will have the following constants:
FUNC_name
FUNC_DECIMALS
FUNC_Name
FUNC_NAME
FUNC_SYMBOL

@iikirilov iikirilov added the needs-review issue/PR needs review from maintainer label Aug 14, 2019
@iikirilov
Copy link
Contributor

iikirilov commented Aug 18, 2019

Thanks for the submission but I disagree with the approach. I don't think the issue is with web3j. It is more an issue of the naming convention from the Solidity developer. I think it is bad practice to have the same name with a different case for different variables.

I would suggest that the Solidity code is modified e.g. DEFAULT_NAME and Name rather than NAME and Name for variable names.

@kostind
Copy link
Contributor Author

kostind commented Aug 19, 2019

I completely agree with you about the naming convention.
The issue was marked as a bug, so I've tried to solve it and investigate code generation in web3j.

@iikirilov
Copy link
Contributor

fixes #680

@iikirilov
Copy link
Contributor

@kostind thanks for taking a look - I did not understand the issue but with your code it is obvious :) I will get a colleague to review this and give their opinion.

@kostind
Copy link
Contributor Author

kostind commented Aug 19, 2019

@iikirilov I'm happy to help :-) Thanks.

Copy link
Member

@antonydenyer antonydenyer left a comment

Choose a reason for hiding this comment

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

I guess the more interesting question is as a user of web3j what do you expect to happen. Should we keep to the normal Java naming conventions or bend them to match Solidity?

Personally, I think we should keep the naming convention we have but throw a compile error when you have duplicates.

@kostind
Copy link
Contributor Author

kostind commented Aug 21, 2019

I usually avoid such situation with function/variable names.
An error can be thrown in case of duplicated fields (!duplicateFunctionNames.isEmpty()), it's very simple to change.

The only concern here if we need to interact with a smart contract which has already been deployed and can't be upgraded.

@antonydenyer
Copy link
Member

I usually avoid such situation with function/variable names.
An error can be thrown in case of duplicated fields (!duplicateFunctionNames.isEmpty()), it's very simple to change.

I think that's the way to go with this.

The only concern here if we need to interact with a smart contract which has already been deployed and can't be upgraded.

That's true, I think what would be nice would be a halfway house between a fully generated wrapper and eth.call. Perhaps we could have something like contract.call("MethodName", args) ?

@kostind
Copy link
Contributor Author

kostind commented Aug 22, 2019

That's true, I think what would be nice would be a halfway house between a fully generated wrapper and eth.call. Perhaps we could have something like contract.call("MethodName", args) ?

Did you mean that we can always build methods for working with duplicated functions by hand and don't use generated wrappers for them?
Something like:

 public RemoteCall<String> NAME() {
        final Function function = new Function("NAME", 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

@antonydenyer
Copy link
Member

The problem is that executeRemoteCallSingleValueReturn is protected so you would need to extend your generated class. Just wondering if there's something nice we can. Perhaps not.

@antonydenyer
Copy link
Member

With this PR I think we should prevent code generation for anything that will cause a clash. When clashes are found output a warning to the user.

@kostind
Copy link
Contributor Author

kostind commented Aug 23, 2019

With this PR I think we should prevent code generation for anything that will cause a clash. When clashes are found output a warning to the user.

Thank you for your suggestions.
I'm going to update it next week.
I will also change testDuplicateField in order to read a message from System.err and probably prevent System.exit.

@iikirilov
Copy link
Contributor

iikirilov commented Aug 23, 2019

The only concern here if we need to interact with a smart contract which has already been deployed and can't be upgraded.

Good point.

Just to clarify the resolution is to successfully generate a wrapper without the duplicate fields (i.e. it must compile) and to output warnings on the command line for the user.

@kostind
Copy link
Contributor Author

kostind commented Aug 28, 2019

@antonydenyer Thank you for the approval.
@iikirilov Please take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants