Change toWei.
This commit is contained in:
parent
46c252a44e
commit
7c1755cc9c
@ -172,8 +172,10 @@ class Utils
|
||||
} elseif (is_string($number)) {
|
||||
if (self::isZeroPrefixed($number)) {
|
||||
$number = self::stripZero($number);
|
||||
$bn = new BigNumber($number, 16);
|
||||
} else {
|
||||
$bn = new BigNumber($number);
|
||||
}
|
||||
$bn = new BigNumber($number, 16);
|
||||
} elseif (!$number instanceof BigNumber){
|
||||
throw new InvalidArgumentException('toWei number must be BigNumber, string or int.');
|
||||
}
|
||||
|
@ -122,14 +122,18 @@ class UtilsTest extends TestCase
|
||||
|
||||
$this->assertEquals($bn->toString(), '1');
|
||||
|
||||
$bn = Utils::toWei('1', 'wei');
|
||||
$bn = Utils::toWei('18', 'wei');
|
||||
|
||||
$this->assertEquals($bn->toString(), '1');
|
||||
$this->assertEquals($bn->toString(), '18');
|
||||
|
||||
$bn = Utils::toWei(1, 'wei');
|
||||
|
||||
$this->assertEquals($bn->toString(), '1');
|
||||
|
||||
$bn = Utils::toWei(0x11, 'wei');
|
||||
|
||||
$this->assertEquals($bn->toString(), '17');
|
||||
|
||||
$bn = Utils::toWei('1', 'ether');
|
||||
|
||||
$this->assertEquals($bn->toString(), '1000000000000000000');
|
||||
@ -151,16 +155,21 @@ class UtilsTest extends TestCase
|
||||
$this->assertEquals($bnq->toString(), '0');
|
||||
$this->assertEquals($bnr->toString(), '1');
|
||||
|
||||
list($bnq, $bnr) = Utils::toEther('1', 'wei');
|
||||
list($bnq, $bnr) = Utils::toEther('18', 'wei');
|
||||
|
||||
$this->assertEquals($bnq->toString(), '0');
|
||||
$this->assertEquals($bnr->toString(), '1');
|
||||
$this->assertEquals($bnr->toString(), '18');
|
||||
|
||||
list($bnq, $bnr) = Utils::toEther(1, 'wei');
|
||||
|
||||
$this->assertEquals($bnq->toString(), '0');
|
||||
$this->assertEquals($bnr->toString(), '1');
|
||||
|
||||
list($bnq, $bnr) = Utils::toEther(0x11, 'wei');
|
||||
|
||||
$this->assertEquals($bnq->toString(), '0');
|
||||
$this->assertEquals($bnr->toString(), '17');
|
||||
|
||||
list($bnq, $bnr) = Utils::toEther('1', 'kether');
|
||||
|
||||
$this->assertEquals($bnq->toString(), '1000');
|
||||
|
Loading…
Reference in New Issue
Block a user