Skip to content

Commit

Permalink
Reverting test structure change
Browse files Browse the repository at this point in the history
Signed-off-by: dwertent <[email protected]>
  • Loading branch information
dwertent committed Aug 15, 2024
1 parent 0ae11b9 commit 55cf059
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions internal/events/blockchain_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,54 +151,34 @@ func TestContractEventWrongNS(t *testing.T) {

}

// TODO: Add test case for event not existing
func TestPersistBlockchainEventDuplicate(t *testing.T) {
type testCase struct {
name string
event *core.BlockchainEvent
existingID *fftypes.UUID
expectedID *fftypes.UUID
expectedError error
expectedCreated bool
}
em := newTestEventManager(t)
defer em.cleanup(t)

testCases := []testCase{
{
name: "Event already exists",
event: &core.BlockchainEvent{
ID: fftypes.NewUUID(),
Name: "Changed",
Namespace: "ns1",
ProtocolID: "10/20/30",
Output: fftypes.JSONObject{
"value": "1",
},
Info: fftypes.JSONObject{
"blockNumber": "10",
},
Listener: fftypes.NewUUID(),
},
existingID: fftypes.NewUUID(),
expectedID: fftypes.NewUUID(),
expectedError: nil,
expectedCreated: false,
ev := &core.BlockchainEvent{
ID: fftypes.NewUUID(),
Name: "Changed",
Namespace: "ns1",
ProtocolID: "10/20/30",
Output: fftypes.JSONObject{
"value": "1",
},
Info: fftypes.JSONObject{
"blockNumber": "10",
},
// TODO: Add test case for event not existing
Listener: fftypes.NewUUID(),
}
existingID := fftypes.NewUUID()

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
em := newTestEventManager(t)
defer em.cleanup(t)
em.mth.On("InsertOrGetBlockchainEvent", mock.Anything, ev).
Return(&core.BlockchainEvent{ID: existingID}, nil)

em.mth.On("InsertOrGetBlockchainEvent", mock.Anything, tc.event).
Return(&core.BlockchainEvent{ID: tc.existingID}, tc.expectedError)
created, err := em.maybePersistBlockchainEvent(em.ctx, ev, nil)
assert.NoError(t, err)
assert.Equal(t, existingID, ev.ID)
assert.False(t, created)

created, err := em.maybePersistBlockchainEvent(em.ctx, tc.event, nil)
assert.NoError(t, err)
assert.Equal(t, tc.existingID, tc.event.ID)
assert.Equal(t, tc.expectedCreated, created)
})
}
}

func TestGetTopicForChainListenerFallback(t *testing.T) {
Expand Down

0 comments on commit 55cf059

Please sign in to comment.