Skip to content

Commit

Permalink
Only initializing if there's an error
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst committed Sep 28, 2023
1 parent 3f2a21f commit 9e32841
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions internal/assets/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/assets/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 9e32841

Please sign in to comment.