2024-03-22 18:53:53 +01:00
|
|
|
// makeTest generates a test for the configured tracer by running
|
|
|
|
// a prestate reassembled and a call trace run, assembling all the
|
|
|
|
// gathered information into a test case.
|
|
|
|
var makeTest = function(tx, traceConfig) {
|
|
|
|
// Generate the genesis block from the block, transaction and prestate data
|
|
|
|
var block = eth.getBlock(eth.getTransaction(tx).blockHash);
|
|
|
|
var genesis = eth.getBlock(block.parentHash);
|
|
|
|
|
|
|
|
delete genesis.gasUsed;
|
|
|
|
delete genesis.logsBloom;
|
|
|
|
delete genesis.parentHash;
|
|
|
|
delete genesis.receiptsRoot;
|
|
|
|
delete genesis.sha3Uncles;
|
|
|
|
delete genesis.size;
|
|
|
|
delete genesis.transactions;
|
|
|
|
delete genesis.transactionsRoot;
|
|
|
|
delete genesis.uncles;
|
|
|
|
|
|
|
|
genesis.gasLimit = genesis.gasLimit.toString();
|
|
|
|
genesis.number = genesis.number.toString();
|
|
|
|
genesis.timestamp = genesis.timestamp.toString();
|
|
|
|
|
|
|
|
genesis.alloc = debug.traceTransaction(tx, {tracer: "prestateTracer"});
|
|
|
|
for (var key in genesis.alloc) {
|
|
|
|
var nonce = genesis.alloc[key].nonce;
|
|
|
|
if (nonce) {
|
|
|
|
genesis.alloc[key].nonce = nonce.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
genesis.config = admin.nodeInfo.protocols.eth.config;
|
|
|
|
|
|
|
|
// Generate the call trace and produce the test input
|
|
|
|
var result = debug.traceTransaction(tx, traceConfig);
|
|
|
|
delete result.time;
|
|
|
|
|
2024-04-01 20:53:56 +08:00
|
|
|
var context = {
|
|
|
|
number: block.number.toString(),
|
|
|
|
difficulty: block.difficulty,
|
|
|
|
timestamp: block.timestamp.toString(),
|
|
|
|
gasLimit: block.gasLimit.toString(),
|
|
|
|
miner: block.miner,
|
|
|
|
};
|
|
|
|
if (block.baseFeePerGas) {
|
|
|
|
context.baseFeePerGas = block.baseFeePerGas.toString();
|
|
|
|
}
|
|
|
|
|
2024-03-22 18:53:53 +01:00
|
|
|
console.log(JSON.stringify({
|
|
|
|
genesis: genesis,
|
2024-04-01 20:53:56 +08:00
|
|
|
context: context,
|
2024-03-22 18:53:53 +01:00
|
|
|
input: eth.getRawTransaction(tx),
|
|
|
|
result: result,
|
2024-09-02 10:30:33 +02:00
|
|
|
tracerConfig: traceConfig.tracerConfig,
|
2024-03-22 18:53:53 +01:00
|
|
|
}, null, 2));
|
2024-04-01 20:53:56 +08:00
|
|
|
}
|