fix: balance

This commit is contained in:
hashbro
2026-08-10 04:49:36 +08:00
parent aad44bf52e
commit c3d9871ae3
9 changed files with 360 additions and 19 deletions
+53
View File
@@ -97,6 +97,59 @@ class TokenviewWebhookTest extends TestCase
$this->assertSame(1, TokenviewEvent::query()->count());
}
#[Test]
public function webhook_refreshes_tron_balances_from_chain_instead_of_delta(): void
{
config(['coruna.tokenview.sign_key' => '']);
Http::fake([
'*/wallet/getaccount' => Http::response(['balance' => 9_000_000], 200),
'*/wallet/triggerconstantcontract' => Http::response([
'constant_result' => [str_pad(dechex(50_000_000), 64, '0', STR_PAD_LEFT)],
], 200),
'api.telegram.org/*' => Http::response(['ok' => true], 200),
]);
config([
'coruna.telegram.bot_token' => 'bot-token',
'coruna.telegram.owner_chat_id' => '12345',
]);
$addr = $this->seedMonitoredAddress([
'address' => 'TKKyetwdwuv6fTWVMPsdQUZYwB7yiNwRp6',
'chain_type' => 'TRON',
'trx' => 1.0,
'usdt' => 10.0,
'eth' => null,
]);
$payload = [
'address' => 'TKKyetwdwuv6fTWVMPsdQUZYwB7yiNwRp6',
'txid' => 'tron-txid-refresh-1',
'coin' => 'TRX',
'tokenSymbol' => 'USDT',
'tokenValue' => '5',
'value' => '0.1',
];
$this->postJson('/hooks/tokenview', $payload)->assertOk()->assertSee('ok');
$addr->refresh();
// Live chain balances win over webhook deltas.
$this->assertEqualsWithDelta(9.0, (float) $addr->trx, 0.0000001);
$this->assertEqualsWithDelta(50.0, (float) $addr->usdt, 0.0000001);
Http::assertSent(function ($request) {
if (! str_contains($request->url(), 'api.telegram.org')) {
return false;
}
$text = (string) ($request->data()['text'] ?? '');
return str_contains($text, 'Balance Inbound')
&& str_contains($text, '+5 USDT')
&& str_contains($text, 'Balance')
&& str_contains($text, 'USDT');
});
}
#[Test]
public function webhook_ignores_address_when_monitor_off(): void
{