Skip to content

Commit 4842eaa

Browse files
committed
test: Added IntegratedAddressTest and AlreadyIntegratedAddressException
1 parent 995a4f2 commit 4842eaa

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/Enum/ErrorCode.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use RefRing\MoneroRpcPhp\Exception\AccountIndexOutOfBoundException;
88
use RefRing\MoneroRpcPhp\Exception\AddressIndexOutOfBoundException;
99
use RefRing\MoneroRpcPhp\Exception\AddressNotInWalletException;
10+
use RefRing\MoneroRpcPhp\Exception\AlreadyIntegratedAddressException;
1011
use RefRing\MoneroRpcPhp\Exception\AttributeNotFoundException;
1112
use RefRing\MoneroRpcPhp\Exception\AuthenticationException;
1213
use RefRing\MoneroRpcPhp\Exception\BlockNotAcceptedException;
@@ -56,6 +57,7 @@ enum ErrorCode: string
5657
case TransactionHasNoDestination = "Transaction has no destination";
5758
case InvalidHostOrSubnet = "Unsupported host/subnet type";
5859
case NoIpOrHostSupplied = "No ip/host supplied";
60+
case AlreadyIntegratedAddress = "Already integrated address";
5961

6062
public static function getErrorCodeFromString(string $error): self
6163
{
@@ -129,6 +131,7 @@ public function toException(int|string ...$placeHolders): MoneroRpcException
129131
self::TransactionHasNoDestination => new InvalidDestinationException($message),
130132
self::InvalidHostOrSubnet => new InvalidHostOrSubnetException($message),
131133
self::NoIpOrHostSupplied => new NoIpOrHostSuppliedException($message),
134+
self::AlreadyIntegratedAddress => new AlreadyIntegratedAddressException($message),
132135
};
133136

134137
return $exception;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RefRing\MoneroRpcPhp\Exception;
6+
7+
use Exception;
8+
9+
final class AlreadyIntegratedAddressException extends Exception implements MoneroRpcException
10+
{
11+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RefRing\MoneroRpcPhp\Tests\integration;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use RefRing\MoneroRpcPhp\ClientBuilder;
9+
use RefRing\MoneroRpcPhp\Exception\AlreadyIntegratedAddressException;
10+
use RefRing\MoneroRpcPhp\Exception\InvalidAddressException;
11+
use RefRing\MoneroRpcPhp\Exception\InvalidPaymentIdException;
12+
use RefRing\MoneroRpcPhp\Model\Address;
13+
use RefRing\MoneroRpcPhp\Tests\TestHelper;
14+
use RefRing\MoneroRpcPhp\WalletRpcClient;
15+
16+
class IntegratedAddressTest extends TestCase
17+
{
18+
private const SEED = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted';
19+
private const WALLET_ADDRESS = '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm';
20+
private const PAYMENT_ID_1 = '0123456789abcdef';
21+
private const INTEGRATED_ADDRESS_1 = '4CMe2PUhs4J4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfSbLRB61BQVATzerHGj';
22+
23+
private const DIFFERENT_ADDRESS = '46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK';
24+
private const PAYMENT_ID_2 = '1122334455667788';
25+
private const INTEGRATED_ADDRESS_2 = '4GYjoMG9Y2BBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCVSs1ZojwrDCGS5rUuo';
26+
27+
private static WalletRpcClient $rpcClient;
28+
29+
public static function setUpBeforeClass(): void
30+
{
31+
self::$rpcClient = (new ClientBuilder(getenv('WALLET_RPC_URL')))
32+
->buildWalletClient();
33+
34+
// Close any open wallet, then restore the test wallet
35+
try {
36+
self::$rpcClient->closeWallet();
37+
} catch (\Throwable) {
38+
// Ignore if no wallet is loaded
39+
}
40+
41+
$result = self::$rpcClient->restoreDeterministicWallet(TestHelper::getRandomWalletName(), '', self::SEED);
42+
self::assertSame(self::WALLET_ADDRESS, (string) $result->address);
43+
self::assertSame(self::SEED, $result->seed);
44+
}
45+
46+
public function testMakeIntegratedAddressWithLocalAddress(): void
47+
{
48+
$result = self::$rpcClient->makeIntegratedAddress(null, self::PAYMENT_ID_1);
49+
50+
$this->assertSame(self::INTEGRATED_ADDRESS_1, $result->integratedAddress);
51+
$this->assertSame(self::PAYMENT_ID_1, $result->paymentId);
52+
}
53+
54+
public function testSplitIntegratedAddressLocal(): void
55+
{
56+
$result = self::$rpcClient->splitIntegratedAddress(self::INTEGRATED_ADDRESS_1);
57+
58+
$this->assertSame(self::WALLET_ADDRESS, (string) $result->standardAddress);
59+
$this->assertSame(self::PAYMENT_ID_1, $result->paymentId);
60+
}
61+
62+
public function testMakeIntegratedAddressWithDifferentAddress(): void
63+
{
64+
$result = self::$rpcClient->makeIntegratedAddress(self::DIFFERENT_ADDRESS, self::PAYMENT_ID_2);
65+
66+
$this->assertSame(self::INTEGRATED_ADDRESS_2, $result->integratedAddress);
67+
$this->assertSame(self::PAYMENT_ID_2, $result->paymentId);
68+
}
69+
70+
public function testSplitIntegratedAddressDifferent(): void
71+
{
72+
$result = self::$rpcClient->splitIntegratedAddress(self::INTEGRATED_ADDRESS_2);
73+
74+
$this->assertSame(self::DIFFERENT_ADDRESS, (string) $result->standardAddress);
75+
$this->assertSame(self::PAYMENT_ID_2, $result->paymentId);
76+
}
77+
78+
public function testBadPaymentId(): void
79+
{
80+
$this->expectException(InvalidPaymentIdException::class);
81+
self::$rpcClient->makeIntegratedAddress(self::DIFFERENT_ADDRESS, '11223344556677880');
82+
83+
$this->expectException(InvalidPaymentIdException::class);
84+
self::$rpcClient->makeIntegratedAddress(self::DIFFERENT_ADDRESS, '112233445566778');
85+
86+
$this->expectException(InvalidPaymentIdException::class);
87+
self::$rpcClient->makeIntegratedAddress(self::DIFFERENT_ADDRESS, '112233445566778g');
88+
89+
$this->expectException(InvalidPaymentIdException::class);
90+
self::$rpcClient->makeIntegratedAddress(self::DIFFERENT_ADDRESS, '1122334455667788112233445566778811223344556677881122334455667788');
91+
}
92+
93+
public function testMakeIntegratedAddressWithBadStandardAddress(): void
94+
{
95+
$this->expectException(InvalidAddressException::class);
96+
self::$rpcClient->makeIntegratedAddress('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerr', self::PAYMENT_ID_2);
97+
}
98+
99+
public function testMakeIntegratedAddressWithIntegratedAddressAsStandardAddress(): void
100+
{
101+
$this->expectException(AlreadyIntegratedAddressException::class);
102+
// Using an integrated address where a standard address is expected
103+
self::$rpcClient->makeIntegratedAddress(self::INTEGRATED_ADDRESS_2, self::PAYMENT_ID_2);
104+
}
105+
}

0 commit comments

Comments
 (0)