diff --git a/src/Methods/Personal/ListAccounts.php b/src/Methods/Personal/ListAccounts.php index 9bc4e15..a742767 100644 --- a/src/Methods/Personal/ListAccounts.php +++ b/src/Methods/Personal/ListAccounts.php @@ -16,6 +16,13 @@ use Web3\Methods\EthMethod; class ListAccounts extends EthMethod { + /** + * validators + * + * @var array + */ + protected $validators = []; + /** * inputFormatters * diff --git a/src/Methods/Personal/NewAccount.php b/src/Methods/Personal/NewAccount.php index 3043276..7af5fa6 100644 --- a/src/Methods/Personal/NewAccount.php +++ b/src/Methods/Personal/NewAccount.php @@ -13,10 +13,20 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; use Web3\Methods\EthMethod; +use Web3\Validators\StringValidator; use Web3\Formatters\StringFormatter; class NewAccount extends EthMethod { + /** + * validators + * + * @var array + */ + protected $validators = [ + StringValidator::class + ]; + /** * inputFormatters * diff --git a/src/Methods/Personal/SendTransaction.php b/src/Methods/Personal/SendTransaction.php index f49c5c8..733f1fb 100644 --- a/src/Methods/Personal/SendTransaction.php +++ b/src/Methods/Personal/SendTransaction.php @@ -13,11 +13,22 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; use Web3\Methods\EthMethod; +use Web3\Validators\TransactionValidator; +use Web3\Validators\StringValidator; use Web3\Formatters\TransactionFormatter; use Web3\Formatters\StringFormatter; class SendTransaction extends EthMethod { + /** + * validators + * + * @var array + */ + protected $validators = [ + TransactionValidator::class, StringValidator::class + ]; + /** * inputFormatters * diff --git a/src/Methods/Personal/UnlockAccount.php b/src/Methods/Personal/UnlockAccount.php index 5a0568c..0e2155d 100644 --- a/src/Methods/Personal/UnlockAccount.php +++ b/src/Methods/Personal/UnlockAccount.php @@ -13,12 +13,24 @@ namespace Web3\Methods\Personal; use InvalidArgumentException; use Web3\Methods\EthMethod; +use Web3\Validators\AddressValidator; +use Web3\Validators\StringValidator; +use Web3\Validators\QuantityValidator; use Web3\Formatters\AddressFormatter; use Web3\Formatters\StringFormatter; use Web3\Formatters\QuantityFormatter; class UnlockAccount extends EthMethod { + /** + * validators + * + * @var array + */ + protected $validators = [ + AddressValidator::class, StringValidator::class, QuantityValidator::class + ]; + /** * inputFormatters * diff --git a/src/Personal.php b/src/Personal.php index 5563581..44f09b5 100644 --- a/src/Personal.php +++ b/src/Personal.php @@ -103,10 +103,11 @@ class Personal } else { $methodObject = $this->methods[$method]; } - $inputs = $methodObject->transform($arguments, $methodObject->inputFormatters); - $methodObject->arguments = $inputs; - - $this->provider->send($methodObject, $callback); + if ($methodObject->validate($arguments)) { + $inputs = $methodObject->transform($arguments, $methodObject->inputFormatters); + $methodObject->arguments = $inputs; + $this->provider->send($methodObject, $callback); + } } } diff --git a/test/unit/PersonalBatchTest.php b/test/unit/PersonalBatchTest.php index d15dba8..0c21cec 100644 --- a/test/unit/PersonalBatchTest.php +++ b/test/unit/PersonalBatchTest.php @@ -47,4 +47,28 @@ class PersonalBatchTest extends TestCase $this->assertTrue(is_string($data[1])); }); } + + /** + * testWrongParam + * + * @return void + */ + public function testWrongParam() + { + $this->expectException(RuntimeException::class); + + $personal = $this->personal; + + $personal->batch(true); + $personal->listAccounts(); + $personal->newAccount($personal); + + $personal->provider->execute(function ($err, $data) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue(is_string($data[0])); + $this->assertEquals($data[1], $this->testHash); + }); + } } \ No newline at end of file