From 3907305f76a8bf0592f7098198b2e23041366c0d Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Tue, 26 Dec 2017 17:35:39 +0800 Subject: [PATCH] UintegerType --- src/Contracts/Types/Uinteger.php | 49 +++++++++++++++++++++ test/unit/UintegerTypeTest.php | 75 ++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 src/Contracts/Types/Uinteger.php create mode 100644 test/unit/UintegerTypeTest.php diff --git a/src/Contracts/Types/Uinteger.php b/src/Contracts/Types/Uinteger.php new file mode 100644 index 0000000..560c349 --- /dev/null +++ b/src/Contracts/Types/Uinteger.php @@ -0,0 +1,49 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Contracts\Types; + +use Web3\Contracts\SolidityType; +use Web3\Contracts\Types\IType; + +class Uinteger extends SolidityType implements IType +{ + /** + * construct + * + * @return void + */ + public function __construct() + { + // + } + + /** + * isType + * + * @param string $name + * @return bool + */ + public function isType($name) + { + return (preg_match('/uint([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/UintegerTypeTest.php b/test/unit/UintegerTypeTest.php new file mode 100644 index 0000000..a1eec9d --- /dev/null +++ b/test/unit/UintegerTypeTest.php @@ -0,0 +1,75 @@ + 'uint', + 'result' => true + ], [ + 'value' => 'uint[]', + 'result' => true + ], [ + 'value' => 'uint[4]', + 'result' => true + ], [ + 'value' => 'uint[][]', + 'result' => true + ], [ + 'value' => 'uint[3][]', + 'result' => true + ], [ + 'value' => 'uint[][6][]', + 'result' => true + ], [ + 'value' => 'uint32', + 'result' => true + ], [ + 'value' => 'uint64[4]', + 'result' => true + ], + ]; + + /** + * solidityType + * + * @var \Web3\Contracts\SolidityType + */ + protected $solidityType; + + /** + * setUp + * + * @return void + */ + public function setUp() + { + parent::setUp(); + $this->solidityType = new Uinteger; + } + + /** + * 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