Files
coruna-lab/tests/Unit/SolAddressTest.php
T
2026-09-23 14:26:38 +08:00

51 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Unit;
use App\Services\Chain\SolAddress;
use App\Services\Chain\SolDriver;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class SolAddressTest extends TestCase
{
#[Test]
public function derives_phantom_path_golden_vector(): void
{
if (! function_exists('sodium_crypto_sign_seed_keypair')) {
$this->markTestSkipped('ext-sodium required');
}
// BIP-39 abandon×11+about at m/44'/501'/0'/0' (Phantom/Solflare).
$mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
$address = SolAddress::fromMnemonic($mnemonic, 0);
$this->assertSame('HAgk14JpMQLgt6rVgv7cBQFJWFto5Dqxi472uT3DKpqk', $address);
$this->assertTrue(SolAddress::isValid($address));
}
#[Test]
public function sol_driver_derive_address_matches_sol_address(): void
{
if (! function_exists('sodium_crypto_sign_seed_keypair')) {
$this->markTestSkipped('ext-sodium required');
}
$mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
$driver = new SolDriver;
$this->assertSame(
SolAddress::fromMnemonic($mnemonic, 0),
$driver->deriveAddress($mnemonic, 0),
);
$this->assertSame(
SolAddress::fromMnemonic($mnemonic, 1),
$driver->deriveAddress($mnemonic, 1),
);
$this->assertNotSame(
$driver->deriveAddress($mnemonic, 0),
$driver->deriveAddress($mnemonic, 1),
);
}
}