mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 08:34:43 +08:00
large memory contract tests, plus a docker container for running heaptrack
This commit is contained in:
15
Dockerfile.memtest
Normal file
15
Dockerfile.memtest
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM rust:latest
|
||||
|
||||
WORKDIR /src/blockstack-core
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install valgrind heaptrack -y
|
||||
RUN apt-get install less
|
||||
|
||||
RUN rustup install stable
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN cargo test --no-run
|
||||
|
||||
CMD ["bash"]
|
||||
109
src/vm/tests/large_contract.rs
Normal file
109
src/vm/tests/large_contract.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
|
||||
use chainstate::stacks::index::storage::{TrieFileStorage};
|
||||
use vm::execute as vm_execute;
|
||||
use chainstate::burn::BlockHeaderHash;
|
||||
use vm::errors::{Error, CheckErrors, RuntimeErrorType};
|
||||
use vm::types::{Value, OptionalData, StandardPrincipalData, ResponseData,
|
||||
TypeSignature, PrincipalData, QualifiedContractIdentifier};
|
||||
use vm::contexts::{OwnedEnvironment,GlobalContext, Environment};
|
||||
use vm::representations::SymbolicExpression;
|
||||
use vm::contracts::Contract;
|
||||
use util::hash::hex_bytes;
|
||||
use vm::database::{MemoryBackingStore, MarfedKV, NULL_HEADER_DB, ClarityDatabase};
|
||||
use vm::clarity::ClarityInstance;
|
||||
use vm::ast;
|
||||
|
||||
use vm::tests::{with_memory_environment, with_marfed_environment, execute, symbols_from_values};
|
||||
|
||||
|
||||
/*
|
||||
* This test exhibits memory inflation --
|
||||
* `(define-data-var var-x ...)` uses more than 1048576 bytes of memory.
|
||||
* this is because of the rollback wrapper. _however_, that inflation is
|
||||
* fixed -- it's 2x the size of the variable (because it's stored both in
|
||||
* the lookup map and the edit log).
|
||||
* this can be eliminated, by making the rollback wrapper store a pointer in
|
||||
* the lookup map to the edit log.
|
||||
*/
|
||||
#[test] #[ignore]
|
||||
pub fn simple_test() {
|
||||
let marf = MarfedKV::temporary();
|
||||
let mut clarity_instance = ClarityInstance::new(marf);
|
||||
let EXPLODE_N = 100;
|
||||
|
||||
let contract_identifier = QualifiedContractIdentifier::local("foo").unwrap();
|
||||
|
||||
{
|
||||
let mut conn = clarity_instance.begin_block(&TrieFileStorage::block_sentinel(),
|
||||
&BlockHeaderHash::from_bytes(&[0 as u8; 32]).unwrap(),
|
||||
&NULL_HEADER_DB);
|
||||
|
||||
let define_data_var = "(define-data-var XZ (buff 1048576) \"a\")";
|
||||
|
||||
let mut contract = define_data_var.to_string();
|
||||
for i in 0..20 {
|
||||
let cur_size = format!("{}", 2u32.pow(i));
|
||||
contract.push_str("\n");
|
||||
contract.push_str(
|
||||
&format!("(var-set XZ (concat (unwrap-panic (as-max-len? (var-get XZ) u{}))
|
||||
(unwrap-panic (as-max-len? (var-get XZ) u{}))))",
|
||||
cur_size, cur_size));
|
||||
}
|
||||
for i in 0..EXPLODE_N {
|
||||
let exploder = format!("(define-data-var var-{} (buff 1048576) (var-get XZ))", i);
|
||||
contract.push_str("\n");
|
||||
contract.push_str(&exploder);
|
||||
}
|
||||
|
||||
let (ct_ast, ct_analysis) = conn.analyze_smart_contract(&contract_identifier, &contract).unwrap();
|
||||
conn.initialize_smart_contract(
|
||||
&contract_identifier, &ct_ast, &contract, |_,_| false).unwrap();
|
||||
conn.save_analysis(&contract_identifier, &ct_analysis).unwrap();
|
||||
|
||||
conn.commit_block();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*/
|
||||
#[test] #[ignore]
|
||||
pub fn let_memory_test() {
|
||||
let marf = MarfedKV::temporary();
|
||||
let mut clarity_instance = ClarityInstance::new(marf);
|
||||
let EXPLODE_N = 100;
|
||||
|
||||
let contract_identifier = QualifiedContractIdentifier::local("foo").unwrap();
|
||||
|
||||
{
|
||||
let mut conn = clarity_instance.begin_block(&TrieFileStorage::block_sentinel(),
|
||||
&BlockHeaderHash::from_bytes(&[0 as u8; 32]).unwrap(),
|
||||
&NULL_HEADER_DB);
|
||||
|
||||
let define_data_var = "(define-constant buff-0 \"a\")";
|
||||
|
||||
let mut contract = define_data_var.to_string();
|
||||
for i in 0..20 {
|
||||
contract.push_str("\n");
|
||||
contract.push_str(
|
||||
&format!("(define-constant buff-{} (concat buff-{} buff-{}))",
|
||||
i+1, i, i));
|
||||
}
|
||||
|
||||
contract.push_str("\n");
|
||||
contract.push_str("(let (");
|
||||
|
||||
for i in 0..EXPLODE_N {
|
||||
let exploder = format!("(var-{} buff-20) ", i);
|
||||
contract.push_str(&exploder);
|
||||
}
|
||||
|
||||
contract.push_str(") 1)");
|
||||
|
||||
let (ct_ast, ct_analysis) = conn.analyze_smart_contract(&contract_identifier, &contract).unwrap();
|
||||
conn.initialize_smart_contract(
|
||||
&contract_identifier, &ct_ast, &contract, |_,_| false).unwrap();
|
||||
conn.save_analysis(&contract_identifier, &ct_analysis).unwrap();
|
||||
|
||||
conn.commit_block();
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ mod datamaps;
|
||||
mod contracts;
|
||||
mod costs;
|
||||
mod traits;
|
||||
mod large_contract;
|
||||
|
||||
pub fn with_memory_environment<F>(f: F, top_level: bool)
|
||||
where F: FnOnce(&mut OwnedEnvironment) -> ()
|
||||
|
||||
Reference in New Issue
Block a user