Skip to content

Commit c8f72a3

Browse files
committed
refactoring and tests
1 parent 3ad2370 commit c8f72a3

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

server/services/blockService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (service *blockService) convertToRosettaBlock(block *api.Block) (*types.Blo
220220
Block: &types.Block{
221221
BlockIdentifier: blockToIdentifier(block),
222222
ParentBlockIdentifier: parentBlockIdentifier,
223-
Timestamp: getTimestamp(block.Timestamp, block.TimestampMs),
223+
Timestamp: getTimestampInMS(block.Timestamp, block.TimestampMs),
224224
Transactions: transactions,
225225
Metadata: objectsMap{
226226
"shard": block.Shard,

server/services/converters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ func timestampInMilliseconds(timestamp int64) int64 {
7272
return timestamp * 1000
7373
}
7474

75-
func getTimestamp(timestamp int64, timestampMS int64) int64 {
75+
func getTimestampInMS(timestampSec int64, timestampMS int64) int64 {
7676
if timestampMS > 0 {
7777
return timestampMS
7878
}
79-
return timestampInMilliseconds(timestamp)
79+
return timestampInMilliseconds(timestampSec)
8080
}
8181

8282
func stringToHex(value string) string {

server/services/converters_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ func TestHexToAmount(t *testing.T) {
6464
require.Nil(t, err)
6565
require.Equal(t, "100", amount)
6666
}
67+
68+
func TestGetTimestamp(t *testing.T) {
69+
70+
require.Equal(t, int64(0), getTimestampInMS(0, 0))
71+
require.Equal(t, int64(500000), getTimestampInMS(500, 0))
72+
require.Equal(t, int64(500200), getTimestampInMS(500, 500200))
73+
}

server/services/networkService.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (service *networkService) NetworkStatus(
5656

5757
networkStatusResponse := &types.NetworkStatusResponse{
5858
CurrentBlockIdentifier: blockSummaryToIdentifier(&nodeStatus.LatestBlock),
59-
CurrentBlockTimestamp: getTimestamp(nodeStatus.LatestBlock.Timestamp, nodeStatus.LatestBlock.TimestampMs),
59+
CurrentBlockTimestamp: getTimestampInMS(nodeStatus.LatestBlock.Timestamp, nodeStatus.LatestBlock.TimestampMs),
6060
GenesisBlockIdentifier: service.extension.getGenesisBlockIdentifier(),
6161
OldestBlockIdentifier: blockSummaryToIdentifier(&nodeStatus.OldestBlockWithHistoricalState),
6262
SyncStatus: &types.SyncStatus{

0 commit comments

Comments
 (0)