Skip to content

Commit

Permalink
Update error strings in utils module (web3#3088)
Browse files Browse the repository at this point in the history
* Update error strings in utils module
  • Loading branch information
cgewecke authored and nachomazzara committed Jun 4, 2020
1 parent 2bb8d60 commit 29ebbe6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Released with 1.0.0-beta.37 code base.

### Fixed

- Fix incorrect references to BigNumber in utils.fromWei and utils.toWei error messages (#2468)
- Fix error incorrectly thrown when receipt.status is `null` (#2183)
- Fix incorrectly populating chainId param with `net_version` when signing txs (#2378)
- regeneratorRuntime error fixed (#3058)
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ var fromWei = function(number, unit) {
unit = getUnitValue(unit);

if(!utils.isBN(number) && !_.isString(number)) {
throw new Error('Please pass numbers as strings or BigNumber objects to avoid precision errors.');
throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.');
}

return utils.isBN(number) ? ethjsUnit.fromWei(number, unit) : ethjsUnit.fromWei(number, unit).toString(10);
Expand Down Expand Up @@ -263,7 +263,7 @@ var toWei = function(number, unit) {
unit = getUnitValue(unit);

if(!utils.isBN(number) && !_.isString(number)) {
throw new Error('Please pass numbers as strings or BigNumber objects to avoid precision errors.');
throw new Error('Please pass numbers as strings or BN objects to avoid precision errors.');
}

return utils.isBN(number) ? ethjsUnit.toWei(number, unit) : ethjsUnit.toWei(number, unit).toString(10);
Expand Down
9 changes: 9 additions & 0 deletions test/utils.fromWei.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ describe('lib/utils/utils', function () {
assert.equal(utils.fromWei('1000000000000000000', 'gether'), '0.000000001');
assert.equal(utils.fromWei('1000000000000000000', 'tether'), '0.000000000001');
});

it('should verify "number" arg is string or BN', function () {
try {
utils.fromWei(100000000000, 'wei')
assert.fail();
} catch (error) {
assert(error.message.includes('Please pass numbers as strings or BN objects'))
}
})
});
});
9 changes: 9 additions & 0 deletions test/utils.toWei.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ describe('lib/utils/utils', function () {

assert.throws(function () {utils.toWei(1, 'wei1');}, Error);
});

it('should verify "number" arg is string or BN', function () {
try {
utils.toWei(1, 'wei')
assert.fail();
} catch (error) {
assert(error.message.includes('Please pass numbers as strings or BN objects'))
}
})
});
});

0 comments on commit 29ebbe6

Please sign in to comment.