Skip to content

Commit

Permalink
remove unnecessary err check for sdk functions never return err, test
Browse files Browse the repository at this point in the history
coverage

Signed-off-by: Xin Li <[email protected]>
  • Loading branch information
xin-hedera committed Jan 13, 2025
1 parent 21ac6aa commit 4dd73ad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
26 changes: 7 additions & 19 deletions hedera-mirror-rosetta/app/services/construction_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ func (c *constructionAPIService) getRandomNodeAccountId() (hiero.AccountID, *rTy
return hiero.AccountID{}, errors.ErrNodeAccountIdsEmpty
}

max := big.NewInt(int64(len(nodeAccountIds)))
index, err := rand.Int(rand.Reader, max)
maxValue := big.NewInt(int64(len(nodeAccountIds)))
index, err := rand.Int(rand.Reader, maxValue)
if err != nil {
log.Errorf("Failed to get a random number, use 0 instead: %s", err)
return nodeAccountIds[0], nil
Expand Down Expand Up @@ -712,20 +712,14 @@ func transactionSetMemo(memo interface{}) updater {
return errors.ErrInvalidTransactionMemo
}

if _, err := hiero.TransactionSetTransactionMemo(transaction, value); err != nil {
return errors.ErrInvalidTransactionMemo
}

hiero.TransactionSetTransactionMemo(transaction, value)
return nil
}
}

func transactionSetNodeAccountId(nodeAccountId hiero.AccountID) updater {
return func(transaction hiero.TransactionInterface) *rTypes.Error {
if _, err := hiero.TransactionSetNodeAccountIDs(transaction, []hiero.AccountID{nodeAccountId}); err != nil {
log.Errorf("Failed to set node account id for transaction: %s", err)
return errors.ErrInternalServerError
}
hiero.TransactionSetNodeAccountIDs(transaction, []hiero.AccountID{nodeAccountId})
return nil
}
}
Expand All @@ -738,10 +732,8 @@ func transactionSetTransactionId(payer hiero.AccountID, validStartNanos int64) u
} else {
transactionId = hiero.NewTransactionIDWithValidStart(payer, time.Unix(0, validStartNanos))
}
if _, err := hiero.TransactionSetTransactionID(transaction, transactionId); err != nil {
log.Errorf("Failed to set transaction id: %s", err)
return errors.ErrInternalServerError
}

hiero.TransactionSetTransactionID(transaction, transactionId)
return nil
}
}
Expand All @@ -753,11 +745,7 @@ func transactionSetValidDuration(validDurationSeconds int64) updater {
validDurationSeconds = defaultValidDurationSeconds
}

_, err := hiero.TransactionSetTransactionValidDuration(transaction, time.Second*time.Duration(validDurationSeconds))
if err != nil {
log.Errorf("Failed to set transaction valid duration: %s", err)
return errors.ErrInternalServerError
}
hiero.TransactionSetTransactionValidDuration(transaction, time.Second*time.Duration(validDurationSeconds))
return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/hex"
"fmt"
"github.com/hashgraph/hedera-mirror-node/hedera-mirror-rosetta/app/interfaces"
"github.com/hashgraph/hedera-mirror-node/hedera-mirror-rosetta/app/services/construction"
"math/rand"
"reflect"
"strconv"
Expand Down Expand Up @@ -1133,20 +1134,22 @@ func TestConstructionPayloadsInvalidRequest(t *testing.T) {
Currency: &rTypes.Currency{Symbol: "-100"},
}),
},
{
name: "InvalidMemoType",
customize: payloadsRequestMetadata(addMetadataNodeAccountId(metadata{types.MetadataKeyMemo: 100})),
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// given
mockConstructor := &mocks.MockTransactionConstructor{}
request := getPayloadsRequest(operations, tt.customize)
service, _ := NewConstructionAPIService(nil, onlineBaseService, defaultConfig, mockConstructor)
service, _ := NewConstructionAPIService(nil, onlineBaseService, defaultConfig, construction.NewTransactionConstructor())

// when
response, err := service.ConstructionPayloads(defaultContext, request)

// then
mockConstructor.AssertExpectations(t)
assert.NotNil(t, err)
assert.Nil(t, response)
})
Expand Down
Binary file added hedera-mirror-rosetta/hedera-mirror-rosetta
Binary file not shown.

0 comments on commit 4dd73ad

Please sign in to comment.