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

Add support to Stylus Constructors #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

gligneul
Copy link
Contributor

@gligneul gligneul commented Jan 7, 2025

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 the constructor 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 function factory::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 function factory::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:

  • Deploy a contract without constructors.
  • Deploy a contract with a constructor without arguments.
  • Deploy a contract with a constructor with multiple arguments.
  • Deploy a contract that was already activated. (Deploy the same contract twice).

@gligneul gligneul force-pushed the gligneul/constructors branch 2 times, most recently from af9b474 to e356d1e Compare January 8, 2025 20:38
@gligneul gligneul force-pushed the gligneul/constructors branch from e356d1e to f2a85be Compare January 8, 2025 21:30
@gligneul gligneul requested a review from rauljordan January 8, 2025 22:40
@gligneul gligneul marked this pull request as ready for review January 8, 2025 22:40
@gligneul gligneul requested a review from rory-ocl January 8, 2025 22:40
Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

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

Looks great and very nice that the parse tests were added. I really see the need for us to have an actual testing suite from cargo stylus. No issue really stood out to me from the PR

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