Skip to content

Commit

Permalink
plugin/evm/testutils WithMetrics
Browse files Browse the repository at this point in the history
  • Loading branch information
qdm12 committed Jan 15, 2025
1 parent 91fed7d commit 0de8a89
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
20 changes: 20 additions & 0 deletions plugin/evm/testutils/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package testutils

import (
"testing"

"github.com/ethereum/go-ethereum/metrics"
)

// WithMetrics enables go-ethereum metrics globally for the test.
// If the [metrics.Enabled] is already true, nothing is done.
// Otherwise, it is set to true and is reverted to false when the test finishes.
func WithMetrics(t *testing.T) {
if metrics.Enabled {
return
}
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
18 changes: 3 additions & 15 deletions warp/handlers/signature_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@ import (
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/coreth/plugin/evm/message"
"github.com/ava-labs/coreth/plugin/evm/testutils"
"github.com/ava-labs/coreth/utils"
"github.com/ava-labs/coreth/warp"
"github.com/ava-labs/coreth/warp/warptest"
"github.com/ethereum/go-ethereum/metrics"
"github.com/stretchr/testify/require"
)

func TestMessageSignatureHandler(t *testing.T) {
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
testutils.WithMetrics(t)

database := memdb.New()
snowCtx := utils.TestSnowContext()
Expand Down Expand Up @@ -134,13 +128,7 @@ func TestMessageSignatureHandler(t *testing.T) {
}

func TestBlockSignatureHandler(t *testing.T) {
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
testutils.WithMetrics(t)

database := memdb.New()
snowCtx := utils.TestSnowContext()
Expand Down
18 changes: 3 additions & 15 deletions warp/verifier_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/coreth/plugin/evm/testutils"
"github.com/ava-labs/coreth/utils"
"github.com/ava-labs/coreth/warp/warptest"
"github.com/ethereum/go-ethereum/metrics"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)

func TestAddressedCallSignatures(t *testing.T) {
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
testutils.WithMetrics(t)

database := memdb.New()
snowCtx := utils.TestSnowContext()
Expand Down Expand Up @@ -147,13 +141,7 @@ func TestAddressedCallSignatures(t *testing.T) {
}

func TestBlockSignatures(t *testing.T) {
metricsEnabled := metrics.Enabled
if !metricsEnabled {
metrics.Enabled = true
t.Cleanup(func() {
metrics.Enabled = false
})
}
testutils.WithMetrics(t)

database := memdb.New()
snowCtx := utils.TestSnowContext()
Expand Down

0 comments on commit 0de8a89

Please sign in to comment.