2424use RefRing \MoneroRpcPhp \Exception \TagNotFoundException ;
2525use RefRing \MoneroRpcPhp \Exception \WalletExistsException ;
2626use RefRing \MoneroRpcPhp \Model \Address ;
27+ use RefRing \MoneroRpcPhp \Tests \Attribute \RequiresMoneroVersion ;
28+ use RefRing \MoneroRpcPhp \Tests \Trait \RequiresMoneroVersionTrait ;
2729use RefRing \MoneroRpcPhp \Model \Amount ;
2830use RefRing \MoneroRpcPhp \Tests \KeyPairHelper ;
2931use RefRing \MoneroRpcPhp \Tests \TestHelper ;
3638
3739class BasicWalletTest extends TestCase
3840{
41+ use RequiresMoneroVersionTrait;
42+
3943 private static WalletRpcClient $ rpcClient ;
4044 private static DaemonRpcClient $ daemonRpcClient ;
4145
@@ -57,6 +61,16 @@ public static function setUpBeforeClass(): void
5761 self ::$ daemonRpcClient = (new ClientBuilder (getenv ('DAEMON_RPC_URL ' )))->buildDaemonClient ();
5862 }
5963
64+ protected function setUp (): void
65+ {
66+ $ this ->checkMoneroVersionRequirements ();
67+ }
68+
69+ protected static function getDaemonRpcClient (): DaemonRpcClient
70+ {
71+ return self ::$ daemonRpcClient ;
72+ }
73+
6074 public function testGetVersion (): void
6175 {
6276 $ version = self ::$ rpcClient ->getVersion ();
@@ -557,4 +571,31 @@ public function testQueryKey(string $seed): void
557571 $ result = self ::$ rpcClient ->queryKey (QueryKeyType::MNEMONIC );
558572 $ this ->assertSame ($ seed , $ result ->key );
559573 }
574+
575+ #[RequiresMoneroVersion('0.18.4.1 ' )]
576+ public function testUpdateLookahead (): void
577+ {
578+ // Restore the test wallet
579+ self ::$ rpcClient ->restoreDeterministicWallet ('' , '' , TestHelper::WALLET_1_MNEMONIC );
580+
581+ // The subaddress at index (0, 999) should not be accessible with default lookahead
582+ $ address0_999 = new Address (TestHelper::MAINNET_SUBADDRESS_0_999 );
583+
584+ // Verify the address is not in the current lookahead table
585+ $ addressNotFound = false ;
586+ try {
587+ self ::$ rpcClient ->getAddressIndex ($ address0_999 );
588+ } catch (AddressNotInWalletException ) {
589+ $ addressNotFound = true ;
590+ }
591+ $ this ->assertTrue ($ addressNotFound , 'Address at index (0, 999) should not be in the lookahead table before extending it ' );
592+
593+ // Update the lookahead and verify the high index address is now in the table
594+ self ::$ rpcClient ->setSubaddressLookahead (50 , 1000 );
595+
596+ $ result = self ::$ rpcClient ->getAddressIndex ($ address0_999 );
597+ $ this ->assertSame (0 , $ result ->index ->major );
598+ $ this ->assertSame (999 , $ result ->index ->minor );
599+ }
600+
560601}
0 commit comments