Fix HexFormatter and add HexFormatter test.
This commit is contained in:
parent
180e2d3cdb
commit
1b427bcb90
@ -30,8 +30,6 @@ class HexFormatter implements IFormatter
|
|||||||
|
|
||||||
if (Utils::isZeroPrefixed($value)) {
|
if (Utils::isZeroPrefixed($value)) {
|
||||||
return $value;
|
return $value;
|
||||||
} elseif (Utils::isHex($value)) {
|
|
||||||
$value = '0x' . $value;
|
|
||||||
} else {
|
} else {
|
||||||
$value = Utils::toHex($value, true);
|
$value = Utils::toHex($value, true);
|
||||||
}
|
}
|
||||||
|
49
test/unit/HexFormatterTest.php
Normal file
49
test/unit/HexFormatterTest.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Test\Unit;
|
||||||
|
|
||||||
|
use Test\TestCase;
|
||||||
|
use Web3\Formatters\HexFormatter;
|
||||||
|
|
||||||
|
class HexFormatterTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* formatter
|
||||||
|
*
|
||||||
|
* @var \Web3\Formatters\HexFormatter
|
||||||
|
*/
|
||||||
|
protected $formatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setUp
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->formatter = new HexFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testFormat
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFormat()
|
||||||
|
{
|
||||||
|
$formatter = $this->formatter;
|
||||||
|
|
||||||
|
$hex = $formatter->format('ae');
|
||||||
|
$this->assertEquals($hex, '0x6165');
|
||||||
|
|
||||||
|
$hex = $formatter->format('0xabce');
|
||||||
|
$this->assertEquals($hex, '0xabce');
|
||||||
|
|
||||||
|
$hex = $formatter->format('123');
|
||||||
|
$this->assertEquals($hex, '0x7b');
|
||||||
|
|
||||||
|
$hex = $formatter->format(12);
|
||||||
|
$this->assertEquals($hex, '0xc');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user