From 86b70f26c6763ff3aa32fb325f86faecae78db97 Mon Sep 17 00:00:00 2001 From: sc0Vu Date: Wed, 7 Feb 2018 11:45:08 +0800 Subject: [PATCH] Add Net tests. --- test/unit/NetApiTest.php | 15 +++++++++++++++ test/unit/NetTest.php | 20 +++++++++++++++++++- test/unit/PersonalTest.php | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/unit/NetApiTest.php b/test/unit/NetApiTest.php index 3766a3c..1aab1eb 100644 --- a/test/unit/NetApiTest.php +++ b/test/unit/NetApiTest.php @@ -3,6 +3,7 @@ namespace Test\Unit; use RuntimeException; +use InvalidArgumentException; use Test\TestCase; use phpseclib\Math\BigInteger as BigNumber; @@ -96,4 +97,18 @@ class NetApiTest extends TestCase $this->assertTrue(true); }); } + + /** + * testWrongCallback + * + * @return void + */ + public function testWrongCallback() + { + $this->expectException(InvalidArgumentException::class); + + $net = $this->net; + + $net->version(); + } } \ No newline at end of file diff --git a/test/unit/NetTest.php b/test/unit/NetTest.php index 2e4190c..bff7b4e 100644 --- a/test/unit/NetTest.php +++ b/test/unit/NetTest.php @@ -7,6 +7,7 @@ use Test\TestCase; use Web3\Providers\HttpProvider; use Web3\RequestManagers\RequestManager; use Web3\RequestManagers\HttpRequestManager; +use Web3\Net; class NetTest extends TestCase { @@ -36,7 +37,7 @@ class NetTest extends TestCase */ public function testInstance() { - $net = $this->net; + $net = new Net($this->testHost); $this->assertTrue($net->provider instanceof HttpProvider); $this->assertTrue($net->provider->requestManager instanceof RequestManager); @@ -54,5 +55,22 @@ class NetTest extends TestCase $net->provider = new HttpProvider($requestManager); $this->assertEquals($net->provider->requestManager->host, 'http://localhost:8545'); + + $net->provider = null; + + $this->assertEquals($net->provider->requestManager->host, 'http://localhost:8545'); + } + + /** + * testCallThrowRuntimeException + * + * @return void + */ + public function testCallThrowRuntimeException() + { + $this->expectException(RuntimeException::class); + + $net = new Net(null); + $net->version(); } } \ No newline at end of file diff --git a/test/unit/PersonalTest.php b/test/unit/PersonalTest.php index 5a3689c..1b97b81 100644 --- a/test/unit/PersonalTest.php +++ b/test/unit/PersonalTest.php @@ -70,7 +70,7 @@ class PersonalTest extends TestCase { $this->expectException(RuntimeException::class); - $personal = new personal(null); + $personal = new Personal(null); $personal->newAccount(''); } } \ No newline at end of file