Skip to content

Commit

Permalink
Fixes for multiple filters
Browse files Browse the repository at this point in the history
Signed-off-by: Nicko Guyer <[email protected]>
  • Loading branch information
nguyer committed Mar 6, 2024
1 parent 135cfb0 commit 7f233a0
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEGIN;
ALTER TABLE contractlisteners DROP COLUMN filters;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
DROP INDEX contractlisteners_filter_hash;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
COMMIT;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE contractlisteners DROP COLUMN filters;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
DROP INDEX contractlisteners_filter_hash;
ALTER TABLE contractlisteners DROP COLUMN filter_hash;
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
ALTER TABLE contractlisteners ADD COLUMN filters TEXT;
ALTER TABLE contractlisteners ADD COLUMN filter_hash CHAR(64);
CREATE INDEX contractlisteners_filter_hash ON contractlisteners(filter_hash);

-- SQLite doesn't support dropping NOT NULL constraints so we have to move
-- everything to a temp colum, create a new column, then copy the data back
Expand All @@ -10,6 +12,3 @@ UPDATE contractlisteners SET event = event_tmp;
UPDATE contractlisteners SET location = location_tmp;
ALTER TABLE contractlisteners DROP COLUMN event_tmp;
ALTER TABLE contractlisteners DROP COLUMN location_tmp;

ALTER TABLE contractlisteners ADD COLUMN filter_hash CHAR(64);
CREATE INDEX contractlisteners_filter_hash ON contractlisteners(filter_hash);
6 changes: 3 additions & 3 deletions internal/blockchain/ethereum/ethereum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ func TestAddSubscriptionMultipleFilters(t *testing.T) {
defer cancel()
httpmock.ActivateNonDefault(e.client.GetClient())
defer httpmock.DeactivateAndReset()
e.streamID = "es-1"
e.streamID["ns1"] = "es-1"
e.streams = &streamManager{
client: e.client,
}
Expand Down Expand Up @@ -2118,7 +2118,7 @@ func TestAddSubscriptionInvalidAbi(t *testing.T) {
defer cancel()
httpmock.ActivateNonDefault(e.client.GetClient())
defer httpmock.DeactivateAndReset()
e.streamID = "es-1"
e.streamID["ns1"] = "es-1"
e.streams = &streamManager{
client: e.client,
}
Expand Down Expand Up @@ -2214,7 +2214,7 @@ func TestAddSubscriptionBadLocation(t *testing.T) {
httpmock.ActivateNonDefault(e.client.GetClient())
defer httpmock.DeactivateAndReset()

e.streamID = "es-1"
e.streamID["ns1"] = "es-1"
e.streams = &streamManager{
client: e.client,
}
Expand Down
2 changes: 1 addition & 1 deletion internal/blockchain/ethereum/eventstream.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
24 changes: 21 additions & 3 deletions internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,10 @@ func TestAddContractListenerNameConflict(t *testing.T) {
}

mbi.On("NormalizeContractLocation", context.Background(), blockchain.NormalizeListener, sub.Location).Return(sub.Location, nil)
mdi.On("GetContractListener", context.Background(), "ns1", "sub1").Return(&core.ContractListener{}, nil)
// mdi.On("GetContractListener", context.Background(), "ns1", "sub1").Return(&core.ContractListener{}, nil)

_, err := cm.AddContractListener(context.Background(), sub)
assert.Regexp(t, "FF10312", err)
assert.Regexp(t, "FF10317", err)

mbi.AssertExpectations(t)
mdi.AssertExpectations(t)
Expand All @@ -1249,6 +1249,8 @@ func TestAddContractListenerNameError(t *testing.T) {
mbi := cm.blockchain.(*blockchainmocks.Plugin)
mdi := cm.database.(*databasemocks.Plugin)

ffiID := fftypes.NewUUID()

sub := &core.ContractListenerInput{
ContractListener: core.ContractListener{
Name: "sub1",
Expand All @@ -1257,9 +1259,25 @@ func TestAddContractListenerNameError(t *testing.T) {
}.String()),
Topic: "test-topic",
},
EventPath: "changed",
Filters: core.ListenerFiltersInput{
&core.ListenerFilterInput{
ListenerFilter: core.ListenerFilter{
Interface: &fftypes.FFIReference{
ID: ffiID,
},
},
EventPath: "set",
},
},
}

mdi.On("GetFFIByID", context.Background(), "ns1", ffiID).Return(&fftypes.FFI{}, nil)
mdi.On("GetFFIEvent", context.Background(), "ns1", ffiID, "set").Return(&fftypes.FFIEvent{
FFIEventDefinition: fftypes.FFIEventDefinition{
Name: "eventName",
},
}, nil)
mbi.On("GenerateEventSignature", context.Background(), mock.Anything).Return("eventSignature")
mbi.On("NormalizeContractLocation", context.Background(), blockchain.NormalizeListener, sub.Location).Return(sub.Location, nil)
mdi.On("GetContractListener", context.Background(), "ns1", "sub1").Return(nil, fmt.Errorf("pop"))

Expand Down

0 comments on commit 7f233a0

Please sign in to comment.