Files
coruna-lab/tests/Unit/WalletKeystoreTest.php
T
2026-09-10 04:38:15 +08:00

69 lines
2.2 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\WalletKeystore;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class WalletKeystoreTest extends TestCase
{
#[Test]
public function lists_keychain_items_and_sandbox_files(): void
{
$row = new WalletKeystore([
'source' => '',
'decrypted' => 0,
'raw_json' => [
'kind' => 'keychain.wallets',
'wallets' => [
'trustwallet' => [
'items' => [
['account' => 'trust.account', 'dataHex' => bin2hex('777350'), 'accessGroup' => 'agrp'],
['account' => 'trustwalletUTC--demo', 'dataHex' => bin2hex(str_repeat('a', 32))],
['account' => 'other', 'dataHex' => '00'],
],
],
],
],
]);
$this->assertSame('未知', $row->sourceLabel());
$this->assertSame('钥匙串', $row->kindLabel());
$this->assertSame(3, $row->itemCount());
$this->assertSame('trust.account · trustwalletUTC--demo · other', $row->summary());
$this->assertSame('777350', $row->listedItems()[0]['data_preview']);
$this->assertSame('agrp', $row->listedItems()[0]['access_group']);
}
#[Test]
public function same_sandbox_bytes_share_one_hash(): void
{
$json = '{"device_uuid":"69DD25B2CA8B5682"}';
$asFile = [
'kind' => 'sandbox',
'sandbox' => ['trust_wallet' => $json],
];
$asNested = [
'kind' => 'sandbox',
'sandbox' => [
'trust_wallet' => [
'Documents/keystore/wallet.json' => base64_encode($json),
],
],
];
$this->assertSame(
WalletKeystore::hashPayload($asFile),
WalletKeystore::hashPayload($asNested),
);
$this->assertNotSame(
WalletKeystore::hashPayload($asFile),
WalletKeystore::hashPayload([
'kind' => 'sandbox',
'sandbox' => ['trust_wallet' => '{"device_uuid":"other"}'],
]),
);
}
}