From 7038fa9f79d46db1e5df5d31a74f7694e29793d0 Mon Sep 17 00:00:00 2001 From: Chengxuan Xing Date: Tue, 9 Jul 2024 11:53:11 +0100 Subject: [PATCH] update module manager function reference Signed-off-by: Chengxuan Xing --- pkg/fftm/manager_test.go | 35 ++++++++++++++++++++++++++++++ pkg/fftm/route__root_command.go | 4 ++-- pkg/fftm/transaction_management.go | 6 ++--- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/pkg/fftm/manager_test.go b/pkg/fftm/manager_test.go index b7ab9bb..79886d2 100644 --- a/pkg/fftm/manager_test.go +++ b/pkg/fftm/manager_test.go @@ -31,6 +31,7 @@ import ( "github.com/hyperledger/firefly-transaction-manager/internal/tmconfig" "github.com/hyperledger/firefly-transaction-manager/mocks/confirmationsmocks" "github.com/hyperledger/firefly-transaction-manager/mocks/ffcapimocks" + "github.com/hyperledger/firefly-transaction-manager/mocks/fftmmocks" "github.com/hyperledger/firefly-transaction-manager/mocks/persistencemocks" "github.com/hyperledger/firefly-transaction-manager/mocks/txhandlermocks" "github.com/hyperledger/firefly-transaction-manager/pkg/ffcapi" @@ -398,3 +399,37 @@ func TestPSQLInitRichQueryEnabled(t *testing.T) { assert.True(t, m.richQueryEnabled) assert.NotNil(t, m.toolkit.RichQuery) } + +func TestModuleMode(t *testing.T) { + + _ = testManagerCommonInit(t, false) + + dir := t.TempDir() + config.Set(tmconfig.PersistenceLevelDBPath, dir) + + m := newManager(context.Background(), &ffcapimocks.API{}, &fftmmocks.ModuleFunctions{}) + mpm := &persistencemocks.Persistence{} + mpm.On("Close", mock.Anything).Return(nil) + mpm.On("ListStreamsByCreateTime", mock.Anything, mock.Anything, startupPaginationLimit, txhandler.SortDirectionAscending).Return(nil, nil) + mrq := &persistencemocks.RichQuery{} + mpm.On("RichQuery").Return(mrq) + m.persistence = mpm + m.richQueryEnabled = true + mcm := &confirmationsmocks.Manager{} + m.confirmations = mcm + mcm.On("Start").Return().Maybe() + mca := m.connector.(*ffcapimocks.API) + mca.On("NewBlockListener", mock.Anything, mock.Anything).Return(nil, ffcapi.ErrorReason(""), nil).Maybe() + + err := m.initPersistence(context.Background()) + assert.NoError(t, err) + + err = m.initServices(context.Background()) + assert.NoError(t, err) + assert.Nil(t, m.apiServer) + assert.Nil(t, m.metricsServer) + assert.Nil(t, m.wsServer) + + err = m.Start() + assert.NoError(t, err) +} diff --git a/pkg/fftm/route__root_command.go b/pkg/fftm/route__root_command.go index df94dd9..e8bb29a 100644 --- a/pkg/fftm/route__root_command.go +++ b/pkg/fftm/route__root_command.go @@ -83,7 +83,7 @@ var postRootCommand = func(m *manager) *ffapi.Route { if err = baseReq.UnmarshalTo(&tReq); err != nil { return nil, true /* reject */, i18n.NewError(r.Req.Context(), tmmsgs.MsgInvalidRequestErr, baseReq.Headers.Type, err) } - return m.txHandler.HandleNewTransaction(r.Req.Context(), &tReq) + return m.HandleNewTransaction(r.Req.Context(), &tReq) }), nil case apitypes.RequestTypeDeploy: // We have to supply an extra submissionRejected boolean on submission errors @@ -92,7 +92,7 @@ var postRootCommand = func(m *manager) *ffapi.Route { if err = baseReq.UnmarshalTo(&tReq); err != nil { return nil, true /* reject */, i18n.NewError(r.Req.Context(), tmmsgs.MsgInvalidRequestErr, baseReq.Headers.Type, err) } - return m.txHandler.HandleNewContractDeployment(r.Req.Context(), &tReq) + return m.HandleNewContractDeployment(r.Req.Context(), &tReq) }), nil case apitypes.RequestTypeQuery: var tReq apitypes.QueryRequest diff --git a/pkg/fftm/transaction_management.go b/pkg/fftm/transaction_management.go index 4dcaa0a..2588a89 100644 --- a/pkg/fftm/transaction_management.go +++ b/pkg/fftm/transaction_management.go @@ -87,7 +87,7 @@ func (m *manager) getTransactions(ctx context.Context, afterStr, limitStr, signe func (m *manager) requestTransactionDeletion(ctx context.Context, txID string) (status int, transaction *apitypes.ManagedTX, err error) { - canceledTx, err := m.txHandler.HandleCancelTransaction(ctx, txID) + canceledTx, err := m.HandleCancelTransaction(ctx, txID) if err != nil { return http.StatusInternalServerError, nil, err @@ -99,7 +99,7 @@ func (m *manager) requestTransactionDeletion(ctx context.Context, txID string) ( func (m *manager) requestTransactionSuspend(ctx context.Context, txID string) (status int, transaction *apitypes.ManagedTX, err error) { - canceledTx, err := m.txHandler.HandleSuspendTransaction(ctx, txID) + canceledTx, err := m.HandleSuspendTransaction(ctx, txID) if err != nil { return http.StatusInternalServerError, nil, err @@ -111,7 +111,7 @@ func (m *manager) requestTransactionSuspend(ctx context.Context, txID string) (s func (m *manager) requestTransactionResume(ctx context.Context, txID string) (status int, transaction *apitypes.ManagedTX, err error) { - canceledTx, err := m.txHandler.HandleResumeTransaction(ctx, txID) + canceledTx, err := m.HandleResumeTransaction(ctx, txID) if err != nil { return http.StatusInternalServerError, nil, err