| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 | 
							- <?php
 
- namespace Test\Unit;
 
- use RuntimeException;
 
- use InvalidArgumentException;
 
- use Test\TestCase;
 
- use Web3\Shh;
 
- class ShhApiTest extends TestCase
 
- {
 
-     /**
 
-      * shh
 
-      * 
 
-      * @var Web3\Shh
 
-      */
 
-     protected $shh;
 
-     /**
 
-      * setUp
 
-      * 
 
-      * @return void
 
-      */
 
-     public function setUp()
 
-     {
 
-         parent::setUp();
 
-         $this->shh = $this->web3->shh;
 
-     }
 
-     /**
 
-      * testVersion
 
-      * 
 
-      * @return void
 
-      */    
 
-     public function testVersion()
 
-     {
 
-         $shh = $this->shh;
 
-         $shh->version(function ($err, $version) {
 
-             if ($err !== null) {
 
-                 return $this->fail($err->getMessage());
 
-             }
 
-             $this->assertTrue(is_string($version));
 
-         });
 
-     }
 
-     /**
 
-      * testNewIdentity
 
-      * Comment because ganache-cli only implement shh_version.
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testNewIdentity()
 
-     // {
 
-     //     $shh = $this->shh;
 
-     //     $shh->newIdentity(function ($err, $identity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertEquals(mb_strlen($identity), 132);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testHasIdentity
 
-      * Comment because ganache-cli only implement shh_version.
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testHasIdentity()
 
-     // {
 
-     //     $shh = $this->shh;
 
-     //     $newIdentity = '0x' . implode('', array_fill(0, 120, '0'));
 
-     //     $shh->hasIdentity($newIdentity, function ($err, $hasIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertFalse($hasIdentity);
 
-     //     });
 
-     //     $shh->newIdentity(function ($err, $identity) use (&$newIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $newIdentity = $identity;
 
-     //         $this->assertEquals(mb_strlen($identity), 132);
 
-     //     });
 
-     //     $shh->hasIdentity($newIdentity, function ($err, $hasIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue($hasIdentity);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testNewGroup
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testNewGroup()
 
-     // {
 
-     //     $shh = $this->shh;
 
-     //     $shh->newGroup(function ($err, $group) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertEquals(mb_strlen($group), 132);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testAddToGroup
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testAddToGroup()
 
-     // {
 
-     //     $shh = $this->shh;
 
-     //     $newIdentity = '';
 
-     //     $shh->newIdentity(function ($err, $identity) use (&$newIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $newIdentity = $identity;
 
-     //         $this->assertEquals(mb_strlen($identity), 132);
 
-     //     });
 
-     //     $shh->addToGroup($newIdentity, function ($err, $hasAdded) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue($hasAdded);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testPost
 
-      * Comment because ganache-cli only implement shh_version.
 
-      * 
 
-      * @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);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testNewFilter
 
-      * Comment because ganache-cli only implement shh_version.
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testNewFilter()
 
-     // {
 
-     //     $shh = $this->shh;
 
-     //     $toIdentity = '';
 
-     //     // 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) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(is_string($filterId));
 
-     //     });
 
-     //     $shh->newFilter([
 
-     //         'to' => $toIdentity,
 
-     //         'topics' => [null, "0x776869737065722d636861742d636c69656e74", "0x4d5a695276454c39425154466b61693532"],
 
-     //     ], function ($err, $filterId) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(is_string($filterId));
 
-     //     });
 
-     //     $shh->newFilter([
 
-     //         'to' => $toIdentity,
 
-     //         'topics' => ["0x776869737065722d636861742d636c69656e74", ["0x776869737065722d636861742d636c69656e74", "0x4d5a695276454c39425154466b61693532"]],
 
-     //     ], function ($err, $filterId) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(is_string($filterId));
 
-     //     });
 
-     // }
 
-     /**
 
-      * 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);
 
-     //     });
 
-     // }
 
-     /**
 
-      * 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));
 
-     //     });
 
-     // }
 
-     /**
 
-      * testGetMessages
 
-      * Comment because ganache-cli only implement shh_version.
 
-      * 
 
-      * @return void
 
-      */    
 
-     // public function testGetMessages()
 
-     // {
 
-     //     $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->getMessages($filter, function ($err, $messages) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(is_array($messages));
 
-     //     });
 
-     //     $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->getMessages($filter, function ($err, $messages) use ($fromIdentity, $toIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(is_array($messages));
 
-     //         $this->assertEquals($fromIdentity, $messages[0]->from);
 
-     //         $this->assertEquals($toIdentity, $messages[0]->to);
 
-     //         $this->assertEquals('0x07b2274797065223a226d6', $messages[0]->payload);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testWrongParam
 
-      * We transform data and throw invalid argument exception
 
-      * instead of runtime exception.
 
-      * 
 
-      * @return void
 
-      */
 
-     // public function testWrongParam()
 
-     // {
 
-     //     $this->expectException(RuntimeException::class);
 
-     //     $shh = $this->shh;
 
-     //     $shh->hasIdentity('0', function ($err, $hasIdentity) {
 
-     //         if ($err !== null) {
 
-     //             return $this->fail($err->getMessage());
 
-     //         }
 
-     //         $this->assertTrue(true);
 
-     //     });
 
-     // }
 
-     /**
 
-      * testUnallowedMethod
 
-      * 
 
-      * @return void
 
-      */
 
-     public function testUnallowedMethod()
 
-     {
 
-         $this->expectException(RuntimeException::class);
 
-         $shh = $this->shh;
 
-         $shh->hello(function ($err, $hello) {
 
-             if ($err !== null) {
 
-                 return $this->fail($err->getMessage());
 
-             }
 
-             $this->assertTrue(true);
 
-         });
 
-     }
 
-     /**
 
-      * testWrongCallback
 
-      * 
 
-      * @return void
 
-      */
 
-     public function testWrongCallback()
 
-     {
 
-         $this->expectException(InvalidArgumentException::class);
 
-         $shh = $this->shh;
 
-         $shh->version();
 
-     }
 
- }
 
 
  |