BnbScanServiceTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Module\Blockchain\Tests\Unit;
  3. use App\Module\Blockchain\Services\BscScanService;
  4. use App\Module\Transaction\Enums\ACCOUNT_TYPE;
  5. use Tests\TestCase;
  6. use Illuminate\Support\Facades\Http;
  7. use Illuminate\Support\Facades\Cache;
  8. /**
  9. * BscScan API 真实接口测试
  10. * 注意:需要配置有效的BSCSCAN_API_KEY才能运行
  11. */
  12. class BnbScanServiceTest extends TestCase
  13. {
  14. protected BscScanService $service;
  15. protected string $testAddress = '0xc5981423927fC49270477505013222e70E4C9173';
  16. protected string $testTxHash = '0x60d9401026de26d6871ed00e2fbbe8b3ae5349a4d634ae14981653d1ed729a64';
  17. //
  18. public function setUp(): void
  19. {
  20. parent::setUp();
  21. $this->service = new BscScanService();
  22. }
  23. /**
  24. * 测试获取BNB余额
  25. * @test
  26. */
  27. public function testGetBnbBalance()
  28. {
  29. $balance = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::BNB);
  30. dump($balance);
  31. // 验证返回值为数字类型且大于等于0
  32. $this->assertIsNumeric($balance);
  33. $this->assertGreaterThanOrEqual(0, $balance);
  34. $balanceUsdt = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::USDT);
  35. dump($balanceUsdt);
  36. $balanceURAUS = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::URAUS);
  37. dump($balanceURAUS);
  38. }
  39. public function testGetTxInfo()
  40. {
  41. $this->service->enableResponseSaving(true);
  42. $txInfo = $this->service->getTransactionStatus($this->testTxHash, ACCOUNT_TYPE::BNB);
  43. dump($txInfo);
  44. }
  45. }