Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: use nextest for unit tests, disable grcov collation and codecov o… #3811

Merged
merged 12 commits into from
Jul 27, 2023
30 changes: 23 additions & 7 deletions .github/workflows/bitcoin-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
- name: Checkout the latest code
id: git_checkout
uses: actions/checkout@v3

- name: Reclaim disk space
id: cleanup
run: |
sudo apt-get remove -y '^dotnet-.*'
sudo apt-get remove -y '^llvm-.*'
sudo apt-get remove -y 'php.*'
sudo apt-get remove -y '^mongodb-.*'
sudo apt-get remove -y '^mysql-.*'
sudo apt-get remove -y azure-cli google-cloud-sdk google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
sudo apt-get autoremove -y
sudo apt-get clean
docker system prune --force

- name: Build bitcoin integration testing image
id: build_docker_image
env:
Expand All @@ -35,15 +49,17 @@ jobs:
run: |
rm .dockerignore
docker build -f ./.github/actions/bitcoin-int-tests/Dockerfile.generic.bitcoin-tests -t stacks-blockchain:integrations .

- name: Export docker image as tarball
id: export_docker_image
run: docker save -o integration-image.tar stacks-blockchain:integrations
run: docker save stacks-blockchain:integrations | gzip > integration-image.tar.gz

- name: Upload built docker image
id: upload_docker_image
uses: actions/upload-artifact@v3
with:
name: integration-image.tar
path: integration-image.tar
name: integration-image.tar.gz
path: integration-image.tar.gz

# Run integration tests using sampled genesis block
sampled-genesis:
Expand Down Expand Up @@ -130,10 +146,10 @@ jobs:
id: download_docker_image
uses: actions/download-artifact@v3
with:
name: integration-image.tar
name: integration-image.tar.gz
- name: Load docker image
id: load_docker_image
run: docker load -i integration-image.tar && rm integration-image.tar
run: docker load -i integration-image.tar.gz && rm integration-image.tar.gz
- name: All integration tests with sampled genesis
id: bitcoin_integration_tests
timeout-minutes: 30
Expand Down Expand Up @@ -169,10 +185,10 @@ jobs:
id: download_docker_image
uses: actions/download-artifact@v3
with:
name: integration-image.tar
name: integration-image.tar.gz
- name: Load docker image
id: load_docker_image
run: docker load -i integration-image.tar && rm integration-image.tar
run: docker load -i integration-image.tar.gz && rm integration-image.tar.gz
- name: Atlas integration tests
id: atlas_integration_tests
timeout-minutes: 40
Expand Down
23 changes: 22 additions & 1 deletion .github/workflows/stacks-blockchain-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,39 @@ jobs:
run: |
rustup component add llvm-tools-preview
cargo install grcov
- name: Add nextest
run: |
cargo install cargo-nextest
- name: Checkout the latest code
id: git_checkout
uses: actions/checkout@v3
- name: Run units tests (with coverage)
id: unit_tests_codecov
# unset the coverage instrumentation flags.
# these slow tests down a lot locally (5-10x), and since
# grcov cannot collect this coverage data right now anyways,
# this is a speed win.
#env:
# RUSTFLAGS: -Cinstrument-coverage
# LLVM_PROFILE_FILE: stacks-blockchain-%p-%m.profraw
run: |
cargo nextest run --workspace
- name: Collate grcov
# grcov doesn't work with cargo nextest currently, getting
# that to work again will have to happen separately. Getting unit
# test run times below 2 hours is more important for now.
if: ${{ false }}
id: unit_tests_grcov
env:
RUSTFLAGS: -Cinstrument-coverage
LLVM_PROFILE_FILE: stacks-blockchain-%p-%m.profraw
run: |
cargo test --workspace
grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*" -o lcov.info
- name: Upload codecov results
# grcov doesn't work with cargo nextest currently, getting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. i'll have to double check my fork - i was under the impression this was working in that fork's workflows. lack of an error != it's working though, so i'll verify that.

# that to work again will have to happen separately. Getting unit
# test run times below 2 hours is more important for now.
if: ${{ false }}
uses: codecov/codecov-action@v3
id: codedov
with:
Expand Down
13 changes: 0 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 62 additions & 26 deletions src/clarity_vm/tests/analysis_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use clarity::vm::contracts::Contract;
use clarity::vm::costs::ExecutionCost;
use clarity::vm::database::{ClarityDatabase, NULL_BURN_STATE_DB, NULL_HEADER_DB};
use clarity::vm::errors::{CheckErrors, Error, RuntimeErrorType};
use clarity::vm::execute as vm_execute;
use clarity::vm::functions::NativeFunctions;
use clarity::vm::representations::SymbolicExpression;
use clarity::vm::test_util::{TEST_BURN_STATE_DB, TEST_HEADER_DB};
use clarity::vm::tests::{execute, symbols_from_values, UnitTestBurnStateDB};
use clarity::vm::types::{
AssetIdentifier, PrincipalData, QualifiedContractIdentifier, ResponseData, Value,
};
use clarity::vm::{execute as vm_execute, ContractName};
use stacks_common::util::hash::hex_bytes;

use crate::chainstate::stacks::index::ClarityMarfTrieId;
Expand All @@ -44,12 +44,11 @@ use crate::types::StacksEpochId;
use clarity::vm::tests::test_only_mainnet_to_chain_id;
use clarity::vm::ClarityVersion;

pub fn test_tracked_costs(
prog: &str,
fn setup_tracked_cost_test(
use_mainnet: bool,
epoch: StacksEpochId,
version: ClarityVersion,
) -> ExecutionCost {
) -> ClarityInstance {
let marf = MarfedKV::temporary();
let chain_id = test_only_mainnet_to_chain_id(use_mainnet);
let mut clarity_instance = ClarityInstance::new(use_mainnet, chain_id, marf);
Expand All @@ -70,21 +69,6 @@ pub fn test_tracked_costs(
(define-map map-foo { a: int } { b: int })
(define-public (foo-exec (a int)) (ok 1))";

let contract_self = format!(
"(define-map map-foo {{ a: int }} {{ b: int }})
(define-non-fungible-token nft-foo int)
(define-fungible-token ft-foo)
(define-data-var var-foo int 0)
(define-constant tuple-foo (tuple (a 1)))
(define-constant list-foo (list true))
(define-constant list-bar (list 1))
(define-constant str-foo \"foobar\")
(use-trait trait-1 .contract-trait.trait-1)
(define-public (execute (contract <trait-1>)) (ok {}))",
prog
);

let self_contract_id = QualifiedContractIdentifier::new(p1_principal.clone(), "self".into());
let other_contract_id =
QualifiedContractIdentifier::new(p1_principal.clone(), "contract-other".into());
let trait_contract_id =
Expand Down Expand Up @@ -192,10 +176,53 @@ pub fn test_tracked_costs(
conn.commit_block();
}

clarity_instance
}

fn test_tracked_costs(
prog: &str,
epoch: StacksEpochId,
version: ClarityVersion,
prog_id: usize,
clarity_instance: &mut ClarityInstance,
) -> ExecutionCost {
let contract_self = format!(
"(define-map map-foo {{ a: int }} {{ b: int }})
(define-non-fungible-token nft-foo int)
(define-fungible-token ft-foo)
(define-data-var var-foo int 0)
(define-constant tuple-foo (tuple (a 1)))
(define-constant list-foo (list true))
(define-constant list-bar (list 1))
(define-constant str-foo \"foobar\")
(use-trait trait-1 .contract-trait.trait-1)
(define-public (execute (contract <trait-1>)) (ok {}))",
prog
);

let p1 = vm_execute("'SZ2J6ZY48GV1EZ5V2V5RB9MP66SW86PYKKQ9H6DPR")
.unwrap()
.unwrap();

let p1_principal = match p1 {
Value::Principal(PrincipalData::Standard(ref data)) => data.clone(),
_ => panic!(),
};

let self_contract_id = QualifiedContractIdentifier::new(
p1_principal.clone(),
ContractName::try_from(format!("self-{}", prog_id)).unwrap(),
);

let burn_state_db = UnitTestBurnStateDB {
epoch_id: epoch,
ast_rules: ASTRules::PrecheckSize,
};

{
let mut conn = clarity_instance.begin_block(
&StacksBlockId([3 as u8; 32]),
&StacksBlockId([4 as u8; 32]),
&StacksBlockId([4 + prog_id as u8; 32]),
&TEST_HEADER_DB,
&burn_state_db,
);
Expand Down Expand Up @@ -226,15 +253,17 @@ pub fn test_tracked_costs(
}

fn epoch_21_test_all(use_mainnet: bool, version: ClarityVersion) {
let baseline = test_tracked_costs("1", use_mainnet, StacksEpochId::Epoch21, version);
let mut instance = setup_tracked_cost_test(use_mainnet, StacksEpochId::Epoch21, version);

let baseline = test_tracked_costs("1", StacksEpochId::Epoch21, version, 0, &mut instance);

for f in NativeFunctions::ALL.iter() {
for (ix, f) in NativeFunctions::ALL.iter().enumerate() {
if version < f.get_version() {
continue;
}

let test = get_simple_test(f);
let cost = test_tracked_costs(test, use_mainnet, StacksEpochId::Epoch21, version);
let cost = test_tracked_costs(test, StacksEpochId::Epoch21, version, ix + 1, &mut instance);
assert!(cost.exceeds(&baseline));
}
}
Expand All @@ -252,21 +281,28 @@ fn epoch_21_test_all_testnet() {
}

fn epoch_205_test_all(use_mainnet: bool) {
let mut instance = setup_tracked_cost_test(
use_mainnet,
StacksEpochId::Epoch2_05,
ClarityVersion::Clarity1,
);
let baseline = test_tracked_costs(
"1",
use_mainnet,
StacksEpochId::Epoch2_05,
ClarityVersion::Clarity1,
0,
&mut instance,
);

for f in NativeFunctions::ALL.iter() {
for (ix, f) in NativeFunctions::ALL.iter().enumerate() {
if f.get_version() == ClarityVersion::Clarity1 {
let test = get_simple_test(f);
let cost = test_tracked_costs(
test,
use_mainnet,
StacksEpochId::Epoch2_05,
ClarityVersion::Clarity1,
ix + 1,
&mut instance,
);
assert!(cost.exceeds(&baseline));
}
Expand Down
Loading