Skip to content

Commit 317a4a5

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

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

test/t8n/t8n.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,25 @@ 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 computed_tx_hash = keccak256(rlp::encode(tx));
108+
109+
if (j_txs[i].contains("hash"))
110+
{
111+
const auto loaded_tx_hash_opt =
112+
evmc::from_hex<bytes32>(j_txs[i]["hash"].get<std::string>());
113+
114+
if (loaded_tx_hash_opt != computed_tx_hash)
115+
throw std::logic_error("transaction hash mismatched: computed " +
116+
hex0x(computed_tx_hash) + ", expected " +
117+
hex0x(loaded_tx_hash_opt.value()));
118+
}
119+
106120
if (holds_alternative<std::error_code>(res))
107121
{
108122
const auto ec = std::get<std::error_code>(res);
109123
json::json j_rejected_tx;
110-
j_rejected_tx["hash"] = j_txs[i]["hash"];
124+
j_rejected_tx["hash"] = hex0x(computed_tx_hash);
111125
j_rejected_tx["index"] = i;
112126
j_rejected_tx["error"] = ec.message();
113127
j_result["rejected"].push_back(j_rejected_tx);
@@ -120,7 +134,8 @@ int main(int argc, const char* argv[])
120134

121135
txs_logs.insert(txs_logs.end(), tx_logs.begin(), tx_logs.end());
122136
auto& j_receipt = j_result["receipts"][j_result["receipts"].size()];
123-
j_receipt["transactionHash"] = j_txs[i]["hash"];
137+
138+
j_receipt["transactionHash"] = hex0x(computed_tx_hash);
124139
j_receipt["gasUsed"] = hex0x(static_cast<uint64_t>(receipt.gas_used));
125140
j_receipt["cumulativeGasUsed"] = j_receipt["gasUsed"];
126141

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

166181
std::ofstream{output_dir / output_alloc_file} << std::setw(2) << j_alloc;
167182
}
168-
catch (...)
183+
catch (const std::exception& e)
169184
{
170-
std::cerr << "Unhandled exception" << std::endl;
185+
std::cerr << e.what() << std::endl;
186+
return 1;
171187
}
172188

173189
return 0;

0 commit comments

Comments
 (0)