Skip to content

Commit

Permalink
refactor: remove unused onchain state fns
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Oct 22, 2024
1 parent 80ec710 commit 48ac727
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 56 deletions.
10 changes: 0 additions & 10 deletions core/meterer/onchain_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
// OnchainPaymentState is an interface for getting information about the current chain state for payments.
type OnchainPayment interface {
RefreshOnchainPaymentState(ctx context.Context, tx *eth.Transactor) error
GetActiveReservations(ctx context.Context) (map[string]core.ActiveReservation, error)
GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error)
GetOnDemandPayments(ctx context.Context) (map[string]core.OnDemandPayment, error)
GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error)
GetOnDemandQuorumNumbers(ctx context.Context) ([]uint8, error)
}
Expand Down Expand Up @@ -86,10 +84,6 @@ func (pcs *OnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context,
return nil
}

func (pcs *OnchainPaymentState) GetActiveReservations(ctx context.Context, blockNumber uint) (map[string]core.ActiveReservation, error) {
return pcs.ActiveReservations, nil
}

// GetActiveReservationByAccount returns a pointer to the active reservation for the given account ID; no writes will be made to the reservation
func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.ActiveReservation, error) {
if reservation, ok := pcs.ActiveReservations[accountID]; ok {
Expand All @@ -107,10 +101,6 @@ func (pcs *OnchainPaymentState) GetActiveReservationByAccount(ctx context.Contex
return res, nil
}

func (pcs *OnchainPaymentState) GetOnDemandPayments(ctx context.Context, blockNumber uint) (map[string]core.OnDemandPayment, error) {
return pcs.OnDemandPayments, nil
}

// GetOnDemandPaymentByAccount returns a pointer to the on-demand payment for the given account ID; no writes will be made to the payment
func (pcs *OnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (core.OnDemandPayment, error) {
if payment, ok := pcs.OnDemandPayments[accountID]; ok {
Expand Down
26 changes: 0 additions & 26 deletions core/meterer/onchain_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ func TestGetCurrentBlockNumber(t *testing.T) {
assert.Equal(t, uint32(1000), blockNumber)
}

func TestGetActiveReservations(t *testing.T) {
mockState := &mock.MockOnchainPaymentState{}
ctx := context.Background()
expectedReservations := map[string]core.ActiveReservation{
"account1": dummyActiveReservation,
}
mockState.On("GetActiveReservations", testifymock.Anything, testifymock.Anything).Return(expectedReservations, nil)

reservations, err := mockState.GetActiveReservations(ctx)
assert.NoError(t, err)
assert.Equal(t, expectedReservations, reservations)
}

func TestGetActiveReservationByAccount(t *testing.T) {
mockState := &mock.MockOnchainPaymentState{}
ctx := context.Background()
Expand All @@ -65,19 +52,6 @@ func TestGetActiveReservationByAccount(t *testing.T) {
assert.Equal(t, dummyActiveReservation, reservation)
}

func TestGetOnDemandPayments(t *testing.T) {
mockState := &mock.MockOnchainPaymentState{}
ctx := context.Background()
expectedPayments := map[string]core.OnDemandPayment{
"account1": dummyOnDemandPayment,
}
mockState.On("GetOnDemandPayments", testifymock.Anything, testifymock.Anything).Return(expectedPayments, nil)

payments, err := mockState.GetOnDemandPayments(ctx)
assert.NoError(t, err)
assert.Equal(t, expectedPayments, payments)
}

func TestGetOnDemandPaymentByAccount(t *testing.T) {
mockState := &mock.MockOnchainPaymentState{}
ctx := context.Background()
Expand Down
18 changes: 0 additions & 18 deletions core/mock/payment_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ func (m *MockOnchainPaymentState) RefreshOnchainPaymentState(ctx context.Context
return args.Error(0)
}

func (m *MockOnchainPaymentState) GetActiveReservations(ctx context.Context) (map[string]core.ActiveReservation, error) {
args := m.Called()
var value map[string]core.ActiveReservation
if args.Get(0) != nil {
value = args.Get(0).(map[string]core.ActiveReservation)
}
return value, args.Error(1)
}

func (m *MockOnchainPaymentState) GetActiveReservationByAccount(ctx context.Context, accountID string) (core.ActiveReservation, error) {
args := m.Called(ctx, accountID)
var value core.ActiveReservation
Expand All @@ -47,15 +38,6 @@ func (m *MockOnchainPaymentState) GetActiveReservationByAccount(ctx context.Cont
return value, args.Error(1)
}

func (m *MockOnchainPaymentState) GetOnDemandPayments(ctx context.Context) (map[string]core.OnDemandPayment, error) {
args := m.Called()
var value map[string]core.OnDemandPayment
if args.Get(0) != nil {
value = args.Get(0).(map[string]core.OnDemandPayment)
}
return value, args.Error(1)
}

func (m *MockOnchainPaymentState) GetOnDemandPaymentByAccount(ctx context.Context, accountID string) (core.OnDemandPayment, error) {
args := m.Called(ctx, accountID)
var value core.OnDemandPayment
Expand Down
4 changes: 2 additions & 2 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ type Transactor interface {
// GetActiveReservations returns active reservations (end timestamp > current timestamp)
GetActiveReservations(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]ActiveReservation, error)

// GetActiveReservations returns active reservations (end timestamp > current timestamp)
// GetActiveReservationByAccount returns active reservation by account ID
GetActiveReservationByAccount(ctx context.Context, blockNumber uint32, accountID string) (ActiveReservation, error)

// GetOnDemandPayments returns all on-demand payments
GetOnDemandPayments(ctx context.Context, blockNumber uint32, accountIDs []string) (map[string]OnDemandPayment, error)

// GetOnDemandPayments returns all on-demand payments
// GetOnDemandPaymentByAccount returns on-demand payment of an account
GetOnDemandPaymentByAccount(ctx context.Context, blockNumber uint32, accountID string) (OnDemandPayment, error)
}

0 comments on commit 48ac727

Please sign in to comment.