@@ -3555,6 +3555,120 @@ pub mod test {
35553555 conn. commit_block ( ) ;
35563556 }
35573557
3558+ #[ test]
3559+ fn process_post_conditions_tokens_deny_2097 ( ) {
3560+ let privk_origin = StacksPrivateKey :: from_hex (
3561+ "027682d2f7b05c3801fe4467883ab4cff0568b5e36412b5289e83ea5b519de8a01" ,
3562+ )
3563+ . unwrap ( ) ;
3564+ let privk_recipient = StacksPrivateKey :: from_hex (
3565+ "7e3af4db6af6b3c67e2c6c6d7d5983b519f4d9b3a6e00580ae96dcace3bde8bc01" ,
3566+ )
3567+ . unwrap ( ) ;
3568+ let auth_origin = TransactionAuth :: from_p2pkh ( & privk_origin) . unwrap ( ) ;
3569+ let auth_recv = TransactionAuth :: from_p2pkh ( & privk_recipient) . unwrap ( ) ;
3570+ let addr_publisher = auth_origin. origin ( ) . address_testnet ( ) ;
3571+ let addr_principal = addr_publisher. to_account_principal ( ) ;
3572+
3573+ let contract = "
3574+ (define-constant owner 'ST3X2W2SH9XQZRHHYJ21KWGTT1N6WX3D48K1NSTPE)
3575+ (define-fungible-token connect-token)
3576+ (begin (ft-mint? connect-token u100000000 owner))
3577+ (define-public (transfer (recipient principal) (amount uint))
3578+ (ok (ft-transfer? connect-token amount tx-sender recipient)))
3579+ "
3580+ . to_string ( ) ;
3581+
3582+ let contract_name = ContractName :: try_from ( "hello-world" ) . unwrap ( ) ;
3583+
3584+ let recv_addr = StacksAddress :: from_public_keys (
3585+ C32_ADDRESS_VERSION_TESTNET_SINGLESIG ,
3586+ & AddressHashMode :: SerializeP2PKH ,
3587+ 1 ,
3588+ & vec ! [ StacksPublicKey :: from_private( & privk_recipient) ] ,
3589+ )
3590+ . unwrap ( ) ;
3591+ let recv_principal = recv_addr. to_account_principal ( ) ;
3592+ let contract_id = QualifiedContractIdentifier :: new (
3593+ StandardPrincipalData :: from ( addr_publisher. clone ( ) ) ,
3594+ contract_name. clone ( ) ,
3595+ ) ;
3596+ let _contract_principal = PrincipalData :: Contract ( contract_id. clone ( ) ) ;
3597+
3598+ let asset_info = AssetInfo {
3599+ contract_address : addr_publisher. clone ( ) ,
3600+ contract_name : contract_name. clone ( ) ,
3601+ asset_name : ClarityName :: try_from ( "connect-token" ) . unwrap ( ) ,
3602+ } ;
3603+
3604+ let mut tx_contract = StacksTransaction :: new (
3605+ TransactionVersion :: Testnet ,
3606+ auth_origin. clone ( ) ,
3607+ TransactionPayload :: new_smart_contract ( & "hello-world" . to_string ( ) , & contract) . unwrap ( ) ,
3608+ ) ;
3609+
3610+ tx_contract. chain_id = 0x80000000 ;
3611+ tx_contract. set_fee_rate ( 0 ) ;
3612+
3613+ let mut signer = StacksTransactionSigner :: new ( & tx_contract) ;
3614+ signer. sign_origin ( & privk_origin) . unwrap ( ) ;
3615+
3616+ let signed_contract_tx = signer. get_tx ( ) . unwrap ( ) ;
3617+
3618+ let mut tx_contract_call = StacksTransaction :: new (
3619+ TransactionVersion :: Testnet ,
3620+ auth_origin. clone ( ) ,
3621+ TransactionPayload :: new_contract_call (
3622+ addr_publisher. clone ( ) ,
3623+ "hello-world" ,
3624+ "transfer" ,
3625+ vec ! [ Value :: Principal ( recv_principal. clone( ) ) , Value :: UInt ( 10 ) ] ,
3626+ )
3627+ . unwrap ( ) ,
3628+ ) ;
3629+
3630+ tx_contract_call. chain_id = 0x80000000 ;
3631+ tx_contract_call. set_fee_rate ( 0 ) ;
3632+ tx_contract_call. set_origin_nonce ( 1 ) ;
3633+
3634+ tx_contract_call. post_condition_mode = TransactionPostConditionMode :: Deny ;
3635+ tx_contract_call. add_post_condition ( TransactionPostCondition :: Fungible (
3636+ PostConditionPrincipal :: Origin ,
3637+ asset_info. clone ( ) ,
3638+ FungibleConditionCode :: SentEq ,
3639+ 10 ,
3640+ ) ) ;
3641+
3642+ let mut signer = StacksTransactionSigner :: new ( & tx_contract_call) ;
3643+ signer. sign_origin ( & privk_origin) . unwrap ( ) ;
3644+ let contract_call_tx = signer. get_tx ( ) . unwrap ( ) ;
3645+
3646+ let mut chainstate = instantiate_chainstate (
3647+ false ,
3648+ 0x80000000 ,
3649+ "process-post-conditions-tokens-deny-2097" ,
3650+ ) ;
3651+ let mut conn = chainstate. block_begin (
3652+ & NULL_BURN_STATE_DB ,
3653+ & FIRST_BURNCHAIN_CONSENSUS_HASH ,
3654+ & FIRST_STACKS_BLOCK_HASH ,
3655+ & ConsensusHash ( [ 1u8 ; 20 ] ) ,
3656+ & BlockHeaderHash ( [ 1u8 ; 32 ] ) ,
3657+ ) ;
3658+
3659+ // publish contract
3660+ let _ =
3661+ StacksChainState :: process_transaction ( & mut conn, & signed_contract_tx, false ) . unwrap ( ) ;
3662+
3663+ let ( _fee, receipt) =
3664+ StacksChainState :: process_transaction ( & mut conn, & contract_call_tx, false ) . unwrap ( ) ;
3665+
3666+ assert_eq ! ( receipt. post_condition_aborted, true ) ;
3667+ assert_eq ! ( receipt. result. to_string( ) , "(ok (err u1))" ) ;
3668+
3669+ conn. commit_block ( ) ;
3670+ }
3671+
35583672 fn make_account ( principal : & PrincipalData , nonce : u64 , balance : u128 ) -> StacksAccount {
35593673 let mut stx_balance = STXBalance :: zero ( ) ;
35603674 stx_balance. credit ( balance, 0 ) . unwrap ( ) ;
0 commit comments