diff --git a/internal/assets/operations.go b/internal/assets/operations.go index 9e79e2783..f16349180 100644 --- a/internal/assets/operations.go +++ b/internal/assets/operations.go @@ -24,6 +24,7 @@ import ( "github.com/hyperledger/firefly-common/pkg/i18n" "github.com/hyperledger/firefly-common/pkg/log" "github.com/hyperledger/firefly/internal/coremsgs" + "github.com/hyperledger/firefly/internal/operations" "github.com/hyperledger/firefly/internal/txcommon" "github.com/hyperledger/firefly/pkg/core" ) @@ -124,14 +125,15 @@ func (am *assetManager) RunOperation(ctx context.Context, op *core.PreparedOpera } switch data.Transfer.Type { case core.TokenTransferTypeMint: - return nil, core.OpPhaseInitializing, plugin.MintTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) + err = plugin.MintTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) case core.TokenTransferTypeTransfer: - return nil, core.OpPhaseInitializing, plugin.TransferTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) + err = plugin.TransferTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) case core.TokenTransferTypeBurn: - return nil, core.OpPhaseInitializing, plugin.BurnTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) + err = plugin.BurnTokens(ctx, op.NamespacedIDString(), data.Pool.Locator, data.Transfer, data.Pool.Methods) default: panic(fmt.Sprintf("unknown transfer type: %v", data.Transfer.Type)) } + return nil, operations.ErrTernary(err, core.OpPhaseInitializing, core.OpPhasePending), err case approvalData: plugin, err := am.selectTokenPlugin(ctx, data.Pool.Connector) diff --git a/internal/assets/operations_test.go b/internal/assets/operations_test.go index e261ecf08..f4c79bb4e 100644 --- a/internal/assets/operations_test.go +++ b/internal/assets/operations_test.go @@ -126,7 +126,7 @@ func TestPrepareAndRunTransfer(t *testing.T) { _, phase, err := am.RunOperation(context.Background(), po) - assert.Equal(t, core.OpPhaseInitializing, phase) + assert.Equal(t, core.OpPhasePending, phase) assert.NoError(t, err) mti.AssertExpectations(t) @@ -475,7 +475,7 @@ func TestRunOperationTransferMint(t *testing.T) { _, phase, err := am.RunOperation(context.Background(), opTransfer(op, pool, transfer)) - assert.Equal(t, core.OpPhaseInitializing, phase) + assert.Equal(t, core.OpPhasePending, phase) assert.NoError(t, err) mti.AssertExpectations(t) @@ -503,7 +503,7 @@ func TestRunOperationTransferMintWithInterface(t *testing.T) { _, phase, err := am.RunOperation(context.Background(), opTransfer(op, pool, transfer)) - assert.Equal(t, core.OpPhaseInitializing, phase) + assert.Equal(t, core.OpPhasePending, phase) assert.NoError(t, err) mti.AssertExpectations(t) @@ -530,7 +530,7 @@ func TestRunOperationTransferBurn(t *testing.T) { _, phase, err := am.RunOperation(context.Background(), opTransfer(op, pool, transfer)) - assert.Equal(t, core.OpPhaseInitializing, phase) + assert.Equal(t, core.OpPhasePending, phase) assert.NoError(t, err) mti.AssertExpectations(t) @@ -557,7 +557,7 @@ func TestRunOperationTransfer(t *testing.T) { _, phase, err := am.RunOperation(context.Background(), opTransfer(op, pool, transfer)) - assert.Equal(t, core.OpPhaseInitializing, phase) + assert.Equal(t, core.OpPhasePending, phase) assert.NoError(t, err) mti.AssertExpectations(t)