Add BigNumberFormatter test.

This commit is contained in:
sc0Vu 2018-02-07 16:45:02 +08:00
parent 76c54335d6
commit 5989f167b3
3 changed files with 47 additions and 7 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace Test\Unit;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use Web3\Formatters\BigNumberFormatter;
class BigNumberFormatterTest extends TestCase
{
/**
* formatter
*
* @var \Web3\Formatters\BigNumberFormatter
*/
protected $formatter;
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->formatter = new BigNumberFormatter;
}
/**
* testFormat
*
* @return void
*/
public function testFormat()
{
$formatter = $this->formatter;
$bigNumber = $formatter->format(1);
$this->assertEquals($bigNumber->toString(), '1');
$this->assertTrue($bigNumber instanceof BigNumber);
}
}

View File

@ -10,7 +10,7 @@ class BooleanFormatterTest extends TestCase
/**
* formatter
*
* @var \Web3\Formatters\Boolean
* @var \Web3\Formatters\BooleanFormatter
*/
protected $formatter;
@ -35,11 +35,9 @@ class BooleanFormatterTest extends TestCase
$formatter = $this->formatter;
$boolean = $formatter->format(true);
$this->assertEquals($boolean, 1);
$boolean = $formatter->format(false);
$this->assertEquals($boolean, 0);
}
}

View File

@ -10,7 +10,7 @@ class IntegerFormatterTest extends TestCase
/**
* formatter
*
* @var \Web3\Formatters\Integer
* @var \Web3\Formatters\IntegerFormatter
*/
protected $formatter;
@ -35,15 +35,15 @@ class IntegerFormatterTest extends TestCase
$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');
}
}