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

Interacts using typechain #12

Merged
merged 8 commits into from
May 13, 2019

Conversation

0xsarvesh
Copy link
Contributor

fixes #7

This PR generates type script contract interacts. Generated interacts are not committed, they should be generated as part of the build process.

Currently interacts are generated with npm run generate and post hook of npm install

Interacts are manually tested, to check script refer 0xsarvesh@a508b20

Also, check discussion about Typechain Vs 0x@ab-gen in the ticket

Copy link
Contributor

@deepesh-kn deepesh-kn left a comment

Choose a reason for hiding this comment

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

Nice work 💯
Just a comment related to git ignore of interacts.

@@ -14,3 +14,6 @@ build/

# NPM package generated files:
dist/contracts.json

# Do not track generated wrapper, it should be part of build script
interacts/*
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that you have added postinstall script.
Its mentioned in the typechain documentation not to commit the interacts. What will be the disadvantages if the interacts are committed?

I am thinking in general, If we publish an NPM package, will the interacts be available? Or the project that consumes the package needs to handle the interact generation separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

The interacts would still be part of the published package in my opinion, just not part of the repository. That way, it is guaranteed that the interacts are always up to date with the latest code changes on the solidity layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Interacts will be available in the published package, it's just they are not tracked by git rather generated each time. This will make sure that everyone has the latest interacts.

At the time of publishing, the latest interacts will be generated(as a build step)and published.

Copy link
Contributor

@abhayks1 abhayks1 May 9, 2019

Choose a reason for hiding this comment

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

Yes, Interacts will be available in the published package, it's just they are not tracked by git rather generated each time.

Will it not be confusing on github if there are modules/libraries/helpers written on top of generated interacts 💭 ? Written modules will be tracked in git but the dynamic interacts will not be.

e.g. https://github.com/OpenST/openst.js/blob/develop/lib/helper/User.js
User.js is written on top of multiple contract interacts. So we will commit User.js in github calling generated interacts methods which will not be tracked in github.
One option is we describe this clearly in readme but I just feel it will be confusing for open source community looking at the code.

What do you think 🤔 ?

Copy link
Contributor Author

@0xsarvesh 0xsarvesh May 9, 2019

Choose a reason for hiding this comment

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

In the contract repository, there shouldn't be any complex class which uses multiple interacts. They should go into Interaction layer like mosaic.js, openst.js where these thin interact will always be available with published npm of contracts in my opinion.

@schemar schemar self-assigned this May 9, 2019
@schemar
Copy link
Contributor

schemar commented May 9, 2019

Reviewing!

Copy link
Contributor

@schemar schemar left a comment

Choose a reason for hiding this comment

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

Very nice 👍

Should we somehow provide something to the consumer to ease deployment or do we expect them to write that themselves? 🤔

@@ -14,3 +14,6 @@ build/

# NPM package generated files:
dist/contracts.json

# Do not track generated wrapper, it should be part of build script
interacts/*
Copy link
Contributor

Choose a reason for hiding this comment

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

The interacts would still be part of the published package in my opinion, just not part of the repository. That way, it is guaranteed that the interacts are always up to date with the latest code changes on the solidity layer.

"target": "web3-1.0.0",
"outDir" : "interacts"
}
]
Copy link
Contributor

Choose a reason for hiding this comment

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

😱

package.json Outdated Show resolved Hide resolved
@schemar schemar removed their assignment May 9, 2019
@0xsarvesh
Copy link
Contributor Author

Very nice 👍

Should we somehow provide something to the consumer to ease deployment or do we expect them to write that themselves? 🤔

I also feel theoretically it should be possible to deploy contracts from generated interacts as they extend from web3.eth.contracts which has deploy method.

I have created a ticket to research on this. #13

@abhayks1 abhayks1 self-assigned this May 9, 2019
@abhayks1
Copy link
Contributor

abhayks1 commented May 9, 2019

Nice work 💯Typechain looks like a simple to use option.

I have few questions comparing with our existing interacts approach:

  • How typechain takes care of validations for the interact methods? Does it also generates validations along with contract interact code? Raising this point because in the past we had discussions on adding validations for the JS layers and their respective unit tests 🤔

  • Referring to PR description:
    Interacts are manually tested, to check script refer sarvesh-ost@a508b20

This means positive/negative unit tests needs to be manually written using sinon after generating the interacts covering all the cases. Right ❓

@abhayks1 abhayks1 removed their assignment May 9, 2019
@0xsarvesh
Copy link
Contributor Author

Nice work 💯Typechain looks like a simple to use option.

I have few questions comparing with our existing interacts approach:

  • How typechain takes care of validations for the interact methods? Does it also generates validations along with contract interact code? Raising this point because in the past we had discussions on adding validations for the JS layers and their respective unit tests 🤔

Typechain generates interacts in typescript where types are checked at compile time. Which means you can't pass a complex object at the place of string.
But checks like conversion decimal should be less than 5 or conversion rate should be greater than zero are not handled here.

  • Referring to PR description:
    Interacts are manually tested, to check script refer sarvesh-ost@a508b20

This means positive/negative unit tests needs to be manually written using sinon after generating the interacts covering all the cases. Right ❓

No, I don't think unit testing of generated interacts is required that would mean we will be testing the generator tool(that it generates the correct classes). However, we should definitely use these interacts for unit testing of contract logic.

Copy link
Contributor

@schemar schemar left a comment

Choose a reason for hiding this comment

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

Almost done, just these minor remarks.

package.json Show resolved Hide resolved
@schemar schemar assigned schemar and unassigned schemar May 10, 2019
Copy link
Contributor

@schemar schemar left a comment

Choose a reason for hiding this comment

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

LGTM 🐧

@schemar schemar merged commit 8a2b98f into OpenST:develop May 13, 2019
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.

Script to auto-generate contract interacts files
4 participants