Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
2.9 kB · 100 lines
PHP
at dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101<?php
declare(strict_types=1);
namespace SocialDept\AtpSignals\Tests\Unit;
use PHPUnit\Framework\TestCase;use SocialDept\AtpSignals\Core\CID;
class CIDTest extends TestCase{ public function test_parse_binary_cidv1(): void { // CIDv1: version=1, codec=0x71 (dag-cbor), sha256 hash $hash = str_repeat("\x00", 32); $binary = "\x01\x71\x12\x20" . $hash;
$cid = CID::fromBinary($binary);
$this->assertSame(1, $cid->version); $this->assertSame(0x71, $cid->codec); $this->assertSame("\x12\x20" . $hash, $cid->hash); }
public function test_parse_binary_cidv0(): void { // CIDv0: starts with 0x12 (sha256) 0x20 (32 bytes) $hash = str_repeat("\x00", 32); $binary = "\x12\x20" . $hash;
$cid = CID::fromBinary($binary);
$this->assertSame(0, $cid->version); $this->assertSame(0x70, $cid->codec); // dag-pb $this->assertSame("\x12\x20" . $hash, $cid->hash); }
public function test_to_string_cidv1(): void { $hash = str_repeat("\x00", 32); $binary = "\x01\x71\x12\x20" . $hash; $cid = CID::fromBinary($binary);
$str = $cid->toString();
// Should start with 'b' (base32 prefix) $this->assertStringStartsWith('b', $str);
// Should be able to parse it back $parsed = CID::fromString($str); $this->assertSame($cid->version, $parsed->version); $this->assertSame($cid->codec, $parsed->codec); }
public function test_to_binary_cidv1(): void { $hash = str_repeat("\x00", 32); $binary = "\x01\x71\x12\x20" . $hash; $cid = CID::fromBinary($binary);
$this->assertSame($binary, $cid->toBinary()); }
public function test_round_trip_binary(): void { $hash = hash('sha256', 'test', true); $binary = "\x01\x71\x12\x20" . $hash;
$cid = CID::fromBinary($binary); $encoded = $cid->toBinary(); $decoded = CID::fromBinary($encoded);
$this->assertSame($cid->version, $decoded->version); $this->assertSame($cid->codec, $decoded->codec); $this->assertSame($cid->hash, $decoded->hash); }
public function test_round_trip_string(): void { $hash = hash('sha256', 'test', true); $binary = "\x01\x71\x12\x20" . $hash; $cid = CID::fromBinary($binary);
$str = $cid->toString(); $parsed = CID::fromString($str);
$this->assertSame($cid->version, $parsed->version); $this->assertSame($cid->codec, $parsed->codec); $this->assertSame($cid->hash, $parsed->hash); }
public function test_to_string_magic_method(): void { $hash = str_repeat("\x00", 32); $binary = "\x01\x71\x12\x20" . $hash; $cid = CID::fromBinary($binary);
$this->assertSame($cid->toString(), (string) $cid); }}