Skip to content

Commit 6e3e39b

Browse files
committed
t8n: Compute tx hash instead of taking if from json. Add exc printing.
1 parent 60977de commit 6e3e39b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

test/t8n/t8n.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,24 @@ int main(int argc, const char* argv[])
103103
tx.chain_id = chain_id;
104104

105105
auto res = state::transition(state, block, tx, rev, vm);
106+
107+
const auto tx_computed_hash = keccak256(rlp::encode(tx));
108+
109+
if (j_txs[i].contains("hash") && j_txs[i]["hash"].is_string())
110+
{
111+
const auto tx_loaded_hash_opt =
112+
evmc::from_hex<bytes32>(j_txs[i]["hash"].get<std::string>());
113+
114+
if (tx_loaded_hash_opt.has_value() &&
115+
tx_loaded_hash_opt.value() != tx_computed_hash)
116+
throw std::logic_error("hash mismatch");
117+
}
118+
106119
if (holds_alternative<std::error_code>(res))
107120
{
108121
const auto ec = std::get<std::error_code>(res);
109122
json::json j_rejected_tx;
110-
j_rejected_tx["hash"] = j_txs[i]["hash"];
123+
j_rejected_tx["hash"] = hex0x(tx_computed_hash);
111124
j_rejected_tx["index"] = i;
112125
j_rejected_tx["error"] = ec.message();
113126
j_result["rejected"].push_back(j_rejected_tx);
@@ -120,7 +133,8 @@ int main(int argc, const char* argv[])
120133

121134
txs_logs.insert(txs_logs.end(), tx_logs.begin(), tx_logs.end());
122135
auto& j_receipt = j_result["receipts"][j_result["receipts"].size()];
123-
j_receipt["transactionHash"] = j_txs[i]["hash"];
136+
137+
j_receipt["transactionHash"] = hex0x(tx_computed_hash);
124138
j_receipt["gasUsed"] = hex0x(static_cast<uint64_t>(receipt.gas_used));
125139
j_receipt["cumulativeGasUsed"] = j_receipt["gasUsed"];
126140

@@ -165,9 +179,10 @@ int main(int argc, const char* argv[])
165179

166180
std::ofstream{output_dir / output_alloc_file} << std::setw(2) << j_alloc;
167181
}
168-
catch (...)
182+
catch (const std::exception& e)
169183
{
170-
std::cerr << "Unhandled exception" << std::endl;
184+
std::cerr << e.what() << std::endl;
185+
return 1;
171186
}
172187

173188
return 0;

0 commit comments

Comments
 (0)