Skip to content

Commit

Permalink
Merge pull request #1341 from kaleido-io/tx-op-status
Browse files Browse the repository at this point in the history
Automatically check operation status when querying pending transaction
  • Loading branch information
nguyer authored Jul 5, 2023
2 parents 9391be4 + eccb680 commit 816463c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/orchestrator/txn_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
29 changes: 29 additions & 0 deletions internal/orchestrator/txn_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -940,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")
}

0 comments on commit 816463c

Please # to comment.