@@ -1634,6 +1634,67 @@ mod tests {
1634
1634
}
1635
1635
Tapscript :: parse_insane ( & script. into_script ( ) ) . unwrap_err ( ) ;
1636
1636
}
1637
+
1638
+ #[ test]
1639
+ fn test_context_global_consensus ( ) {
1640
+ // Test from string tests
1641
+ type LegacyMs = Miniscript < String , Legacy > ;
1642
+ type Segwitv0Ms = Miniscript < String , Segwitv0 > ;
1643
+ type BareMs = Miniscript < String , BareCtx > ;
1644
+
1645
+ // multisig script of 20 pubkeys exceeds 520 bytes
1646
+ let pubkey_vec_20: Vec < String > = ( 0 ..20 ) . map ( |x| x. to_string ( ) ) . collect ( ) ;
1647
+ // multisig script of 300 pubkeys exceeds 10,000 bytes
1648
+ let pubkey_vec_300: Vec < String > = ( 0 ..300 ) . map ( |x| x. to_string ( ) ) . collect ( ) ;
1649
+
1650
+ // wrong multi_a for non-tapscript, while exceeding consensus size limit
1651
+ let legacy_multi_a_ms =
1652
+ LegacyMs :: from_str ( & format ! ( "multi_a(20,{})" , pubkey_vec_20. join( "," ) ) ) ;
1653
+ let segwit_multi_a_ms =
1654
+ Segwitv0Ms :: from_str ( & format ! ( "multi_a(300,{})" , pubkey_vec_300. join( "," ) ) ) ;
1655
+ let bare_multi_a_ms =
1656
+ BareMs :: from_str ( & format ! ( "multi_a(300,{})" , pubkey_vec_300. join( "," ) ) ) ;
1657
+
1658
+ // Should panic for wrong multi_a, even if it exceeds the max consensus size
1659
+ assert_eq ! (
1660
+ legacy_multi_a_ms. unwrap_err( ) . to_string( ) ,
1661
+ "Multi a(CHECKSIGADD) only allowed post tapscript"
1662
+ ) ;
1663
+ assert_eq ! (
1664
+ segwit_multi_a_ms. unwrap_err( ) . to_string( ) ,
1665
+ "Multi a(CHECKSIGADD) only allowed post tapscript"
1666
+ ) ;
1667
+ assert_eq ! (
1668
+ bare_multi_a_ms. unwrap_err( ) . to_string( ) ,
1669
+ "Multi a(CHECKSIGADD) only allowed post tapscript"
1670
+ ) ;
1671
+
1672
+ // multisig script of 20 pubkeys exceeds 520 bytes
1673
+ let multi_ms = format ! ( "multi(20,{})" , pubkey_vec_20. join( "," ) ) ;
1674
+ // other than legacy, and_v to build 15 nested 20-of-20 multisig script
1675
+ // to exceed 10,000 bytes without violation of threshold limit(max: 20)
1676
+ let and_v_nested_multi_ms =
1677
+ format ! ( "and_v(v:{}," , multi_ms) . repeat ( 14 ) + & multi_ms + "))))))))))))))" ;
1678
+
1679
+ // correct multi for non-tapscript, but exceeding consensus size limit
1680
+ let legacy_multi_ms = LegacyMs :: from_str ( & multi_ms) ;
1681
+ let segwit_multi_ms = Segwitv0Ms :: from_str ( & and_v_nested_multi_ms) ;
1682
+ let bare_multi_ms = BareMs :: from_str ( & and_v_nested_multi_ms) ;
1683
+
1684
+ // Should panic for exceeding the max consensus size, as multi properly used
1685
+ assert_eq ! (
1686
+ legacy_multi_ms. unwrap_err( ) . to_string( ) ,
1687
+ "The Miniscript corresponding Script would be larger than MAX_SCRIPT_ELEMENT_SIZE bytes."
1688
+ ) ;
1689
+ assert_eq ! (
1690
+ segwit_multi_ms. unwrap_err( ) . to_string( ) ,
1691
+ "The Miniscript corresponding Script would be larger than MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."
1692
+ ) ;
1693
+ assert_eq ! (
1694
+ bare_multi_ms. unwrap_err( ) . to_string( ) ,
1695
+ "The Miniscript corresponding Script would be larger than MAX_STANDARD_P2WSH_SCRIPT_SIZE bytes."
1696
+ ) ;
1697
+ }
1637
1698
}
1638
1699
1639
1700
#[ cfg( bench) ]
0 commit comments