@@ -29,7 +29,7 @@ const NOTE_ID: felt252 = 'NOTE_ID';
2929/// Resolves the `('USER', 'DAPP', nonce)` sub-account via the range view.
3030fn sub_account_info (anonymizer : ContractAddress , nonce : u64 ) -> SubAccountInfo {
3131 let infos = anonymizer_disp (anonymizer )
32- . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), nonce , nonce + 1 );
32+ . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), nonce , nonce + 1 , false );
3333 * infos [0 ]
3434}
3535
@@ -620,7 +620,7 @@ fn test_get_sub_accounts_resolves_deployed_and_undeployed() {
620620 deploy_nonce (components , 1 );
621621
622622 // Nonce 2 is undeployed; the view resolves every nonce in range with an is_deployed flag.
623- let infos = anonymizer . get_sub_accounts (partial , 0 , 3 );
623+ let infos = anonymizer . get_sub_accounts (partial , 0 , 3 , false );
624624 assert_eq! (infos . len (), 3 );
625625 assert_eq! ((* infos [0 ]). nonce, 0 );
626626 assert! ((* infos [0 ]). is_deployed);
@@ -632,16 +632,42 @@ fn test_get_sub_accounts_resolves_deployed_and_undeployed() {
632632 assert! (undeployed . address. is_non_zero ());
633633}
634634
635+ #[test]
636+ fn test_get_sub_accounts_until_undeployed_returns_deployed_prefix () {
637+ let components = deploy_components ();
638+ let anonymizer = anonymizer_disp (components . anonymizer);
639+ let partial = partial_commitment (' USER' , ' DAPP' );
640+ deploy_nonce (components , 0 );
641+ deploy_nonce (components , 1 );
642+
643+ // Nonce 2 is the first gap; until_undeployed resolves the deployed prefix and omits the gap on.
644+ let infos = anonymizer . get_sub_accounts (partial , 0 , 5 , true );
645+ assert_eq! (infos . len (), 2 );
646+ assert_eq! ((* infos [0 ]). nonce, 0 );
647+ assert_eq! ((* infos [1 ]). nonce, 1 );
648+ }
649+
650+ #[test]
651+ fn test_get_sub_accounts_until_undeployed_on_leading_gap_is_empty () {
652+ let components = deploy_components ();
653+ let anonymizer = anonymizer_disp (components . anonymizer);
654+ let partial = partial_commitment (' USER' , ' DAPP' );
655+
656+ // The range's first nonce is undeployed, so the deployed prefix is empty.
657+ let infos = anonymizer . get_sub_accounts (partial , 0 , 5 , true );
658+ assert_eq! (infos . len (), 0 );
659+ }
660+
635661#[test]
636662fn test_get_sub_accounts_computed_address_matches_deploy () {
637663 let components = deploy_components ();
638664 let anonymizer = anonymizer_disp (components . anonymizer);
639665 let partial = partial_commitment (' USER' , ' DAPP' );
640666
641- let before = * anonymizer . get_sub_accounts (partial , 0 , 1 )[0 ];
667+ let before = * anonymizer . get_sub_accounts (partial , 0 , 1 , false )[0 ];
642668 assert! (! before . is_deployed);
643669 deploy_nonce (components , 0 );
644- let after = * anonymizer . get_sub_accounts (partial , 0 , 1 )[0 ];
670+ let after = * anonymizer . get_sub_accounts (partial , 0 , 1 , false )[0 ];
645671 assert! (after . is_deployed);
646672 // The address computed before deployment matches the actual on-chain deploy address.
647673 assert_eq! (before . address, after . address);
@@ -651,10 +677,11 @@ fn test_get_sub_accounts_computed_address_matches_deploy() {
651677fn test_get_sub_accounts_scopes_by_dapp_and_nonce () {
652678 let components = deploy_components ();
653679 let anonymizer = anonymizer_disp (components . anonymizer);
654- let dapp = anonymizer . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 0 , 2 );
680+ let dapp = anonymizer . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 0 , 2 , false );
655681 let nonce0 = * dapp [0 ];
656682 let nonce1 = * dapp [1 ];
657- let other_dapp = * anonymizer . get_sub_accounts (partial_commitment (' USER' , ' OTHER' ), 0 , 1 )[0 ];
683+ let other_dapp = * anonymizer
684+ . get_sub_accounts (partial_commitment (' USER' , ' OTHER' ), 0 , 1 , false )[0 ];
658685 assert! (nonce0 . address != nonce1 . address);
659686 assert! (nonce0 . address != other_dapp . address);
660687}
@@ -668,7 +695,7 @@ fn test_get_sub_accounts_from_start_nonce() {
668695 deploy_nonce (components , 1 );
669696
670697 // Scanning from nonce 1 skips nonce 0; entries carry their own nonce.
671- let infos = anonymizer . get_sub_accounts (partial , 1 , 3 );
698+ let infos = anonymizer . get_sub_accounts (partial , 1 , 3 , false );
672699 assert_eq! (infos . len (), 2 );
673700 assert_eq! ((* infos [0 ]). nonce, 1 );
674701 assert! ((* infos [0 ]). is_deployed);
@@ -680,7 +707,7 @@ fn test_get_sub_accounts_from_start_nonce() {
680707fn test_get_sub_accounts_empty_range () {
681708 let components = deploy_components ();
682709 let infos = anonymizer_disp (components . anonymizer)
683- . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 5 , 5 );
710+ . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 5 , 5 , false );
684711 assert_eq! (infos . len (), 0 );
685712}
686713
@@ -689,13 +716,13 @@ fn test_get_sub_accounts_empty_range() {
689716fn test_get_sub_accounts_range_too_large_reverts () {
690717 let components = deploy_components ();
691718 anonymizer_disp (components . anonymizer)
692- . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 0 , MAX_SCAN_RANGE + 1 );
719+ . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 0 , MAX_SCAN_RANGE + 1 , false );
693720}
694721
695722#[test]
696723#[should_panic(expected: ' INVALID_RANGE' )]
697724fn test_get_sub_accounts_inverted_range_reverts () {
698725 let components = deploy_components ();
699726 anonymizer_disp (components . anonymizer)
700- . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 5 , 3 );
727+ . get_sub_accounts (partial_commitment (' USER' , ' DAPP' ), 5 , 3 , false );
701728}
0 commit comments