BytesType
This commit is contained in:
parent
62a21e4455
commit
55c168736f
49
src/Contracts/Types/Bytes.php
Normal file
49
src/Contracts/Types/Bytes.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@ use InvalidArgumentException;
|
|||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
use Web3\Contracts\Types\Boolean;
|
use Web3\Contracts\Types\Boolean;
|
||||||
|
|
||||||
class BoolTypeTest extends TestCase
|
class BooleanTypeTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* testTypes
|
* testTypes
|
75
test/unit/BytesTypeTest.php
Normal file
75
test/unit/BytesTypeTest.php
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user