@@ -976,4 +976,71 @@ mod tests {
976976 assert_eq ! ( pset. n_inputs( ) , n_inputs - 1 ) ;
977977 assert_eq ! ( pset. n_outputs( ) , n_outputs - 1 ) ;
978978 }
979+
980+ #[ test]
981+ fn pset_issuance ( ) {
982+ use std:: str:: FromStr ;
983+ use rand:: { self , SeedableRng } ;
984+ let secp = secp256k1_zkp:: Secp256k1 :: new ( ) ;
985+ #[ allow( deprecated) ]
986+ let mut rng = rand:: rngs:: StdRng :: seed_from_u64 ( 0 ) ;
987+
988+ let policy = crate :: AssetId :: from_str ( "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225" ) . unwrap ( ) ;
989+ let pk = bitcoin:: key:: PublicKey :: from_str ( "020202020202020202020202020202020202020202020202020202020202020202" ) . unwrap ( ) ;
990+ let script = crate :: Script :: from_hex ( "0014d2bcde17e7744f6377466ca1bd35d212954674c8" ) . unwrap ( ) ;
991+ let sats_in = 10000 ;
992+ let sats_fee = 1000 ;
993+ let btc_txout_secrets = TxOutSecrets {
994+ asset_bf : AssetBlindingFactor :: from_str ( "1111111111111111111111111111111111111111111111111111111111111111" ) . unwrap ( ) ,
995+ value_bf : ValueBlindingFactor :: from_str ( "2222222222222222222222222222222222222222222222222222222222222222" ) . unwrap ( ) ,
996+ value : sats_in,
997+ asset : policy,
998+ } ;
999+ let previous_output = TxOut :: default ( ) ; // Does not match btc_txout_secrets
1000+ let prevout = OutPoint :: default ( ) ;
1001+ let sats_asset = 10 ;
1002+ let sats_token = 1 ;
1003+
1004+ let mut pset = PartiallySignedTransaction :: new_v2 ( ) ;
1005+ let mut input = Input :: from_prevout ( prevout) ;
1006+ input. witness_utxo = Some ( previous_output) ;
1007+ input. issuance_value_amount = Some ( sats_asset) ;
1008+ input. issuance_inflation_keys = Some ( sats_token) ;
1009+ let ( asset, token) = input. issuance_ids ( ) ;
1010+ pset. add_input ( input) ;
1011+
1012+ // Add asset
1013+ let mut output = Output :: new_explicit ( script. clone ( ) , sats_asset, asset, Some ( pk) ) ;
1014+ output. blinder_index = Some ( 0 ) ;
1015+ pset. add_output ( output) ;
1016+ // Add token
1017+ let mut output = Output :: new_explicit ( script. clone ( ) , sats_token, token, Some ( pk) ) ;
1018+ output. blinder_index = Some ( 0 ) ;
1019+ pset. add_output ( output) ;
1020+ // Add L-BTC
1021+ let mut output = Output :: new_explicit ( script. clone ( ) , sats_in - sats_fee, policy, Some ( pk) ) ;
1022+ output. blinder_index = Some ( 0 ) ;
1023+ pset. add_output ( output) ;
1024+ // Add fee
1025+ let output = Output :: new_explicit ( crate :: Script :: new ( ) , sats_fee, policy, None ) ;
1026+ pset. add_output ( output) ;
1027+
1028+ let mut inp_txout_sec = HashMap :: new ( ) ;
1029+ inp_txout_sec. insert ( 0 , btc_txout_secrets) ;
1030+
1031+ let err = pset. blind_last ( & mut rng, & secp, & inp_txout_sec) . unwrap_err ( ) ;
1032+ assert_eq ! ( err, PsetBlindError :: BlindingIssuanceUnsupported ( 0 ) ) ;
1033+
1034+ let input = & mut pset. inputs_mut ( ) [ 0 ] ;
1035+ input. blinded_issuance = Some ( 0x01 ) ;
1036+ let err = pset. blind_last ( & mut rng, & secp, & inp_txout_sec) . unwrap_err ( ) ;
1037+ assert_eq ! ( err, PsetBlindError :: BlindingIssuanceUnsupported ( 0 ) ) ;
1038+
1039+ let input = & mut pset. inputs_mut ( ) [ 0 ] ;
1040+ input. blinded_issuance = Some ( 0x00 ) ;
1041+ pset. blind_last ( & mut rng, & secp, & inp_txout_sec) . unwrap ( ) ;
1042+ let pset_bytes = encode:: serialize ( & pset) ;
1043+ let pset_des = encode:: deserialize ( & pset_bytes) . unwrap ( ) ;
1044+ assert_eq ! ( pset, pset_des) ;
1045+ }
9791046}
0 commit comments