shh_hasIdentity
This commit is contained in:
parent
5d54bc29c3
commit
647da46e09
61
src/Methods/Shh/HasIdentity.php
Normal file
61
src/Methods/Shh/HasIdentity.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of web3.php package.
|
||||||
|
*
|
||||||
|
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||||
|
*
|
||||||
|
* @author Peter Lai <alk03073135@gmail.com>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Web3\Methods\Shh;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use Web3\Methods\EthMethod;
|
||||||
|
use Web3\Validators\IdentityValidator;
|
||||||
|
|
||||||
|
class HasIdentity extends EthMethod
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* validators
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $validators = [
|
||||||
|
IdentityValidator::class
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inputFormatters
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $inputFormatters = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
// }
|
||||||
|
}
|
@ -38,7 +38,7 @@ class Shh
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $allowedMethods = [
|
private $allowedMethods = [
|
||||||
'shh_version'
|
'shh_version', 'shh_newIdentity', 'shh_hasIdentity'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,4 +59,59 @@ class ShhApiTest extends TestCase
|
|||||||
$this->assertEquals(mb_strlen($identity), 132);
|
$this->assertEquals(mb_strlen($identity), 132);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testHasIdentity
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
@ -47,4 +47,28 @@ class ShhBatchTest extends TestCase
|
|||||||
$this->assertEquals(mb_strlen($data[1]), 132);
|
$this->assertEquals(mb_strlen($data[1]), 132);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testWrongParam
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongParam()
|
||||||
|
{
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
|
$shh = $this->shh;
|
||||||
|
|
||||||
|
$shh->batch(true);
|
||||||
|
$shh->version();
|
||||||
|
$shh->hasIdentity('0');
|
||||||
|
|
||||||
|
$shh->provider->execute(function ($err, $data) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail('Got error!');
|
||||||
|
}
|
||||||
|
$this->assertTrue(is_string($data[0]));
|
||||||
|
$this->assertFalse($data[1]);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user