Web3 apis and test.
This commit is contained in:
parent
2eefb14b64
commit
e6adbdd303
@ -16,6 +16,13 @@ use Web3\Methods\EthMethod;
|
|||||||
|
|
||||||
class ClientVersion extends EthMethod
|
class ClientVersion extends EthMethod
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* validators
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $validators = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputFormatters
|
* inputFormatters
|
||||||
*
|
*
|
||||||
|
@ -14,9 +14,19 @@ namespace Web3\Methods\Web3;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Web3\Methods\EthMethod;
|
use Web3\Methods\EthMethod;
|
||||||
use Web3\Formatters\HexFormatter;
|
use Web3\Formatters\HexFormatter;
|
||||||
|
use Web3\Validators\StringValidator;
|
||||||
|
|
||||||
class Sha3 extends EthMethod
|
class Sha3 extends EthMethod
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* validators
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $validators = [
|
||||||
|
StringValidator::class
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputFormatters
|
* inputFormatters
|
||||||
*
|
*
|
||||||
|
11
src/Web3.php
11
src/Web3.php
@ -132,11 +132,20 @@ class Web3
|
|||||||
} else {
|
} else {
|
||||||
$methodObject = $this->methods[$method];
|
$methodObject = $this->methods[$method];
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
if ($methodObject->validate($arguments)) {
|
||||||
$inputs = $methodObject->transform($arguments, $methodObject->inputFormatters);
|
$inputs = $methodObject->transform($arguments, $methodObject->inputFormatters);
|
||||||
$methodObject->arguments = $inputs;
|
$methodObject->arguments = $inputs;
|
||||||
|
|
||||||
$this->provider->send($methodObject, $callback);
|
$this->provider->send($methodObject, $callback);
|
||||||
}
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if (is_callable($callback) === true) {
|
||||||
|
call_user_func($callback, $e, null);
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,13 +102,13 @@ class Web3ApiTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testWrongParam()
|
public function testWrongParam()
|
||||||
{
|
{
|
||||||
$this->expectException(RuntimeException::class);
|
// $this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
$web3 = $this->web3;
|
$web3 = $this->web3;
|
||||||
|
|
||||||
$web3->sha3($web3, function ($err, $hash) {
|
$web3->sha3($web3, function ($err, $hash) {
|
||||||
if ($err !== null) {
|
if ($err !== null) {
|
||||||
return $this->fail($err->getMessage());
|
return $this->assertTrue($err instanceof RuntimeException);
|
||||||
}
|
}
|
||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
});
|
});
|
||||||
|
@ -54,4 +54,28 @@ class Web3BatchTest extends TestCase
|
|||||||
$this->assertEquals($data[1], $this->testHash);
|
$this->assertEquals($data[1], $this->testHash);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testWrongParam
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongParam()
|
||||||
|
{
|
||||||
|
$this->expectException(RuntimeException::class);
|
||||||
|
|
||||||
|
$web3 = $this->web3;
|
||||||
|
|
||||||
|
$web3->batch(true);
|
||||||
|
$web3->clientVersion();
|
||||||
|
$web3->sha3($web3);
|
||||||
|
|
||||||
|
$web3->provider->execute(function ($err, $data) {
|
||||||
|
if ($err !== null) {
|
||||||
|
return $this->fail('Got error!');
|
||||||
|
}
|
||||||
|
$this->assertTrue(is_string($data[0]));
|
||||||
|
$this->assertEquals($data[1], $this->testHash);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user