From 49e19415b3433f035498e4aebcc290a7fabe2b36 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 7 Feb 2018 11:48:37 +0800 Subject: [PATCH] Add Eth tests. --- test/unit/EthApiTest.php | 15 +++++++++++++++ test/unit/EthTest.php | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/test/unit/EthApiTest.php b/test/unit/EthApiTest.php index 0d4cc4b..5a267fb 100644 --- a/test/unit/EthApiTest.php +++ b/test/unit/EthApiTest.php @@ -3,6 +3,7 @@ namespace Test\Unit; use RuntimeException; +use InvalidArgumentException; use Test\TestCase; use phpseclib\Math\BigInteger as BigNumber; @@ -825,4 +826,18 @@ class EthApiTest extends TestCase $this->assertTrue(true); }); } + + /** + * testWrongCallback + * + * @return void + */ + public function testWrongCallback() + { + $this->expectException(InvalidArgumentException::class); + + $eth = $this->eth; + + $eth->protocolVersion(); + } } \ No newline at end of file diff --git a/test/unit/EthTest.php b/test/unit/EthTest.php index 8b587fc..50295bd 100644 --- a/test/unit/EthTest.php +++ b/test/unit/EthTest.php @@ -7,6 +7,7 @@ use Test\TestCase; use Web3\Providers\HttpProvider; use Web3\RequestManagers\RequestManager; use Web3\RequestManagers\HttpRequestManager; +use Web3\Eth; class EthTest extends TestCase { @@ -36,7 +37,7 @@ class EthTest extends TestCase */ public function testInstance() { - $eth = $this->eth; + $eth = new Eth($this->testHost); $this->assertTrue($eth->provider instanceof HttpProvider); $this->assertTrue($eth->provider->requestManager instanceof RequestManager); @@ -54,5 +55,22 @@ class EthTest extends TestCase $eth->provider = new HttpProvider($requestManager); $this->assertEquals($eth->provider->requestManager->host, 'http://localhost:8545'); + + $eth->provider = null; + + $this->assertEquals($eth->provider->requestManager->host, 'http://localhost:8545'); + } + + /** + * testCallThrowRuntimeException + * + * @return void + */ + public function testCallThrowRuntimeException() + { + $this->expectException(RuntimeException::class); + + $eth = new Eth(null); + $eth->protocolVersion(); } } \ No newline at end of file