Skip to content

Commit

Permalink
test_cost_contract_short_circuits passing for mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorycoppola committed Nov 19, 2021
1 parent 4439b1e commit 37e8788
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/vm/costs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,7 @@ impl LimitedCostTracker {
LimitedCostTracker::new(use_mainnet, ExecutionCost::max_value(), clarity_db, epoch)
}

pub fn new_free_on_network(use_mainnet:bool) -> LimitedCostTracker {
if !use_mainnet{
panic!("oh no");
}
pub fn new_free_on_network(use_mainnet: bool) -> LimitedCostTracker {
LimitedCostTracker {
cost_function_references: HashMap::new(),
cost_contracts: HashMap::new(),
Expand Down Expand Up @@ -801,8 +798,12 @@ fn compute_cost(
let mainnet = cost_tracker.mainnet;
let mut null_store = NullBackingStore::new();
let conn = null_store.as_clarity_db();
let mut global_context =
GlobalContext::new(mainnet, conn, LimitedCostTracker::new_free_on_network(mainnet), eval_in_epoch);
let mut global_context = GlobalContext::new(
mainnet,
conn,
LimitedCostTracker::new_free_on_network(mainnet),
eval_in_epoch,
);

let cost_contract = cost_tracker
.cost_contracts
Expand Down
15 changes: 12 additions & 3 deletions src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ pub fn eval_all(
/// This method executes the program in Epoch 2.0 *and* Epoch 2.05 and asserts
/// that the result is the same before returning the result
#[cfg(test)]
pub fn execute_on_network(program: &str, use_mainnet:bool) -> Result<Option<Value>> {
pub fn execute_on_network(program: &str, use_mainnet: bool) -> Result<Option<Value>> {
let epoch_200_result = execute_in_epoch(program, StacksEpochId::Epoch20, use_mainnet);
let epoch_205_result = execute_in_epoch(program, StacksEpochId::Epoch2_05, use_mainnet);
assert_eq!(
Expand All @@ -394,12 +394,21 @@ pub fn execute(program: &str) -> Result<Option<Value>> {
}

#[cfg(test)]
pub fn execute_in_epoch(program: &str, epoch: StacksEpochId, use_mainnet:bool) -> Result<Option<Value>> {
pub fn execute_in_epoch(
program: &str,
epoch: StacksEpochId,
use_mainnet: bool,
) -> Result<Option<Value>> {
let contract_id = QualifiedContractIdentifier::transient();
let mut contract_context = ContractContext::new(contract_id.clone());
let mut marf = MemoryBackingStore::new();
let conn = marf.as_clarity_db();
let mut global_context = GlobalContext::new(false, conn, LimitedCostTracker::new_free_on_network(use_mainnet), epoch);
let mut global_context = GlobalContext::new(
false,
conn,
LimitedCostTracker::new_free_on_network(use_mainnet),
epoch,
);
global_context.execute(|g| {
let parsed = ast::build_ast(&contract_id, program, &mut ())?.expressions;
eval_all(&parsed, &mut contract_context, g)
Expand Down
10 changes: 5 additions & 5 deletions src/vm/tests/costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ use vm::errors::{CheckErrors, Error, RuntimeErrorType};
use vm::functions::NativeFunctions;
use vm::representations::SymbolicExpression;
use vm::tests::{
execute, execute_on_network, is_committed, is_err_code, symbols_from_values, with_marfed_environment,
with_memory_environment, TEST_BURN_STATE_DB, TEST_HEADER_DB,
execute, execute_on_network, is_committed, is_err_code, symbols_from_values,
with_marfed_environment, with_memory_environment, TEST_BURN_STATE_DB, TEST_HEADER_DB,
};
use vm::types::{AssetIdentifier, PrincipalData, QualifiedContractIdentifier, ResponseData, Value};

Expand All @@ -49,7 +49,7 @@ use rstest::rstest;

lazy_static! {
static ref COST_VOTING_MAINNET_CONTRACT: QualifiedContractIdentifier =
boot_code_id("cost-voting", false);
boot_code_id("cost-voting", true);
static ref COST_VOTING_TESTNET_CONTRACT: QualifiedContractIdentifier =
boot_code_id("cost-voting", false);
}
Expand Down Expand Up @@ -942,8 +942,8 @@ fn test_cost_contract_short_circuits(#[case] use_mainnet: bool) {
db.set_entry_unknown_descriptor(
voting_contract_to_use,
"confirmed-proposals",
execute("{ confirmed-id: u0 }"),
execute(&value),
execute_on_network("{ confirmed-id: u0 }", use_mainnet),
execute_on_network(&value, use_mainnet),
)
.unwrap();
db.commit();
Expand Down
2 changes: 1 addition & 1 deletion src/vm/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ pub fn execute(s: &str) -> Value {
vm_execute(s).unwrap().unwrap()
}

pub fn execute_on_network(s: &str, use_mainnet:bool) -> Value {
pub fn execute_on_network(s: &str, use_mainnet: bool) -> Value {
vm_execute_on_network(s, use_mainnet).unwrap().unwrap()
}

Expand Down

0 comments on commit 37e8788

Please sign in to comment.