web3.php/test/unit/IntegerFormatterTest.php
sc0Vu a87010fc4c Add test
Add test for toHex(48), thanks @refear99
2018-04-25 10:07:06 +08:00

55 lines
1.3 KiB
PHP

<?php
namespace Test\Unit;
use Test\TestCase;
use Web3\Formatters\IntegerFormatter;
class IntegerFormatterTest extends TestCase
{
/**
* formatter
*
* @var \Web3\Formatters\IntegerFormatter
*/
protected $formatter;
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->formatter = new IntegerFormatter;
}
/**
* testFormat
*
* @return void
*/
public function testFormat()
{
$formatter = $this->formatter;
$hex = $formatter->format('1');
$this->assertEquals($hex, implode('', array_fill(0, 63, '0')) . '1');
$hex = $formatter->format('-1');
$this->assertEquals($hex, implode('', array_fill(0, 64, 'f')));
$hex = $formatter->format('ae');
$this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . 'ae');
$hex = $formatter->format('1', 20);
$this->assertEquals($hex, implode('', array_fill(0, 19, '0')) . '1');
$hex = $formatter->format(48);
$this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
$hex = $formatter->format('48');
$this->assertEquals($hex, implode('', array_fill(0, 62, '0')) . '30');
}
}