@@ -1165,7 +1165,7 @@ mod tests {
1165
1165
use std:: str:: FromStr ;
1166
1166
use std:: string:: String ;
1167
1167
1168
- use miniscript:: { satisfy, Segwitv0 } ;
1168
+ use miniscript:: { satisfy, Legacy , Segwitv0 } ;
1169
1169
use policy:: Liftable ;
1170
1170
use script_num_size;
1171
1171
use BitcoinSig ;
@@ -1514,6 +1514,54 @@ mod tests {
1514
1514
n_elements,
1515
1515
) ;
1516
1516
}
1517
+
1518
+ #[ test]
1519
+ fn shared_limits ( ) {
1520
+ // Test the maximum number of OPs with a 67-of-68 multisig
1521
+ let ( keys, _) = pubkeys_and_a_sig ( 68 ) ;
1522
+ let keys: Vec < Concrete < bitcoin:: PublicKey > > =
1523
+ keys. iter ( ) . map ( |pubkey| Concrete :: Key ( * pubkey) ) . collect ( ) ;
1524
+ let thresh_res: Result < SegwitMiniScript , _ > =
1525
+ Concrete :: Threshold ( keys. len ( ) - 1 , keys) . compile ( ) ;
1526
+ let ops_count = thresh_res. clone ( ) . and_then ( |m| Ok ( m. ext . ops_count_sat ) ) ;
1527
+ assert_eq ! (
1528
+ thresh_res,
1529
+ Err ( CompilerError :: LimitsExceeded ) ,
1530
+ "Compilation succeeded with '{:?}' OP count (sat)" ,
1531
+ ops_count,
1532
+ ) ;
1533
+ // For legacy too..
1534
+ let ( keys, _) = pubkeys_and_a_sig ( 68 ) ;
1535
+ let keys: Vec < Concrete < bitcoin:: PublicKey > > =
1536
+ keys. iter ( ) . map ( |pubkey| Concrete :: Key ( * pubkey) ) . collect ( ) ;
1537
+ let thresh_res = Concrete :: Threshold ( keys. len ( ) - 1 , keys) . compile :: < Legacy > ( ) ;
1538
+ let ops_count = thresh_res. clone ( ) . and_then ( |m| Ok ( m. ext . ops_count_sat ) ) ;
1539
+ assert_eq ! (
1540
+ thresh_res,
1541
+ Err ( CompilerError :: LimitsExceeded ) ,
1542
+ "Compilation succeeded with '{:?}' OP count (sat)" ,
1543
+ ops_count,
1544
+ ) ;
1545
+
1546
+ // Test that we refuse to compile policies with duplicated keys
1547
+ let ( keys, _) = pubkeys_and_a_sig ( 1 ) ;
1548
+ let key = Concrete :: Key ( keys[ 0 ] ) ;
1549
+ let res = Concrete :: Or ( vec ! [ ( 1 , key. clone( ) ) , ( 1 , key. clone( ) ) ] ) . compile :: < Segwitv0 > ( ) ;
1550
+ assert_eq ! (
1551
+ res,
1552
+ Err ( CompilerError :: PolicyError (
1553
+ policy:: concrete:: PolicyError :: DuplicatePubKeys
1554
+ ) )
1555
+ ) ;
1556
+ // Same for legacy
1557
+ let res = Concrete :: Or ( vec ! [ ( 1 , key. clone( ) ) , ( 1 , key) ] ) . compile :: < Legacy > ( ) ;
1558
+ assert_eq ! (
1559
+ res,
1560
+ Err ( CompilerError :: PolicyError (
1561
+ policy:: concrete:: PolicyError :: DuplicatePubKeys
1562
+ ) )
1563
+ ) ;
1564
+ }
1517
1565
}
1518
1566
1519
1567
#[ cfg( all( test, feature = "unstable" ) ) ]
0 commit comments