Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transaction/pool endpoint issues #6651

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
}
Loading