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.
This PR adds support to deploying a Stylus contract using the Stylus Factory. The factory will deploy the contract, activate it, and initialize it by calling the constructor.
First, we add a new function (
get_constructor_signature
) in the export-abi module to get the constructor signature from the export binary. This function will call the binary and pass theconstructor
subcommand to get the constructor definition. If the SDK doesn't support constructors, the function will return that no constructor is present to be backward compatible.Then, the code that deploys the contract will call
get_constructor_signature
to decide whether it should use the factory. If no constructors are present, cargo-stylus will behave as it did previously. If the contract has a constructor, the functionfactory::parse_constructor_args
will validate the CLI args to ensure there is a factory address, and it will validate the constructor arguments provided by the user match what the constructor expects. This function verifies all arguments and creates a structure that will later be used in deployment. Finally, the functionfactory::deploy
deploys the contract by calling the factory.I did a few manual tests to ensure cargo-stylus works appropriately. For future work, we should create a few end-to-end tests, making sure all cases work correctly. Here are some test cases I did: