BytesType

This commit is contained in:
sc0Vu 2017-12-26 17:07:46 +08:00
parent 62a21e4455
commit 55c168736f
3 changed files with 125 additions and 1 deletions

View File

@ -0,0 +1,49 @@
<?php
/**
* This file is part of web3.php package.
*
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
*
* @author Peter Lai <alk03073135@gmail.com>
* @license MIT
*/
namespace Web3\Contracts\Types;
use Web3\Contracts\SolidityType;
use Web3\Contracts\Types\IType;
class Bytes extends SolidityType implements IType
{
/**
* construct
*
* @return void
*/
public function __construct()
{
//
}
/**
* isType
*
* @param string $name
* @return bool
*/
public function isType($name)
{
return (preg_match('/bytes([0-9]{1,})?(\[([0-9]+)\])?/', $name) === 1);
}
/**
* isDynamicType
*
* @return bool
*/
public function isDynamicType()
{
return false;
}
}

View File

@ -6,7 +6,7 @@ use InvalidArgumentException;
use Test\TestCase;
use Web3\Contracts\Types\Boolean;
class BoolTypeTest extends TestCase
class BooleanTypeTest extends TestCase
{
/**
* testTypes

View File

@ -0,0 +1,75 @@
<?php
namespace Test\Unit;
use InvalidArgumentException;
use Test\TestCase;
use Web3\Contracts\Types\Bytes;
class BytesTypeTest extends TestCase
{
/**
* testTypes
*
* @var array
*/
protected $testTypes = [
[
'value' => 'bytes',
'result' => true
], [
'value' => 'bytes[]',
'result' => true
], [
'value' => 'bytes[4]',
'result' => true
], [
'value' => 'bytes[][]',
'result' => true
], [
'value' => 'bytes[3][]',
'result' => true
], [
'value' => 'bytes[][6][]',
'result' => true
], [
'value' => 'bytes32',
'result' => true
], [
'value' => 'bytes8[4]',
'result' => true
],
];
/**
* solidityType
*
* @var \Web3\Contracts\SolidityType
*/
protected $solidityType;
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->solidityType = new Bytes;
}
/**
* testIsType
*
* @return void
*/
public function testIsType()
{
$solidityType = $this->solidityType;
foreach ($this->testTypes as $type) {
$this->assertEquals($solidityType->isType($type['value']), $type['result']);
}
}
}