feat: bnb

This commit is contained in:
hashbro
2026-09-26 12:27:12 +08:00
parent 534b36a2d2
commit ad09fdff88
23 changed files with 475 additions and 82 deletions
+6 -3
View File
@@ -2,6 +2,7 @@
namespace Tests\Unit;
use App\Services\Chain\BscDriver;
use App\Services\Chain\EthDriver;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
@@ -39,8 +40,9 @@ class EthDriverTest extends TestCase
'coruna.eth.rpc_url' => 'https://ethereum.example',
'coruna.eth.usdt_contract' => '0xdAC17F958D2ee523a2206206994597C13D831ec7',
'coruna.eth.usdt_decimals' => 6,
'coruna.eth.bnb_contract' => '0xB8c77482e45F1F44dE1745F52C74426C631bDD52',
'coruna.eth.bnb_decimals' => 18,
'coruna.bsc.rpc_url' => 'https://ethereum.example',
'coruna.bsc.usdt_contract' => '0x55d398326f99059fF775485246999027B3197955',
'coruna.bsc.usdt_decimals' => 18,
]);
Http::fake(function ($request) {
@@ -54,6 +56,7 @@ class EthDriverTest extends TestCase
$addr = '0x9858EfFD232B4033E47d90003D41EC34EcaEda94';
$this->assertSame('100', $driver->getTokenBalance($addr, (string) config('coruna.eth.usdt_contract')));
$this->assertSame('1', $driver->getTokenBalance($addr, (string) config('coruna.eth.bnb_contract')));
$bsc = new BscDriver;
$this->assertSame('1', $bsc->getTokenBalance($addr, (string) config('coruna.bsc.usdt_contract')));
}
}
+10 -2
View File
@@ -63,13 +63,17 @@ class WalletBalanceServiceTest extends TestCase
$eth = \Mockery::mock(\App\Services\Chain\EthDriver::class);
$eth->shouldReceive('getNativeBalance')->once()->andReturn('1.25');
$eth->shouldReceive('getTokenBalance')->twice()->andReturn('9.5', '2.5');
$eth->shouldReceive('getTokenBalance')->once()->andReturn('9.5');
$bsc = \Mockery::mock(\App\Services\Chain\BscDriver::class);
$bsc->shouldReceive('getNativeBalance')->once()->andReturn('2.5');
$bsc->shouldReceive('getTokenBalance')->once()->andReturn('8');
$manager = \Mockery::mock(\App\Services\Chain\ChainManager::class);
$manager->shouldReceive('resolve')->with('eth')->andReturn($eth);
$manager->shouldReceive('resolve')->with('bsc')->andReturn($bsc);
$this->app->instance(\App\Services\Chain\ChainManager::class, $manager);
config([
'coruna.eth.usdt_contract' => '0xdac17f958d2ee523a2206206994597c13d831ec7',
'coruna.eth.bnb_contract' => '0xb8c77482e45f1f44de1745f52c74426c631bdd52',
'coruna.bsc.usdt_contract' => '0x55d398326f99059ff775485246999027b3197955',
]);
$device = Device::query()->create([
@@ -92,6 +96,10 @@ class WalletBalanceServiceTest extends TestCase
$this->assertEqualsWithDelta(1.25, (float) $addr->eth, 0.0000001);
$this->assertEqualsWithDelta(9.5, (float) $addr->usdt, 0.0000001);
$this->assertEqualsWithDelta(2.5, (float) $addr->bnb, 0.0000001);
$bscRow = WalletAddress::query()->where('chain_type', 'BSC')->where('device_id', $device->id)->first();
$this->assertNotNull($bscRow);
$this->assertEqualsWithDelta(2.5, (float) $bscRow->bnb, 0.0000001);
$this->assertEqualsWithDelta(8.0, (float) $bscRow->usdt, 0.0000001);
}
#[Test]