github.com/lmittmann/w3@v0.20.0/module/debug/trace_test.go (about)

     1  package debug_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ethereum/go-ethereum/core/vm"
     7  	"github.com/holiman/uint256"
     8  	"github.com/lmittmann/w3"
     9  	"github.com/lmittmann/w3/module/debug"
    10  	"github.com/lmittmann/w3/rpctest"
    11  	"github.com/lmittmann/w3/w3types"
    12  )
    13  
    14  func TestTraceTx(t *testing.T) {
    15  	rpctest.RunTestCases(t, []rpctest.TestCase[*debug.Trace]{
    16  		{
    17  			Golden: "traceTx__1150000_0",
    18  			Call:   debug.TraceTx(w3.H("0x38f299591902bfada359527fa6b9b597a959c41c6f72a3b484807fbf52dc8abe"), nil),
    19  			WantRet: &debug.Trace{
    20  				Gas: 22224,
    21  			},
    22  		},
    23  		{
    24  			Golden: "traceTx__12244000_0",
    25  			Call:   debug.TraceTx(w3.H("0xac503dd98281d4d52c2043e297a6e684d175339a7ebf831605fe593f01ce82c3"), &debug.TraceConfig{EnableStack: true, EnableMemory: true, EnableStorage: true, Limit: 3}),
    26  			WantRet: &debug.Trace{
    27  				Gas: 46121,
    28  				StructLogs: []*debug.StructLog{
    29  					{Pc: 0, Op: vm.PUSH1, Gas: 228380, GasCost: 3, Depth: 1},
    30  					{Pc: 2, Op: vm.PUSH1, Gas: 228377, GasCost: 3, Depth: 1, Stack: []uint256.Int{*uint256.NewInt(0x60)}},
    31  					{
    32  						Pc: 4, Op: vm.MSTORE, Gas: 228374, GasCost: 12, Depth: 1, Stack: []uint256.Int{*uint256.NewInt(0x60), *uint256.NewInt(0x40)},
    33  						Memory: w3.B("0x" +
    34  							"0000000000000000000000000000000000000000000000000000000000000000" +
    35  							"0000000000000000000000000000000000000000000000000000000000000000" +
    36  							"0000000000000000000000000000000000000000000000000000000000000000"),
    37  					},
    38  				},
    39  			},
    40  		},
    41  	})
    42  }
    43  
    44  func TestTraceCall(t *testing.T) {
    45  	rpctest.RunTestCases(t, []rpctest.TestCase[*debug.Trace]{
    46  		{
    47  			Golden: "traceCall",
    48  			Call: debug.TraceCall(&w3types.Message{
    49  				From:  w3.A("0x000000000000000000000000000000000000c0Fe"),
    50  				To:    w3.APtr("0x000000000000000000000000000000000000dEaD"),
    51  				Value: w3.I("1 ether"),
    52  			}, nil, &debug.TraceConfig{Overrides: w3types.State{
    53  				w3.A("0x000000000000000000000000000000000000c0Fe"): {Balance: w3.I("1 ether")},
    54  			}}),
    55  			WantRet: &debug.Trace{
    56  				Gas: 21000,
    57  			},
    58  		},
    59  	})
    60  }