2019-11-21 16:19:22 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-11-23 17:57:05 +00:00
|
|
|
"github.com/status-im/status-go/eth-node/crypto"
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
2019-11-21 16:19:22 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMessageID(t *testing.T) {
|
|
|
|
key, err := crypto.GenerateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
keyBytes := crypto.FromECDSAPub(&key.PublicKey)
|
|
|
|
|
|
|
|
data := []byte("test")
|
2019-11-23 17:57:05 +00:00
|
|
|
expectedID := types.HexBytes(crypto.Keccak256(append(keyBytes, data...)))
|
2019-11-21 16:19:22 +00:00
|
|
|
require.Equal(t, expectedID, MessageID(&key.PublicKey, data))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTimestampInMs(t *testing.T) {
|
|
|
|
ts := TimestampInMs(1555274502548) // random timestamp in milliseconds
|
|
|
|
tt := ts.Time()
|
|
|
|
require.Equal(t, tt.UnixNano(), 1555274502548*int64(time.Millisecond))
|
|
|
|
require.Equal(t, ts, TimestampInMsFromTime(tt))
|
|
|
|
}
|