Skip to content

Commit

Permalink
Merge pull request #6651 from multiversx/mx-16113_fix_transaction_poo…
Browse files Browse the repository at this point in the history
…l_endpoint

Fix transaction/pool endpoint issues
  • Loading branch information
sstanculeanu authored Dec 6, 2024
2 parents 5656a3e + 9ac1370 commit 73c8af3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions node/external/transactionAPI/apiTransactionProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.Wrap
rcvUsernameField: wrappedTx.Tx.GetRcvUserName(),
dataField: wrappedTx.Tx.GetData(),
valueField: getTxValue(wrappedTx),
senderShardID: wrappedTx.SenderShardID,
receiverShardID: wrappedTx.ReceiverShardID,
senderShardID: atp.shardCoordinator.ComputeId(wrappedTx.Tx.GetSndAddr()),
receiverShardID: atp.shardCoordinator.ComputeId(wrappedTx.Tx.GetRcvAddr()),
}

guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler)
Expand Down
15 changes: 14 additions & 1 deletion node/external/transactionAPI/apiTransactionProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,9 @@ func TestApiTransactionProcessor_GetTransactionsPoolForSender(t *testing.T) {
NumberOfShardsCalled: func() uint32 {
return 1
},
ComputeIdCalled: func(address []byte) uint32 {
return 1 // force to return different from 0
},
}
atp, err := NewAPITransactionProcessor(args)
require.NoError(t, err)
Expand All @@ -945,7 +948,17 @@ func TestApiTransactionProcessor_GetTransactionsPoolForSender(t *testing.T) {
for i, tx := range res.Transactions {
require.Equal(t, expectedHashes[i], tx.TxFields[hashField])
require.Equal(t, expectedValues[i], tx.TxFields[valueField])
require.Equal(t, sender, tx.TxFields["sender"])
require.Equal(t, sender, tx.TxFields[senderField])
require.Equal(t, uint32(1), tx.TxFields[senderShardID])
require.Equal(t, uint32(1), tx.TxFields[senderShardID])
}

res, err = atp.GetTransactionsPoolForSender(sender, "sender,value") // no hash, should be by default
require.NoError(t, err)
for i, tx := range res.Transactions {
require.Equal(t, expectedHashes[i], tx.TxFields[hashField])
require.Equal(t, expectedValues[i], tx.TxFields[valueField])
require.Equal(t, sender, tx.TxFields[senderField])
}

// if no tx is found in pool for a sender, it isn't an error, but return empty slice
Expand Down
5 changes: 4 additions & 1 deletion node/external/transactionAPI/fieldsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ func newFieldsHandler(parameters string) fieldsHandler {
}

parameters = strings.ToLower(parameters)
fieldsMap := sliceToMap(strings.Split(parameters, separator))
fieldsMap[hashField] = struct{}{} // hashField should always be returned

return fieldsHandler{
fieldsMap: sliceToMap(strings.Split(parameters, separator)),
fieldsMap: fieldsMap,
}
}

Expand Down
2 changes: 2 additions & 0 deletions node/external/transactionAPI/fieldsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ func Test_newFieldsHandler(t *testing.T) {
for _, field := range splitFields {
require.True(t, fh.IsFieldSet(field), fmt.Sprintf("field %s is not set", field))
}
require.True(t, fh.IsFieldSet(hashField), "hashField should have been returned by default")

fh = newFieldsHandler("*")
for _, field := range splitFields {
require.True(t, fh.IsFieldSet(field))
}
require.True(t, fh.IsFieldSet(hashField), "hashField should have been returned by default")
}

0 comments on commit 73c8af3

Please sign in to comment.