2021-11-09 14:15:45 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-02-17 15:00:46 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
2021-11-09 14:15:45 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2023-02-17 15:00:46 +00:00
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/pb"
|
2021-11-09 14:15:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func makeRequest(t *testing.T) *http.Request {
|
|
|
|
request, err := http.NewRequest(http.MethodPost, "url", bytes.NewReader([]byte("")))
|
|
|
|
require.NoError(t, err)
|
|
|
|
return request
|
|
|
|
}
|
2023-02-17 15:00:46 +00:00
|
|
|
|
|
|
|
func TestBase64Encoding(t *testing.T) {
|
|
|
|
input := "Hello World"
|
|
|
|
|
2023-11-07 19:48:43 +00:00
|
|
|
rpcMsg, err := ProtoToRPC(&pb.WakuMessage{
|
|
|
|
Payload: []byte(input),
|
|
|
|
ContentTopic: "test",
|
2023-02-17 15:00:46 +00:00
|
|
|
})
|
2023-11-07 19:48:43 +00:00
|
|
|
require.NoError(t, err)
|
2023-02-17 15:00:46 +00:00
|
|
|
|
|
|
|
jsonBytes, err := json.Marshal(rpcMsg)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
m := make(map[string]interface{})
|
|
|
|
err = json.Unmarshal(jsonBytes, &m)
|
|
|
|
require.NoError(t, err)
|
2023-02-23 13:15:05 +00:00
|
|
|
require.Equal(t, base64.StdEncoding.EncodeToString([]byte(input)), m["payload"])
|
2023-02-17 15:00:46 +00:00
|
|
|
|
2023-09-11 14:24:05 +00:00
|
|
|
decodedRPCMsg := new(RPCWakuMessage)
|
|
|
|
err = json.Unmarshal(jsonBytes, decodedRPCMsg)
|
2023-02-17 15:00:46 +00:00
|
|
|
require.NoError(t, err)
|
2023-09-11 14:24:05 +00:00
|
|
|
require.Equal(t, input, string(decodedRPCMsg.Payload))
|
2023-02-17 15:00:46 +00:00
|
|
|
}
|