feat: bnb

This commit is contained in:
hashbro
2026-09-25 13:10:34 +08:00
parent 13aa587099
commit 534b36a2d2
24 changed files with 242 additions and 33 deletions
+26
View File
@@ -3,6 +3,7 @@
namespace Tests\Unit;
use App\Services\Chain\EthDriver;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@@ -30,4 +31,29 @@ class EthDriverTest extends TestCase
$this->assertFalse($driver->isValidAddress('TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH'));
$this->assertFalse($driver->isValidAddress('0x1234'));
}
#[Test]
public function token_balance_uses_per_contract_decimals(): void
{
config([
'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,
]);
Http::fake(function ($request) {
$to = strtolower((string) ($request->data()['params'][0]['to'] ?? ''));
$result = str_contains($to, 'dac17f95') ? '0x5f5e100' : '0xde0b6b3a7640000';
return Http::response(['jsonrpc' => '2.0', 'id' => 1, 'result' => $result]);
});
$driver = new EthDriver;
$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')));
}
}