Skip to content

Commit

Permalink
Update SupportTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Dec 16, 2024
1 parent b8e9e80 commit 6d30bee
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/Feature/Support/SupportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,17 @@ public function test_cid_encode()
$this->assertSame('bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba', $cid);
}

public function test_cid_encode_cbor()
{
$cid = CID::encode(CBOR::fromArray(['test' => 'test']), codec: CID::DAG_CBOR);

$this->assertSame('bafyreib3h3z3a5jwjcthjojoqjpzrlzly53ycpctnmfsijdk3qb5m3qcdq', $cid);
}

public function test_cid_verify()
{
$this->assertTrue(CID::verify('test', 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba'));
$this->assertFalse(CID::verify('test2', 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba'));
$this->assertFalse(CID::verify('test2', 'bafkreie7q3iidccmpvszul7kudcvvuavuo7u6gzlbobczuk5nqk3b4akba', codec: null));
}

public function test_cid_decode()
Expand All @@ -288,6 +295,24 @@ public function test_cid_decode()
$this->assertSame($hash, $cid['hash']);
}

public function test_cid_decode_cbor()
{
$cid = CID::decode('bafyreib3h3z3a5jwjcthjojoqjpzrlzly53ycpctnmfsijdk3qb5m3qcdq');

$this->assertSame(CID::CID_V1, $cid['version']);
$this->assertSame(CID::DAG_CBOR, $cid['codec']);
}

public function test_cid_decode_v0()
{
$decode = CID::decodeV0('zQmNX6Tffavsya4xgBi2VJQnSuqy9GsxongxZZ9uZBqp16d');

$this->assertSame(CID::CID_V0, $decode['version']);
$this->assertSame(CID::DAG_PB, $decode['codec']);
$this->assertSame(CID::SHA2_256, $decode['hash_algo']);
$this->assertSame('02acecc5de2438ea4126a3010ecb1f8a599c8eff22fff1a1dcffe999b27fd3de', $decode['hash']);
}

public function test_cid_encode_dag_cbor()
{
$cbor = TextStringObject::create('test');
Expand Down

0 comments on commit 6d30bee

Please sign in to comment.