@@ -2551,7 +2551,48 @@ pub mod test {
2551
2551
2552
2552
let signed_tx = signer. get_tx ( ) . unwrap ( ) ;
2553
2553
2554
- for ( dbi, burn_db) in ALL_BURN_DBS . iter ( ) . enumerate ( ) {
2554
+ // invalid contract-calls
2555
+ let contract_calls = vec ! [
2556
+ (
2557
+ addr. clone( ) ,
2558
+ "hello-world" ,
2559
+ "set-bar-not-a-method" ,
2560
+ vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2561
+ ) , // call into non-existant method
2562
+ (
2563
+ addr. clone( ) ,
2564
+ "hello-world-not-a-contract" ,
2565
+ "set-bar" ,
2566
+ vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2567
+ ) , // call into non-existant contract
2568
+ (
2569
+ addr_2. clone( ) ,
2570
+ "hello-world" ,
2571
+ "set-bar" ,
2572
+ vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2573
+ ) , // address does not have a contract
2574
+ ( addr. clone( ) , "hello-world" , "set-bar" , vec![ Value :: Int ( 1 ) ] ) , // wrong number of args (too few)
2575
+ (
2576
+ addr. clone( ) ,
2577
+ "hello-world" ,
2578
+ "set-bar" ,
2579
+ vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2580
+ ) , // wrong number of args (too many)
2581
+ (
2582
+ addr. clone( ) ,
2583
+ "hello-world" ,
2584
+ "set-bar" ,
2585
+ vec![ Value :: buff_from( [ 0xff , 4 ] . to_vec( ) ) . unwrap( ) , Value :: Int ( 1 ) ] ,
2586
+ ) , // wrong arg type
2587
+ (
2588
+ addr. clone( ) ,
2589
+ "hello-world" ,
2590
+ "set-bar" ,
2591
+ vec![ Value :: UInt ( 1 ) , Value :: Int ( 1 ) ] ,
2592
+ ) , // wrong arg type
2593
+ ] ;
2594
+
2595
+ for ( dbi, burn_db) in PRE_21_DBS . iter ( ) . enumerate ( ) {
2555
2596
let mut conn = chainstate. block_begin (
2556
2597
burn_db,
2557
2598
& FIRST_BURNCHAIN_CONSENSUS_HASH ,
@@ -2562,52 +2603,11 @@ pub mod test {
2562
2603
let ( _fee, _) =
2563
2604
StacksChainState :: process_transaction ( & mut conn, & signed_tx, false ) . unwrap ( ) ;
2564
2605
2565
- // invalid contract-calls
2566
- let contract_calls = vec ! [
2567
- (
2568
- addr. clone( ) ,
2569
- "hello-world" ,
2570
- "set-bar-not-a-method" ,
2571
- vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2572
- ) , // call into non-existant method
2573
- (
2574
- addr. clone( ) ,
2575
- "hello-world-not-a-contract" ,
2576
- "set-bar" ,
2577
- vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2578
- ) , // call into non-existant contract
2579
- (
2580
- addr_2. clone( ) ,
2581
- "hello-world" ,
2582
- "set-bar" ,
2583
- vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2584
- ) , // address does not have a contract
2585
- ( addr. clone( ) , "hello-world" , "set-bar" , vec![ Value :: Int ( 1 ) ] ) , // wrong number of args (too few)
2586
- (
2587
- addr. clone( ) ,
2588
- "hello-world" ,
2589
- "set-bar" ,
2590
- vec![ Value :: Int ( 1 ) , Value :: Int ( 1 ) , Value :: Int ( 1 ) ] ,
2591
- ) , // wrong number of args (too many)
2592
- (
2593
- addr. clone( ) ,
2594
- "hello-world" ,
2595
- "set-bar" ,
2596
- vec![ Value :: buff_from( [ 0xff , 4 ] . to_vec( ) ) . unwrap( ) , Value :: Int ( 1 ) ] ,
2597
- ) , // wrong arg type
2598
- (
2599
- addr. clone( ) ,
2600
- "hello-world" ,
2601
- "set-bar" ,
2602
- vec![ Value :: UInt ( 1 ) , Value :: Int ( 1 ) ] ,
2603
- ) , // wrong arg type
2604
- ] ;
2605
-
2606
2606
let next_nonce = 0 ;
2607
2607
2608
- for contract_call in contract_calls {
2608
+ for contract_call in contract_calls. iter ( ) {
2609
2609
let ( contract_addr, contract_name, contract_function, contract_args) =
2610
- contract_call;
2610
+ contract_call. clone ( ) ;
2611
2611
let mut tx_contract_call = StacksTransaction :: new (
2612
2612
TransactionVersion :: Testnet ,
2613
2613
auth_2. clone ( ) ,
@@ -2649,6 +2649,64 @@ pub mod test {
2649
2649
}
2650
2650
conn. commit_block ( ) ;
2651
2651
}
2652
+
2653
+ // in 2.1, all of these are mineable -- the fee will be collected, and the nonce(s) will
2654
+ // advance, but no state changes go through
2655
+ let mut conn = chainstate. block_begin (
2656
+ & TestBurnStateDB_21 ,
2657
+ & FIRST_BURNCHAIN_CONSENSUS_HASH ,
2658
+ & FIRST_STACKS_BLOCK_HASH ,
2659
+ & ConsensusHash ( [ 3u8 ; 20 ] ) ,
2660
+ & BlockHeaderHash ( [ 3u8 ; 32 ] ) ,
2661
+ ) ;
2662
+ let ( _fee, _) =
2663
+ StacksChainState :: process_transaction ( & mut conn, & signed_tx, false ) . unwrap ( ) ;
2664
+
2665
+ let mut next_nonce = 0 ;
2666
+
2667
+ for contract_call in contract_calls. iter ( ) {
2668
+ let ( contract_addr, contract_name, contract_function, contract_args) =
2669
+ contract_call. clone ( ) ;
2670
+ let mut tx_contract_call = StacksTransaction :: new (
2671
+ TransactionVersion :: Testnet ,
2672
+ auth_2. clone ( ) ,
2673
+ TransactionPayload :: new_contract_call (
2674
+ contract_addr. clone ( ) ,
2675
+ contract_name,
2676
+ contract_function,
2677
+ contract_args,
2678
+ )
2679
+ . unwrap ( ) ,
2680
+ ) ;
2681
+
2682
+ tx_contract_call. chain_id = 0x80000000 ;
2683
+ tx_contract_call. set_tx_fee ( 0 ) ;
2684
+ tx_contract_call. set_origin_nonce ( next_nonce) ;
2685
+
2686
+ let mut signer_2 = StacksTransactionSigner :: new ( & tx_contract_call) ;
2687
+ signer_2. sign_origin ( & privk_2) . unwrap ( ) ;
2688
+
2689
+ let signed_tx_2 = signer_2. get_tx ( ) . unwrap ( ) ;
2690
+
2691
+ let account_2 =
2692
+ StacksChainState :: get_account ( & mut conn, & addr_2. to_account_principal ( ) ) ;
2693
+
2694
+ assert_eq ! ( account_2. nonce, next_nonce) ;
2695
+
2696
+ // this is expected to be mined
2697
+ let res = StacksChainState :: process_transaction ( & mut conn, & signed_tx_2, false ) ;
2698
+ assert ! ( res. is_ok( ) ) ;
2699
+
2700
+ next_nonce += 1 ;
2701
+ let account_2 =
2702
+ StacksChainState :: get_account ( & mut conn, & addr_2. to_account_principal ( ) ) ;
2703
+ assert_eq ! ( account_2. nonce, next_nonce) ;
2704
+
2705
+ // no state change though
2706
+ let var_res = StacksChainState :: get_data_var ( & mut conn, & contract_id, "bar" ) . unwrap ( ) ;
2707
+ assert ! ( var_res. is_some( ) ) ;
2708
+ assert_eq ! ( var_res, Some ( Value :: Int ( 1 ) ) ) ;
2709
+ }
2652
2710
}
2653
2711
2654
2712
#[ test]
@@ -8594,6 +8652,7 @@ pub mod test {
8594
8652
(use-trait trait .foo.foo)
8595
8653
8596
8654
(define-data-var mutex bool true)
8655
+ (define-data-var executed bool false)
8597
8656
8598
8657
(define-public (flip)
8599
8658
(ok (var-set mutex (not (var-get mutex))))
@@ -8605,6 +8664,7 @@ pub mod test {
8605
8664
(ok (internal (if (var-get mutex)
8606
8665
(begin
8607
8666
(print \" some case\" )
8667
+ (var-set executed true)
8608
8668
(some ref)
8609
8669
)
8610
8670
none
@@ -8645,7 +8705,7 @@ pub mod test {
8645
8705
8646
8706
tx_runtime_checkerror_trait. post_condition_mode = TransactionPostConditionMode :: Allow ;
8647
8707
tx_runtime_checkerror_trait. chain_id = 0x80000000 ;
8648
- tx_runtime_checkerror_trait. set_tx_fee ( 0 ) ;
8708
+ tx_runtime_checkerror_trait. set_tx_fee ( 1 ) ;
8649
8709
tx_runtime_checkerror_trait. set_origin_nonce ( 0 ) ;
8650
8710
8651
8711
let mut signer = StacksTransactionSigner :: new ( & tx_runtime_checkerror_trait) ;
@@ -8666,7 +8726,7 @@ pub mod test {
8666
8726
8667
8727
tx_runtime_checkerror_impl. post_condition_mode = TransactionPostConditionMode :: Allow ;
8668
8728
tx_runtime_checkerror_impl. chain_id = 0x80000000 ;
8669
- tx_runtime_checkerror_impl. set_tx_fee ( 0 ) ;
8729
+ tx_runtime_checkerror_impl. set_tx_fee ( 1 ) ;
8670
8730
tx_runtime_checkerror_impl. set_origin_nonce ( 1 ) ;
8671
8731
8672
8732
let mut signer = StacksTransactionSigner :: new ( & tx_runtime_checkerror_impl) ;
@@ -8687,7 +8747,7 @@ pub mod test {
8687
8747
8688
8748
tx_runtime_checkerror. post_condition_mode = TransactionPostConditionMode :: Allow ;
8689
8749
tx_runtime_checkerror. chain_id = 0x80000000 ;
8690
- tx_runtime_checkerror. set_tx_fee ( 0 ) ;
8750
+ tx_runtime_checkerror. set_tx_fee ( 1 ) ;
8691
8751
tx_runtime_checkerror. set_origin_nonce ( 2 ) ;
8692
8752
8693
8753
let mut signer = StacksTransactionSigner :: new ( & tx_runtime_checkerror) ;
@@ -8711,7 +8771,7 @@ pub mod test {
8711
8771
8712
8772
tx_test_trait_checkerror. post_condition_mode = TransactionPostConditionMode :: Allow ;
8713
8773
tx_test_trait_checkerror. chain_id = 0x80000000 ;
8714
- tx_test_trait_checkerror. set_tx_fee ( 0 ) ;
8774
+ tx_test_trait_checkerror. set_tx_fee ( 1 ) ;
8715
8775
tx_test_trait_checkerror. set_origin_nonce ( 3 ) ;
8716
8776
8717
8777
let mut signer = StacksTransactionSigner :: new ( & tx_test_trait_checkerror) ;
@@ -8732,14 +8792,19 @@ pub mod test {
8732
8792
8733
8793
tx_runtime_checkerror_cc_contract. post_condition_mode = TransactionPostConditionMode :: Allow ;
8734
8794
tx_runtime_checkerror_cc_contract. chain_id = 0x80000000 ;
8735
- tx_runtime_checkerror_cc_contract. set_tx_fee ( 0 ) ;
8795
+ tx_runtime_checkerror_cc_contract. set_tx_fee ( 1 ) ;
8736
8796
tx_runtime_checkerror_cc_contract. set_origin_nonce ( 3 ) ;
8737
8797
8738
8798
let mut signer = StacksTransactionSigner :: new ( & tx_runtime_checkerror_cc_contract) ;
8739
8799
signer. sign_origin ( & privk) . unwrap ( ) ;
8740
8800
8741
8801
let signed_runtime_checkerror_cc_contract_tx = signer. get_tx ( ) . unwrap ( ) ;
8742
8802
8803
+ let contract_id = QualifiedContractIdentifier :: new (
8804
+ StandardPrincipalData :: from ( addr. clone ( ) ) ,
8805
+ ContractName :: from ( "trait-checkerror" ) ,
8806
+ ) ;
8807
+
8743
8808
// in 2.0, this invalidates the block
8744
8809
let mut conn = chainstate. block_begin (
8745
8810
& TestBurnStateDB_20 ,
@@ -8755,20 +8820,20 @@ pub mod test {
8755
8820
false ,
8756
8821
)
8757
8822
. unwrap ( ) ;
8758
- assert_eq ! ( fee, 0 ) ;
8823
+ assert_eq ! ( fee, 1 ) ;
8759
8824
8760
8825
let ( fee, _) = StacksChainState :: process_transaction (
8761
8826
& mut conn,
8762
8827
& signed_runtime_checkerror_impl_tx,
8763
8828
false ,
8764
8829
)
8765
8830
. unwrap ( ) ;
8766
- assert_eq ! ( fee, 0 ) ;
8831
+ assert_eq ! ( fee, 1 ) ;
8767
8832
8768
8833
let ( fee, _) =
8769
8834
StacksChainState :: process_transaction ( & mut conn, & signed_runtime_checkerror_tx, false )
8770
8835
. unwrap ( ) ;
8771
- assert_eq ! ( fee, 0 ) ;
8836
+ assert_eq ! ( fee, 1 ) ;
8772
8837
8773
8838
let err = StacksChainState :: process_transaction (
8774
8839
& mut conn,
@@ -8783,6 +8848,8 @@ pub mod test {
8783
8848
} else {
8784
8849
panic ! ( "Did not get unchecked interpreter error" ) ;
8785
8850
}
8851
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
8852
+ assert_eq ! ( acct. nonce, 3 ) ;
8786
8853
8787
8854
let err = StacksChainState :: process_transaction (
8788
8855
& mut conn,
@@ -8797,6 +8864,9 @@ pub mod test {
8797
8864
} else {
8798
8865
panic ! ( "Did not get unchecked interpreter error" ) ;
8799
8866
}
8867
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
8868
+ assert_eq ! ( acct. nonce, 3 ) ;
8869
+
8800
8870
conn. commit_block ( ) ;
8801
8871
8802
8872
// in 2.05, this invalidates the block
@@ -8814,20 +8884,20 @@ pub mod test {
8814
8884
false ,
8815
8885
)
8816
8886
. unwrap ( ) ;
8817
- assert_eq ! ( fee, 0 ) ;
8887
+ assert_eq ! ( fee, 1 ) ;
8818
8888
8819
8889
let ( fee, _) = StacksChainState :: process_transaction (
8820
8890
& mut conn,
8821
8891
& signed_runtime_checkerror_impl_tx,
8822
8892
false ,
8823
8893
)
8824
8894
. unwrap ( ) ;
8825
- assert_eq ! ( fee, 0 ) ;
8895
+ assert_eq ! ( fee, 1 ) ;
8826
8896
8827
8897
let ( fee, _) =
8828
8898
StacksChainState :: process_transaction ( & mut conn, & signed_runtime_checkerror_tx, false )
8829
8899
. unwrap ( ) ;
8830
- assert_eq ! ( fee, 0 ) ;
8900
+ assert_eq ! ( fee, 1 ) ;
8831
8901
8832
8902
let err = StacksChainState :: process_transaction (
8833
8903
& mut conn,
@@ -8842,6 +8912,8 @@ pub mod test {
8842
8912
} else {
8843
8913
panic ! ( "Did not get unchecked interpreter error" ) ;
8844
8914
}
8915
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
8916
+ assert_eq ! ( acct. nonce, 3 ) ;
8845
8917
8846
8918
let err = StacksChainState :: process_transaction (
8847
8919
& mut conn,
@@ -8856,6 +8928,9 @@ pub mod test {
8856
8928
} else {
8857
8929
panic ! ( "Did not get unchecked interpreter error" ) ;
8858
8930
}
8931
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
8932
+ assert_eq ! ( acct. nonce, 3 ) ;
8933
+
8859
8934
conn. commit_block ( ) ;
8860
8935
8861
8936
// in 2.1, this is a runtime error
@@ -8881,28 +8956,37 @@ pub mod test {
8881
8956
false ,
8882
8957
)
8883
8958
. unwrap ( ) ;
8884
- assert_eq ! ( fee, 0 ) ;
8959
+ assert_eq ! ( fee, 1 ) ;
8885
8960
8886
8961
let ( fee, _) = StacksChainState :: process_transaction (
8887
8962
& mut conn,
8888
8963
& signed_runtime_checkerror_impl_tx,
8889
8964
false ,
8890
8965
)
8891
8966
. unwrap ( ) ;
8892
- assert_eq ! ( fee, 0 ) ;
8967
+ assert_eq ! ( fee, 1 ) ;
8893
8968
8894
8969
let ( fee, _) =
8895
8970
StacksChainState :: process_transaction ( & mut conn, & signed_runtime_checkerror_tx, false )
8896
8971
. unwrap ( ) ;
8897
- assert_eq ! ( fee, 0 ) ;
8972
+ assert_eq ! ( fee, 1 ) ;
8898
8973
8899
8974
let ( fee, tx_receipt) = StacksChainState :: process_transaction (
8900
8975
& mut conn,
8901
8976
& signed_test_trait_checkerror_tx,
8902
8977
false ,
8903
8978
)
8904
8979
. unwrap ( ) ;
8905
- assert_eq ! ( fee, 0 ) ;
8980
+ assert_eq ! ( fee, 1 ) ;
8981
+
8982
+ // nonce keeps advancing despite error
8983
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
8984
+ assert_eq ! ( acct. nonce, 4 ) ;
8985
+
8986
+ // no state change materialized
8987
+ let executed_var =
8988
+ StacksChainState :: get_data_var ( & mut conn, & contract_id, "executed" ) . unwrap ( ) ;
8989
+ assert_eq ! ( executed_var, Some ( Value :: Bool ( false ) ) ) ;
8906
8990
8907
8991
assert ! ( tx_receipt. vm_error. is_some( ) ) ;
8908
8992
let err_str = tx_receipt. vm_error . unwrap ( ) ;
@@ -8916,7 +9000,16 @@ pub mod test {
8916
9000
false ,
8917
9001
)
8918
9002
. unwrap ( ) ;
8919
- assert_eq ! ( fee, 0 ) ;
9003
+ assert_eq ! ( fee, 1 ) ;
9004
+
9005
+ // nonce keeps advancing despite error
9006
+ let acct = StacksChainState :: get_account ( & mut conn, & addr. into ( ) ) ;
9007
+ assert_eq ! ( acct. nonce, 5 ) ;
9008
+
9009
+ // no state change materialized
9010
+ let executed_var =
9011
+ StacksChainState :: get_data_var ( & mut conn, & contract_id, "executed" ) . unwrap ( ) ;
9012
+ assert_eq ! ( executed_var, Some ( Value :: Bool ( false ) ) ) ;
8920
9013
8921
9014
assert ! ( tx_receipt. vm_error. is_some( ) ) ;
8922
9015
let err_str = tx_receipt. vm_error . unwrap ( ) ;
0 commit comments