@@ -9,10 +9,11 @@ import (
99 "github.com/ethereum/go-ethereum/core/types"
1010 "github.com/stretchr/testify/require"
1111 "go.opentelemetry.io/otel"
12- "go.opentelemetry.io/otel/attribute"
1312 "go.opentelemetry.io/otel/codes"
1413 "go.opentelemetry.io/otel/sdk/trace"
1514 "go.opentelemetry.io/otel/sdk/trace/tracetest"
15+
16+ "github.com/evstack/ev-node/pkg/telemetry/testutil"
1617)
1718
1819// setupTestEthRPCTracing creates a traced eth RPC client with an in-memory span recorder
@@ -90,13 +91,13 @@ func TestTracedEthRPCClient_HeaderByNumber_Success(t *testing.T) {
9091
9192 // verify attributes
9293 attrs := span .Attributes ()
93- requireAttribute (t , attrs , "method" , "eth_getBlockByNumber" )
94- requireAttribute (t , attrs , "block_number" , "100" )
95- requireAttribute (t , attrs , "block_hash" , expectedHeader .Hash ().Hex ())
96- requireAttribute (t , attrs , "state_root" , expectedHeader .Root .Hex ())
97- requireAttribute (t , attrs , "gas_limit" , int64 (expectedHeader .GasLimit ))
98- requireAttribute (t , attrs , "gas_used" , int64 (expectedHeader .GasUsed ))
99- requireAttribute (t , attrs , "timestamp" , int64 (expectedHeader .Time ))
94+ testutil . RequireAttribute (t , attrs , "method" , "eth_getBlockByNumber" )
95+ testutil . RequireAttribute (t , attrs , "block_number" , "100" )
96+ testutil . RequireAttribute (t , attrs , "block_hash" , expectedHeader .Hash ().Hex ())
97+ testutil . RequireAttribute (t , attrs , "state_root" , expectedHeader .Root .Hex ())
98+ testutil . RequireAttribute (t , attrs , "gas_limit" , int64 (expectedHeader .GasLimit ))
99+ testutil . RequireAttribute (t , attrs , "gas_used" , int64 (expectedHeader .GasUsed ))
100+ testutil . RequireAttribute (t , attrs , "timestamp" , int64 (expectedHeader .Time ))
100101}
101102
102103func TestTracedEthRPCClient_HeaderByNumber_Latest (t * testing.T ) {
@@ -131,7 +132,7 @@ func TestTracedEthRPCClient_HeaderByNumber_Latest(t *testing.T) {
131132
132133 // verify block_number is "latest" when nil
133134 attrs := span .Attributes ()
134- requireAttribute (t , attrs , "block_number" , "latest" )
135+ testutil . RequireAttribute (t , attrs , "block_number" , "latest" )
135136}
136137
137138func TestTracedEthRPCClient_HeaderByNumber_Error (t * testing.T ) {
@@ -206,8 +207,8 @@ func TestTracedEthRPCClient_GetTxs_Success(t *testing.T) {
206207
207208 // verify attributes
208209 attrs := span .Attributes ()
209- requireAttribute (t , attrs , "method" , "txpoolExt_getTxs" )
210- requireAttribute (t , attrs , "tx_count" , len (expectedTxs ))
210+ testutil . RequireAttribute (t , attrs , "method" , "txpoolExt_getTxs" )
211+ testutil . RequireAttribute (t , attrs , "tx_count" , len (expectedTxs ))
211212}
212213
213214func TestTracedEthRPCClient_GetTxs_EmptyPool (t * testing.T ) {
@@ -235,7 +236,7 @@ func TestTracedEthRPCClient_GetTxs_EmptyPool(t *testing.T) {
235236
236237 // verify tx_count is 0
237238 attrs := span .Attributes ()
238- requireAttribute (t , attrs , "tx_count" , 0 )
239+ testutil . RequireAttribute (t , attrs , "tx_count" , 0 )
239240}
240241
241242func TestTracedEthRPCClient_GetTxs_Error (t * testing.T ) {
@@ -276,26 +277,3 @@ func TestTracedEthRPCClient_GetTxs_Error(t *testing.T) {
276277 require .NotEqual (t , "tx_count" , string (attr .Key ))
277278 }
278279}
279-
280- // requireAttribute is a helper to check span attributes
281- func requireAttribute (t * testing.T , attrs []attribute.KeyValue , key string , expected interface {}) {
282- t .Helper ()
283- found := false
284- for _ , attr := range attrs {
285- if string (attr .Key ) == key {
286- found = true
287- switch v := expected .(type ) {
288- case string :
289- require .Equal (t , v , attr .Value .AsString ())
290- case int64 :
291- require .Equal (t , v , attr .Value .AsInt64 ())
292- case int :
293- require .Equal (t , int64 (v ), attr .Value .AsInt64 ())
294- default :
295- t .Fatalf ("unsupported attribute type: %T" , expected )
296- }
297- break
298- }
299- }
300- require .True (t , found , "attribute %s not found" , key )
301- }
0 commit comments