diff --git a/src/Contracts/Types/Bytes.php b/src/Contracts/Types/Bytes.php new file mode 100644 index 0000000..c061998 --- /dev/null +++ b/src/Contracts/Types/Bytes.php @@ -0,0 +1,49 @@ + + * + * @author Peter Lai + * @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; + } +} \ No newline at end of file diff --git a/test/unit/BoolTypeTest.php b/test/unit/BooleanTypeTest.php similarity index 96% rename from test/unit/BoolTypeTest.php rename to test/unit/BooleanTypeTest.php index 2f05f6e..73304b3 100644 --- a/test/unit/BoolTypeTest.php +++ b/test/unit/BooleanTypeTest.php @@ -6,7 +6,7 @@ use InvalidArgumentException; use Test\TestCase; use Web3\Contracts\Types\Boolean; -class BoolTypeTest extends TestCase +class BooleanTypeTest extends TestCase { /** * testTypes diff --git a/test/unit/BytesTypeTest.php b/test/unit/BytesTypeTest.php new file mode 100644 index 0000000..34a837d --- /dev/null +++ b/test/unit/BytesTypeTest.php @@ -0,0 +1,75 @@ + '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']); + } + } +} \ No newline at end of file