diff --git a/src/Methods/Shh/Post.php b/src/Methods/Shh/Post.php new file mode 100644 index 0000000..a4708fb --- /dev/null +++ b/src/Methods/Shh/Post.php @@ -0,0 +1,64 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Shh; + +use InvalidArgumentException; +use Web3\Methods\EthMethod; +use Web3\Formatters\PostFormatter; +use Web3\Validators\PostValidator; + +class Post extends EthMethod +{ + /** + * validators + * + * @var array + */ + protected $validators = [ + PostValidator::class + ]; + + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = [ + PostFormatter::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 87e15e9..dd73e64 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_version', 'shh_newIdentity', 'shh_hasIdentity', 'shh_post' // doesn't exist: 'shh_newGroup', 'shh_addToGroup' ]; diff --git a/test/unit/ShhApiTest.php b/test/unit/ShhApiTest.php index c6567dd..3f0660d 100644 --- a/test/unit/ShhApiTest.php +++ b/test/unit/ShhApiTest.php @@ -138,6 +138,64 @@ class ShhApiTest extends TestCase // }); // } + /** + * testPost + * + * @return void + */ + public function testPost() + { + $shh = $this->shh; + $fromIdentity = ''; + $toIdentity = ''; + + // create fromIdentity and toIdentity to prevent unknown identity error + $shh->newIdentity(function ($err, $identity) use (&$fromIdentity) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $fromIdentity = $identity; + + $this->assertEquals(mb_strlen($identity), 132); + }); + $shh->newIdentity(function ($err, $identity) use (&$toIdentity) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $toIdentity = $identity; + + $this->assertEquals(mb_strlen($identity), 132); + }); + + $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->post([ + 'from' => $fromIdentity, + 'to' => $toIdentity, + 'topics' => ["0x776869737065722d636861742d636c69656e74", "0x4d5a695276454c39425154466b61693532"], + 'payload' => "0x7b2274797065223a226d6", + 'priority' => 123, + 'ttl' => 123, + ], function ($err, $isSent) { + if ($err !== null) { + return $this->fail($err->getMessage()); + } + $this->assertTrue($isSent); + }); + } + /** * testWrongParam * We transform data and throw invalid argument exception