go-waku/waku/v2/rpc/util_test.go

40 lines
911 B
Go
Raw Normal View History

package rpc
import (
"bytes"
2023-02-17 15:00:46 +00:00
"encoding/base64"
"encoding/json"
"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"
)
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"
rpcMsg := ProtoToRPC(&pb.WakuMessage{
Payload: []byte(input),
})
jsonBytes, err := json.Marshal(rpcMsg)
require.NoError(t, err)
m := make(map[string]interface{})
err = json.Unmarshal(jsonBytes, &m)
require.NoError(t, err)
require.Equal(t, base64.URLEncoding.EncodeToString([]byte(input)), m["payload"])
decodedRpcMsg := new(RPCWakuMessage)
err = json.Unmarshal(jsonBytes, decodedRpcMsg)
require.NoError(t, err)
require.Equal(t, input, string(decodedRpcMsg.Payload))
}