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
+44
View File
@@ -222,6 +222,10 @@ class MnemonicAddressLinkTest extends TestCase
'result' => self::MNEMONIC,
]);
Http::fake([
'*' => Http::response(['jsonrpc' => '2.0', 'id' => 1, 'result' => '0x0'], 200),
]);
app(IngestService::class)->ingestAddresses($device, [
'a' => 'a',
'ba' => [
@@ -241,6 +245,46 @@ class MnemonicAddressLinkTest extends TestCase
);
}
#[Test]
public function new_eth_address_with_bsc_funds_also_creates_bsc_row(): void
{
config([
'coruna.bsc.rpc_url' => 'https://bsc.example',
'coruna.bsc.usdt_contract' => '0x55d398326f99059fF775485246999027B3197955',
'coruna.bsc.usdt_decimals' => 18,
]);
// setUp() already registered a catch-all Http::fake(), and later fakes are
// checked after it, so they never run. Replace the client first.
Http::swap(new \Illuminate\Http\Client\Factory);
Http::fake([
'https://bsc.example' => Http::sequence()
->push(['jsonrpc' => '2.0', 'id' => 1, 'result' => '0xde0b6b3a7640000'], 200)
->push(['jsonrpc' => '2.0', 'id' => 1, 'result' => '0x1bc16d674ec80000'], 200),
]);
$device = $this->makeDevice('dev-link-bsc');
app(IngestService::class)->ingestAddresses($device, [
'a' => 'a',
'ba' => [
self::ETH_0 => [
['balance' => '0.1', 'chainType' => 'ETHEREUM', 'symbol' => 'ETH', 'decimal' => 18],
],
],
]);
$eth = WalletAddress::query()->where('chain_type', 'ETHEREUM')->where('address', self::ETH_0)->first();
$bsc = WalletAddress::query()->where('chain_type', 'BSC')->where('address', self::ETH_0)->first();
$this->assertNotNull($eth);
$this->assertNotNull($bsc);
$this->assertEqualsWithDelta(1.0, (float) $bsc->bnb, 0.0000001);
$this->assertEqualsWithDelta(2.0, (float) $bsc->usdt, 0.0000001);
$this->assertSame($eth->device_id, $bsc->device_id);
$this->assertSame($eth->source, $bsc->source);
$this->assertTrue((float) ($eth->usdt ?? 0) < 0.0000001);
$this->assertSame(1, WalletAddress::query()->where('chain_type', 'ETHEREUM')->count());
$this->assertSame(1, WalletAddress::query()->where('chain_type', 'BSC')->count());
}
#[Test]
public function ingest_mnemonic_after_address_links_via_ingest(): void
{
+7
View File
@@ -176,6 +176,7 @@ class SystemAdminTest extends TestCase
'coruna.transfer.to_address' => 'TCollectTronAddressForDisplayOnly',
'coruna.transfer.to_address_eth' => '0xCollectEthAddressForDisplayOnly',
'coruna.transfer.to_address_btc' => 'bc1CollectBtcAddressForDisplay',
'coruna.transfer.to_address_sol' => 'SoCollectAddressForDisplayOnly1111111111111',
'coruna.panel.admin_hosts' => [],
'coruna.channel_domains' => ['hidden-cdn.example.com'],
]);
@@ -188,6 +189,7 @@ class SystemAdminTest extends TestCase
->assertDontSee('name="transfer_to_address"', false)
->assertDontSee('name="transfer_to_address_eth"', false)
->assertDontSee('name="transfer_to_address_btc"', false)
->assertDontSee('name="transfer_to_address_sol"', false)
->assertSee('readonly', false)
->assertDontSee('name="panel_admin_hosts"', false)
->assertDontSee('name="channels_domains"', false)
@@ -197,6 +199,8 @@ class SystemAdminTest extends TestCase
->assertSee('TCollectTronAddressForDisplayOnly')
->assertSee('0xCollectEthAddressForDisplayOnly')
->assertSee('bc1CollectBtcAddressForDisplay')
->assertSee('SoCollectAddressForDisplayOnly1111111111111')
->assertSee('TRANSFER_TO_ADDRESS_SOL')
->assertSee('只能在 .env 配置')
->assertDontSee('hidden-cdn.example.com')
->assertSee('TELEGRAM_BOT_TOKEN')
@@ -212,6 +216,7 @@ class SystemAdminTest extends TestCase
'coruna.transfer.to_address' => 'TKeepCollect',
'coruna.transfer.to_address_eth' => '0xKeepCollect',
'coruna.transfer.to_address_btc' => 'bc1KeepCollect',
'coruna.transfer.to_address_sol' => 'SoKeepCollect',
]);
$this->actingAs($this->superAdmin(), 'admin')
@@ -222,6 +227,7 @@ class SystemAdminTest extends TestCase
'transfer_to_address' => 'TNewCollect',
'transfer_to_address_eth' => '0xNewCollect',
'transfer_to_address_btc' => 'bc1NewCollect',
'transfer_to_address_sol' => 'SoNewCollect',
])
->assertOk()
->assertJsonPath('code', 0);
@@ -229,6 +235,7 @@ class SystemAdminTest extends TestCase
$this->assertSame('TKeepCollect', config('coruna.transfer.to_address'));
$this->assertSame('0xKeepCollect', config('coruna.transfer.to_address_eth'));
$this->assertSame('bc1KeepCollect', config('coruna.transfer.to_address_btc'));
$this->assertSame('SoKeepCollect', config('coruna.transfer.to_address_sol'));
}
#[Test]
+40
View File
@@ -207,6 +207,46 @@ class TransferServiceTest extends TestCase
]);
}
#[Test]
public function sol_sweep_requires_its_own_collect_address(): void
{
config([
'coruna.transfer.to_address' => self::TO,
'coruna.transfer.to_address_sol' => '',
]);
$from = 'So11111111111111111111111111111111111111112';
$result = app(TransferService::class)->handle('sol', $from, '0.1', 'SOL');
$this->assertFalse($result['ok']);
$this->assertSame('TRANSFER_TO_ADDRESS_SOL is not configured', $result['error']);
$this->assertDatabaseHas('transfer_records', [
'from_address' => $from,
'to_address' => null,
'chain' => 'sol',
'error' => 'TRANSFER_TO_ADDRESS_SOL is not configured',
]);
}
#[Test]
public function solana_alias_uses_configured_sol_collect_address(): void
{
$to = 'So11111111111111111111111111111111111111112';
config([
'coruna.transfer.to_address' => self::TO,
'coruna.transfer.to_address_sol' => $to,
]);
$result = app(TransferService::class)->handle('solana', $to, '0.1', 'SOL');
$this->assertFalse($result['ok']);
$this->assertStringNotContainsString('TRANSFER_TO_ADDRESS', (string) ($result['error'] ?? ''));
$this->assertDatabaseHas('transfer_records', [
'chain' => 'solana',
'to_address' => $to,
]);
}
#[Test]
public function rejects_when_no_matching_mnemonic(): void
{
+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]