web3j
web3j copied to clipboard
Add a condition on the duplicated event names
What does this PR do?
Add a condition on the name of the events of the java wrapper
Where should the reviewer start?
There is just a one file.
Why is it needed?
Based on Issue #1781, for contracts which have 'overloaded' events (same name, but different signatures) the Java Wrapper creates those events as different instances of the Event class, but with the same variable name, thus resulting in an error. This PR adds the changeEventsName()
method which uses an HashMap to count the occurences of an event name, and for those with more than one occurence, it will change the name putting a number at its end, e.g.
public static final Event ACTIONPAUSED_EVENT = new Event("ActionPaused",
Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
;
public static final Event ACTIONPAUSED1_EVENT = new Event("ActionPaused",
Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Utf8String>() {}, new TypeReference<Bool>() {}));
;
Added the unit test. Not sure if that's the proper way of doing it, please check. I had to put the buildFunctionDefinitions package-private since it was not accessible inside tests.
I also removed the usage of changeEventsName() in buildFuncNameConstants(), l.742 since the function operate just on TYPE_FUNCTION objects (correct me if I'm wrong).
Apparently my Unit Test is not working. On my local machine, anyway, it correctly builds and passes tests.
I won't add it to this release as it affects the wrapper and has to be carefully tested also by us. We keep the PR open for finding a better solution.
@gtebrean can you please give me some more information if you have them? With the new commit the eventName passed in the constructor should be the same. In my local env. the tests passed, but apparently there's still something which I'm doing wrongly since the checks failed.
@gtebrean can you please give me some more information if you have them? With the new commit the eventName passed in the constructor should be the same. In my local env. the tests passed, but apparently there's still something which I'm doing wrongly since the checks failed.
jobs are complaining that: org.web3j.codegen.SolidityFunctionWrapperTest > testBuildFunctionDuplicatedEventNames() FAILED org.opentest4j.AssertionFailedError at SolidityFunctionWrapperTest.java:1038.
It fails to create the wrapper, make sure you have latest changes from master.
@gtebrean can you please give me some more information if you have them? With the new commit the eventName passed in the constructor should be the same. In my local env. the tests passed, but apparently there's still something which I'm doing wrongly since the checks failed.
jobs are complaining that: org.web3j.codegen.SolidityFunctionWrapperTest > testBuildFunctionDuplicatedEventNames() FAILED org.opentest4j.AssertionFailedError at SolidityFunctionWrapperTest.java:1038.
It fails to create the wrapper, make sure you have latest changes from master.
My branch when I commited was up-to-date with master. The method org.web3j.codegen.SolidityFunctionWrapperTest > testBuildFunctionDuplicatedEventNames() is the unit test I created my self for this PR, but in my local env is passing the test, whereas in the jobs it's not. Which could be the cause? Error logs aren't really useful.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.