@@ -317,16 +317,29 @@ mod shutdown_script_tests {
317317 assert_eq ! ( shutdown_script. into_inner( ) , op_return_script) ;
318318 assert ! ( ShutdownScript :: try_from( op_return_script) . is_ok( ) ) ;
319319
320- let mut pushdata_vec = Builder :: new ( )
321- . push_opcode ( opcodes:: all:: OP_RETURN )
322- . push_opcode ( opcodes:: all:: OP_PUSHDATA1 )
323- . into_bytes ( ) ;
324- pushdata_vec. push ( 80 ) ;
325- pushdata_vec. extend_from_slice ( & [ 1u8 ; 80 ] ) ;
326- let pushdata_script = ScriptBuf :: from_bytes ( pushdata_vec) ;
327- let pushdata_shutdown_script = ShutdownScript :: try_from ( pushdata_script) . unwrap ( ) ;
328- assert ! ( pushdata_shutdown_script. is_compatible( & simple_close_features( ) ) ) ;
329- assert ! ( !pushdata_shutdown_script. is_compatible( & InitFeatures :: empty( ) ) ) ;
320+ let assert_pushdata_script_compat = |len| {
321+ let mut pushdata_vec = Builder :: new ( )
322+ . push_opcode ( opcodes:: all:: OP_RETURN )
323+ . push_opcode ( opcodes:: all:: OP_PUSHDATA1 )
324+ . into_bytes ( ) ;
325+ pushdata_vec. push ( len as u8 ) ;
326+ pushdata_vec. extend_from_slice ( & vec ! [ 1u8 ; len] ) ;
327+ let pushdata_script = ScriptBuf :: from_bytes ( pushdata_vec) ;
328+ let pushdata_shutdown_script = ShutdownScript :: try_from ( pushdata_script) . unwrap ( ) ;
329+ assert ! ( pushdata_shutdown_script. is_compatible( & simple_close_features( ) ) ) ;
330+ assert ! ( !pushdata_shutdown_script. is_compatible( & InitFeatures :: empty( ) ) ) ;
331+ } ;
332+
333+ // For `option_simple_close` we assert compatibility with `OP_PUSHDATA1` scripts for the
334+ // intended length range of 76 to 80 bytes.
335+ assert_pushdata_script_compat ( 76 ) ;
336+ assert_pushdata_script_compat ( 80 ) ;
337+
338+ // While the `option_simple_close` spec prescribes the use of `OP_PUSHBYTES_0` up to 75
339+ // bytes, we follow Postel's law and accept if our counterparty would create an
340+ // `OP_PUSHDATA1` script for less than 76 bytes of payload.
341+ assert_pushdata_script_compat ( 75 ) ;
342+ assert_pushdata_script_compat ( 6 ) ;
330343 }
331344
332345 #[ test]
0 commit comments