2021-11-18 13:21:36 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/status-im/go-waku/waku/v2/node"
|
2021-12-08 08:52:27 +00:00
|
|
|
"github.com/status-im/go-waku/waku/v2/protocol/pb"
|
2021-11-18 13:21:36 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func makePrivateService(t *testing.T) *PrivateService {
|
|
|
|
n, err := node.New(context.Background(), node.WithWakuRelay())
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = n.Start()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
return &PrivateService{n}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetV1SymmetricKey(t *testing.T) {
|
|
|
|
d := makePrivateService(t)
|
|
|
|
defer d.node.Stop()
|
|
|
|
|
|
|
|
var reply SymmetricKeyReply
|
|
|
|
err := d.GetV1SymmetricKey(
|
|
|
|
makeRequest(t),
|
|
|
|
&Empty{},
|
|
|
|
&reply,
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, reply.Key)
|
|
|
|
}
|
|
|
|
|
2021-12-08 08:52:27 +00:00
|
|
|
func TestGetV1AsymmetricKey(t *testing.T) {
|
2021-11-18 13:21:36 +00:00
|
|
|
d := makePrivateService(t)
|
|
|
|
defer d.node.Stop()
|
|
|
|
|
|
|
|
var reply KeyPairReply
|
|
|
|
err := d.GetV1AsymmetricKeypair(
|
|
|
|
makeRequest(t),
|
|
|
|
&Empty{},
|
|
|
|
&reply,
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotEmpty(t, reply.PulicKey)
|
2021-12-08 08:52:27 +00:00
|
|
|
require.NotEmpty(t, reply.PrivateKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostV1SymmetricMessage(t *testing.T) {
|
|
|
|
d := makePrivateService(t)
|
|
|
|
defer d.node.Stop()
|
|
|
|
|
|
|
|
var reply SuccessReply
|
|
|
|
err := d.PostV1SymmetricMessage(
|
|
|
|
makeRequest(t),
|
|
|
|
&SymmetricMessageArgs{
|
|
|
|
Topic: "test",
|
|
|
|
Message: pb.WakuMessage{Payload: []byte("test")},
|
|
|
|
SymKey: "abc",
|
|
|
|
},
|
|
|
|
&reply,
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, reply.Success)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPostV1AsymmetricMessage(t *testing.T) {
|
|
|
|
d := makePrivateService(t)
|
|
|
|
defer d.node.Stop()
|
|
|
|
|
|
|
|
var reply SuccessReply
|
|
|
|
err := d.PostV1AsymmetricMessage(
|
|
|
|
makeRequest(t),
|
|
|
|
&AsymmetricMessageArgs{
|
|
|
|
Topic: "test",
|
|
|
|
Message: pb.WakuMessage{Payload: []byte("test")},
|
|
|
|
PublicKey: "045ded6a56c88173e87a88c55b96956964b1bd3351b5fcb70950a4902fbc1bc0ceabb0ac846c3a4b8f2f6024c0e19f0a7f6a4865035187de5463f34012304fc7c5",
|
|
|
|
},
|
|
|
|
&reply,
|
|
|
|
)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, reply.Success)
|
2021-11-18 13:21:36 +00:00
|
|
|
}
|