-
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.
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
- Loading branch information
1 parent
ec94e7b
commit 8c9b33b
Showing
8 changed files
with
218 additions
and
13 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
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 postTransactionSuspend = func(m *manager) *ffapi.Route { | ||
return &ffapi.Route{ | ||
Name: "postTransactionSuspend", | ||
Path: "/transactions/{transactionId}", | ||
Method: http.MethodDelete, | ||
PathParams: []*ffapi.PathParam{ | ||
{Name: "transactionId", Description: tmmsgs.APIParamTransactionID}, | ||
}, | ||
QueryParams: nil, | ||
Description: tmmsgs.APIEndpointPostTransactionSuspend, | ||
JSONInputValue: nil, | ||
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.requestTransactionDeletion(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 TestPostTransactionSuspend(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 | ||
emptyInput := map[string]interface{}{} | ||
res, err := resty.New().R(). | ||
SetResult(&txOut). | ||
Body(emptyInput). | ||
Post(fmt.Sprintf("%s/transactions/%s/suspend", url, txID)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 202, res.StatusCode()) | ||
assert.Equal(t, txID, txOut.ID) | ||
} | ||
|
||
func TestPostTransactionSuspendFailed(t *testing.T) { | ||
url, m, done := newTestManager(t) | ||
defer done() | ||
|
||
err := m.Start() | ||
assert.NoError(t, err) | ||
mth := txhandlermocks.TransactionHandler{} | ||
mth.On("HandleCancelTransaction", mock.Anything, "1234").Return(nil, fmt.Errorf("error")).Once() | ||
m.txHandler = &mth | ||
|
||
var txOut *apitypes.ManagedTX | ||
res, err := resty.New().R(). | ||
SetResult(&txOut). | ||
Delete(fmt.Sprintf("%s/transactions/%s", 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