Commit baaf6200 authored by protolambda's avatar protolambda Committed by GitHub

op-node: move derivation test metrics to test utils package (#3610)

Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 5dadba52
......@@ -8,12 +8,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/log"
)
type fakeAttributesQueue struct {
......@@ -193,7 +194,7 @@ func TestEngineQueue_Finalize(t *testing.T) {
t.Log("refF0", refF0.Hash)
t.Log("refF1", refF1.Hash)
metrics := &TestMetrics{}
metrics := &testutils.TestDerivationMetrics{}
eng := &testutils.MockEngine{}
// we find the common point to initialize to by comparing the L1 origins in the L2 chain with the L1 chain
l1F := &testutils.MockL1Source{}
......
......@@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/testutils"
)
......@@ -60,30 +59,4 @@ func RepeatStep(t *testing.T, step func(ctx context.Context, outer Progress) err
return nil
}
// TestMetrics implements the metrics used in the derivation pipeline as no-op operations.
// Optionally a test may hook into the metrics
type TestMetrics struct {
recordL1Ref func(name string, ref eth.L1BlockRef)
recordL2Ref func(name string, ref eth.L2BlockRef)
recordUnsafePayloads func(length uint64, memSize uint64, next eth.BlockID)
}
func (t *TestMetrics) RecordL1Ref(name string, ref eth.L1BlockRef) {
if t.recordL1Ref != nil {
t.recordL1Ref(name, ref)
}
}
func (t *TestMetrics) RecordL2Ref(name string, ref eth.L2BlockRef) {
if t.recordL2Ref != nil {
t.recordL2Ref(name, ref)
}
}
func (t *TestMetrics) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) {
if t.recordUnsafePayloads != nil {
t.recordUnsafePayloads(length, memSize, next)
}
}
var _ Metrics = (*TestMetrics)(nil)
var _ Metrics = (*testutils.TestDerivationMetrics)(nil)
package testutils
import "github.com/ethereum-optimism/optimism/op-node/eth"
// TestDerivationMetrics implements the metrics used in the derivation pipeline as no-op operations.
// Optionally a test may hook into the metrics
type TestDerivationMetrics struct {
FnRecordL1Ref func(name string, ref eth.L1BlockRef)
FnRecordL2Ref func(name string, ref eth.L2BlockRef)
FnRecordUnsafePayloads func(length uint64, memSize uint64, next eth.BlockID)
}
func (t *TestDerivationMetrics) RecordL1Ref(name string, ref eth.L1BlockRef) {
if t.FnRecordL1Ref != nil {
t.FnRecordL1Ref(name, ref)
}
}
func (t *TestDerivationMetrics) RecordL2Ref(name string, ref eth.L2BlockRef) {
if t.FnRecordL2Ref != nil {
t.FnRecordL2Ref(name, ref)
}
}
func (t *TestDerivationMetrics) RecordUnsafePayloadsBuffer(length uint64, memSize uint64, next eth.BlockID) {
if t.FnRecordUnsafePayloads != nil {
t.FnRecordUnsafePayloads(length, memSize, next)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment