Add Web3 tests.

This commit is contained in:
sc0Vu 2018-02-07 11:13:55 +08:00
parent 718a913902
commit 9e75e523be
2 changed files with 33 additions and 1 deletions

View File

@ -3,6 +3,7 @@
namespace Test\Unit; namespace Test\Unit;
use RuntimeException; use RuntimeException;
use InvalidArgumentException;
use Test\TestCase; use Test\TestCase;
class Web3ApiTest extends TestCase class Web3ApiTest extends TestCase
@ -113,4 +114,18 @@ class Web3ApiTest extends TestCase
$this->assertTrue(true); $this->assertTrue(true);
}); });
} }
/**
* testWrongCallback
*
* @return void
*/
public function testWrongCallback()
{
$this->expectException(InvalidArgumentException::class);
$web3 = $this->web3;
$web3->sha3('hello world');
}
} }

View File

@ -49,7 +49,8 @@ class Web3Test extends TestCase
*/ */
public function testInstance() public function testInstance()
{ {
$web3 = $this->web3; $requestManager = new HttpRequestManager('http://localhost:8545');
$web3 = new Web3(new HttpProvider($requestManager));
$this->assertTrue($web3->provider instanceof HttpProvider); $this->assertTrue($web3->provider instanceof HttpProvider);
$this->assertTrue($web3->provider->requestManager instanceof RequestManager); $this->assertTrue($web3->provider->requestManager instanceof RequestManager);
@ -72,5 +73,21 @@ class Web3Test extends TestCase
$web3->provider = new HttpProvider($requestManager); $web3->provider = new HttpProvider($requestManager);
$this->assertEquals($web3->provider->requestManager->host, 'http://localhost:8545'); $this->assertEquals($web3->provider->requestManager->host, 'http://localhost:8545');
$web3->provider = null;
$this->assertEquals($web3->provider->requestManager->host, 'http://localhost:8545');
}
/**
* testCallThrowRuntimeException
*
* @return void
*/
public function testCallThrowRuntimeException()
{
$this->expectException(RuntimeException::class);
$web3 = new Web3(null);
$web3->sha3('hello world');
} }
} }