Fix failing test case

pull/459/head
Animesh Gaitonde 6 years ago committed by animeshg
parent 19aa386ae4
commit 76a8ef1560
  1. 2
      api/proto/identity/identity.go
  2. 13
      api/proto/identity/identity_test.go

@ -46,7 +46,7 @@ func GetIdentityMessageType(message []byte) (MessageType, error) {
if len(message) < 1 { if len(message) < 1 {
return 0, errors.New("failed to get identity message type: no data available") return 0, errors.New("failed to get identity message type: no data available")
} }
return MessageType(message[2]), nil return MessageType(message[0]), nil
} }
// GetIdentityMessagePayload message payload from the identity message // GetIdentityMessagePayload message payload from the identity message

@ -3,11 +3,14 @@ package identity
import ( import (
"strings" "strings"
"testing" "testing"
"github.com/harmony-one/harmony/api/proto"
) )
func TestRegisterIdentityMessage(t *testing.T) { func TestRegisterIdentityMessage(t *testing.T) {
registerIdentityMessage := ConstructIdentityMessage(Register, []byte("registerIdentityMessage")) registerIdentityMessage := ConstructIdentityMessage(Register, []byte("registerIdentityMessage"))
messageType, err := GetIdentityMessageType(registerIdentityMessage) msgPayload, err := proto.GetMessagePayload(registerIdentityMessage)
messageType, err := GetIdentityMessageType(msgPayload)
if err != nil { if err != nil {
t.Errorf("Error thrown in geting message type") t.Errorf("Error thrown in geting message type")
} }
@ -18,7 +21,8 @@ func TestRegisterIdentityMessage(t *testing.T) {
func TestAcknowledgeIdentityMessage(t *testing.T) { func TestAcknowledgeIdentityMessage(t *testing.T) {
registerAcknowledgeMessage := ConstructIdentityMessage(Acknowledge, []byte("acknowledgeIdentityMsgPayload")) registerAcknowledgeMessage := ConstructIdentityMessage(Acknowledge, []byte("acknowledgeIdentityMsgPayload"))
messageType, err := GetIdentityMessageType(registerAcknowledgeMessage) msgPayload, err := proto.GetMessagePayload(registerAcknowledgeMessage)
messageType, err := GetIdentityMessageType(msgPayload)
if err != nil { if err != nil {
t.Errorf("Error thrown in geting message type") t.Errorf("Error thrown in geting message type")
} }
@ -29,6 +33,11 @@ func TestAcknowledgeIdentityMessage(t *testing.T) {
func TestInvalidIdentityMessage(t *testing.T) { func TestInvalidIdentityMessage(t *testing.T) {
registerInvalidMessage := ConstructIdentityMessage(3, []byte("acknowledgeIdentityMsgPayload")) registerInvalidMessage := ConstructIdentityMessage(3, []byte("acknowledgeIdentityMsgPayload"))
registerInvalidMessagePayload, err := GetIdentityMessagePayload(registerInvalidMessage)
if err != nil {
t.Errorf("Error thrown in geting message type from invalid message")
}
_ = registerInvalidMessagePayload
messageType, err := GetIdentityMessageType(registerInvalidMessage) messageType, err := GetIdentityMessageType(registerInvalidMessage)
if err != nil { if err != nil {
t.Errorf("Error thrown in geting message type from invalid message") t.Errorf("Error thrown in geting message type from invalid message")

Loading…
Cancel
Save