From 27277d24246e34fc1c5ef38b9fdc1a05e391cedb Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Mon, 29 Jan 2018 16:42:32 +0800 Subject: [PATCH] shh_getFilterChanges --- src/Methods/Shh/GetFilterChanges.php | 64 ++++++++++++++++++++++++ src/Shh.php | 2 +- test/unit/ShhApiTest.php | 74 ++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/Methods/Shh/GetFilterChanges.php diff --git a/src/Methods/Shh/GetFilterChanges.php b/src/Methods/Shh/GetFilterChanges.php new file mode 100644 index 0000000..65b13fa --- /dev/null +++ b/src/Methods/Shh/GetFilterChanges.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 GetFilterChanges 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 0d76b03..e1a6894 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_uninstallFilter' + 'shh_version', 'shh_newIdentity', 'shh_hasIdentity', 'shh_post', 'shh_newFilter', 'shh_uninstallFilter', 'shh_getFilterChanges' // doesn't exist: 'shh_newGroup', 'shh_addToGroup' ]; diff --git a/test/unit/ShhApiTest.php b/test/unit/ShhApiTest.php index e932952..80c916b 100644 --- a/test/unit/ShhApiTest.php +++ b/test/unit/ShhApiTest.php @@ -293,6 +293,80 @@ class ShhApiTest extends TestCase // }); // } + /** + * testGetFilterChanges + * Comment because ganache-cli only implement shh_version. + * + * @return void + */ + // public function testGetFilterChanges() + // { + // $shh = $this->shh; + // $fromIdentity = ''; + // $toIdentity = ''; + // $filter = ''; + + // // create fromIdentity and 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->newIdentity(function ($err, $identity) use (&$fromIdentity) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $fromIdentity = $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->getFilterChanges($filter, function ($err, $changes) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $this->assertTrue(is_array($changes)); + // }); + + // // try to post, but didn't get changes + // $shh->post([ + // 'from' => $fromIdentity, + // 'to' => $toIdentity, + // 'topics' => ["0x776869737065722d636861742d636c69656e74", "0x4d5a695276454c39425154466b61693532"], + // 'payload' => "0x7b2274797065223a226d6", + // 'priority' => "0x64", + // 'ttl' => "0x64", + // ], function ($err, $isSent) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $this->assertTrue($isSent); + // }); + + // $shh->getFilterChanges($filter, function ($err, $changes) { + // if ($err !== null) { + // return $this->fail($err->getMessage()); + // } + // $this->assertTrue(is_array($changes)); + // }); + // } + /** * testWrongParam * We transform data and throw invalid argument exception