| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Module\Blockchain\Tests\Unit;
- use App\Module\Blockchain\Services\BscScanService;
- use App\Module\Transaction\Enums\ACCOUNT_TYPE;
- use Tests\TestCase;
- use Illuminate\Support\Facades\Http;
- use Illuminate\Support\Facades\Cache;
- /**
- * BscScan API 真实接口测试
- * 注意:需要配置有效的BSCSCAN_API_KEY才能运行
- */
- class BnbScanServiceTest extends TestCase
- {
- protected BscScanService $service;
- protected string $testAddress = '0xc5981423927fC49270477505013222e70E4C9173';
- protected string $testTxHash = '0x60d9401026de26d6871ed00e2fbbe8b3ae5349a4d634ae14981653d1ed729a64';
- //
- public function setUp(): void
- {
- parent::setUp();
- $this->service = new BscScanService();
- }
- /**
- * 测试获取BNB余额
- * @test
- */
- public function testGetBnbBalance()
- {
- $balance = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::BNB);
- dump($balance);
- // 验证返回值为数字类型且大于等于0
- $this->assertIsNumeric($balance);
- $this->assertGreaterThanOrEqual(0, $balance);
- $balanceUsdt = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::USDT);
- dump($balanceUsdt);
- $balanceURAUS = $this->service->getBalance($this->testAddress, ACCOUNT_TYPE::URAUS);
- dump($balanceURAUS);
- }
- public function testGetTxInfo()
- {
- $this->service->enableResponseSaving(true);
- $txInfo = $this->service->getTransactionStatus($this->testTxHash, ACCOUNT_TYPE::BNB);
- dump($txInfo);
- }
- }
|