feat: autotransfer

This commit is contained in:
hashbro
2026-08-17 02:03:17 +08:00
parent 376b442880
commit a32043df71
42 changed files with 3268 additions and 256 deletions
+52 -3
View File
@@ -55,8 +55,20 @@ class WalletBalanceServiceTest extends TestCase
}
#[Test]
public function skips_non_tron_chains(): void
public function refreshes_eth_and_persists_to_address_row(): void
{
Http::fake([
'*/v1/accounts/*' => Http::response(['data' => []], 200),
]);
$eth = \Mockery::mock(\App\Services\Chain\EthDriver::class);
$eth->shouldReceive('getNativeBalance')->once()->andReturn('1.25');
$eth->shouldReceive('getTokenBalance')->once()->andReturn('9.5');
$manager = \Mockery::mock(\App\Services\Chain\ChainManager::class);
$manager->shouldReceive('resolve')->with('eth')->andReturn($eth);
$this->app->instance(\App\Services\Chain\ChainManager::class, $manager);
config(['coruna.eth.usdt_contract' => '0xdac17f958d2ee523a2206206994597c13d831ec7']);
$device = Device::query()->create([
'device_id' => 'dev-bal-2',
'channel_id' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
@@ -67,12 +79,49 @@ class WalletBalanceServiceTest extends TestCase
'chain_type' => 'ETH',
'source' => 'MetaMask',
'eth' => 1.0,
'usdt' => 0,
'monitor' => 1,
]);
$ok = app(WalletBalanceService::class)->refresh($addr);
$this->assertFalse($ok);
$this->assertTrue($ok);
$addr->refresh();
$this->assertEqualsWithDelta(1.0, (float) $addr->eth, 0.0000001);
$this->assertEqualsWithDelta(1.25, (float) $addr->eth, 0.0000001);
$this->assertEqualsWithDelta(9.5, (float) $addr->usdt, 0.0000001);
}
#[Test]
public function refresh_persists_even_when_balances_unchanged(): void
{
Http::fake([
'*/v1/accounts/*' => Http::response([
'data' => [[
'balance' => 0,
'trc20' => [],
]],
'success' => true,
], 200),
]);
$device = Device::query()->create([
'device_id' => 'dev-bal-persist',
'channel_id' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
]);
$addr = WalletAddress::query()->create([
'device_id' => $device->id,
'address' => 'TKKyetwdwuv6fTWVMPsdQUZYwB7yiNwRp6',
'chain_type' => 'TRON',
'source' => 'imToken',
'trx' => 0,
'usdt' => 0,
]);
$before = (string) $addr->updated_at;
sleep(1);
$this->assertTrue(app(WalletBalanceService::class)->refresh($addr));
$addr->refresh();
$this->assertNotSame($before, (string) $addr->updated_at);
$this->assertEqualsWithDelta(0.0, (float) $addr->trx, 0.0000001);
$this->assertEqualsWithDelta(0.0, (float) $addr->usdt, 0.0000001);
}
}