Fix class generation when using Forge generated ABI files #139
+730
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ABI files that Forge generates after running
forge buildcontain a"bytecode"field similar to the behavior of Truffle/Hardhat. However, Truffle/Hardhat set"bytecode"to a JSON string value, whereas Forge sets"bytecode"to an object that looks like this:When generating sources from ABI files using web3j-maven-plugin, the plugin properly generates Contract Java wrappers, however the
BINARYfield of the contract is always an empty string"". This is a sneaky error because it does not fail compilation, but makes it impossible to deploy the contract via the.deploymethod. Even worse, calls to.deploydo not throw an exception or fail in any way, but rather end up deploying an empty contract on chain.This PR updates
JavaClassGeneratorMojo.parseAbiFileto handle Forge generated ABI files when parsing to correctly set theBINARYfield of generated classes to"bytecode"."object"if"bytecode"is a JSON object (ie when generated by Forge), or"bytecode"when"bytecode"is a JSON String.I added a sample ERC20.json ABI file generated via Forge to the test resources, as well as the test
abi-sourcesproject. Please let me know if there are additional tests I should write.