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

Support codegen directly from Truffle json contract files #228

Merged
merged 19 commits into from
Nov 12, 2017

Conversation

eepstein
Copy link
Contributor

@eepstein eepstein commented Nov 9, 2017

See #226 .

This allows tighter integration of web3j tools with the Truffle suite so that there's more assurance code will work across both libraries.

   Changes were made to master after this fork and before the commit of the Truffle import functionality.
@codecov
Copy link

codecov bot commented Nov 9, 2017

Codecov Report

Merging #228 into master will decrease coverage by 0.5%.
The diff coverage is 62.29%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #228      +/-   ##
============================================
- Coverage     77.32%   76.82%   -0.51%     
- Complexity     1534     1558      +24     
============================================
  Files           209      211       +2     
  Lines          5580     5731     +151     
  Branches        895      908      +13     
============================================
+ Hits           4315     4403      +88     
- Misses         1066     1119      +53     
- Partials        199      209      +10
Impacted Files Coverage Δ Complexity Δ
...onsole/src/main/java/org/web3j/console/Runner.java 0% <0%> (ø) 0 <0> (ø) ⬇️
utils/src/main/java/org/web3j/utils/Strings.java 75% <100%> (-6.25%) 12 <5> (+2)
...eb3j/codegen/SolidityFunctionWrapperGenerator.java 59.61% <100%> (+1.28%) 4 <2> (-5) ⬇️
core/src/main/java/org/web3j/tx/Contract.java 74.33% <100%> (+1.69%) 36 <6> (+6) ⬆️
.../protocol/core/methods/response/AbiDefinition.java 100% <100%> (ø) 44 <4> (+7) ⬆️
...ava/org/web3j/codegen/SolidityFunctionWrapper.java 97.71% <100%> (+0.16%) 97 <4> (+4) ⬆️
...j/codegen/TruffleJsonFunctionWrapperGenerator.java 41.41% <41.41%> (ø) 5 <5> (?)
...va/org/web3j/codegen/FunctionWrapperGenerator.java 62.5% <62.5%> (ø) 7 <7> (?)
...ore/src/main/java/org/web3j/utils/Observables.java 80% <0%> (-8%) 9% <0%> (-2%)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8098c6a...9c435af. Read the comment docs.

@eepstein
Copy link
Contributor Author

eepstein commented Nov 9, 2017

Seems unfair: My pull request is getting penalized because it picked up (and merged in) changes made by Conor, notably additions to the code that didn't include tests to cover that new code.

assertThat(toCsv(Collections.singletonList("a")), is("a"));
assertThat(toCsv(Arrays.asList("a", "b", "c")), is("a, b, c"));
}

@Test
public void testJoin() {
Copy link
Contributor

Choose a reason for hiding this comment

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

How come you removed this 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.

That test was removed because I removed the Strings.join method since Java has a static String.join() method https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.CharSequence...- but again, if this is targetting JDK 1.6, then... whoops, undo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@conor10 : do I need to put back in the hand-rolled Strings.join() utility method to support JDK 1.6 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave the test in.

You can update the join util to be:

    public static String join(List<String> src, String delimiter) {
        return src == null ? null : String.join(delimiter, src.toArray(new String[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.

Will do.

When I checked usages, the only place the code referenced that method is in the Strings utility class itself. The toCsv() method was calling it.

@@ -19,16 +21,11 @@

@Test
public void testToCsv() {
assertThat(toCsv(Collections.<String>emptyList()), is(""));
assertThat(toCsv(Collections.emptyList()), is(""));
Copy link
Contributor

Choose a reason for hiding this comment

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

The parameterized value is so that this function works with Java 1.6 in the Android branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Android. Ah-ha. Maybe it's better then to change the gradle file to require Java v 1.6 ? (Unless I missed it, I may have only checked the top-level config and not the module's config.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to change these lines in the root build.gradle file:

sourceCompatibility = 1.8
targetCompatibility = 1.8

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-bin.zip
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you consciously make these changes, or is your local gradle wrapper once downloaded different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry about that. I thought I'd excluded the gradle wrapper folder entirely. Accident on my side if so.

Side note (and why I missed it): I always include it in my .ignore file since i view keeping the build tool in the repo as ... weird, rather I just have a gradle wrapper command to run when first pulling. Of course that means I've installed gradle, but then, most envs require you install the build tool. If some user is developing java they've already downloaded the JDK - and not just the JRE - and so they're 90% there.

* Subclasses should implement this method to return pre-existing addresses for deployed
* contracts.
*
* @param networkId the network id, for example "1" for the main-net, "3" for ropsten, etc.
Copy link
Contributor

Choose a reason for hiding this comment

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

You could put a link to the org.web3j.tx.ChainId class in this Javadoc

Copy link
Contributor Author

@eepstein eepstein Nov 9, 2017

Choose a reason for hiding this comment

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

I actually searched the code base for ropsten, but I think I forgot to make it a case insensitive search. Hadn't seen ChainId. Curious why not just make that an enum?

Also, ChainId values are bytes, but the max value of a byte is 255 (unsigned). And the doc referenced actually shows 1337 as one of the recommended ids.

Shall we change ChainId to an enum and make the values int or, better, long ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for using a byte, is to support EIP-155, where you place a byte value in the raw transaction object - see here.

That being said further down the discussion in the original EIP it is mentioned that the v value when the transaction is RLP encoded shouldn't be limited to a single byte. So web3j could be enhanced to accomodate this. I've created a separate issue for this.

Copy link
Contributor

@conor10 conor10 left a comment

Choose a reason for hiding this comment

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

@eepstein
Copy link
Contributor Author

eepstein commented Nov 9, 2017

updating. i don't have the tools installed to build the docs, so here's hoping my edits are good

@conor10
Copy link
Contributor

conor10 commented Nov 10, 2017 via email

@conor10 conor10 merged commit 6e9c09b into hyperledger-web3j:master Nov 12, 2017
@conor10
Copy link
Contributor

conor10 commented Nov 12, 2017

Thanks again @eepstein, this is a great enhancement.

franz-see pushed a commit to franz-see/web3j that referenced this pull request Aug 3, 2018
Support codegen directly from Truffle json contract files
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