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

refactor: run substrate-contracts-node in pop up contract if it does not exist #206

Merged
merged 10 commits into from
Jun 17, 2024

Conversation

AlexD10S
Copy link
Collaborator

Closes #35

Reviewer Considerations

  • The GitHub functionality is the same code as in the pop_parachains crate. I copied the necessary logic into the pop_contracts crate, but does it make more sense to just import the pop_parachains crate instead?
    Ideally, we should have a common crate as suggested here: Organization: crates/common #124, but that seems out of scope for this PR.
  • The contracts node runs in the background, so after the contract deployment is finished, it remains running. The user will need to manually stop it.

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 64.85149% with 71 lines in your changes missing coverage. Please review.

Project coverage is 57.31%. Comparing base (2713de5) to head (b2ba47c).
Report is 1 commits behind head on main.

@@            Coverage Diff             @@
##             main     #206      +/-   ##
==========================================
+ Coverage   56.58%   57.31%   +0.72%     
==========================================
  Files          33       34       +1     
  Lines        3513     3697     +184     
  Branches     3513     3697     +184     
==========================================
+ Hits         1988     2119     +131     
- Misses       1232     1239       +7     
- Partials      293      339      +46     
Files Coverage Δ
crates/pop-cli/src/main.rs 27.41% <ø> (+0.43%) ⬆️
crates/pop-contracts/src/errors.rs 0.00% <ø> (ø)
crates/pop-cli/src/commands/up/contract.rs 0.00% <0.00%> (ø)
crates/pop-contracts/src/utils/git.rs 78.82% <78.82%> (ø)
crates/pop-contracts/src/utils/contracts_node.rs 64.00% <64.00%> (ø)

Copy link
Contributor

@al3mart al3mart left a comment

Choose a reason for hiding this comment

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

Nice!

Overall I think this flow is nicer.

Regarding that git duplicated code I agree we should move in the way of having a common crate, or maybe it makes sense importing it from the existing one just to be able to move ahead and then we address the common crate later on.

Given that we are launching a para for the user if no arguments are given, we could also use //Alice by default if no other suri is given.

When dry-running the changes I got:

◆  Local node started successfully in the background.
│  
▲  NOTE: The contracts node is running in the background with process ID 188188. Please close it manually when done testing.
│  
┌   Pop CLI : Deploy a smart contract
│
Error: Invalid number of input arguments: expected 1, 0 provided

I just built a contract and run pop up contract --suri //Alice. @AlexD10S did you see this ?

README.md Outdated Show resolved Hide resolved
@Moliholy
Copy link
Contributor

Moliholy commented Jun 14, 2024

Given that we are launching a para for the user if no arguments are given, we could also use //Alice by default if no other suri is given.

@al3mart just some heads up: when using EthereumSignature instead of MultiSignature, //Alice does not work. Instead, Alith private key should be used as the uri.

You can check whether the blockchain uses EthereumSignature by checking the chainspec includes the isEthereum: true flag.

@AlexD10S
Copy link
Collaborator Author

Nice!

Overall I think this flow is nicer.

Regarding that git duplicated code I agree we should move in the way of having a common crate, or maybe it makes sense importing it from the existing one just to be able to move ahead and then we address the common crate later on.

Given that we are launching a para for the user if no arguments are given, we could also use //Alice by default if no other suri is given.

When dry-running the changes I got:

◆  Local node started successfully in the background.
│  
▲  NOTE: The contracts node is running in the background with process ID 188188. Please close it manually when done testing.
│  
┌   Pop CLI : Deploy a smart contract
│
Error: Invalid number of input arguments: expected 1, 0 provided

I just built a contract and run pop up contract --suri //Alice. @AlexD10S did you see this ?

The error thrown is correct. To initialize the contract, you must call the constructor method. If not specified, pop-cli uses 'new' by default. For the smart contract you are trying to deploy, this constructor expects one argument:

        #[ink(constructor)]
        pub fn new(init_value: bool) -> Self {

The argument has to be specified with the --args flag. If you try pop up contract --suri //Alice --args false works.
The same behaviour happens with cargo-contracts. If you try cargo contract instantiate --suri //Alice you will see the same error.

Also, I pushed a new commit implementing your suggestion to use the dev account by default (//Alice) if the account for deploying the contract is not specified (--suri).

@peterwht peterwht requested a review from al3mart June 14, 2024 15:35
@al3mart
Copy link
Contributor

al3mart commented Jun 14, 2024

The error thrown is correct. To initialize the contract, you must call the constructor method.

So right! That was a bad review from my side. For whatever reason I started passing no arguments on my testing. 🙏

@AlexD10S
Copy link
Collaborator Author

The error thrown is correct. To initialize the contract, you must call the constructor method.

So right! That was a bad review from my side. For whatever reason I started passing no arguments on my testing. 🙏

You made a good point; the error message is not very clear. However, I'm unsure how we can improve it because the error is thrown by the contract_extrinsics. We could add a check in pop-cli to retrieve the constructor and compare the expected arguments.

@AlexD10S
Copy link
Collaborator Author

@al3mart just some heads up: when using EthereumSignature instead of MultiSignature, //Alice does not work. Instead, Alith private key should be used as the uri.

You can check whether the blockchain uses EthereumSignature by checking the chainspec includes the isEthereum: true flag.

In my opinion, this is out of scope for this PR. We are safe using //Alice if no --suri is indicated. This is just a default scenario. If the chain has EthereumSignature, the user will have to specify the keys they want to use. But thanks for sharing, please feel free to add it to the issues, and we will consider adding this feature..

Copy link
Contributor

@al3mart al3mart left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexD10S AlexD10S merged commit 08b2e24 into main Jun 17, 2024
15 checks passed
@AlexD10S AlexD10S deleted the alex/run-contract-node-for-test branch June 17, 2024 08:14
@AlexD10S AlexD10S mentioned this pull request Jul 8, 2024
2 tasks
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.

pop up contract: run substrate-contracts-node if it does not exist
4 participants