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

fix incorrectly versioned bn.js type export #4418

Merged

Conversation

mrice32
Copy link

@mrice32 mrice32 commented Oct 1, 2021

Description

The @types/bn.js package is not listed as a dependency in all packages that have an index.d.ts file that calls require("bn.js"). This causes downstream typescript users to resolve a type from a nested web3 dependency (ethereumjs-utils), which uses bn.js@5.X.X rather than bn.js@4.X.X as web3 does. The result is that web3 uses bn.js@4.X.X in js, but exports the bn.js@5.X.X type.

For users, this can result in compilation errors if using the bn.js library directly and using the objects to interact with web3. In the worst case, this can cause typescript users to make invalid calls into these BN objects due to the type mismatch.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran npm run dtslint with success and extended the tests and types if necessary.
  • I ran npm run test:unit with success.
  • I ran npm run test:cov and my test cases cover all the lines and branches of the added code.
  • I ran npm run build and tested dist/web3.min.js in a browser.
  • I have tested my code on the live network.
  • I have checked the Deploy Preview and it looks correct.
  • I have updated the CHANGELOG.md file in the root folder.

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1296720633

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 264 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+2.3%) to 74.836%

Files with Coverage Reduction New Missed Lines %
packages/web3-core-requestmanager/src/jsonrpc.js 1 70.0%
packages/web3-core-helpers/src/formatters.js 6 84.87%
packages/web3-core-helpers/src/errors.js 29 1.56%
packages/web3-utils/src/soliditySha3.js 34 3.43%
packages/web3-utils/src/index.js 43 31.38%
packages/web3-utils/src/utils.js 44 9.66%
packages/web3-eth-accounts/src/index.js 107 23.67%
Totals Coverage Status
Change from base Build 1292310514: 2.3%
Covered Lines: 3224
Relevant Lines: 4073

💛 - Coveralls

@spacesailor24
Copy link
Contributor

Hey there! Thank you for opening this PR, it might actually be a solution to the failing Build / e2e (e2e_gnosis_dex) test

The gnosis dex repo which was renamed to gp-v1-ui uses the toWei method which supports a bn as input. It imports it from dex-js, and dex-js is just re-exporting it from web3-utils. Even though both gp-v1-ui and dex-js import and use bn.js, I didn't find it listed as a dependency in their package.jsons. However, dex-js does import dex-contracts which has bn.js listed as a dependency for version ^5.2.0

I'm not sure why this error would pop up now, but it sounds similar to the problem you were describing by not including bn.js as a dependency

@spacesailor24 spacesailor24 added the 1.x 1.0 related issues label Oct 5, 2021
Copy link
Contributor

@spacesailor24 spacesailor24 left a comment

Choose a reason for hiding this comment

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

The files

  • dist/web3.min.js
  • dist/web3.min.js.map

shouldn't haven been updated, this only happens in release PRs

@philknows
Copy link

As mentioned in today's call, we should try to merge this for 1.6.1 @jdevcs to fix the failing tests.
@spacesailor24 will create a new issue if there's no response from PR author to request changes.

@spacesailor24 spacesailor24 mentioned this pull request Oct 6, 2021
1 task
@mrice32
Copy link
Author

mrice32 commented Oct 6, 2021

As mentioned in today's call, we should try to merge this for 1.6.1 @jdevcs to fix the failing tests. @spacesailor24 will create a new issue if there's no response from PR author to request changes.

Sorry, I can make the changes requested now. Sorry for the delay!

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@mrice32
Copy link
Author

mrice32 commented Oct 6, 2021

The files

  • dist/web3.min.js
  • dist/web3.min.js.map

shouldn't haven been updated, this only happens in release PRs

@spacesailor24 Thanks! This should be fixed now. Let me know if there's anything else that needs to be done before merging.

@@ -472,3 +472,4 @@ Released with 1.0.0-beta.37 code base.
- Format `block.baseFeePerGas` to number (#4330)
- Correct `web3-eth-personal.sendTransaction` example in documentation (#4409)
- Updated README to include Webpack 5 angular support instructions (#4174)
- - Added @types/bn.js dependency to additional packages (notably web3-utils) so the type export aligns with the js.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- - Added @types/bn.js dependency to additional packages (notably web3-utils) so the type export aligns with the js.
- Added @types/bn.js dependency to additional packages (notably web3-utils) so the type export aligns with the js (#4418)

Extra - and missing PR number

@spacesailor24
Copy link
Contributor

I'm going to take over this, some changes need to be applied, namely @types/bn.js was added as a dependency instead of a dev dependency

@mrice32 You'll still be apart of the git history, we're just trying to get the next RC out and want to merge this in to see if it fixes #4436

@spacesailor24 spacesailor24 changed the base branch from 1.x to wyatt/1.x/add-missing-bn-types October 7, 2021 01:38
@spacesailor24 spacesailor24 merged commit eba1cb2 into web3:wyatt/1.x/add-missing-bn-types Oct 7, 2021
@mrice32
Copy link
Author

mrice32 commented Oct 7, 2021

@spacesailor24

I'm going to take over this

Sounds good!

some changes need to be applied, namely @types/bn.js was added as a dependency instead of a dev dependency

I totally could be wrong, but it was my impression that the issue was that it needed to be a regular dependency. If you are depending on this package and using typescript, you need the @types/bn.js package to be installed in the subtree below this package, and (as far as I know) dev deps are only installed during local development within this repo, not for downstream users when they install via npm. If it's not installed the require("bn.js") call within the index.d.ts file will resolve to ethereumjs-utils's version of @types/bn.js instead of the one web3 uses, which causes the issue we're seeing.

Does that make sense?

@spacesailor24
Copy link
Contributor

@mrice32

Yep, I think you're right, corrected myself here. Just waiting for consensus around it from the rest of the team

Thank you for being so responsive and helpful with fixing this!

spacesailor24 added a commit that referenced this pull request Oct 8, 2021
Merging with failing `e2e_gnosis_dex` test as this may fix it

* fix incorrectly versioned bn.js type export (#4418)

* fix incorrectly versioned bn.js type export

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>

* WIP

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>

* WIP

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>

* Update CHANGELOG

Co-authored-by: Matt Rice <matthewcrice32@gmail.com>
@philknows philknows mentioned this pull request Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants