From 039556247079871a826bd870cba9b9fbd6697f63 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 29 Jan 2018 16:33:38 +0800 Subject: [PATCH] shh_uninstallFilter --- src/Methods/Shh/UninstallFilter.php | 64 +++++++++++++++++++++++++++++ src/Shh.php | 2 +- test/unit/ShhApiTest.php | 44 +++++++++++++++++++- 3 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/Methods/Shh/UninstallFilter.php diff --git a/src/Methods/Shh/UninstallFilter.php b/src/Methods/Shh/UninstallFilter.php new file mode 100644 index 0000000..38f586a --- /dev/null +++ b/src/Methods/Shh/UninstallFilter.php @@ -0,0 +1,64 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Shh; + +use InvalidArgumentException; +use Web3\Methods\EthMethod; +use Web3\Validators\QuantityValidator; +use Web3\Formatters\QuantityFormatter; + +class UninstallFilter extends EthMethod +{ + /** + * validators + * + * @var array + */ + protected $validators = [ + QuantityValidator::class + ]; + + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = [ + QuantityFormatter::class + ]; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = []; + + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } +} \ No newline at end of file diff --git a/src/Shh.php b/src/Shh.php index 15a7404..0d76b03 100644 --- a/src/Shh.php +++ b/src/Shh.php @@ -38,7 +38,7 @@ class Shh * @var array */ private $allowedMethods = [ - 'shh_version', 'shh_newIdentity', 'shh_hasIdentity', 'shh_post', 'shh_newFilter' + 'shh_version', 'shh_newIdentity', 'shh_hasIdentity', 'shh_post', 'shh_newFilter', 'shh_uninstallFilter' // doesn't exist: 'shh_newGroup', 'shh_addToGroup' ]; diff --git a/test/unit/ShhApiTest.php b/test/unit/ShhApiTest.php index cf4f0cb..e932952 100644 --- a/test/unit/ShhApiTest.php +++ b/test/unit/ShhApiTest.php @@ -210,7 +210,7 @@ class ShhApiTest extends TestCase // $shh = $this->shh; // $toIdentity = ''; - // // create fromIdentity and toIdentity to prevent unknown identity error + // // create toIdentity to prevent unknown identity error // $shh->newIdentity(function ($err, $identity) use (&$toIdentity) { // if ($err !== null) { // return $this->fail($err->getMessage()); @@ -251,6 +251,48 @@ class ShhApiTest extends TestCase // }); // } + /** + * testUninstallFilter + * Comment because ganache-cli only implement shh_version. + * + * @return void + */ + // public function testUninstallFilter() + // { + // $shh = $this->shh; + // $toIdentity = ''; + // $filter = ''; + + // // create toIdentity to prevent unknown identity error + // $shh->newIdentity(function ($err, $identity) use (&$toIdentity) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $toIdentity = $identity; + + // $this->assertEquals(mb_strlen($identity), 132); + // }); + + // $shh->newFilter([ + // 'to' => $toIdentity, + // 'topics' => ["0x776869737065722d636861742d636c69656e74", "0x4d5a695276454c39425154466b61693532"], + // ], function ($err, $filterId) use (&$filter) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $filter = $filterId; + + // $this->assertTrue(is_string($filterId)); + // }); + + // $shh->uninstallFilter($filter, function ($err, $uninstalled) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $this->assertTrue($uninstalled); + // }); + // } + /** * testWrongParam * We transform data and throw invalid argument exception