Skip to content

Commit

Permalink
Merge pull request #5618 from multiversx/adjust-account-not-found-err…
Browse files Browse the repository at this point in the history
…-tx-api

adjust `account not found` error when sending a transaction
  • Loading branch information
iulianpascalau authored Oct 10, 2023
2 parents b0a361f + 54928b1 commit 30f0fa2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ func TestNode_SendTransactionFromAnUnmintedAccountShouldReturnErrorAtApiLevel(t
tx.Signature, _ = node.OwnAccount.SingleSigner.Sign(node.OwnAccount.SkTxSign, txBuff)

err := node.Node.ValidateTransaction(tx)
assert.True(t, errors.Is(err, process.ErrAccountNotFound))
assert.True(t, errors.Is(err, process.ErrInsufficientFunds))
}
13 changes: 11 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ var log = logger.GetOrCreate("node")
var _ facade.NodeHandler = (*Node)(nil)

// Option represents a functional configuration parameter that can operate
// over the None struct.
//
// over the None struct.
type Option func(*Node) error

type filter interface {
Expand Down Expand Up @@ -705,7 +706,15 @@ func (n *Node) ValidateTransaction(tx *transaction.Transaction) error {
return err
}

return txValidator.CheckTxValidity(intTx)
err = txValidator.CheckTxValidity(intTx)
if errors.Is(err, process.ErrAccountNotFound) {
return fmt.Errorf("%w for address %s",
process.ErrInsufficientFunds,
n.coreComponents.AddressPubKeyConverter().SilentEncode(tx.SndAddr, log),
)
}

return err
}

// ValidateTransactionForSimulation will validate a transaction for use in transaction simulation process
Expand Down
22 changes: 22 additions & 0 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,28 @@ func TestCreateTransaction_TxSignedWithHashNoEnabledShouldErr(t *testing.T) {
assert.Equal(t, process.ErrTransactionSignedWithHashIsNotEnabled, err)
}

func TestValidateTransaction_ShouldAdaptAccountNotFoundError(t *testing.T) {
t.Parallel()

n, _ := node.NewNode(
node.WithCoreComponents(getDefaultCoreComponents()),
node.WithBootstrapComponents(getDefaultBootstrapComponents()),
node.WithProcessComponents(getDefaultProcessComponents()),
node.WithStateComponents(getDefaultStateComponents()),
node.WithCryptoComponents(getDefaultCryptoComponents()),
)

tx := &transaction.Transaction{
SndAddr: bytes.Repeat([]byte("1"), 32),
RcvAddr: bytes.Repeat([]byte("1"), 32),
Value: big.NewInt(37),
Signature: []byte("signature"),
ChainID: []byte("chainID"),
}
err := n.ValidateTransaction(tx)
require.Equal(t, "insufficient funds for address erd1xycnzvf3xycnzvf3xycnzvf3xycnzvf3xycnzvf3xycnzvf3xycspcqad6", err.Error())
}

func TestCreateShardedStores_NilShardCoordinatorShouldError(t *testing.T) {
messenger := getMessenger()
dataPool := dataRetrieverMock.NewPoolsHolderStub()
Expand Down

0 comments on commit 30f0fa2

Please sign in to comment.