Skip to content

Commit

Permalink
t8n: Compute tx hash instead of taking if from json. Add exc printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Mar 22, 2023
1 parent 05e923f commit 7f07913
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/t8n/t8n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,16 @@ int main(int argc, const char* argv[])
tx.chain_id = chain_id;

auto res = state::transition(state, block, tx, rev, vm);

const auto tx_hash = hex0x(keccak256(rlp::encode(tx)));
if (j_txs[i].contains("hash") && j_txs[i]["hash"] != tx_hash)
throw std::invalid_argument("hash mismatch");

if (holds_alternative<std::error_code>(res))
{
const auto ec = std::get<std::error_code>(res);
json::json j_rejected_tx;
j_rejected_tx["hash"] = j_txs[i]["hash"];
j_rejected_tx["hash"] = tx_hash;
j_rejected_tx["index"] = i;
j_rejected_tx["error"] = ec.message();
j_result["rejected"].push_back(j_rejected_tx);
Expand All @@ -120,7 +125,8 @@ int main(int argc, const char* argv[])

txs_logs.insert(txs_logs.end(), tx_logs.begin(), tx_logs.end());
auto& j_receipt = j_result["receipts"][j_result["receipts"].size()];
j_receipt["transactionHash"] = j_txs[i]["hash"];

j_receipt["transactionHash"] = tx_hash;
j_receipt["gasUsed"] = hex0x(static_cast<uint64_t>(receipt.gas_used));
j_receipt["cumulativeGasUsed"] = j_receipt["gasUsed"];

Expand Down Expand Up @@ -165,9 +171,10 @@ int main(int argc, const char* argv[])

std::ofstream{output_dir / output_alloc_file} << j_alloc;
}
catch (...)
catch (const std::exception& e)
{
std::cerr << "Unhandled exception" << std::endl;
std::cerr << e.what() << std::endl;
return 1;
}

return 0;
Expand Down

0 comments on commit 7f07913

Please sign in to comment.