eth/tracers: refactor block context in test runner (#29450)
This commit contains a minor refactoring of the block context used within the test runners. --------- Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
b1f88ef9bd
commit
dcc0b3704d
|
@ -65,10 +65,7 @@ type callTrace struct {
|
||||||
|
|
||||||
// callTracerTest defines a single test to check the call tracer against.
|
// callTracerTest defines a single test to check the call tracer against.
|
||||||
type callTracerTest struct {
|
type callTracerTest struct {
|
||||||
Genesis *core.Genesis `json:"genesis"`
|
tracerTestEnv
|
||||||
Context *callContext `json:"context"`
|
|
||||||
Input string `json:"input"`
|
|
||||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
|
||||||
Result *callTrace `json:"result"`
|
Result *callTrace `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,7 @@ type flatCallTraceResult struct {
|
||||||
|
|
||||||
// flatCallTracerTest defines a single test to check the call tracer against.
|
// flatCallTracerTest defines a single test to check the call tracer against.
|
||||||
type flatCallTracerTest struct {
|
type flatCallTracerTest struct {
|
||||||
Genesis *core.Genesis `json:"genesis"`
|
tracerTestEnv
|
||||||
Context *callContext `json:"context"`
|
|
||||||
Input string `json:"input"`
|
|
||||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
|
||||||
Result []flatCallTrace `json:"result"`
|
Result []flatCallTrace `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ var makeTest = function(tx, traceConfig) {
|
||||||
delete genesis.transactions;
|
delete genesis.transactions;
|
||||||
delete genesis.transactionsRoot;
|
delete genesis.transactionsRoot;
|
||||||
delete genesis.uncles;
|
delete genesis.uncles;
|
||||||
|
delete genesis.withdrawals;
|
||||||
|
delete genesis.withdrawalsRoot;
|
||||||
|
delete genesis.baseFeePerGas;
|
||||||
|
|
||||||
genesis.gasLimit = genesis.gasLimit.toString();
|
genesis.gasLimit = genesis.gasLimit.toString();
|
||||||
genesis.number = genesis.number.toString();
|
genesis.number = genesis.number.toString();
|
||||||
|
@ -60,11 +63,15 @@ var makeTest = function(tx, traceConfig) {
|
||||||
context.baseFeePerGas = block.baseFeePerGas.toString();
|
context.baseFeePerGas = block.baseFeePerGas.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(JSON.stringify({
|
var data = {
|
||||||
genesis: genesis,
|
genesis: genesis,
|
||||||
context: context,
|
context: context,
|
||||||
input: eth.getRawTransaction(tx),
|
input: eth.getRawTransaction(tx),
|
||||||
result: result,
|
result: result,
|
||||||
tracerConfig: traceConfig.tracerConfig,
|
};
|
||||||
}, null, 2));
|
if (traceConfig && traceConfig.tracerConfig) {
|
||||||
|
data.tracerConfig = traceConfig.tracerConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(JSON.stringify(data, null, 2));
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,28 +43,25 @@ type account struct {
|
||||||
Storage map[common.Hash]common.Hash `json:"storage"`
|
Storage map[common.Hash]common.Hash `json:"storage"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// testcase defines a single test to check the stateDiff tracer against.
|
// prestateTracerTest defines a single test to check the stateDiff tracer against.
|
||||||
type testcase struct {
|
type prestateTracerTest struct {
|
||||||
Genesis *core.Genesis `json:"genesis"`
|
tracerTestEnv
|
||||||
Context *callContext `json:"context"`
|
|
||||||
Input string `json:"input"`
|
|
||||||
TracerConfig json.RawMessage `json:"tracerConfig"`
|
|
||||||
Result interface{} `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrestateTracerLegacy(t *testing.T) {
|
func TestPrestateTracerLegacy(t *testing.T) {
|
||||||
testPrestateDiffTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
|
testPrestateTracer("prestateTracerLegacy", "prestate_tracer_legacy", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrestateTracer(t *testing.T) {
|
func TestPrestateTracer(t *testing.T) {
|
||||||
testPrestateDiffTracer("prestateTracer", "prestate_tracer", t)
|
testPrestateTracer("prestateTracer", "prestate_tracer", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrestateWithDiffModeTracer(t *testing.T) {
|
func TestPrestateWithDiffModeTracer(t *testing.T) {
|
||||||
testPrestateDiffTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
|
testPrestateTracer("prestateTracer", "prestate_tracer_with_diff_mode", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
|
func testPrestateTracer(tracerName string, dirPath string, t *testing.T) {
|
||||||
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
|
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to retrieve tracer test suite: %v", err)
|
t.Fatalf("failed to retrieve tracer test suite: %v", err)
|
||||||
|
@ -77,7 +74,7 @@ func testPrestateDiffTracer(tracerName string, dirPath string, t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
test = new(testcase)
|
test = new(prestateTracerTest)
|
||||||
tx = new(types.Transaction)
|
tx = new(types.Transaction)
|
||||||
)
|
)
|
||||||
// Call tracer test found, read if from disk
|
// Call tracer test found, read if from disk
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
||||||
"timestamp": "1709626771",
|
"timestamp": "1709626771",
|
||||||
"withdrawals": [],
|
|
||||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
||||||
"alloc": {
|
"alloc": {
|
||||||
"0x0000000000000000000000000000000000000000": {
|
"0x0000000000000000000000000000000000000000": {
|
||||||
"balance": "0x272e0528"
|
"balance": "0x272e0528"
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
"parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||||
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
"stateRoot": "0x577f42ab21ccfd946511c57869ace0bdf7c217c36f02b7cd3459df0ed1cffc1a",
|
||||||
"timestamp": "1709626771",
|
"timestamp": "1709626771",
|
||||||
"withdrawals": [],
|
|
||||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
||||||
"alloc": {
|
"alloc": {
|
||||||
"0x0000000000000000000000000000000000000000": {
|
"0x0000000000000000000000000000000000000000": {
|
||||||
"balance": "0x272e0528"
|
"balance": "0x272e0528"
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
"number": "1",
|
"number": "1",
|
||||||
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
|
"stateRoot": "0xd2ebe0a7f3572ffe3e5b4c78147376d3fca767f236e4dd23f9151acfec7cb0d1",
|
||||||
"timestamp": "1699617692",
|
"timestamp": "1699617692",
|
||||||
"withdrawals": [],
|
|
||||||
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
|
|
||||||
"alloc": {
|
"alloc": {
|
||||||
"0x0000000000000000000000000000000000000000": {
|
"0x0000000000000000000000000000000000000000": {
|
||||||
"balance": "0x5208"
|
"balance": "0x5208"
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package tracetest
|
package tracetest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
@ -42,7 +43,8 @@ func camel(str string) string {
|
||||||
return strings.Join(pieces, "")
|
return strings.Join(pieces, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
type callContext struct {
|
// traceContext defines a context used to construct the block context
|
||||||
|
type traceContext struct {
|
||||||
Number math.HexOrDecimal64 `json:"number"`
|
Number math.HexOrDecimal64 `json:"number"`
|
||||||
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
||||||
Time math.HexOrDecimal64 `json:"timestamp"`
|
Time math.HexOrDecimal64 `json:"timestamp"`
|
||||||
|
@ -51,7 +53,7 @@ type callContext struct {
|
||||||
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
|
BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
func (c *traceContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
||||||
context := vm.BlockContext{
|
context := vm.BlockContext{
|
||||||
CanTransfer: core.CanTransfer,
|
CanTransfer: core.CanTransfer,
|
||||||
Transfer: core.Transfer,
|
Transfer: core.Transfer,
|
||||||
|
@ -77,3 +79,11 @@ func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext {
|
||||||
}
|
}
|
||||||
return context
|
return context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tracerTestEnv defines a tracer test required fields
|
||||||
|
type tracerTestEnv struct {
|
||||||
|
Genesis *core.Genesis `json:"genesis"`
|
||||||
|
Context *traceContext `json:"context"`
|
||||||
|
Input string `json:"input"`
|
||||||
|
TracerConfig json.RawMessage `json:"tracerConfig"`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue