EthTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use Test\TestCase;
  5. use Web3\Providers\HttpProvider;
  6. use Web3\Eth;
  7. class EthTest extends TestCase
  8. {
  9. /**
  10. * eth
  11. *
  12. * @var \Web3\Eth
  13. */
  14. protected $eth;
  15. /**
  16. * setUp
  17. *
  18. * @return void
  19. */
  20. public function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->eth = $this->web3->eth;
  24. }
  25. /**
  26. * testInstance
  27. *
  28. * @return void
  29. */
  30. public function testInstance()
  31. {
  32. $eth = new Eth($this->testHost);
  33. $this->assertTrue($eth->provider instanceof HttpProvider);
  34. }
  35. /**
  36. * testSetProvider
  37. *
  38. * @return void
  39. */
  40. public function testSetProvider()
  41. {
  42. $eth = $this->eth;
  43. $eth->provider = new HttpProvider('http://localhost:8545');
  44. $this->assertEquals($eth->provider->host, 'http://localhost:8545');
  45. $eth->provider = null;
  46. $this->assertEquals($eth->provider->host, 'http://localhost:8545');
  47. }
  48. /**
  49. * testCallThrowRuntimeException
  50. *
  51. * @return void
  52. */
  53. public function testCallThrowRuntimeException()
  54. {
  55. $this->expectException(RuntimeException::class);
  56. $eth = new Eth(null);
  57. $eth->protocolVersion();
  58. }
  59. }