-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suspend/resume transaction actions to FFTM and simple policy engine
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
- Loading branch information
1 parent
8c9b33b
commit 581fe26
Showing
12 changed files
with
413 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © 2023 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fftm | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/hyperledger/firefly-common/pkg/ffapi" | ||
"github.com/hyperledger/firefly-transaction-manager/internal/tmmsgs" | ||
"github.com/hyperledger/firefly-transaction-manager/pkg/apitypes" | ||
) | ||
|
||
var postTransactionResume = func(m *manager) *ffapi.Route { | ||
return &ffapi.Route{ | ||
Name: "postTransactionResume", | ||
Path: "/transactions/{transactionId}/resume", | ||
Method: http.MethodPost, | ||
PathParams: []*ffapi.PathParam{ | ||
{Name: "transactionId", Description: tmmsgs.APIParamTransactionID}, | ||
}, | ||
QueryParams: nil, | ||
Description: tmmsgs.APIEndpointPostTransactionResume, | ||
JSONInputValue: func() interface{} { return &struct{}{} }, | ||
JSONOutputValue: func() interface{} { return &apitypes.ManagedTX{} }, | ||
JSONOutputCodes: []int{http.StatusOK, http.StatusAccepted}, | ||
JSONHandler: func(r *ffapi.APIRequest) (output interface{}, err error) { | ||
r.SuccessStatus, output, err = m.requestTransactionResume(r.Req.Context(), r.PP["transactionId"]) | ||
return output, err | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright © 2022 Kaleido, Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fftm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/go-resty/resty/v2" | ||
"github.com/hyperledger/firefly-transaction-manager/mocks/txhandlermocks" | ||
"github.com/hyperledger/firefly-transaction-manager/pkg/apitypes" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestPostTransactionResume(t *testing.T) { | ||
|
||
url, m, done := newTestManager(t) | ||
defer done() | ||
tx := newTestTxn(t, m, "0x0aaaaa", 10001, apitypes.TxStatusSucceeded) | ||
txID := tx.ID | ||
|
||
err := m.Start() | ||
assert.NoError(t, err) | ||
|
||
var txOut *apitypes.ManagedTX | ||
res, err := resty.New().R(). | ||
SetResult(&txOut). | ||
SetBody(struct{}{}). | ||
Post(fmt.Sprintf("%s/transactions/%s/resume", url, txID)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 202, res.StatusCode()) | ||
assert.Equal(t, txID, txOut.ID) | ||
} | ||
|
||
func TestPostTransactionResumeFailed(t *testing.T) { | ||
url, m, done := newTestManager(t) | ||
defer done() | ||
|
||
err := m.Start() | ||
assert.NoError(t, err) | ||
mth := txhandlermocks.TransactionHandler{} | ||
mth.On("HandleResumeTransaction", mock.Anything, "1234").Return(nil, fmt.Errorf("error")).Once() | ||
m.txHandler = &mth | ||
|
||
var txOut *apitypes.ManagedTX | ||
res, err := resty.New().R(). | ||
SetResult(&txOut). | ||
SetBody(struct{}{}). | ||
Post(fmt.Sprintf("%s/transactions/%s/resume", url, "1234")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 500, res.StatusCode()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.