Skip to content

Commit f965581

Browse files
Fix tests
1 parent c7704e9 commit f965581

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

internal/indexer/indexer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (i *Indexer) ProcessTransaction(ctx context.Context, transaction ingest.Led
7474
return fmt.Errorf("getting operations participants: %w", err)
7575
}
7676
var dataOp *types.Operation
77-
var effectsStateChanges []types.StateChange
77+
var effectsStateChanges, contractDeployStateChanges []types.StateChange
7878
for opID, opParticipants := range opsParticipants {
7979
dataOp, err = processors.ConvertOperation(&transaction, &opParticipants.OpWrapper.Operation, opID)
8080
if err != nil {
@@ -93,7 +93,7 @@ func (i *Indexer) ProcessTransaction(ctx context.Context, transaction ingest.Led
9393
i.Buffer.PushStateChanges(effectsStateChanges)
9494

9595
// 2.2. Index contract deploy state changes
96-
contractDeployStateChanges, err := i.contractDeployProcessor.ProcessOperation(ctx, opParticipants.OpWrapper)
96+
contractDeployStateChanges, err = i.contractDeployProcessor.ProcessOperation(ctx, opParticipants.OpWrapper)
9797
if err != nil && !errors.Is(err, processors.ErrInvalidOpType) {
9898
return fmt.Errorf("processing contract deploy state changes: %w", err)
9999
}

internal/indexer/indexer_test.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ var (
8888
func TestIndexer_ProcessTransaction(t *testing.T) {
8989
tests := []struct {
9090
name string
91-
setupMocks func(*MockParticipantsProcessor, *MockTokenTransferProcessor, *MockEffectsProcessor, *MockIndexerBuffer)
91+
setupMocks func(*MockParticipantsProcessor, *MockTokenTransferProcessor, *MockOperationProcessor, *MockOperationProcessor, *MockIndexerBuffer)
9292
wantError string
9393
txParticipants set.Set[string]
9494
opsParticipants map[int64]processors.OperationParticipants
9595
}{
9696
{
9797
name: "🟢 successful processing with participants",
98-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
98+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
9999
participants := set.NewSet("alice", "bob")
100100
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(participants, nil)
101101

@@ -116,7 +116,10 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
116116
mockTokenTransfer.On("ProcessTransaction", mock.Anything, mock.Anything).Return(tokenStateChanges, nil)
117117

118118
effectsStateChanges := []types.StateChange{{ID: "effects_sc1"}}
119-
mockEffects.On("ProcessOperation", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(effectsStateChanges, nil)
119+
mockEffects.On("ProcessOperation", mock.Anything, mock.Anything).Return(effectsStateChanges, nil)
120+
121+
contractDeployStateChanges := []types.StateChange{{ID: "contract_deploy_sc1"}}
122+
mockContractDeploy.On("ProcessOperation", mock.Anything, mock.Anything).Return(contractDeployStateChanges, nil)
120123

121124
// Verify transaction was pushed to buffer with correct participants
122125
// PushParticipantTransaction is called once for each participant
@@ -149,6 +152,10 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
149152
mock.MatchedBy(func(stateChanges []types.StateChange) bool {
150153
return len(stateChanges) == 1 && stateChanges[0].ID == "token_sc1"
151154
})).Return()
155+
mockBuffer.On("PushStateChanges",
156+
mock.MatchedBy(func(stateChanges []types.StateChange) bool {
157+
return len(stateChanges) == 1 && stateChanges[0].ID == "contract_deploy_sc1"
158+
})).Return()
152159
},
153160
txParticipants: set.NewSet("alice", "bob"),
154161
opsParticipants: map[int64]processors.OperationParticipants{
@@ -165,7 +172,7 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
165172
},
166173
{
167174
name: "🟢 successful processing without participants",
168-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
175+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
169176
participants := set.NewSet[string]()
170177
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(participants, nil)
171178

@@ -187,14 +194,14 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
187194
},
188195
{
189196
name: "🔴 error getting transaction participants",
190-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
197+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
191198
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(set.NewSet[string](), errors.New("participant error"))
192199
},
193200
wantError: "getting transaction participants: participant error",
194201
},
195202
{
196203
name: "🔴 error getting operations participants",
197-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
204+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
198205
participants := set.NewSet[string]()
199206
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(participants, nil)
200207
mockParticipants.On("GetOperationsParticipants", mock.Anything).Return(map[int64]processors.OperationParticipants{}, errors.New("operations error"))
@@ -203,7 +210,7 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
203210
},
204211
{
205212
name: "🔴 error processing effects state changes",
206-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
213+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
207214
participants := set.NewSet[string]()
208215
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(participants, nil)
209216

@@ -221,13 +228,13 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
221228
mockParticipants.On("GetOperationsParticipants", mock.Anything).Return(opParticipants, nil)
222229

223230
mockBuffer.On("PushParticipantOperation", mock.Anything, mock.Anything, mock.Anything).Return()
224-
mockEffects.On("ProcessOperation", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return([]types.StateChange{}, errors.New("effects error"))
231+
mockEffects.On("ProcessOperation", mock.Anything, mock.Anything).Return([]types.StateChange{}, errors.New("effects error"))
225232
},
226233
wantError: "processing effects state changes: effects error",
227234
},
228235
{
229236
name: "🔴 error processing token transfer state changes",
230-
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockEffectsProcessor, mockBuffer *MockIndexerBuffer) {
237+
setupMocks: func(mockParticipants *MockParticipantsProcessor, mockTokenTransfer *MockTokenTransferProcessor, mockEffects *MockOperationProcessor, mockContractDeploy *MockOperationProcessor, mockBuffer *MockIndexerBuffer) {
231238
participants := set.NewSet[string]()
232239
mockParticipants.On("GetTransactionParticipants", mock.Anything).Return(participants, nil)
233240

@@ -245,18 +252,20 @@ func TestIndexer_ProcessTransaction(t *testing.T) {
245252
// Create mocks
246253
mockParticipants := &MockParticipantsProcessor{}
247254
mockTokenTransfer := &MockTokenTransferProcessor{}
248-
mockEffects := &MockEffectsProcessor{}
255+
mockEffects := &MockOperationProcessor{}
256+
mockContractDeploy := &MockOperationProcessor{}
249257
mockBuffer := &MockIndexerBuffer{}
250258

251259
// Setup mock expectations
252-
tt.setupMocks(mockParticipants, mockTokenTransfer, mockEffects, mockBuffer)
260+
tt.setupMocks(mockParticipants, mockTokenTransfer, mockEffects, mockContractDeploy, mockBuffer)
253261

254262
// Create testable indexer with mocked dependencies
255263
indexer := &Indexer{
256-
Buffer: mockBuffer,
257-
participantsProcessor: mockParticipants,
258-
tokenTransferProcessor: mockTokenTransfer,
259-
effectsProcessor: mockEffects,
264+
Buffer: mockBuffer,
265+
participantsProcessor: mockParticipants,
266+
tokenTransferProcessor: mockTokenTransfer,
267+
effectsProcessor: mockEffects,
268+
contractDeployProcessor: mockContractDeploy,
260269
}
261270

262271
err := indexer.ProcessTransaction(context.Background(), testTx)

internal/indexer/mocks.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func (m *MockTokenTransferProcessor) ProcessTransaction(ctx context.Context, tx
4040
return args.Get(0).([]types.StateChange), args.Error(1)
4141
}
4242

43-
type MockEffectsProcessor struct {
43+
type MockOperationProcessor struct {
4444
mock.Mock
4545
}
4646

47-
func (m *MockEffectsProcessor) ProcessOperation(ctx context.Context, opWrapper *operation_processor.TransactionOperationWrapper) ([]types.StateChange, error) {
47+
func (m *MockOperationProcessor) ProcessOperation(ctx context.Context, opWrapper *operation_processor.TransactionOperationWrapper) ([]types.StateChange, error) {
4848
args := m.Called(ctx, opWrapper)
4949
return args.Get(0).([]types.StateChange), args.Error(1)
5050
}
@@ -99,5 +99,5 @@ var (
9999
_ IndexerBufferInterface = &MockIndexerBuffer{}
100100
_ ParticipantsProcessorInterface = &MockParticipantsProcessor{}
101101
_ TokenTransferProcessorInterface = &MockTokenTransferProcessor{}
102-
_ OperationProcessorInterface = &MockEffectsProcessor{}
102+
_ OperationProcessorInterface = &MockOperationProcessor{}
103103
)

0 commit comments

Comments
 (0)