isZeroPrefixed

This commit is contained in:
sc0Vu 2017-12-22 18:07:31 +08:00
parent adf3e45ccf
commit de19210492
2 changed files with 31 additions and 1 deletions

View File

@ -69,6 +69,20 @@ class Utils
return pack('H*', $value); return pack('H*', $value);
} }
/**
* isZeroPrefixed
*
* @param string
* @return bool
*/
public static function isZeroPrefixed($value)
{
if (!is_string($value)) {
throw new InvalidArgumentException('The value to zeroPrefixed function must be string.');
}
return (strpos($value, '0x') === 0);
}
/** /**
* sha3 * sha3
* keccak256 * keccak256

View File

@ -63,6 +63,22 @@ class UtilsTest extends TestCase
$this->assertEquals($str, '七彩神仙鱼'); $this->assertEquals($str, '七彩神仙鱼');
} }
/**
* testIsZeroPrefixed
*
* @return void
*/
public function testIsZeroPrefixed()
{
$isPrefixed = Utils::isZeroPrefixed($this->testHex);
$this->assertEquals($isPrefixed, false);
$isPrefixed = Utils::isZeroPrefixed('0x' . $this->testHex);
$this->assertEquals($isPrefixed, true);
}
/** /**
* testSha3 * testSha3
* *