This commit is contained in:
hashbro
2026-08-08 05:09:01 +08:00
parent 03a40105fc
commit 74a67c3900
523 changed files with 669 additions and 5965 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
namespace Tests\Unit;
use App\Services\CorunaCrypto;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class CorunaCryptoTest extends TestCase
{
#[Test]
public function session_key_matches_python_vector(): void
{
$crypto = new CorunaCrypto;
$this->assertSame('d2dbe79fbd3f94d09c16a4958b78d1d3', $crypto->deriveArchivePassword(0));
$this->assertSame('7@Lb"`W5_7gXN;68', $crypto->sessionKey());
$this->assertSame(
'9bcc53d7b7523451c4cc2923205575087e6ed47c9fd733be68b76a31ef1be1e4',
hash('sha256', $crypto->sessionKey())
);
}
#[Test]
public function encrypt_decrypt_round_trip(): void
{
$crypto = new CorunaCrypto;
$payload = ['id' => 'lab-device', 'pn' => 'io.metamask', 'apps' => ['io.metamask']];
$ts = '1722585600000';
$enc = $crypto->encryptJson($payload, $ts);
$this->assertSame($ts, $enc['timestamp']);
$this->assertSame($payload, $crypto->decryptJsonBody($enc['body'], $enc['timestamp']));
}
#[Test]
public function null_payload_round_trip(): void
{
$crypto = new CorunaCrypto;
$enc = $crypto->encryptJson(null, '1722585600001');
$this->assertNull($crypto->decryptJsonBody($enc['body'], $enc['timestamp']));
}
#[Test]
public function archive_password_appends_batch_base(): void
{
$crypto = new CorunaCrypto;
$this->assertSame($crypto->sessionKey().'0', $crypto->archivePassword('0'));
$this->assertSame($crypto->sessionKey().'1722585600000', $crypto->archivePassword('1722585600000'));
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace Tests\Unit;
use App\Services\IngestService;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class IngestServiceNormalizeTest extends TestCase
{
#[Test]
public function check_multipart_device_key_maps_to_json_form(): void
{
$this->assertSame(
'000430C910E8E526',
IngestService::normalizeDeviceKey('36323545384530313943303334303030')
);
$this->assertSame(
'000430C910E8E526',
IngestService::normalizeDeviceKey('36323545384530313943303334303030')
);
}
#[Test]
public function plain_json_device_key_passes_through(): void
{
$this->assertSame(
'000430C910E8E526',
IngestService::normalizeDeviceKey('000430C910E8E526')
);
$this->assertSame('dev-photo-1', IngestService::normalizeDeviceKey('dev-photo-1'));
$this->assertNull(IngestService::normalizeDeviceKey(null));
$this->assertSame('', IngestService::normalizeDeviceKey(''));
}
#[Test]
public function extract_device_key_normalizes_form_nested_d(): void
{
$ingest = $this->app->make(IngestService::class);
$this->assertSame(
'000430C910E8E526',
$ingest->extractDeviceKey([
'form' => [
'd' => '36323545384530313943303334303030',
'f' => '36323545384530313943303334303030',
],
])
);
}
#[Test]
public function decode_hex_counter_pair_splits_idx_ftu(): void
{
$this->assertSame([0, 7], IngestService::decodeHexCounterPair('000000000007'));
$this->assertSame([7, 0], IngestService::decodeHexCounterPair('000007000000'));
$this->assertSame([1, 2], IngestService::decodeHexCounterPair('000001000002'));
$this->assertSame([null, null], IngestService::decodeHexCounterPair('bad'));
$this->assertSame([null, null], IngestService::decodeHexCounterPair(null));
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Tests\Unit;
use App\Services\Chain\TronDriver;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class TronDriverTest extends TestCase
{
private const MNEMONIC = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
#[Test]
public function derives_known_tron_address_from_bip44_path(): void
{
$driver = new TronDriver;
$this->assertSame(
'TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH',
$driver->deriveAddress(self::MNEMONIC, 0)
);
}
#[Test]
public function validates_tron_base58_addresses(): void
{
$driver = new TronDriver;
$this->assertTrue($driver->isValidAddress('TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH'));
$this->assertFalse($driver->isValidAddress('0xab5c66752a9e8167967685f1450532fb96d5d24f'));
$this->assertFalse($driver->isValidAddress('Tinvalid'));
}
}