diff --git a/src/Contracts/Types/Str.php b/src/Contracts/Types/Str.php new file mode 100644 index 0000000..9ffc06d --- /dev/null +++ b/src/Contracts/Types/Str.php @@ -0,0 +1,49 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Contracts\Types; + +use Web3\Contracts\SolidityType; +use Web3\Contracts\Types\IType; + +class Str extends SolidityType implements IType +{ + /** + * construct + * + * @return void + */ + public function __construct() + { + // + } + + /** + * isType + * + * @param string $name + * @return bool + */ + public function isType($name) + { + return (preg_match('/string(\[([0-9]+)\])*/', $name) === 1); + } + + /** + * isDynamicType + * + * @return bool + */ + public function isDynamicType() + { + return true; + } +} \ No newline at end of file diff --git a/test/unit/StrTypeTest.php b/test/unit/StrTypeTest.php new file mode 100644 index 0000000..74f3309 --- /dev/null +++ b/test/unit/StrTypeTest.php @@ -0,0 +1,69 @@ + 'string', + 'result' => true + ], [ + 'value' => 'string[]', + 'result' => true + ], [ + 'value' => 'string[4]', + 'result' => true + ], [ + 'value' => 'string[][]', + 'result' => true + ], [ + 'value' => 'string[3][]', + 'result' => true + ], [ + 'value' => 'string[][6][]', + 'result' => true + ], + ]; + + /** + * solidityType + * + * @var \Web3\Contracts\SolidityType + */ + protected $solidityType; + + /** + * setUp + * + * @return void + */ + public function setUp() + { + parent::setUp(); + $this->solidityType = new Str; + } + + /** + * 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