Skip to content

Commit

Permalink
isTestOnly flag for Address helper methods, resolve #6
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzaycev committed Aug 28, 2024
1 parent 31064d3 commit 3248fa2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Olifanton/Interop/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,23 @@ public function toString(?bool $isUserFriendly = null,
return $addressBase64;
}

public function asWallet(): string
public function asWallet(bool $isTestOnly = false): string
{
return $this->toString(
isUserFriendly: true,
isUrlSafe: true,
isBounceable: false,
isTestOnly: $isTestOnly,
);
}

public function asContract(): string
public function asContract(bool $isTestOnly = false): string
{
return $this->toString(
isUserFriendly: true,
isUrlSafe: true,
isBounceable: true,
isTestOnly: $isTestOnly,
);
}

Expand Down
32 changes: 32 additions & 0 deletions tests/Olifanton/Interop/Tests/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,36 @@ public function testAddressFromAddress(): void
Bytes::bytesToHexString($addr->getHashPart()),
);
}

public function testAsWallet(): void
{
$this->assertEquals(
"UQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJKZ",
(new Address("0:0000000000000000000000000000000000000000000000000000000000000000"))->asWallet(),
);
}

public function testAsWalletTestnet(): void
{
$this->assertEquals(
"0QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACkT",
(new Address("0:0000000000000000000000000000000000000000000000000000000000000000"))->asWallet(isTestOnly: true),
);
}

public function testAsContract(): void
{
$this->assertEquals(
"EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c",
(new Address("0:0000000000000000000000000000000000000000000000000000000000000000"))->asContract(),
);
}

public function testAsContractTestnet(): void
{
$this->assertEquals(
"kQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHTW",
(new Address("0:0000000000000000000000000000000000000000000000000000000000000000"))->asContract(isTestOnly: true),
);
}
}

0 comments on commit 3248fa2

Please sign in to comment.