add test cases and optimize

This commit is contained in:
bnovil 2023-10-03 14:54:24 +08:00
parent f2972eeb44
commit e270b23766
2 changed files with 16 additions and 3 deletions

View file

@ -234,8 +234,8 @@ func (ec *Client) TraceTransaction(ctx context.Context, hash common.Hash, config
return result, err return result, err
} }
// TraceChain TraceChaiin subscribes to chain, receiving results from channel BlockTraceResult // TraceChain subscribes to chain, receiving results from channel BlockTraceResult
func (ec *Client) TraceChain(ctx context.Context, ch chan<- BlockTraceResult, start, end rpc.BlockNumber, config *tracers.TraceConfig) (*rpc.ClientSubscription, error) { func (ec *Client) TraceChain(ctx context.Context, ch chan<- *BlockTraceResult, start, end rpc.BlockNumber, config *tracers.TraceConfig) (*rpc.ClientSubscription, error) {
return ec.c.Subscribe(ctx, "debug", ch, "traceChain", start, end, config) return ec.c.Subscribe(ctx, "debug", ch, "traceChain", start, end, config)
} }

View file

@ -598,6 +598,19 @@ func testTraceTransaction(t *testing.T, client *rpc.Client) {
"structLogs": nil, "structLogs": nil,
}, },
}, },
{
txHash: testTransactionHash,
config: &tracers.TraceConfig{
TracerConfig: json.RawMessage(`{"tracer":"callTracer"}`),
},
expectErr: nil,
expect: map[string]interface{}{
"gas": 21000,
"failed": false,
"returnValue": "",
"structLogs": nil,
},
},
} }
for i, testspec := range testSuite { for i, testspec := range testSuite {
result, err := ec.TraceTransaction(context.Background(), testspec.txHash, testspec.config) result, err := ec.TraceTransaction(context.Background(), testspec.txHash, testspec.config)
@ -691,7 +704,7 @@ func testTraceCall(t *testing.T, client *rpc.Client) {
func testTraceChain(t *testing.T, client *rpc.Client) { func testTraceChain(t *testing.T, client *rpc.Client) {
ec := New(client) ec := New(client)
ch := make(chan BlockTraceResult) ch := make(chan *BlockTraceResult)
_, err := ec.TraceChain(context.Background(), ch, 0, 1, nil) _, err := ec.TraceChain(context.Background(), ch, 0, 1, nil)
if err != nil { if err != nil {
t.Fatalf("testTraceChain error: %v", err) t.Fatalf("testTraceChain error: %v", err)