Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"math/big"

"github.com/ethereum-optimism/optimism/devnet-sdk/testing/systest"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -15,12 +15,12 @@ import (
// BalanceReader provides methods to read balances from the chain
type BalanceReader struct {
client *ethclient.Client
t systest.T
t devtest.T
logger log.Logger
}

// NewBalanceReader creates a new BalanceReader instance
func NewBalanceReader(t systest.T, client *ethclient.Client, logger log.Logger) *BalanceReader {
func NewBalanceReader(t devtest.T, client *ethclient.Client, logger log.Logger) *BalanceReader {
return &BalanceReader{
client: client,
t: t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"math/big"

"github.com/ethereum-optimism/optimism/devnet-sdk/testing/systest"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -72,7 +72,7 @@ func (bs *BalanceSnapshot) Sub(start *BalanceSnapshot) *BalanceSnapshot {
}

// AssertSnapshotsEqual compares two balance snapshots and reports differences
func AssertSnapshotsEqual(t systest.T, expected, actual *BalanceSnapshot) {
func AssertSnapshotsEqual(t devtest.T, expected, actual *BalanceSnapshot) {
require.NotNil(t, expected, "Expected snapshot should not be nil")
require.NotNil(t, actual, "Actual snapshot should not be nil")

Expand All @@ -96,3 +96,17 @@ func AssertSnapshotsEqual(t systest.T, expected, actual *BalanceSnapshot) {
assert.True(t, expected.FromBalance.Cmp(actual.FromBalance) == 0,
"WalletBalance mismatch: expected %v, got %v (diff: %v)", expected.FromBalance, actual.FromBalance, new(big.Int).Sub(actual.FromBalance, expected.FromBalance))
}

// SnapshotsEqual compares two balance snapshots and returns true if they are equal
// This is a non-asserting version for unit tests
func SnapshotsEqual(expected, actual *BalanceSnapshot) bool {
if expected == nil || actual == nil {
return expected == actual
}

return expected.BaseFeeVaultBalance.Cmp(actual.BaseFeeVaultBalance) == 0 &&
expected.L1FeeVaultBalance.Cmp(actual.L1FeeVaultBalance) == 0 &&
expected.SequencerFeeVault.Cmp(actual.SequencerFeeVault) == 0 &&
expected.OperatorFeeVault.Cmp(actual.OperatorFeeVault) == 0 &&
expected.FromBalance.Cmp(actual.FromBalance) == 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"math/big"
"testing"

"github.com/ethereum-optimism/optimism/devnet-sdk/testing/systest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -187,102 +186,42 @@ func TestBalanceSnapshot_Sub(t *testing.T) {
})
}

// mockTB is a minimal testing.TB implementation for checking assertion failures
// without failing the actual test.
type mockTB struct {
testing.TB // Embed standard testing.TB for most methods (like Logf)
failed bool
}

func (m *mockTB) Helper() { m.TB.Helper() }
func (m *mockTB) Errorf(string, ...any) { m.failed = true } // Just record failure
func (m *mockTB) Fatalf(string, ...any) { m.failed = true; panic("mock Fatalf") } // Record failure and panic
func (m *mockTB) FailNow() { m.failed = true; panic("mock FailNow") } // Record failure and panic
func (m *mockTB) Fail() { m.failed = true } // Just record failure
func (m *mockTB) Name() string { return m.TB.Name() }
func (m *mockTB) Logf(format string, args ...any) { m.TB.Logf(format, args...) }

// Add other testing.TB methods if needed by systest.NewT or AssertSnapshotsEqual
func (m *mockTB) Cleanup(f func()) { m.TB.Cleanup(f) }
func (m *mockTB) Error(args ...any) { m.failed = true }
func (m *mockTB) Failed() bool { return m.failed } // Reflect our recorded state
func (m *mockTB) Fatal(args ...any) { m.failed = true; panic("mock Fatal") }
func (m *mockTB) Log(args ...any) { m.TB.Log(args...) }
func (m *mockTB) Setenv(key, value string) { m.TB.Setenv(key, value) }
func (m *mockTB) Skip(args ...any) { m.TB.Skip(args...) }
func (m *mockTB) SkipNow() { m.TB.SkipNow() }
func (m *mockTB) Skipf(format string, args ...any) { m.TB.Skipf(format, args...) }
func (m *mockTB) Skipped() bool { return m.TB.Skipped() }
func (m *mockTB) TempDir() string { return m.TB.TempDir() }

func TestAssertSnapshotsEqual(t *testing.T) {
func TestSnapshotsEqual(t *testing.T) {
snap1 := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50))
snap2 := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50))

t.Run("EqualSnapshots", func(t *testing.T) {
mockT := &mockTB{TB: t} // Use the mock TB
systestT := systest.NewT(mockT)
AssertSnapshotsEqual(systestT, snap1, snap2)
assert.False(t, mockT.failed, "AssertSnapshotsEqual should not fail for equal snapshots")
assert.True(t, SnapshotsEqual(snap1, snap2), "Equal snapshots should return true")
})

t.Run("DifferentBaseFee", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(99), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50))
AssertSnapshotsEqual(systestT, snap1, diffSnap)
assert.True(t, mockT.failed, "AssertSnapshotsEqual should fail for different BaseFeeVaultBalance")
assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different BaseFeeVaultBalance should return false")
})

t.Run("DifferentL1Fee", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(99), big.NewInt(30), big.NewInt(40), big.NewInt(50))
AssertSnapshotsEqual(systestT, snap1, diffSnap)
assert.True(t, mockT.failed, "AssertSnapshotsEqual should fail for different L1FeeVaultBalance")
assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different L1FeeVaultBalance should return false")
})

t.Run("DifferentSequencerFee", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(99), big.NewInt(40), big.NewInt(50))
AssertSnapshotsEqual(systestT, snap1, diffSnap)
assert.True(t, mockT.failed, "AssertSnapshotsEqual should fail for different SequencerFeeVault")
assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different SequencerFeeVault should return false")
})

t.Run("DifferentOperatorFee", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(99), big.NewInt(50))
AssertSnapshotsEqual(systestT, snap1, diffSnap)
assert.True(t, mockT.failed, "AssertSnapshotsEqual should fail for different OperatorFeeVault")
assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different OperatorFeeVault should return false")
})

t.Run("DifferentFromBalance", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(99))
AssertSnapshotsEqual(systestT, snap1, diffSnap)
assert.True(t, mockT.failed, "AssertSnapshotsEqual should fail for different FromBalance")
})

// Test require.NotNil checks within AssertSnapshotsEqual (which call FailNow)
t.Run("NilExpected", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
// Use assert.Panics because require.NotNil calls t.FailNow() which our mock makes panic
assert.Panics(t, func() {
AssertSnapshotsEqual(systestT, nil, snap2)
}, "AssertSnapshotsEqual should panic via FailNow when expected is nil")
assert.True(t, mockT.failed) // Check if FailNow was triggered
assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different FromBalance should return false")
})

t.Run("NilActual", func(t *testing.T) {
mockT := &mockTB{TB: t}
systestT := systest.NewT(mockT)
assert.Panics(t, func() {
AssertSnapshotsEqual(systestT, snap1, nil)
}, "AssertSnapshotsEqual should panic via FailNow when actual is nil")
assert.True(t, mockT.failed) // Check if FailNow was triggered
t.Run("NilSnapshots", func(t *testing.T) {
assert.True(t, SnapshotsEqual(nil, nil), "Both nil should return true")
assert.False(t, SnapshotsEqual(snap1, nil), "One nil should return false")
assert.False(t, SnapshotsEqual(nil, snap1), "One nil should return false")
})
}
10 changes: 5 additions & 5 deletions op-acceptance-tests/tests/isthmus/operator_fee/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"math/big"

"github.com/ethereum-optimism/optimism/devnet-sdk/testing/systest"
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -14,13 +14,13 @@ import (
)

type stateGetterAdapterFactory struct {
t systest.T
t devtest.T
client *ethclient.Client
}

// stateGetterAdapter adapts the ethclient to implement the StateGetter interface
type stateGetterAdapter struct {
t systest.T
t devtest.T
client *ethclient.Client
ctx context.Context
blockNumber *big.Int
Expand All @@ -30,7 +30,7 @@ func (f *stateGetterAdapterFactory) NewStateGetterAdapter(blockNumber *big.Int)
return &stateGetterAdapter{
t: f.t,
client: f.client,
ctx: f.t.Context(),
ctx: f.t.Ctx(),
blockNumber: blockNumber,
}
}
Expand All @@ -52,7 +52,7 @@ type FeeChecker struct {
}

// NewFeeChecker creates a new FeeChecker instance
func NewFeeChecker(t systest.T, client *ethclient.Client, chainConfig *params.ChainConfig, logger log.Logger) *FeeChecker {
func NewFeeChecker(t devtest.T, client *ethclient.Client, chainConfig *params.ChainConfig, logger log.Logger) *FeeChecker {
logger.Debug("Creating fee checker", "chainID", chainConfig.ChainID)

// Create state getter adapter factory
Expand Down
Loading