@@ -24,8 +24,9 @@ use clarity::vm::contexts::{
24
24
use clarity:: vm:: contracts:: Contract ;
25
25
use clarity:: vm:: costs:: cost_functions:: ClarityCostFunction ;
26
26
use clarity:: vm:: costs:: {
27
- parse_cost, ClarityCostFunctionEvaluator , ClarityCostFunctionReference , CostErrors ,
28
- DefaultVersion , ExecutionCost , LimitedCostTracker , COSTS_1_NAME , COSTS_2_NAME , COSTS_3_NAME ,
27
+ compute_cost, parse_cost, ClarityCostFunctionEvaluator , ClarityCostFunctionReference ,
28
+ CostErrors , DefaultVersion , ExecutionCost , LimitedCostTracker , COSTS_1_NAME , COSTS_2_NAME ,
29
+ COSTS_3_NAME ,
29
30
} ;
30
31
use clarity:: vm:: database:: { ClarityDatabase , MemoryBackingStore } ;
31
32
use clarity:: vm:: errors:: { CheckErrors , Error , RuntimeErrorType } ;
@@ -885,19 +886,16 @@ fn eval_cost_fn(
885
886
let mainnet = owned_env. is_mainnet ( ) ;
886
887
let boot_costs_id = boot_code_id ( cost_contract_name, mainnet) ;
887
888
let cost_fn_name = cost_fn. get_name_str ( ) ;
888
-
889
- let exec = format ! ( "({cost_fn_name} u{argument})" ) ;
890
-
891
- let exec_result = owned_env
892
- . eval_read_only ( & boot_costs_id, & exec)
893
- . map ( |( value, _, _) | Some ( value) ) ;
894
-
889
+ let cost_tracker = owned_env. mut_cost_tracker ( ) ;
890
+ let data = match cost_tracker {
891
+ LimitedCostTracker :: Free => panic ! ( ) ,
892
+ LimitedCostTracker :: Limited ( data) => data,
893
+ } ;
895
894
let clarity_cost_fn_ref = ClarityCostFunctionReference {
896
895
contract_id : boot_costs_id,
897
896
function_name : cost_fn_name. to_string ( ) ,
898
897
} ;
899
-
900
- parse_cost ( & clarity_cost_fn_ref. to_string ( ) , exec_result)
898
+ compute_cost ( data, clarity_cost_fn_ref, & [ argument] , data. epoch )
901
899
}
902
900
903
901
fn eval_replaced_cost_fn (
@@ -926,7 +924,13 @@ fn proptest_cost_fn(cost_fn: &ClarityCostFunction, cost_contract_name: &str) {
926
924
inputs. push ( 2u64 . pow ( i) + 1 ) ;
927
925
} ) ;
928
926
for use_mainnet in [ true , false ] {
929
- with_owned_env ( StacksEpochId :: latest ( ) , use_mainnet, |mut owned_env| {
927
+ let epoch = match cost_contract_name {
928
+ COSTS_1_NAME => StacksEpochId :: Epoch20 ,
929
+ COSTS_2_NAME => StacksEpochId :: Epoch2_05 ,
930
+ COSTS_3_NAME => StacksEpochId :: latest ( ) ,
931
+ _ => panic ! ( ) ,
932
+ } ;
933
+ with_owned_env ( epoch, use_mainnet, |mut owned_env| {
930
934
for i in inputs. iter ( ) {
931
935
eprintln ! ( "Evaluating {cost_contract_name}.{cost_fn}({i})" ) ;
932
936
let clar_evaled = eval_cost_fn ( & mut owned_env, cost_contract_name, cost_fn, * i) ;
0 commit comments