Skip to content

Commit a701f70

Browse files
committed
Add EEST make directive and fix test run
1 parent 428d1f0 commit a701f70

File tree

4 files changed

+88
-32
lines changed

4 files changed

+88
-32
lines changed

.editorconfig

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[*]
2+
cpp_indent_braces=false
3+
cpp_indent_multi_line_relative_to=innermost_parenthesis
4+
cpp_indent_within_parentheses=indent
5+
cpp_indent_preserve_within_parentheses=false
6+
cpp_indent_case_labels=false
7+
cpp_indent_case_contents=true
8+
cpp_indent_case_contents_when_block=false
9+
cpp_indent_lambda_braces_when_parameter=true
10+
cpp_indent_goto_labels=one_left
11+
cpp_indent_preprocessor=leftmost_column
12+
cpp_indent_access_specifiers=false
13+
cpp_indent_namespace_contents=true
14+
cpp_indent_preserve_comments=false
15+
cpp_new_line_before_open_brace_namespace=ignore
16+
cpp_new_line_before_open_brace_type=ignore
17+
cpp_new_line_before_open_brace_function=ignore
18+
cpp_new_line_before_open_brace_block=ignore
19+
cpp_new_line_before_open_brace_lambda=ignore
20+
cpp_new_line_scope_braces_on_separate_lines=false
21+
cpp_new_line_close_brace_same_line_empty_type=false
22+
cpp_new_line_close_brace_same_line_empty_function=false
23+
cpp_new_line_before_catch=true
24+
cpp_new_line_before_else=true
25+
cpp_new_line_before_while_in_do_while=false
26+
cpp_space_before_function_open_parenthesis=remove
27+
cpp_space_within_parameter_list_parentheses=false
28+
cpp_space_between_empty_parameter_list_parentheses=false
29+
cpp_space_after_keywords_in_control_flow_statements=true
30+
cpp_space_within_control_flow_statement_parentheses=false
31+
cpp_space_before_lambda_open_parenthesis=false
32+
cpp_space_within_cast_parentheses=false
33+
cpp_space_after_cast_close_parenthesis=false
34+
cpp_space_within_expression_parentheses=false
35+
cpp_space_before_block_open_brace=true
36+
cpp_space_between_empty_braces=false
37+
cpp_space_before_initializer_list_open_brace=false
38+
cpp_space_within_initializer_list_braces=true
39+
cpp_space_preserve_in_initializer_list=true
40+
cpp_space_before_open_square_bracket=false
41+
cpp_space_within_square_brackets=false
42+
cpp_space_before_empty_square_brackets=false
43+
cpp_space_between_empty_square_brackets=false
44+
cpp_space_group_square_brackets=true
45+
cpp_space_within_lambda_brackets=false
46+
cpp_space_between_empty_lambda_brackets=false
47+
cpp_space_before_comma=false
48+
cpp_space_after_comma=true
49+
cpp_space_remove_around_member_operators=true
50+
cpp_space_before_inheritance_colon=true
51+
cpp_space_before_constructor_colon=true
52+
cpp_space_remove_before_semicolon=true
53+
cpp_space_after_semicolon=false
54+
cpp_space_remove_around_unary_operator=true
55+
cpp_space_around_binary_operator=insert
56+
cpp_space_around_assignment_operator=insert
57+
cpp_space_pointer_reference_alignment=left
58+
cpp_space_around_ternary_operator=insert
59+
cpp_wrap_preserve_blocks=one_liners

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ eest_blockchain_tests eest-blockchain-tests:
33
cmake -B build/eest -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DTESTS_DIR=third_party/eest-fixtures/blockchain_tests
44
cmake --build build/eest
55
ctest --test-dir build/eest --parallel
6+
7+
rv32im_eest_blockchain_tests:
8+
cd qemu_runner && make rv32im_eest_blockchain_tests

qemu_runner/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ if(TESTS_DIR)
124124
)
125125
set_tests_properties(${TEST_NAME} PROPERTIES SKIP_RETURN_CODE 2)
126126
endforeach()
127-
endif()
127+
endif()

zilk_core/dev/state_transition.cpp

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "state_transition.hpp"
55

66
#include <bit>
7+
#include <format>
78
#include <fstream>
8-
#include <iostream>
99
#include <stdexcept>
1010

1111
#include <magic_enum.hpp>
@@ -22,6 +22,7 @@
2222
#include <zilk_core/core/types/address.hpp>
2323
#include <zilk_core/core/types/evmc_bytes32.hpp>
2424
#include <zilk_core/dev/common/ecc_key_pair.hpp>
25+
#include <zilk_core/print.hpp>
2526

2627
#include "expected_state.hpp"
2728

@@ -47,7 +48,7 @@ StateTransition::StateTransition(const std::string& unified_rlp_str) noexcept {
4748

4849
// Read from binary
4950
unified_rlp_ = ByteView{reinterpret_cast<const uint8_t*>(unified_rlp_str.data()), unified_rlp_str.size()};
50-
std::cout << "in ctor unified_rlp_str RLP length: " << unified_rlp_str.size() << " unified_rlp_ RLP length: " << unified_rlp_.size() << "\n";
51+
sys_println(std::format("in ctor unified_rlp_str RLP length: {} unified_rlp_ RLP length: {}", unified_rlp_str.size(), unified_rlp_.size()).c_str());
5152
}
5253

5354
StateTransition::StateTransition(const bool terminate_on_error, const bool show_diagnostics) noexcept
@@ -335,7 +336,7 @@ namespace {
335336
if (invalid) {
336337
return Status::kPassed;
337338
}
338-
std::cout << "Failure to read hex" << std::endl;
339+
sys_println("Failure to read hex");
339340
return Status::kFailed;
340341
}
341342

@@ -361,7 +362,7 @@ namespace {
361362
if (invalid) {
362363
return Status::kPassed;
363364
}
364-
std::cout << "Failure to decode RLP" << std::endl;
365+
sys_println("Failure to decode RLP");
365366
return Status::kFailed;
366367
}
367368

@@ -370,13 +371,13 @@ namespace {
370371
if (invalid) {
371372
return Status::kPassed;
372373
}
373-
std::cout << "Validation error " << magic_enum::enum_name<ValidationResult>(err) << std::endl;
374+
sys_println(std::format("Validation error {}", magic_enum::enum_name<ValidationResult>(err)).c_str());
374375
return Status::kFailed;
375376
}
376377

377378
if (invalid) {
378-
std::cout << "Invalid block executed successfully\n";
379-
std::cout << "Expected: " << json_block["expectException"] << std::endl;
379+
sys_println("Invalid block executed successfully");
380+
sys_println(std::format("Expected: {}", json_block["expectException"].dump()).c_str());
380381
return Status::kFailed;
381382
}
382383

@@ -385,13 +386,12 @@ namespace {
385386

386387
bool post_check(const InMemoryState& state, const nlohmann::json& expected) {
387388
if (state.accounts().size() != expected.size()) {
388-
std::cout << "Account number mismatch: " << state.accounts().size() << " != " << expected.size()
389-
<< std::endl;
389+
sys_println(std::format("Account number mismatch: {} != {}", state.accounts().size(), expected.size()).c_str());
390390

391391
// Find and report accounts missing from the expected set.
392392
for (const auto& [addr, _] : state.accounts()) {
393393
if (const auto addr_hex = "0x" + hex(addr); !expected.contains(addr_hex)) {
394-
std::cout << "Unexpected account: " << addr_hex << std::endl;
394+
sys_println(std::format("Unexpected account: {}", addr_hex).c_str());
395395
}
396396
}
397397

@@ -404,36 +404,32 @@ namespace {
404404

405405
std::optional<Account> account{state.read_account(address)};
406406
if (!account) {
407-
std::cout << "Missing account " << entry.key() << std::endl;
407+
sys_println(std::format("Missing account {}", entry.key()).c_str());
408408
return false;
409409
}
410410

411411
const auto expected_balance{intx::from_string<intx::uint256>(j["balance"].get<std::string>())};
412412
if (account->balance != expected_balance) {
413-
std::cout << "Balance mismatch for " << entry.key() << ":\n"
414-
<< to_string(account->balance, 16) << " != " << j["balance"] << std::endl;
413+
sys_println(std::format("Balance mismatch for {}:\n{} != {}", entry.key(), to_string(account->balance, 16), j["balance"].get<std::string>()).c_str());
415414
return false;
416415
}
417416

418417
const auto expected_nonce{intx::from_string<intx::uint256>(j["nonce"].get<std::string>())};
419418
if (account->nonce != expected_nonce) {
420-
std::cout << "Nonce mismatch for " << entry.key() << ":\n"
421-
<< account->nonce << " != " << j["nonce"] << std::endl;
419+
sys_println(std::format("Nonce mismatch for {}:\n{} != {}", entry.key(), account->nonce, j["nonce"].get<std::string>()).c_str());
422420
return false;
423421
}
424422

425423
auto expected_code{j["code"].get<std::string>()};
426424
Bytes actual_code{state.read_code(address, account->code_hash)};
427425
if (actual_code != from_hex(expected_code)) {
428-
std::cout << "Code mismatch for " << entry.key() << ":\n"
429-
<< to_hex(actual_code) << " != " << expected_code << std::endl;
426+
sys_println(std::format("Code mismatch for {}:\n{} != {}", entry.key(), to_hex(actual_code), expected_code).c_str());
430427
return false;
431428
}
432429

433430
size_t storage_size{state.storage_size(address, account->incarnation)};
434431
if (storage_size != j["storage"].size()) {
435-
std::cout << "Storage size mismatch for " << entry.key() << ":\n"
436-
<< storage_size << " != " << j["storage"].size() << std::endl;
432+
sys_println(std::format("Storage size mismatch for {}:\n{} != {}", entry.key(), storage_size, j["storage"].size()).c_str());
437433
return false;
438434
}
439435

@@ -442,8 +438,7 @@ namespace {
442438
Bytes expected_value{from_hex(storage.value().get<std::string>()).value()};
443439
evmc::bytes32 actual_value{state.read_storage(address, account->incarnation, to_bytes32(key))};
444440
if (actual_value != to_bytes32(expected_value)) {
445-
std::cout << "Storage mismatch for " << entry.key() << " at " << storage.key() << ":\n"
446-
<< to_hex(actual_value) << " != " << to_hex(expected_value) << std::endl;
441+
sys_println(std::format("Storage mismatch for {} at {}:\n{} != {}", entry.key(), storage.key(), to_hex(actual_value), to_hex(expected_value)).c_str());
447442
return false;
448443
}
449444
}
@@ -487,15 +482,15 @@ namespace {
487482
const auto network{json_test["network"].get<std::string>()};
488483
const auto config_it{test::kNetworkConfig.find(network)};
489484
if (config_it == test::kNetworkConfig.end()) {
490-
std::cout << "unknown network " << network << std::endl;
485+
sys_println(std::format("unknown network {}", network).c_str());
491486
return Status::kSkipped;
492487
}
493488
auto genesisRLPStr = json_test["genesisRLP"].get<std::string>();
494489
Bytes genesis_rlp{from_hex(genesisRLPStr).value()};
495490
ByteView genesis_view{genesis_rlp};
496491
Block genesis_block;
497492
if (!rlp::decode(genesis_view, genesis_block)) {
498-
std::cout << "Failure to decode genesisRLP" << std::endl;
493+
sys_println("Failure to decode genesisRLP");
499494
return Status::kFailed;
500495
}
501496

@@ -514,8 +509,7 @@ namespace {
514509
evmc::bytes32 state_root{state.state_root_hash()};
515510
std::string expected_hex{json_test["postStateHash"].get<std::string>()};
516511
if (state_root != to_bytes32(from_hex(expected_hex).value())) {
517-
std::cout << "postStateHash mismatch:\n"
518-
<< to_hex(state_root) << " != " << expected_hex << std::endl;
512+
sys_println(std::format("postStateHash mismatch:\n{} != {}", to_hex(state_root), expected_hex).c_str());
519513
return Status::kFailed;
520514
}
521515
return Status::kPassed;
@@ -538,16 +532,16 @@ uint64_t StateTransition::run(uint32_t num_runs, bool is_test) {
538532
bool any_failed = false;
539533
bool any_skipped = false;
540534
for (const auto& [name, test] : base_json_.items()) {
541-
std::cout << " " << name << ":\n";
535+
sys_println(std::format(" {}:", name).c_str());
542536
const auto result = blockchain_test(test);
543537
if (result.failed != 0) {
544538
any_failed = true;
545-
std::cout << " FAILED\n";
539+
sys_println(" FAILED");
546540
} else if (result.skipped != 0) {
547-
std::cout << " SKIPPED\n";
541+
sys_println(" SKIPPED");
548542
any_skipped = true;
549543
} else {
550-
std::cout << " passed\n";
544+
sys_println(" passed");
551545
}
552546
}
553547
if (any_failed)
@@ -557,7 +551,7 @@ uint64_t StateTransition::run(uint32_t num_runs, bool is_test) {
557551
return 0;
558552
}
559553

560-
std::cout << "Running State transition. num_runs=" << num_runs << "\n";
554+
sys_println(std::format("Running State transition. num_runs={}", num_runs).c_str());
561555
failed_count_ = 0;
562556
total_count_ = 0;
563557
uint64_t total_gas = 0;
@@ -591,7 +585,7 @@ uint64_t StateTransition::run(uint32_t num_runs, bool is_test) {
591585
txn_validation == ValidationResult::kOk) {
592586
//============== [TESTING ONLY] SIMULATING MULTIPLE RUNS=====
593587
for (uint32_t i = 0; i < num_runs; i++) {
594-
std::cout << "Inside multiple runs loop\n";
588+
sys_println("Inside multiple runs loop");
595589

596590
auto state_cp = read_genesis_allocation(test_data_["pre"]);
597591
ExecutionProcessor ccprocessor{block, *rule_set, state_cp, config, true};

0 commit comments

Comments
 (0)