This repository was archived by the owner on Mar 5, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -975,7 +975,7 @@ Converts any `ether value <http://ethdocs.org/en/latest/ether.html>`_ value into
975975Parameters
976976----------
977977
978- 1. ``number `` - ``String|Number| BN ``: The value.
978+ 1. ``number `` - ``String|BN ``: The value.
9799792. ``unit `` - ``String `` (optional, defaults to ``"ether" ``): The ether to convert from. Possible units are:
980980 - ``noether ``: '0'
981981 - ``wei ``: '1'
@@ -1009,7 +1009,7 @@ Parameters
10091009Returns
10101010-------
10111011
1012- ``String|BN ``: If a number, or string is given it returns a number string, otherwise a `BN.js <https://github.com/indutny/bn.js/ >`_ instance.
1012+ ``String|BN ``: If a string is given it returns a number string, otherwise a `BN.js <https://github.com/indutny/bn.js/ >`_ instance.
10131013
10141014-------
10151015Example
@@ -1049,7 +1049,7 @@ Converts any `wei <http://ethereum.stackexchange.com/questions/253/the-ether-den
10491049Parameters
10501050----------
10511051
1052- 1. ``number `` - ``String|Number| BN ``: The value in wei.
1052+ 1. ``number `` - ``String|BN ``: The value in wei.
105310532. ``unit `` - ``String `` (optional, defaults to ``"ether" ``): The ether to convert to. Possible units are:
10541054 - ``noether ``: '0'
10551055 - ``wei ``: '1'
@@ -1083,7 +1083,7 @@ Parameters
10831083Returns
10841084-------
10851085
1086- ``String|BN ``: If a number, or string is given it returns a number string, otherwise a ` BN.js < https://github.com/indutny/bn.js/ >`_ instance .
1086+ ``String ``: It always returns a string number .
10871087
10881088-------
10891089Example
Original file line number Diff line number Diff line change @@ -27,5 +27,13 @@ describe('lib/utils/utils', function () {
2727 assert ( error . message . includes ( 'Please pass numbers as strings or BN objects' ) )
2828 }
2929 } )
30+ // fromWei always returns string
31+ it ( 'should return the correct type' , function ( ) {
32+ var weiString = '100000000000000000' ;
33+ var weiBN = utils . toBN ( weiString ) ;
34+
35+ assert ( typeof utils . fromWei ( weiString ) === 'string' ) ;
36+ assert ( typeof utils . fromWei ( weiBN ) === 'string' ) ;
37+ } )
3038 } ) ;
3139} ) ;
Original file line number Diff line number Diff line change @@ -35,13 +35,25 @@ describe('lib/utils/utils', function () {
3535 assert . throws ( function ( ) { utils . toWei ( 1 , 'wei1' ) ; } , Error ) ;
3636 } ) ;
3737
38+
3839 it ( 'should verify "number" arg is string or BN' , function ( ) {
3940 try {
4041 utils . toWei ( 1 , 'wei' )
4142 assert . fail ( ) ;
4243 } catch ( error ) {
4344 assert ( error . message . includes ( 'Please pass numbers as strings or BN objects' ) )
4445 }
46+ } ) ;
47+
48+ // toWei returns string when given string, BN when given BN
49+ it ( 'should return the correct type' , function ( ) {
50+ var weiString = '1' ;
51+ var weiBN = utils . toBN ( weiString ) ;
52+
53+ var bn = utils . toWei ( weiBN ) ;
54+
55+ assert ( utils . isBN ( bn ) ) ;
56+ assert ( typeof utils . toWei ( weiString ) === 'string' ) ;
4557 } )
4658 } ) ;
4759} ) ;
You can’t perform that action at this time.
0 commit comments