From 0f7542f7cb8a11af5e93a4a36cbf8f3540716241 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 13 Jun 2023 14:14:51 -0400 Subject: [PATCH 1/2] Automatically check operation status when querying pending transaction Signed-off-by: Nicko Guyer --- go.mod | 2 +- go.sum | 2 -- internal/orchestrator/txn_status.go | 9 +++++++++ internal/orchestrator/txn_status_test.go | 3 +++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index bc55f48ca1..96cb591829 100644 --- a/go.mod +++ b/go.mod @@ -85,4 +85,4 @@ require ( gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect -) \ No newline at end of file +) diff --git a/go.sum b/go.sum index 2303f73d79..8b2090be34 100644 --- a/go.sum +++ b/go.sum @@ -676,8 +676,6 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hyperledger/firefly-common v1.2.14 h1:HON9GJZXvrL0l2AG5DWHSGiBh05hElgFS5lm1OPR83M= -github.com/hyperledger/firefly-common v1.2.14/go.mod h1:17lOH4YufiPy82LpKm8fPa/YXJ0pUyq01zK1CmklJwM= github.com/hyperledger/firefly-common v1.2.15 h1:WdNB65IJvIyiOhVW3nxB3sQKqtJbdJ7ie0PJIM11CSU= github.com/hyperledger/firefly-common v1.2.15/go.mod h1:17lOH4YufiPy82LpKm8fPa/YXJ0pUyq01zK1CmklJwM= github.com/hyperledger/firefly-signer v1.1.8 h1:XyJjZXesih2dWYG31m5ZYt4irH7/PdkRutMPld7AqKE= diff --git a/internal/orchestrator/txn_status.go b/internal/orchestrator/txn_status.go index 2d0a30f3e7..e6503626f7 100644 --- a/internal/orchestrator/txn_status.go +++ b/internal/orchestrator/txn_status.go @@ -81,6 +81,15 @@ func (or *orchestrator) GetTransactionStatus(ctx context.Context, id string) (*c } for _, op := range ops { result.Details = append(result.Details, txOperationStatus(op)) + if op.Status == core.OpStatusPending { + // Check to see if there's an update + // Operations can stay in "Pending" if FireFly was down when a TX receipt became available + opWithDetail, err := or.GetOperationByIDWithStatus(ctx, op.ID.String()) + if err != nil { + return nil, err + } + op = &opWithDetail.Operation + } if op.Retry == nil { updateStatus(result, op.Status) } diff --git a/internal/orchestrator/txn_status_test.go b/internal/orchestrator/txn_status_test.go index b01e31fcd9..779a60daf3 100644 --- a/internal/orchestrator/txn_status_test.go +++ b/internal/orchestrator/txn_status_test.go @@ -650,6 +650,9 @@ func TestGetTransactionStatusTokenTransferRetry(t *testing.T) { or.mth.On("GetTransactionByIDCached", mock.Anything, txID).Return(tx, nil) or.mdi.On("GetOperations", mock.Anything, "ns", mock.Anything).Return(ops, nil, nil) + or.mom.On("GetOperationByIDCached", mock.Anything, op1ID).Return(ops[0], nil) + or.mom.On("GetOperationByIDCached", mock.Anything, op2ID).Return(ops[1], nil) + or.mbi.On("GetTransactionStatus", mock.Anything, mock.Anything).Return(nil, nil) or.mdi.On("GetBlockchainEvents", mock.Anything, "ns", mock.Anything).Return(events, nil, nil) or.mdi.On("GetTokenTransfers", mock.Anything, "ns", mock.Anything).Return(transfers, nil, nil) From d8a0b399367dd2be74f909701a3ada507eefc202 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Tue, 13 Jun 2023 14:33:29 -0400 Subject: [PATCH 2/2] Add error branch coverage Signed-off-by: Nicko Guyer --- internal/orchestrator/txn_status_test.go | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/orchestrator/txn_status_test.go b/internal/orchestrator/txn_status_test.go index 779a60daf3..8aedb21e57 100644 --- a/internal/orchestrator/txn_status_test.go +++ b/internal/orchestrator/txn_status_test.go @@ -943,3 +943,29 @@ func TestGetTransactionStatusUnknownType(t *testing.T) { or.mdi.AssertExpectations(t) } + +func TestGetTransactionStatusOpStatusError(t *testing.T) { + or := newTestOrchestrator() + + txID := fftypes.NewUUID() + tx := &core.Transaction{ + Namespace: "ns1", + Type: core.TransactionTypeTokenTransfer, + } + op1ID := fftypes.NewUUID() + ops := []*core.Operation{ + { + Namespace: "ns1", + Status: core.OpStatusPending, + ID: op1ID, + Type: core.OpTypeTokenTransfer, + }, + } + + or.mth.On("GetTransactionByIDCached", mock.Anything, txID).Return(tx, nil) + or.mdi.On("GetOperations", mock.Anything, "ns", mock.Anything).Return(ops, nil, nil) + or.mom.On("GetOperationByIDCached", mock.Anything, op1ID).Return(nil, fmt.Errorf("pop")) + + _, err := or.GetTransactionStatus(context.Background(), txID.String()) + assert.EqualError(t, err, "pop") +}