2023-10-24 16:26:02 +00:00
|
|
|
package pb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateRequest(t *testing.T) {
|
2023-11-07 19:48:43 +00:00
|
|
|
request := PushRpc{}
|
2023-10-24 16:26:02 +00:00
|
|
|
require.ErrorIs(t, request.ValidateRequest(), errMissingRequestID)
|
|
|
|
request.RequestId = "test"
|
|
|
|
require.ErrorIs(t, request.ValidateRequest(), errMissingQuery)
|
2023-11-07 19:48:43 +00:00
|
|
|
request.Request = &PushRequest{}
|
2023-10-24 16:26:02 +00:00
|
|
|
require.ErrorIs(t, request.ValidateRequest(), errMissingPubsubTopic)
|
2023-11-07 19:48:43 +00:00
|
|
|
request.Request.PubsubTopic = "test"
|
2023-10-24 16:26:02 +00:00
|
|
|
require.ErrorIs(t, request.ValidateRequest(), errMissingMessage)
|
2023-11-07 19:48:43 +00:00
|
|
|
request.Request.Message = &pb.WakuMessage{
|
2023-10-24 16:26:02 +00:00
|
|
|
Payload: []byte{1, 2, 3},
|
|
|
|
ContentTopic: "test",
|
|
|
|
}
|
|
|
|
require.NoError(t, request.ValidateRequest())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateResponse(t *testing.T) {
|
2023-11-07 19:48:43 +00:00
|
|
|
response := PushRpc{}
|
2023-10-24 16:26:02 +00:00
|
|
|
require.ErrorIs(t, response.ValidateResponse("test"), errMissingRequestID)
|
|
|
|
response.RequestId = "test1"
|
|
|
|
require.ErrorIs(t, response.ValidateResponse("test"), errRequestIDMismatch)
|
|
|
|
response.RequestId = "test"
|
|
|
|
require.ErrorIs(t, response.ValidateResponse("test"), errMissingResponse)
|
|
|
|
response.Response = &PushResponse{}
|
|
|
|
require.NoError(t, response.ValidateResponse("test"))
|
|
|
|
}
|