web3.php/test/unit/UtilsTest.php
sc0Vu ffb02edee7 Web3\Utils
- toHex
- hexToBin
2017-12-20 11:49:52 +08:00

65 lines
1.2 KiB
PHP

<?php
namespace Test\Unit;
use InvalidArgumentException;
use Test\TestCase;
use Web3\Utils;
class UtilsTest extends TestCase
{
/**
* testHex
* 'hello world'
* you can check by call pack('H*', $hex)
*
* @var string
*/
protected $testHex = '68656c6c6f20776f726c64';
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
}
/**
* testToHex
*
* @return void
*/
public function testToHex()
{
$hex = Utils::toHex('hello world');
$this->assertEquals($hex, $this->testHex);
$hexPrefixed = Utils::toHex('hello world', true);
$this->assertEquals($hexPrefixed, '0x' . $this->testHex);
}
/**
* testHexToBin
*
* @return void
*/
public function testHexToBin()
{
$str = Utils::hexToBin($this->testHex);
$this->assertEquals($str, 'hello world');
$str = Utils::hexToBin('0x' . $this->testHex);
$this->assertEquals($str, 'hello world');
$str = Utils::hexToBin('0xe4b883e5bda9e7a59ee4bb99e9b1bc');
$this->assertEquals($str, '七彩神仙鱼');
}
}