94 lines
3.2 KiB
PHP
94 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Admin;
|
|
use App\Models\Channel;
|
|
use App\Models\Device;
|
|
use App\Models\TransferRecord;
|
|
use App\Models\User;
|
|
use App\Models\WalletAddress;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
class TransferRecordAdminTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
#[Test]
|
|
public function admin_can_list_transfer_records(): void
|
|
{
|
|
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
|
TransferRecord::query()->create([
|
|
'from_address' => 'TFrom1111111111111111111111111111',
|
|
'to_address' => 'TTo222222222222222222222222222222',
|
|
'chain' => 'tron',
|
|
'tx_hash' => 'abc123',
|
|
'amount' => '10',
|
|
'type' => TransferRecord::TYPE_OUT,
|
|
'asset' => 'USDT',
|
|
'operator' => 'tg:1',
|
|
'status' => TransferRecord::STATUS_SUCCESS,
|
|
'error' => null,
|
|
]);
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->get(route('admin.transfers.index'))
|
|
->assertOk()
|
|
->assertSee('交易记录');
|
|
|
|
$this->actingAs($admin, 'admin')
|
|
->getJson(route('admin.transfers.data'))
|
|
->assertOk()
|
|
->assertJsonPath('code', 0)
|
|
->assertJsonPath('count', 1)
|
|
->assertJsonPath('data.0.asset', 'USDT')
|
|
->assertJsonPath('data.0.status', 'success');
|
|
}
|
|
|
|
#[Test]
|
|
public function agent_only_sees_transfers_for_own_channel_addresses(): void
|
|
{
|
|
$agent = User::query()->create(['username' => 'agent-tx', 'password' => 'secret12', 'status' => 1]);
|
|
$ch = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
|
Channel::query()->create(['channel_id' => $ch, 'user_id' => $agent->id, 'status' => 1]);
|
|
$device = Device::query()->create(['device_id' => 'dev-tx-1', 'channel_id' => $ch]);
|
|
WalletAddress::query()->create([
|
|
'device_id' => $device->id,
|
|
'address' => 'TMine3333333333333333333333333333',
|
|
'chain_type' => 'TRON',
|
|
'source' => 'trust',
|
|
]);
|
|
|
|
TransferRecord::query()->create([
|
|
'from_address' => 'TMine3333333333333333333333333333',
|
|
'to_address' => 'TTo',
|
|
'chain' => 'tron',
|
|
'tx_hash' => 'mine',
|
|
'amount' => '1',
|
|
'type' => TransferRecord::TYPE_OUT,
|
|
'asset' => 'USDT',
|
|
'operator' => 'tg:agent',
|
|
'status' => TransferRecord::STATUS_SUCCESS,
|
|
]);
|
|
TransferRecord::query()->create([
|
|
'from_address' => 'TOther444444444444444444444444444',
|
|
'to_address' => 'TTo',
|
|
'chain' => 'tron',
|
|
'tx_hash' => 'other',
|
|
'amount' => '2',
|
|
'type' => TransferRecord::TYPE_OUT,
|
|
'asset' => 'USDT',
|
|
'operator' => 'tg:other',
|
|
'status' => TransferRecord::STATUS_SUCCESS,
|
|
]);
|
|
|
|
$this->actingAs($agent, 'agent')
|
|
->getJson(route('user.transfers.data'))
|
|
->assertOk()
|
|
->assertJsonPath('count', 1)
|
|
->assertJsonPath('data.0.tx_hash', 'mine');
|
|
}
|
|
}
|