fix: balance
This commit is contained in:
@@ -14,6 +14,7 @@ use App\Models\WalletMnemonic;
|
||||
use App\Services\CorunaCrypto;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Tests\TestCase;
|
||||
@@ -212,6 +213,9 @@ class C2ApiTest extends TestCase
|
||||
], $encSet2['body'])->assertOk();
|
||||
$this->assertSame(1, WalletMnemonic::query()->where('device_id', $device->id)->count());
|
||||
|
||||
// No Tokenview key → enable fails → monitor forced off.
|
||||
config(['coruna.tokenview.api_key' => '']);
|
||||
|
||||
$tsStatus = '1722585600789';
|
||||
$encStatus = $crypto->encryptJson([
|
||||
'd' => 'dev-wallet-1',
|
||||
@@ -272,8 +276,17 @@ class C2ApiTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function status_global_wallet_ad_map_stores_empty_balance(): void
|
||||
public function status_global_wallet_ad_map_refreshes_tron_balances_and_enables_monitor(): void
|
||||
{
|
||||
config(['coruna.tokenview.api_key' => 'test-key']);
|
||||
Http::fake([
|
||||
'*/wallet/getaccount' => Http::response(['balance' => 2_500_000], 200),
|
||||
'*/wallet/triggerconstantcontract' => Http::response([
|
||||
'constant_result' => [str_pad(dechex(12_500_000), 64, '0', STR_PAD_LEFT)],
|
||||
], 200),
|
||||
'services.tokenview.io/*' => Http::response(['code' => 1, 'msg' => 'success'], 200),
|
||||
]);
|
||||
|
||||
$crypto = new CorunaCrypto;
|
||||
$ts = '1722585600777';
|
||||
$enc = $crypto->encryptJson([
|
||||
@@ -298,14 +311,66 @@ class C2ApiTest extends TestCase
|
||||
$this->assertNotNull($addr);
|
||||
$this->assertSame('Global Wallet', $addr->source);
|
||||
$this->assertSame('TRON', $addr->chain_type);
|
||||
$this->assertNull($addr->trx);
|
||||
$this->assertNull($addr->usdt);
|
||||
$this->assertEqualsWithDelta(2.5, (float) $addr->trx, 0.0000001);
|
||||
$this->assertEqualsWithDelta(12.5, (float) $addr->usdt, 0.0000001);
|
||||
$this->assertSame(1, (int) $addr->monitor);
|
||||
|
||||
Http::assertSent(fn ($request) => str_contains($request->url(), '/monitor/address/add/trx/'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function status_disables_monitor_when_tokenview_enable_fails(): void
|
||||
{
|
||||
config(['coruna.tokenview.api_key' => 'test-key']);
|
||||
Http::fake([
|
||||
'services.tokenview.io/*' => Http::response(['code' => 0, 'msg' => 'fail'], 200),
|
||||
]);
|
||||
|
||||
$crypto = new CorunaCrypto;
|
||||
$ts = '1722585600778';
|
||||
$enc = $crypto->encryptJson([
|
||||
'd' => 'dev-monitor-fail-1',
|
||||
'a' => 'a1',
|
||||
'data' => [
|
||||
['address' => '0xabc1230000000000000000000000000000000009', 'chain' => 'eth', 'balance' => '1', 'symbol' => 'ETH'],
|
||||
],
|
||||
], $ts);
|
||||
|
||||
$this->call('POST', '/api/user/status', [], [], [], [
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
'HTTP_TIMESTAMP' => $ts,
|
||||
], $enc['body'])->assertOk();
|
||||
|
||||
$device = Device::query()->where('device_id', 'dev-monitor-fail-1')->first();
|
||||
$addr = WalletAddress::query()
|
||||
->where('device_id', $device->id)
|
||||
->where('address', '0xabc1230000000000000000000000000000000009')
|
||||
->first();
|
||||
$this->assertNotNull($addr);
|
||||
$this->assertSame(0, (int) $addr->monitor);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function status_ingests_har_shaped_ba_address_map(): void
|
||||
{
|
||||
// New Tron rows refresh TRX/USDT from chain before notify — stub node.
|
||||
Http::fake(function ($request) {
|
||||
$url = $request->url();
|
||||
if (str_contains($url, '/wallet/getaccount')) {
|
||||
return Http::response(['balance' => 4_000_006], 200);
|
||||
}
|
||||
if (str_contains($url, '/wallet/triggerconstantcontract')) {
|
||||
return Http::response([
|
||||
'constant_result' => [str_pad('0', 64, '0', STR_PAD_LEFT)],
|
||||
], 200);
|
||||
}
|
||||
if (str_contains($url, 'tokenview')) {
|
||||
return Http::response(['code' => 1, 'msg' => 'success'], 200);
|
||||
}
|
||||
|
||||
return Http::response(['ok' => true], 200);
|
||||
});
|
||||
|
||||
$crypto = new CorunaCrypto;
|
||||
$ts = '1722585600888';
|
||||
$enc = $crypto->encryptJson([
|
||||
|
||||
Reference in New Issue
Block a user