@@ -872,5 +872,93 @@ describe('Sol Transfer Builder V2', () => {
872872 `input amount ${ excessiveAmount } exceeds max safe int 9007199254740991`
873873 ) ;
874874 } ) ;
875+
876+ it ( 'should fail with more than 9 recipients with ATA creation' , async ( ) => {
877+ const txBuilder = factory . getTransferBuilderV2 ( ) ;
878+ txBuilder . nonce ( recentBlockHash ) ;
879+ txBuilder . sender ( authAccount . pub ) ;
880+ txBuilder . feePayer ( feePayerAccount . pub ) ;
881+
882+ // Generate 10 unique recipients for ATA creation
883+ const recipients : string [ ] = [ ] ;
884+ for ( let i = 0 ; i < 10 ; i ++ ) {
885+ const keypair = new KeyPair ( ) ;
886+ recipients . push ( keypair . getKeys ( ) . pub ) ;
887+ }
888+
889+ for ( const address of recipients ) {
890+ txBuilder . send ( { address, amount, tokenName : nameUSDC } ) ;
891+ txBuilder . createAssociatedTokenAccount ( {
892+ ownerAddress : address ,
893+ tokenName : nameUSDC ,
894+ } ) ;
895+ }
896+
897+ await txBuilder
898+ . build ( )
899+ . should . be . rejectedWith (
900+ / T r a n s a c t i o n t o o l a r g e : 1 0 r e c i p i e n t s w i t h 1 0 A T A c r e a t i o n s .* m a x i m u m 9 r e c i p i e n t s w i t h A T A c r e a t i o n /
901+ ) ;
902+ } ) ;
903+
904+ it ( 'should fail with more than 18 token recipients without ATA creation' , async ( ) => {
905+ const txBuilder = factory . getTransferBuilderV2 ( ) ;
906+ txBuilder . nonce ( recentBlockHash ) ;
907+ txBuilder . sender ( authAccount . pub ) ;
908+ txBuilder . feePayer ( feePayerAccount . pub ) ;
909+
910+ // Add 19 token recipients without ATA creation (reusing addresses is fine without ATA)
911+ for ( let i = 0 ; i < 19 ; i ++ ) {
912+ // Only use first 3 addresses to avoid invalid address at index 3
913+ const address = testData . addresses . validAddresses [ i % 3 ] ;
914+ txBuilder . send ( { address, amount, tokenName : nameUSDC } ) ;
915+ }
916+
917+ await txBuilder
918+ . build ( )
919+ . should . be . rejectedWith ( / T r a n s a c t i o n t o o l a r g e : 1 9 r e c i p i e n t s .* m a x i m u m 1 8 r e c i p i e n t s w i t h o u t A T A c r e a t i o n / ) ;
920+ } ) ;
921+
922+ it ( 'should succeed with 9 recipients with ATA creation' , async ( ) => {
923+ const txBuilder = factory . getTransferBuilderV2 ( ) ;
924+ txBuilder . nonce ( recentBlockHash ) ;
925+ txBuilder . sender ( authAccount . pub ) ;
926+ txBuilder . feePayer ( feePayerAccount . pub ) ;
927+
928+ // Generate exactly 9 unique recipients for ATA creation
929+ const recipients : string [ ] = [ ] ;
930+ for ( let i = 0 ; i < 9 ; i ++ ) {
931+ const keypair = new KeyPair ( ) ;
932+ recipients . push ( keypair . getKeys ( ) . pub ) ;
933+ }
934+
935+ for ( const address of recipients ) {
936+ txBuilder . send ( { address, amount, tokenName : nameUSDC } ) ;
937+ txBuilder . createAssociatedTokenAccount ( {
938+ ownerAddress : address ,
939+ tokenName : nameUSDC ,
940+ } ) ;
941+ }
942+
943+ const tx = await txBuilder . build ( ) ;
944+ tx . should . be . ok ( ) ;
945+ } ) ;
946+
947+ it ( 'should succeed with 18 token recipients without ATA creation' , async ( ) => {
948+ const txBuilder = factory . getTransferBuilderV2 ( ) ;
949+ txBuilder . nonce ( recentBlockHash ) ;
950+ txBuilder . sender ( authAccount . pub ) ;
951+ txBuilder . feePayer ( feePayerAccount . pub ) ;
952+
953+ // Add exactly 18 token recipients without ATA creation (reusing addresses is fine without ATA)
954+ for ( let i = 0 ; i < 18 ; i ++ ) {
955+ // Only use first 3 addresses to avoid invalid address at index 3
956+ const address = testData . addresses . validAddresses [ i % 3 ] ;
957+ txBuilder . send ( { address, amount, tokenName : nameUSDC } ) ;
958+ }
959+
960+ const tx = await txBuilder . build ( ) ;
961+ tx . should . be . ok ( ) ;
962+ } ) ;
875963 } ) ;
876964} ) ;
0 commit comments