a bit more testing prep

This commit is contained in:
Aaron Blankstein
2021-05-10 19:51:02 -05:00
parent 828b7f0e78
commit b8dec67665
6 changed files with 44 additions and 8 deletions

View File

@@ -37,8 +37,11 @@ use vm::types::{
TupleData, TupleTypeSignature, TypeSignature, Value, NONE,
};
use crate::types::proof::{ClarityMarfTrieId, TrieMerkleProof};
use crate::util::boot::boot_code_id;
use crate::{
core::StacksEpoch,
types::proof::{ClarityMarfTrieId, TrieMerkleProof},
};
use crate::{
core::StacksEpochId,
types::chainstate::{
@@ -235,7 +238,7 @@ impl BurnStateDB for TestSimBurnStateDB {
}
fn get_stacks_epoch(&self, height: u32) -> Option<StacksEpoch> {
let epoch_begin_index = match self.epoch_bounds.binary_search(height as u64) {
let epoch_begin_index = match self.epoch_bounds.binary_search(&(height as u64)) {
Ok(index) => index,
Err(index) => {
if index == 0 {
@@ -251,8 +254,8 @@ impl BurnStateDB for TestSimBurnStateDB {
};
let epoch_id = match epoch_begin_index {
0 => Epoch20,
1 => Epoch21,
0 => StacksEpochId::Epoch20,
1 => StacksEpochId::Epoch21,
_ => panic!("Epoch unknown"),
};
@@ -261,6 +264,7 @@ impl BurnStateDB for TestSimBurnStateDB {
end_height: self
.epoch_bounds
.get(epoch_begin_index + 1)
.cloned()
.unwrap_or(u64::max_value()),
epoch_id,
})
@@ -329,6 +333,25 @@ impl HeadersDB for TestSimHeadersDB {
}
}
#[test]
fn simple_epoch21_test() {
let mut sim = ClarityTestSim::new();
sim.epoch_bounds = vec![0, 3];
let delegator = StacksPrivateKey::new();
sim.execute_next_block(|env| {
env.initialize_contract(POX_CONTRACT_TESTNET.clone(), &BOOT_CODE_POX_TESTNET, None)
.unwrap()
});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
sim.execute_next_block(|_env| {});
}
#[test]
fn recency_tests() {
let mut sim = ClarityTestSim::new();

View File

@@ -26,6 +26,8 @@ use vm::functions::NativeFunctions;
use vm::types::QualifiedContractIdentifier;
use vm::variables::NativeVariables;
use crate::vm::ClarityVersion;
/// Checks whether or not a contract only contains arithmetic expressions (for example, defining a
/// map would not pass this check).
/// This check is useful in determining the validity of new potential cost functions.
@@ -37,6 +39,7 @@ fn arithmetic_check(contract: &str) -> Result<(), Error> {
contract_identifier,
expressions,
LimitedCostTracker::new_free(),
ClarityVersion::Clarity1,
);
ArithmeticOnlyChecker::run(&analysis)

View File

@@ -1878,7 +1878,8 @@ mod test {
}
let conn = store.as_clarity_db(&DOC_HEADER_DB, &DOC_POX_STATE_DB);
let mut contract_context = ContractContext::new(contract_id.clone());
let mut contract_context =
ContractContext::new(contract_id.clone(), crate::vm::ClarityVersion::Clarity1);
let mut global_context = GlobalContext::new(false, conn, LimitedCostTracker::new_free());
global_context

View File

@@ -134,6 +134,7 @@ define_versioned_named_enum!(NativeFunctions(ClarityVersion) {
GetStxBalance("stx-get-balance", ClarityVersion::Clarity1),
StxTransfer("stx-transfer?", ClarityVersion::Clarity1),
StxBurn("stx-burn?", ClarityVersion::Clarity1),
GetAccountLockup("stx-account?", ClarityVersion::Clarity2),
});
impl NativeFunctions {

View File

@@ -384,6 +384,8 @@ mod test {
Value,
};
use super::ClarityVersion;
#[test]
fn test_simple_user_function() {
//
@@ -413,7 +415,10 @@ mod test {
);
let context = LocalContext::new();
let mut contract_context = ContractContext::new(QualifiedContractIdentifier::transient());
let mut contract_context = ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity1,
);
let mut marf = MemoryBackingStore::new();
let mut global_context =

View File

@@ -33,8 +33,8 @@ use vm::types::{PrincipalData, ResponseData, SequenceData, SequenceSubtype};
use vm::{eval, execute as vm_execute};
use vm::{CallStack, ContractContext, Environment, GlobalContext, LocalContext, Value};
use crate::clarity_vm::database::MemoryBackingStore;
use crate::types::chainstate::StacksAddress;
use crate::{clarity_vm::database::MemoryBackingStore, vm::ClarityVersion};
use chainstate::stacks::C32_ADDRESS_VERSION_TESTNET_SINGLESIG;
#[test]
@@ -380,7 +380,10 @@ fn test_simple_if_functions() {
);
let context = LocalContext::new();
let mut contract_context = ContractContext::new(QualifiedContractIdentifier::transient());
let mut contract_context = ContractContext::new(
QualifiedContractIdentifier::transient(),
ClarityVersion::Clarity1,
);
let mut marf = MemoryBackingStore::new();
let mut global_context =
GlobalContext::new(false, marf.as_clarity_db(), LimitedCostTracker::new_free());