diff --git a/dev/generate b/dev/generate index 9290934f..e82af341 100755 --- a/dev/generate +++ b/dev/generate @@ -3,6 +3,7 @@ set -e go generate ./... +# Generate mocks mockery rm -rf pkg/proto/**/*.pb.go pkg/proto/**/*.pb.gw.go pkg/proto/**/*.swagger.json if ! buf generate https://github.com/xmtp/proto.git#branch=main,subdir=proto; then diff --git a/pkg/mls/store/store.go b/pkg/mls/store/store.go index 59cf8f6e..2eda3cc6 100644 --- a/pkg/mls/store/store.go +++ b/pkg/mls/store/store.go @@ -128,7 +128,7 @@ func (s *Store) PublishIdentityUpdate(ctx context.Context, req *identity.Publish return errors.New("inbox log is full") } - updates := make([]*associations.IdentityUpdate, 0, len(inboxLogEntries)+1) + updates := make([]*associations.IdentityUpdate, 0, len(inboxLogEntries)) for _, log := range inboxLogEntries { identityUpdate := &associations.IdentityUpdate{} if err := proto.Unmarshal(log.IdentityUpdateProto, identityUpdate); err != nil { diff --git a/pkg/mls/store/store_test.go b/pkg/mls/store/store_test.go index 723d1277..e48fbc90 100644 --- a/pkg/mls/store/store_test.go +++ b/pkg/mls/store/store_test.go @@ -18,6 +18,7 @@ import ( "github.com/xmtp/xmtp-node-go/pkg/proto/identity/associations" mlsv1 "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1" test "github.com/xmtp/xmtp-node-go/pkg/testing" + testutils "github.com/xmtp/xmtp-node-go/pkg/testing" "github.com/xmtp/xmtp-node-go/pkg/utils" ) @@ -44,7 +45,7 @@ func TestPublishIdentityUpdateParallel(t *testing.T) { // Create a mapping of inboxes to addresses inboxes := make(map[string]string) for i := 0; i < 50; i++ { - inboxes[utils.HexEncode([]byte(fmt.Sprintf("inbox_%d", i)))] = fmt.Sprintf("address_%d", i) + inboxes[testutils.RandomInboxId()] = fmt.Sprintf("address_%d", i) } mockMlsValidation := mocks.NewMockMLSValidationService(t) diff --git a/pkg/mlsvalidate/mocks/mock.gen.go b/pkg/mlsvalidate/mocks/mock.gen.go new file mode 100644 index 00000000..fef93f1f --- /dev/null +++ b/pkg/mlsvalidate/mocks/mock.gen.go @@ -0,0 +1,142 @@ +// Code generated by MockGen. DO NOT EDIT. +// Source: ./pkg/mlsvalidate/service.go +// +// Generated by this command: +// +// mockgen -package mocks -source ./pkg/mlsvalidate/service.go MLSValidationService +// + +// Package mocks is a generated GoMock package. +package mocks + +import ( + context "context" + reflect "reflect" + + mlsvalidate "github.com/xmtp/xmtp-node-go/pkg/mlsvalidate" + apiv1 "github.com/xmtp/xmtp-node-go/pkg/proto/identity/api/v1" + associations "github.com/xmtp/xmtp-node-go/pkg/proto/identity/associations" + apiv10 "github.com/xmtp/xmtp-node-go/pkg/proto/mls/api/v1" + gomock "go.uber.org/mock/gomock" +) + +// MockMLSValidationService is a mock of MLSValidationService interface. +type MockMLSValidationService struct { + ctrl *gomock.Controller + recorder *MockMLSValidationServiceMockRecorder +} + +// MockMLSValidationServiceMockRecorder is the mock recorder for MockMLSValidationService. +type MockMLSValidationServiceMockRecorder struct { + mock *MockMLSValidationService +} + +// NewMockMLSValidationService creates a new mock instance. +func NewMockMLSValidationService(ctrl *gomock.Controller) *MockMLSValidationService { + mock := &MockMLSValidationService{ctrl: ctrl} + mock.recorder = &MockMLSValidationServiceMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockMLSValidationService) EXPECT() *MockMLSValidationServiceMockRecorder { + return m.recorder +} + +// GetAssociationState mocks base method. +func (m *MockMLSValidationService) GetAssociationState(ctx context.Context, oldUpdates, newUpdates []*associations.IdentityUpdate) (*mlsvalidate.AssociationStateResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetAssociationState", ctx, oldUpdates, newUpdates) + ret0, _ := ret[0].(*mlsvalidate.AssociationStateResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetAssociationState indicates an expected call of GetAssociationState. +func (mr *MockMLSValidationServiceMockRecorder) GetAssociationState(ctx, oldUpdates, newUpdates any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAssociationState", reflect.TypeOf((*MockMLSValidationService)(nil).GetAssociationState), ctx, oldUpdates, newUpdates) +} + +// ValidateGroupMessages mocks base method. +func (m *MockMLSValidationService) ValidateGroupMessages(ctx context.Context, groupMessages []*apiv10.GroupMessageInput) ([]mlsvalidate.GroupMessageValidationResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateGroupMessages", ctx, groupMessages) + ret0, _ := ret[0].([]mlsvalidate.GroupMessageValidationResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidateGroupMessages indicates an expected call of ValidateGroupMessages. +func (mr *MockMLSValidationServiceMockRecorder) ValidateGroupMessages(ctx, groupMessages any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateGroupMessages", reflect.TypeOf((*MockMLSValidationService)(nil).ValidateGroupMessages), ctx, groupMessages) +} + +// ValidateInboxIdKeyPackages mocks base method. +func (m *MockMLSValidationService) ValidateInboxIdKeyPackages(ctx context.Context, keyPackages [][]byte) ([]mlsvalidate.InboxIdValidationResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateInboxIdKeyPackages", ctx, keyPackages) + ret0, _ := ret[0].([]mlsvalidate.InboxIdValidationResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidateInboxIdKeyPackages indicates an expected call of ValidateInboxIdKeyPackages. +func (mr *MockMLSValidationServiceMockRecorder) ValidateInboxIdKeyPackages(ctx, keyPackages any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateInboxIdKeyPackages", reflect.TypeOf((*MockMLSValidationService)(nil).ValidateInboxIdKeyPackages), ctx, keyPackages) +} + +// ValidateV3KeyPackages mocks base method. +func (m *MockMLSValidationService) ValidateV3KeyPackages(ctx context.Context, keyPackages [][]byte) ([]mlsvalidate.IdentityValidationResult, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ValidateV3KeyPackages", ctx, keyPackages) + ret0, _ := ret[0].([]mlsvalidate.IdentityValidationResult) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// ValidateV3KeyPackages indicates an expected call of ValidateV3KeyPackages. +func (mr *MockMLSValidationServiceMockRecorder) ValidateV3KeyPackages(ctx, keyPackages any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidateV3KeyPackages", reflect.TypeOf((*MockMLSValidationService)(nil).ValidateV3KeyPackages), ctx, keyPackages) +} + +// MockIdentityStore is a mock of IdentityStore interface. +type MockIdentityStore struct { + ctrl *gomock.Controller + recorder *MockIdentityStoreMockRecorder +} + +// MockIdentityStoreMockRecorder is the mock recorder for MockIdentityStore. +type MockIdentityStoreMockRecorder struct { + mock *MockIdentityStore +} + +// NewMockIdentityStore creates a new mock instance. +func NewMockIdentityStore(ctrl *gomock.Controller) *MockIdentityStore { + mock := &MockIdentityStore{ctrl: ctrl} + mock.recorder = &MockIdentityStoreMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use. +func (m *MockIdentityStore) EXPECT() *MockIdentityStoreMockRecorder { + return m.recorder +} + +// GetInboxLogs mocks base method. +func (m *MockIdentityStore) GetInboxLogs(ctx context.Context, req *apiv1.GetIdentityUpdatesRequest) (*apiv1.GetIdentityUpdatesResponse, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetInboxLogs", ctx, req) + ret0, _ := ret[0].(*apiv1.GetIdentityUpdatesResponse) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetInboxLogs indicates an expected call of GetInboxLogs. +func (mr *MockIdentityStoreMockRecorder) GetInboxLogs(ctx, req any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInboxLogs", reflect.TypeOf((*MockIdentityStore)(nil).GetInboxLogs), ctx, req) +}