123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace Test\Unit;
- use RuntimeException;
- use InvalidArgumentException;
- use Test\TestCase;
- class Web3ApiTest extends TestCase
- {
-
- protected $testHex = '0x68656c6c6f20776f726c64';
-
- protected $testHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad';
-
- public function setUp()
- {
- parent::setUp();
- }
-
-
- public function testClientVersion()
- {
- $web3 = $this->web3;
- $web3->clientVersion(function ($err, $version) {
- if ($err !== null) {
- return $this->fail($err->getMessage());
- }
- $this->assertTrue(is_string($version));
- });
- }
-
-
- public function testSha3()
- {
- $web3 = $this->web3;
- $web3->sha3($this->testHex, function ($err, $hash) {
- if ($err !== null) {
- return $this->fail($err->getMessage());
- }
- $this->assertEquals($hash, $this->testHash);
- });
- $web3->sha3('hello world', function ($err, $hash) {
- if ($err !== null) {
- return $this->fail($err->getMessage());
- }
- $this->assertEquals($hash, $this->testHash);
- });
- }
-
- public function testUnallowedMethod()
- {
- $this->expectException(RuntimeException::class);
- $web3 = $this->web3;
- $web3->hello(function ($err, $hello) {
- if ($err !== null) {
- return $this->fail($err->getMessage());
- }
- $this->assertTrue(true);
- });
- }
-
- public function testWrongParam()
- {
- $this->expectException(RuntimeException::class);
- $web3 = $this->web3;
- $web3->sha3($web3, function ($err, $hash) {
- if ($err !== null) {
- return $this->fail($err->getMessage());
- }
- $this->assertTrue(true);
- });
- }
-
- public function testWrongCallback()
- {
- $this->expectException(InvalidArgumentException::class);
- $web3 = $this->web3;
- $web3->sha3('hello world');
- }
- }
|