From 29ebbe6a71dd69b34c5e778218574da743b90b70 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Mon, 7 Oct 2019 21:41:11 -0700 Subject: [PATCH] Update error strings in utils module (#3088) * Update error strings in utils module --- CHANGELOG.md | 1 + packages/web3-utils/src/index.js | 4 ++-- test/utils.fromWei.js | 9 +++++++++ test/utils.toWei.js | 9 +++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee272a38d93..79cc1b5b415 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/web3-utils/src/index.js b/packages/web3-utils/src/index.js index f8920534b34..e2527474b6d 100644 --- a/packages/web3-utils/src/index.js +++ b/packages/web3-utils/src/index.js @@ -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); @@ -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); diff --git a/test/utils.fromWei.js b/test/utils.fromWei.js index c46413d3410..cacf09f18c3 100644 --- a/test/utils.fromWei.js +++ b/test/utils.fromWei.js @@ -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')) + } + }) }); }); diff --git a/test/utils.toWei.js b/test/utils.toWei.js index 7fd84a32dad..4b0cf9487c8 100644 --- a/test/utils.toWei.js +++ b/test/utils.toWei.js @@ -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')) + } + }) }); });