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

Report steps instead of gas in integration tests #316

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions packages/client/src/test.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::serde::Serde;
use core::testing::get_available_gas;
use consensus::types::block::Block;
use consensus::types::chain_state::{ChainState, BlockValidatorImpl};
use consensus::types::utxo_set::{UtxoSet, UtxoSetTrait};
Expand Down Expand Up @@ -42,7 +41,6 @@ struct UtreexoArgs {
/// Prints result to the stdout.
fn main(arguments: Array<felt252>) -> Array<felt252> {
println!("Running integration test... ");
let mut gas_before = get_available_gas();
let mut args = arguments.span();

let Args {
Expand All @@ -55,32 +53,31 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {
match chain_state.validate_and_apply(block, ref utxo_set, execute_script) {
Result::Ok(new_chain_state) => { chain_state = new_chain_state; },
Result::Err(err) => {
println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err);
println!("FAIL: error='{}'", err);
panic!();
},
}
};

if chain_state != expected_chain_state {
println!(
"FAIL: gas_spent={} error='expected chain state {:?}, actual {:?}'",
gas_before - get_available_gas(),
"FAIL: error='expected chain state {:?}, actual {:?}'",
expected_chain_state,
chain_state,
);
panic!();
}

if let Result::Err(err) = utxo_set.finalize() {
println!("FAIL: gas_spent={} error='{}'", gas_before - get_available_gas(), err);
println!("FAIL: error='{}'", err);
panic!();
}

if let Option::Some(UtreexoArgs { mut state, proof, expected_state }) = utreexo_args {
match state.verify_and_delete(@proof, utxo_set.leaves_to_delete.span()) {
Result::Ok(new_state) => { state = new_state; },
Result::Err(err) => {
println!("FAIL: gas_spent={} error='{:?}'", gas_before - get_available_gas(), err);
println!("FAIL: error='{:?}'", err);
panic!();
},
}
Expand All @@ -89,16 +86,13 @@ fn main(arguments: Array<felt252>) -> Array<felt252> {

if state != expected_state {
println!(
"FAIL: gas_spent={} error='expected utreexo state {:?}, actual {:?}'",
gas_before - get_available_gas(),
expected_state,
state,
"FAIL: error='expected utreexo state {:?}, actual {:?}'", expected_state, state,
);
panic!();
}
}

println!("OK: gas_spent={}", gas_before - get_available_gas());
println!("OK");
array![]
}

Expand Down
10 changes: 5 additions & 5 deletions scripts/data/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,24 @@ for test_file in "${test_files[@]}"; do
else
arguments_file="$(dirname "$test_file")/.arguments-$(basename "$test_file")"
python ../../scripts/data/format_args.py --input_file ${test_file} $([[ $execute_scripts -eq 1 ]] && echo "--execute_script") > $arguments_file
output=$(scarb cairo-run --no-build --function main --arguments-file $arguments_file)
gas_spent=$(echo $output | grep -o 'gas_spent=[0-9]*' | sed 's/gas_spent=//')
output=$(scarb cairo-run --no-build --function main --print-resource-usage --arguments-file $arguments_file)
steps=$(echo $output | grep -o 'steps: [0-9]*' | sed 's/steps: //')

if [[ "$nocapture" -eq 1 ]]; then
echo -e "\n$output"
fi

if [[ "$output" == *"FAIL"* ]]; then
echo -e "${RED} fail ${RESET}(gas usage est.: $gas_spent)"
echo -e "${RED} fail ${RESET}(steps: $steps)"
num_fail=$((num_fail + 1))
error=$(echo $output | grep -o "error='[^']*'" | sed "s/error=//")
failures+="\t$test_file — Panicked with $error\n"
elif [[ "$output" == *"OK"* ]]; then
echo -e "${GREEN} ok ${RESET}(gas usage est.: $gas_spent)"
echo -e "${GREEN} ok ${RESET}(steps: $steps)"
num_ok=$((num_ok + 1))
rm $arguments_file
else
echo -e "${RED} fail ${RESET}(gas usage est.: 0)"
echo -e "${RED} fail ${RESET}"
num_fail=$((num_fail + 1))
error=$(echo "$output" | sed '1d' | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g') #spellchecker:disable-line
failures+="\t$test_file — $error\n"
Expand Down
Loading