@@ -445,3 +445,119 @@ describe('Pc.fromHex', () => {
445445 expect ( ( ) => Pc . fromHex ( invalidHex ) ) . toThrow ( ) ;
446446 } ) ;
447447} ) ;
448+
449+ describe ( 'post-condition amount u64 validation' , ( ) => {
450+ const MAX_U64 = BigInt ( '18446744073709551615' ) ; // 2^64 - 1
451+ const OVER_U64 = MAX_U64 + 1n ;
452+ const address = 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6' ;
453+ const ftContract = 'STB44HYPYAT2BB2QE513NSP81HTMYWBJP02HPGK6.token' ;
454+ const ftAsset = `${ ftContract } ::tok` ;
455+
456+ describe ( 'Pc builder rejects amounts exceeding u64' , ( ) => {
457+ test ( 'ustx rejects amount > u64 max' , ( ) => {
458+ expect ( ( ) => Pc . principal ( address ) . willSendEq ( OVER_U64 ) . ustx ( ) ) . toThrow ( ) ;
459+ } ) ;
460+
461+ test ( 'ft rejects amount > u64 max' , ( ) => {
462+ expect ( ( ) => Pc . principal ( address ) . willSendEq ( OVER_U64 ) . ft ( ftContract , 'tok' ) ) . toThrow ( ) ;
463+ } ) ;
464+
465+ test ( 'ustx rejects negative amount' , ( ) => {
466+ expect ( ( ) => Pc . principal ( address ) . willSendEq ( - 1n ) . ustx ( ) ) . toThrow ( ) ;
467+ } ) ;
468+
469+ test ( 'ft rejects negative amount' , ( ) => {
470+ expect ( ( ) => Pc . principal ( address ) . willSendEq ( - 1n ) . ft ( ftContract , 'tok' ) ) . toThrow ( ) ;
471+ } ) ;
472+
473+ test ( 'ustx accepts u64 max exactly' , ( ) => {
474+ const pc = Pc . principal ( address ) . willSendEq ( MAX_U64 ) . ustx ( ) ;
475+ expect ( pc . amount ) . toBe ( MAX_U64 . toString ( ) ) ;
476+ } ) ;
477+
478+ test ( 'ft accepts u64 max exactly' , ( ) => {
479+ const pc = Pc . principal ( address ) . willSendEq ( MAX_U64 ) . ft ( ftContract , 'tok' ) ;
480+ expect ( pc . amount ) . toBe ( MAX_U64 . toString ( ) ) ;
481+ } ) ;
482+ } ) ;
483+
484+ describe ( 'postConditionToWire rejects amounts exceeding u64' , ( ) => {
485+ test ( 'STX post condition rejects amount > u64 max' , ( ) => {
486+ expect ( ( ) =>
487+ postConditionToWire ( {
488+ type : 'stx-postcondition' ,
489+ address,
490+ condition : 'eq' ,
491+ amount : OVER_U64 ,
492+ } )
493+ ) . toThrow ( ) ;
494+ } ) ;
495+
496+ test ( 'FT post condition rejects amount > u64 max' , ( ) => {
497+ expect ( ( ) =>
498+ postConditionToWire ( {
499+ type : 'ft-postcondition' ,
500+ address,
501+ condition : 'eq' ,
502+ amount : OVER_U64 ,
503+ asset : ftAsset as any ,
504+ } )
505+ ) . toThrow ( ) ;
506+ } ) ;
507+
508+ test ( 'STX post condition rejects negative amount' , ( ) => {
509+ expect ( ( ) =>
510+ postConditionToWire ( {
511+ type : 'stx-postcondition' ,
512+ address,
513+ condition : 'eq' ,
514+ amount : - 1n ,
515+ } )
516+ ) . toThrow ( ) ;
517+ } ) ;
518+
519+ test ( 'FT post condition rejects negative amount' , ( ) => {
520+ expect ( ( ) =>
521+ postConditionToWire ( {
522+ type : 'ft-postcondition' ,
523+ address,
524+ condition : 'eq' ,
525+ amount : - 1n ,
526+ asset : ftAsset as any ,
527+ } )
528+ ) . toThrow ( ) ;
529+ } ) ;
530+
531+ test ( 'STX post condition accepts u64 max exactly' , ( ) => {
532+ const wire = postConditionToWire ( {
533+ type : 'stx-postcondition' ,
534+ address,
535+ condition : 'eq' ,
536+ amount : MAX_U64 ,
537+ } ) as STXPostConditionWire ;
538+ expect ( wire . amount ) . toBe ( MAX_U64 ) ;
539+ } ) ;
540+
541+ test ( 'FT post condition accepts u64 max exactly' , ( ) => {
542+ const wire = postConditionToWire ( {
543+ type : 'ft-postcondition' ,
544+ address,
545+ condition : 'eq' ,
546+ amount : MAX_U64 ,
547+ asset : ftAsset as any ,
548+ } ) as FungiblePostConditionWire ;
549+ expect ( wire . amount ) . toBe ( MAX_U64 ) ;
550+ } ) ;
551+
552+ test ( 'STX post condition rejects string amount > u64 max' , ( ) => {
553+ expect ( ( ) =>
554+ postConditionToWire ( {
555+ type : 'stx-postcondition' ,
556+ address,
557+ condition : 'eq' ,
558+ amount : '18446744073709551616' ,
559+ } )
560+ ) . toThrow ( ) ;
561+ } ) ;
562+ } ) ;
563+ } ) ;
0 commit comments