NetApiTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Test\Unit;
  3. use RuntimeException;
  4. use InvalidArgumentException;
  5. use Test\TestCase;
  6. use phpseclib\Math\BigInteger as BigNumber;
  7. class NetApiTest extends TestCase
  8. {
  9. /**
  10. * net
  11. *
  12. * @var Web3\Net
  13. */
  14. protected $net;
  15. /**
  16. * setUp
  17. *
  18. * @return void
  19. */
  20. public function setUp()
  21. {
  22. parent::setUp();
  23. $this->net = $this->web3->net;
  24. }
  25. /**
  26. * testVersion
  27. *
  28. * @return void
  29. */
  30. public function testVersion()
  31. {
  32. $net = $this->net;
  33. $net->version(function ($err, $version) {
  34. if ($err !== null) {
  35. return $this->fail($err->getMessage());
  36. }
  37. $this->assertTrue(is_string($version));
  38. });
  39. }
  40. /**
  41. * testPeerCount
  42. *
  43. * @return void
  44. */
  45. public function testPeerCount()
  46. {
  47. $net = $this->net;
  48. $net->peerCount(function ($err, $count) {
  49. if ($err !== null) {
  50. return $this->fail($err->getMessage());
  51. }
  52. $this->assertTrue($count instanceof BigNumber);
  53. });
  54. }
  55. /**
  56. * testListening
  57. *
  58. * @return void
  59. */
  60. public function testListening()
  61. {
  62. $net = $this->net;
  63. $net->listening(function ($err, $net) {
  64. if ($err !== null) {
  65. return $this->fail($err->getMessage());
  66. }
  67. $this->assertTrue(is_bool($net));
  68. });
  69. }
  70. /**
  71. * testUnallowedMethod
  72. *
  73. * @return void
  74. */
  75. public function testUnallowedMethod()
  76. {
  77. $this->expectException(RuntimeException::class);
  78. $net = $this->net;
  79. $net->hello(function ($err, $hello) {
  80. if ($err !== null) {
  81. return $this->fail($err->getMessage());
  82. }
  83. $this->assertTrue(true);
  84. });
  85. }
  86. /**
  87. * testWrongCallback
  88. *
  89. * @return void
  90. */
  91. public function testWrongCallback()
  92. {
  93. $this->expectException(InvalidArgumentException::class);
  94. $net = $this->net;
  95. $net->version();
  96. }
  97. }