@@ -56,9 +56,10 @@ def setUpClass(cls):
5656 cls .receiver = cls .env .get_receiver ()
5757 cls .sender = cls .env .get_sender ()
5858
59- async def test_invalid_primitives (self ):
59+ async def test_ffi_validation (self ):
6060 too_large_amount = 21_000_000 * 100_000_000 + 1
61- # Invalid outpoint should fail before amount checks.
61+
62+ # Invalid outpoint (txid too long) should fail before amount checks.
6263 txin_invalid = PlainTxIn (
6364 previous_output = PlainOutPoint (txid = "00" * 64 , vout = 0 ),
6465 script_sig = b"" ,
@@ -70,12 +71,11 @@ async def test_invalid_primitives(self):
7071 redeem_script = None ,
7172 witness_script = None ,
7273 )
73- with self .assertRaises (InputPairError ):
74+ with self .assertRaises (InputPairError . InvalidOutPoint ):
7475 InputPair (txin = txin_invalid , psbtin = psbt_in_dummy , expected_weight = None )
7576
76- # Valid outpoint hits amount overflow.
77+ # Valid outpoint hits amount overflow validation .
7778 txin = PlainTxIn (
78- # valid 32-byte txid so we exercise amount overflow instead of outpoint parsing
7979 previous_output = PlainOutPoint (txid = "00" * 32 , vout = 0 ),
8080 script_sig = b"" ,
8181 sequence = 0 ,
@@ -89,15 +89,11 @@ async def test_invalid_primitives(self):
8989 redeem_script = None ,
9090 witness_script = None ,
9191 )
92- amount_oob_variant = getattr (InputPairError , "AmountOutOfRange" , InputPairError )
93- with self .assertRaises (amount_oob_variant ) as ctx :
92+ with self .assertRaises (InputPairError .FfiValidation ) as ctx :
9493 InputPair (txin = txin , psbtin = psbt_in , expected_weight = None )
95- # Cope with bindings that don't expose nested variants.
96- self .assertIsInstance (ctx .exception , InputPairError )
97- if amount_oob_variant is not InputPairError :
98- self .assertIsInstance (ctx .exception , amount_oob_variant )
94+ self .assertIsInstance (ctx .exception [0 ], FfiValidationError .AmountOutOfRange )
9995
100- # Use a real v2 payjoin URI from the receiver harness to avoid the v1 panic path .
96+ # SenderBuilder rejects fee rate overflow .
10197 receiver_address = json .loads (self .receiver .call ("getnewaddress" , []))
10298 services = TestServices .initialize ()
10399 services .wait_for_services_ready ()
@@ -108,26 +104,13 @@ async def test_invalid_primitives(self):
108104 receiver_address , directory , ohttp_keys , recv_persister
109105 ).pj_uri ()
110106
111- sender_prim_variant = getattr (SenderInputError , "Primitive" , SenderInputError )
112- with self .assertRaises (sender_prim_variant ) as ctx :
107+ with self .assertRaises (SenderInputError .FfiValidation ) as ctx :
113108 SenderBuilder (original_psbt (), pj_uri ).build_recommended (2 ** 64 - 1 )
114- if sender_prim_variant is not SenderInputError :
115- self .assertIsInstance (ctx .exception , sender_prim_variant )
116- fee_rate_variant = getattr (PrimitiveError , "FeeRateOutOfRange" , PrimitiveError )
117- cause = ctx .exception .__cause__
118- if cause is not None :
119- self .assertIsInstance (cause , fee_rate_variant )
120- else :
121- self .assertIn ("FeeRateOutOfRange" , str (ctx .exception ))
122-
123- prim_amount_variant = getattr (
124- PrimitiveError , "AmountOutOfRange" , PrimitiveError
125- )
126- with self .assertRaises (prim_amount_variant ) as ctx :
109+ self .assertIsInstance (ctx .exception [0 ], FfiValidationError .FeeRateOutOfRange )
110+
111+ # PjUri rejects amount out of range.
112+ with self .assertRaises (FfiValidationError .AmountOutOfRange ):
127113 pj_uri .set_amount_sats (too_large_amount )
128- self .assertIsInstance (ctx .exception , PrimitiveError )
129- if prim_amount_variant is not PrimitiveError :
130- self .assertIsInstance (ctx .exception , prim_amount_variant )
131114
132115 async def process_receiver_proposal (
133116 self ,
0 commit comments